/* theme.css - design system + per-tab "ambiances". Loaded LAST, after every module stylesheet.

   TOKENS  public (used by all modules): --bg --card --text --muted --accent --accent-soft --border --done-bg --positive --loss
           extra: --edge (card hairline) --glow (neon halo, transparent outside Marches) --field (input fill) --nav-bg (tab bar glass)
                  --glow-a/--glow-b (page corner glows) --grid (neon grid) --hero-a/--hero-b (Finances hero) --shadow-card/--shadow-pop/--sheen (depth)
           colour tokens are registered with @property so they animate when the ambiance changes.
   SCALES  type --fs-2xs..--fs-hero (tabular numerals everywhere), spacing --sp-1..--sp-7, radii 18 / 12 / pill, motion --ease / --spring.
   AMBIANCES  <html data-ambiance="finances|analyse|marches|depenses|notes">, set by theme.js when a .tab-btn is tapped.
     finances deep emerald | analyse indigo-violet | depenses coral-amber | notes slate-sand  (all follow the system light/dark preference)
     marches  NEON: forced carbon black; neon accent follows the sub-tab (<html data-sub>: cyan, magenta, amber) and each asset has
              its own colour (BTC amber-orange, SOL violet-to-mint, NVDA lime, NBIS electric blue) on rows, badges and the detail screen.
   #gate, #loadingScreen and .auth-overlay always use the Finances brand palette. */

/* ---------- 1. Registered colour tokens (animatable) ---------- */
@property --bg { syntax: '<color>'; inherits: true; initial-value: #f2f6f3; }
@property --card { syntax: '<color>'; inherits: true; initial-value: #ffffff; }
@property --text { syntax: '<color>'; inherits: true; initial-value: #10201a; }
@property --muted { syntax: '<color>'; inherits: true; initial-value: #58695f; }
@property --accent { syntax: '<color>'; inherits: true; initial-value: #0b7550; }
@property --accent-soft { syntax: '<color>'; inherits: true; initial-value: rgba(11, 117, 80, .11); }
@property --border { syntax: '<color>'; inherits: true; initial-value: #dfe8e2; }
@property --done-bg { syntax: '<color>'; inherits: true; initial-value: #ebf1ed; }
@property --positive { syntax: '<color>'; inherits: true; initial-value: #157a38; }
@property --loss { syntax: '<color>'; inherits: true; initial-value: #c22b2b; }
@property --edge { syntax: '<color>'; inherits: true; initial-value: rgba(16, 40, 30, .08); }
@property --glow { syntax: '<color>'; inherits: true; initial-value: rgba(0, 0, 0, 0); }
@property --field { syntax: '<color>'; inherits: true; initial-value: #f5f8f6; }
@property --glow-a { syntax: '<color>'; inherits: true; initial-value: rgba(0, 0, 0, 0); }
@property --glow-b { syntax: '<color>'; inherits: true; initial-value: rgba(0, 0, 0, 0); }
@property --grid { syntax: '<color>'; inherits: true; initial-value: rgba(0, 0, 0, 0); }
@property --nav-bg { syntax: '<color>'; inherits: true; initial-value: rgba(255, 255, 255, .78); }

/* ---------- 2. Scales + scheme tokens ---------- */
:root {
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI Variable Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --fs-2xs: .68rem; --fs-xs: .75rem; --fs-sm: .85rem; --fs-md: .95rem; --fs-lg: 1.1rem; --fs-xl: 1.5rem;
  --fs-hero: clamp(2.3rem, 10.5vw, 3.1rem);
  --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px; --sp-5: 20px; --sp-6: 28px; --sp-7: 40px;
  --r-card: 18px; --r-inner: 12px; --r-hero: 26px; --r-pill: 999px;
  --ease: cubic-bezier(.22, .8, .24, 1); --spring: cubic-bezier(.34, 1.45, .5, 1);
  --hero-a: #0b6b4a; --hero-b: #05362c; --hero-shadow: rgba(5, 54, 44, .6);
  --shadow-card: 0 1px 2px rgba(16, 32, 24, .05), 0 10px 26px -14px rgba(16, 40, 30, .2);
  --shadow-pop: 0 28px 60px -22px rgba(16, 32, 24, .45), 0 4px 14px rgba(16, 32, 24, .08);
  --sheen: linear-gradient(180deg, rgba(255, 255, 255, 0), rgba(255, 255, 255, 0));
  --ring: 0 0 0 4px color-mix(in srgb, var(--accent) 22%, transparent);
  color-scheme: light dark;
  transition: --bg .5s ease, --card .5s ease, --text .5s ease, --muted .5s ease, --accent .5s ease, --accent-soft .5s ease,
    --border .5s ease, --done-bg .5s ease, --positive .5s ease, --loss .5s ease, --edge .5s ease, --glow .5s ease,
    --field .5s ease, --glow-a .6s ease, --glow-b .6s ease, --grid .6s ease, --nav-bg .5s ease;
}
:root[data-theme="light"] { color-scheme: light; }

/* FINANCES - emerald (default). The same values are the brand scope of the PIN gate, loader and login. */
:root, :root[data-ambiance="finances"], #gate, #loadingScreen, .auth-overlay {
  --bg: #f2f6f3; --card: #ffffff; --text: #10201a; --muted: #58695f; --accent: #0b7550; --accent-soft: rgba(11, 117, 80, .11);
  --border: #dfe8e2; --done-bg: #ebf1ed; --positive: #157a38; --loss: #c22b2b;
  --edge: rgba(16, 40, 30, .08); --field: #f5f8f6; --nav-bg: rgba(255, 255, 255, .78);
  --glow: rgba(0, 0, 0, 0); --glow-a: rgba(30, 175, 125, .2); --glow-b: rgba(110, 195, 255, .16); --grid: rgba(0, 0, 0, 0);
}
/* ANALYSE - indigo / violet */
:root[data-ambiance="analyse"] {
  --bg: #f3f3fb; --card: #ffffff; --text: #14132b; --muted: #5f5d7a; --accent: #5a3fd0; --accent-soft: rgba(90, 63, 208, .1);
  --border: #e2e0f1; --done-bg: #eceaf7; --positive: #157a38; --loss: #c22b3d;
  --edge: rgba(40, 25, 110, .09); --field: #f6f5fc; --nav-bg: rgba(255, 255, 255, .78);
  --glow-a: rgba(125, 92, 255, .22); --glow-b: rgba(80, 165, 255, .16);
}
/* DEPENSES - coral / amber */
:root[data-ambiance="depenses"] {
  --bg: #fbf4ef; --card: #ffffff; --text: #2a1810; --muted: #7a5f52; --accent: #b5410f; --accent-soft: rgba(181, 65, 15, .1);
  --border: #f0e1d6; --done-bg: #f6ebe3; --positive: #157a38; --loss: #c1213c;
  --edge: rgba(90, 35, 10, .09); --field: #fbf7f4; --nav-bg: rgba(255, 255, 255, .8);
  --glow-a: rgba(255, 140, 80, .26); --glow-b: rgba(255, 195, 90, .2);
}
/* NOTES - slate / sand */
:root[data-ambiance="notes"] {
  --bg: #f4f1ea; --card: #fffdf8; --text: #23262b; --muted: #66665f; --accent: #3f5a78; --accent-soft: rgba(63, 90, 120, .1);
  --border: #e6e1d5; --done-bg: #eeeae0; --positive: #126d36; --loss: #b83232;
  --edge: rgba(60, 45, 20, .1); --field: #f8f5ee; --nav-bg: rgba(255, 253, 248, .8);
  --glow-a: rgba(196, 165, 110, .28); --glow-b: rgba(110, 145, 185, .16);
}

/* dark scheme */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --hero-a: #16785a; --hero-b: #06302a; --hero-shadow: rgba(0, 0, 0, .75);
    --shadow-card: inset 0 1px 0 rgba(255, 255, 255, .06), 0 12px 30px -16px rgba(0, 0, 0, .75);
    --shadow-pop: 0 30px 70px -24px rgba(0, 0, 0, .9), 0 0 0 1px rgba(255, 255, 255, .07);
    --sheen: linear-gradient(180deg, rgba(255, 255, 255, .05), rgba(255, 255, 255, 0) 46%);
  }
  :root:not([data-theme="light"])[data-ambiance="finances"],
  :root:not([data-theme="light"]) :is(#gate, #loadingScreen, .auth-overlay) {
    --bg: #07100d; --card: #0e1915; --text: #e8f4ed; --muted: #8fa79b; --accent: #43d999; --accent-soft: rgba(67, 217, 153, .14);
    --border: rgba(255, 255, 255, .09); --done-bg: #16231e; --positive: #56e08a; --loss: #ff8078;
    --edge: rgba(255, 255, 255, .085); --field: rgba(255, 255, 255, .05); --nav-bg: rgba(14, 25, 21, .72);
    --glow-a: rgba(40, 200, 140, .26); --glow-b: rgba(60, 140, 255, .14);
  }
  :root:not([data-theme="light"])[data-ambiance="analyse"] {
    --bg: #0a0919; --card: #131230; --text: #ecebff; --muted: #9c9ac0; --accent: #a898ff; --accent-soft: rgba(168, 152, 255, .15);
    --border: rgba(200, 190, 255, .12); --done-bg: #1d1b40; --positive: #5be38e; --loss: #ff7c8f;
    --edge: rgba(200, 190, 255, .11); --field: rgba(255, 255, 255, .05); --nav-bg: rgba(19, 18, 48, .72);
    --glow-a: rgba(110, 80, 255, .32); --glow-b: rgba(60, 130, 255, .16);
  }
  :root:not([data-theme="light"])[data-ambiance="depenses"] {
    --bg: #150c08; --card: #21140e; --text: #fbeee6; --muted: #b79a8b; --accent: #ff9d6b; --accent-soft: rgba(255, 157, 107, .15);
    --border: rgba(255, 200, 170, .12); --done-bg: #2d1c14; --positive: #5be38e; --loss: #ff6e86;
    --edge: rgba(255, 200, 170, .11); --field: rgba(255, 255, 255, .05); --nav-bg: rgba(33, 20, 14, .72);
    --glow-a: rgba(255, 110, 50, .28); --glow-b: rgba(255, 180, 60, .15);
  }
  :root:not([data-theme="light"])[data-ambiance="notes"] {
    --bg: #0f1216; --card: #181c22; --text: #eae8e2; --muted: #9a9b95; --accent: #a3bcd8; --accent-soft: rgba(163, 188, 216, .14);
    --border: rgba(255, 255, 255, .09); --done-bg: #232830; --positive: #63dc8c; --loss: #ff8a80;
    --edge: rgba(255, 255, 255, .085); --field: rgba(255, 255, 255, .05); --nav-bg: rgba(24, 28, 34, .74);
    --glow-a: rgba(150, 170, 205, .18); --glow-b: rgba(205, 170, 120, .12);
  }
}

/* MARCHES - NEON carbon. Forced dark whatever the system says. --accent follows the sub-tab. */
:root[data-ambiance="marches"] {
  --bg: #05070c; --card: #0b0f18; --text: #e9f2ff; --muted: #93a1bd; --accent: #22e4ff;
  --accent-soft: color-mix(in srgb, var(--accent) 14%, transparent);
  --border: rgba(130, 160, 255, .16); --done-bg: #121826; --positive: #3dff9a; --loss: #ff5b86;
  --edge: color-mix(in srgb, var(--accent) 38%, transparent); --glow: color-mix(in srgb, var(--accent) 30%, transparent);
  --field: rgba(255, 255, 255, .05); --nav-bg: rgba(8, 11, 18, .74);
  --glow-a: color-mix(in srgb, var(--accent) 20%, transparent); --glow-b: rgba(255, 60, 200, .13); --grid: rgba(150, 175, 255, .035);
  --shadow-card: inset 0 1px 0 rgba(255, 255, 255, .06), 0 14px 34px -18px rgba(0, 0, 0, .9);
  --shadow-pop: 0 30px 70px -24px rgba(0, 0, 0, .95), 0 0 0 1px rgba(255, 255, 255, .07);
  --sheen: linear-gradient(180deg, rgba(255, 255, 255, .05), rgba(255, 255, 255, 0) 46%);
  color-scheme: dark;
}
:root[data-ambiance="marches"][data-sub="portefeuille"] { --accent: #ff5cf0; --glow-b: rgba(34, 228, 255, .12); }
:root[data-ambiance="marches"][data-sub="calculateur"] { --accent: #ffb627; --glow-b: rgba(120, 90, 255, .16); }

/* ---------- 3. Base ---------- */
html { -webkit-text-size-adjust: 100%; }
*::before, *::after { box-sizing: border-box; } /* "*" does not match pseudo-elements: without this the sliding pills drift by their border width */
body {
  font-family: var(--font); font-size: 16px; line-height: 1.4; font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; position: relative;
}
body::before { /* fixed ambient layer: corner glows + neon grid. Oversized 6%: the neon ambiance drifts this layer (transform only, cheap) with room to spare so no edge ever shows. */
  content: ""; position: fixed; inset: -6%; z-index: -1; pointer-events: none;
  background:
    radial-gradient(110% 55% at 100% -8%, var(--glow-a), transparent 62%),
    radial-gradient(90% 50% at -12% 4%, var(--glow-b), transparent 58%),
    linear-gradient(var(--grid) 1px, transparent 1px) 0 0 / 34px 34px,
    linear-gradient(90deg, var(--grid) 1px, transparent 1px) 0 0 / 34px 34px;
}
::selection { background: color-mix(in srgb, var(--accent) 30%, transparent); }
h1 { font-size: 1.3rem; font-weight: 750; letter-spacing: -.025em; line-height: 1.15; margin: 0; }
h2 { font-size: var(--fs-md); font-weight: 650; letter-spacing: -.01em; margin: 0 0 var(--sp-3); gap: 8px; }
:where(button, a, [tabindex], input, select, textarea):focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button { font-family: inherit; -webkit-tap-highlight-color: transparent; touch-action: manipulation;
  transition: transform .18s var(--ease), background-color .25s ease, color .25s ease, border-color .25s ease, box-shadow .25s ease, opacity .2s ease, filter .2s ease; }
button:disabled { cursor: not-allowed; opacity: .6; }
@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop { from { opacity: 0; transform: translateY(12px) scale(.96); } to { opacity: 1; transform: none; } }
@keyframes shimmer { to { transform: translateX(100%); } }
@keyframes pulse { 50% { opacity: .35; transform: scale(.8); } }
@keyframes spin { to { transform: rotate(360deg); } }
.ico { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; display: block; }

/* Surfaces: one recipe for every card */
.bank-section, .history-card, .category-card, .market-card, .composer, .pf-card, .calc-card, .exp-card {
  background: var(--sheen), var(--card); border: 1px solid var(--edge); border-radius: var(--r-card);
  box-shadow: var(--shadow-card), 0 0 28px -10px var(--glow); padding: 18px 16px; margin-bottom: 14px; color: var(--text);
  transition: box-shadow .3s ease, transform .3s var(--ease);
}
.history-card, .category-card { margin-bottom: 0; }
.note, .md-stat { background: var(--sheen), var(--card); border: 1px solid var(--edge); border-radius: 14px; box-shadow: var(--shadow-card); }
@media (hover: hover) { .bank-section:hover, .history-card:hover, .category-card:hover { transform: translateY(-1px); } }

/* Buttons */
.btn-primary, .calc-submit, .exp-submit, .auth-submit, .pf-btn-primary, .md-retry {
  /* accent -> slightly deeper accent: the label colour (--bg) keeps AA contrast over the whole gradient in every ambiance */
  background-image: linear-gradient(180deg, var(--accent), color-mix(in srgb, var(--accent) 86%, #000));
  box-shadow: 0 8px 18px -8px color-mix(in srgb, var(--accent) 70%, transparent), inset 0 1px 0 rgba(255, 255, 255, .28);
  font-weight: 650; border-radius: 14px; letter-spacing: -.005em;
}
.exp-card .exp-submit-confirm { background-image: none; box-shadow: none; }
.btn-primary, .btn-secondary { min-height: 44px; padding: 10px 18px; font-size: var(--fs-md); border-radius: 14px; }
.btn-secondary, .pf-btn-secondary { background: var(--done-bg); color: var(--muted); font-weight: 600; }
.icon-btn { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 14px; color: var(--text);
  background: var(--sheen), var(--card); border: 1px solid var(--edge); box-shadow: var(--shadow-card); }
:is(.btn-primary, .btn-secondary, .icon-btn, .fin-add, .calc-submit, .calc-chip, .exp-submit, .exp-period, .auth-submit, .pf-btn, .pf-add-btn, .md-range, .md-close, .subtab-btn, .tab-btn, .link-btn):active {
  transform: scale(.96); }
@media (hover: hover) {
  :is(.btn-primary, .calc-submit, .exp-submit, .auth-submit, .pf-btn-primary):hover { filter: brightness(1.06); }
  :is(.btn-secondary, .icon-btn, .pf-btn-secondary):hover { filter: brightness(.97); }
}
.link-btn { min-height: 40px; color: var(--muted); }
:is(.fin-actions button, .note-del, .exp-del):active { background: var(--done-bg); color: var(--text); transform: scale(.92); }
@media (hover: hover) {
  .tabs .tab-btn:not(.active):hover, .subtabs .subtab-btn:not(.active):hover, .exp-period[aria-pressed="false"]:hover, .link-btn:hover { color: var(--text); }
}

/* Form controls */
:is(.notes-toolbar input, .notes-toolbar select, .modal input, .modal select, .calc-field input, .calc-field select, .pf-input, .exp-field input, .exp-field select, .auth-input, textarea) {
  min-height: 44px; padding: 10px 12px; border-radius: var(--r-inner); border: 1px solid var(--edge); background-color: var(--field);
  color: var(--text); font-family: inherit; font-size: 16px; transition: border-color .2s ease, box-shadow .2s ease, background-color .2s ease;
}
:is(.notes-toolbar input, .notes-toolbar select, .modal input, .modal select, .calc-field input, .calc-field select, .pf-input, .exp-field input, .exp-field select, .auth-input, textarea):focus {
  outline: none; border-color: var(--accent); box-shadow: var(--ring);
}
:is(.modal input, .modal select, .calc-field input, .calc-field select, .pf-input, .exp-field input, .exp-field select, .notes-toolbar select):disabled { opacity: .55; }
::placeholder { color: var(--muted); opacity: .7; }
select:is(.modal *, .calc-field *, .pf-input, .exp-field *, .notes-toolbar *) {
  -webkit-appearance: none; appearance: none; padding-right: 34px; cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 19px) calc(50% + 1px), calc(100% - 14px) calc(50% + 1px); background-size: 5px 5px; background-repeat: no-repeat;
}
.modal label, .calc-field label, .exp-field label, .pf-field-label, .auth-label { font-weight: 550; letter-spacing: .005em; }

/* ---------- 4. Shell ---------- */
.wrap { max-width: 720px; padding: 16px max(16px, env(safe-area-inset-right)) calc(104px + env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left)); }
.app-header { align-items: center; margin-bottom: 16px; padding-top: 4px; }
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-mark { flex: none; width: 42px; height: 42px; border-radius: 14px; display: grid; place-items: center; font-size: 1.2rem; font-weight: 800; letter-spacing: -.03em;
  color: var(--bg); background: linear-gradient(145deg, color-mix(in srgb, var(--accent) 78%, #fff), color-mix(in srgb, var(--accent) 82%, #000));
  box-shadow: 0 8px 18px -8px color-mix(in srgb, var(--accent) 80%, transparent), 0 0 24px -6px var(--glow), inset 0 1px 0 rgba(255, 255, 255, .4); }
.app-header .sub { display: flex; align-items: center; gap: 6px; margin: 3px 0 0; font-size: var(--fs-xs); font-weight: 500; }
.app-header .sub::before, .live-dot { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--positive); flex: none;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--positive) 22%, transparent); animation: pulse 2.4s ease-in-out infinite; }
.live-dot { display: inline-block; margin-right: 2px; }

/* Bottom navigation: floating glass bar with a sliding active pill */
.tabs {
  position: fixed; z-index: 30; left: 50%; bottom: calc(10px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%);
  width: min(calc(100% - 24px), 460px); margin: 0; padding: 6px; gap: 0; display: grid; grid-template-columns: repeat(5, minmax(0, 1fr));
  background: var(--nav-bg); border: 1px solid var(--edge); border-radius: 26px;
  -webkit-backdrop-filter: blur(22px) saturate(1.8); backdrop-filter: blur(22px) saturate(1.8);
  box-shadow: var(--shadow-pop), 0 0 30px -12px var(--glow);
}
.tabs::before {
  content: ""; position: absolute; top: 6px; bottom: 6px; left: 6px; width: calc((100% - 12px) / 5); border-radius: 20px;
  background: var(--accent-soft); border: 1px solid color-mix(in srgb, var(--accent) 22%, transparent);
  box-shadow: 0 0 22px -6px var(--glow), inset 0 1px 0 rgba(255, 255, 255, .06);
  transform: translateX(calc(var(--tab-i, 0) * 100%)); transition: transform .5s var(--spring), background-color .5s ease, border-color .5s ease;
}
.tabs .tab-btn {
  position: relative; z-index: 1; min-width: 0; min-height: 54px; padding: 8px 0 7px; gap: 3px; border: none; border-radius: 20px;
  background: none; color: var(--muted); font-size: .66rem; font-weight: 600; letter-spacing: .005em;
}
.tabs .tab-btn.active { background: none; color: var(--accent); }
.tab-ico { display: block; line-height: 0; transition: transform .4s var(--spring); }
.tab-btn.active .tab-ico { transform: translateY(-1px) scale(1.06); }
.tab-label { display: block; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* transient save status becomes a toast above the bar */
.status:not(:empty) {
  position: fixed; z-index: 35; left: 50%; bottom: calc(92px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%);
  pointer-events: none; width: max-content; max-width: min(92vw, 420px); margin: 0; padding: 9px 16px; border-radius: var(--r-pill); font-size: var(--fs-xs); font-weight: 600; line-height: 1.3; color: var(--text);
  background: var(--nav-bg); border: 1px solid var(--edge); box-shadow: var(--shadow-pop);
  -webkit-backdrop-filter: blur(16px) saturate(1.6); backdrop-filter: blur(16px) saturate(1.6); animation: pop .3s var(--spring) both;
}
.footer-links { margin-top: 26px; display: flex; flex-wrap: wrap; justify-content: center; gap: 2px 8px; }

/* Entrance: panels stagger in when a tab opens (theme.js adds .enter), and once after unlock */
.panel.enter > *, .subpanel.active { animation: rise .5s var(--ease) both; }
.subpanel.active { animation-duration: .38s; }
.panel.enter > :nth-child(2) { animation-delay: .05s; } .panel.enter > :nth-child(3) { animation-delay: .1s; }
.panel.enter > :nth-child(4) { animation-delay: .15s; } .panel.enter > :nth-child(n+5) { animation-delay: .2s; }
.panel.enter #banksList { animation: none; }
.panel.enter #banksList .bank-section { animation: rise .5s var(--ease) both; }
.panel.enter #banksList .bank-section:nth-child(1) { animation-delay: .1s; } .panel.enter #banksList .bank-section:nth-child(2) { animation-delay: .16s; }
.panel.enter #banksList .bank-section:nth-child(3) { animation-delay: .22s; } .panel.enter #banksList .bank-section:nth-child(n+4) { animation-delay: .28s; }

/* ---------- 5. Finances ---------- */
.grand-total {
  position: relative; overflow: hidden; isolation: isolate; display: flex; flex-direction: column; text-align: left; color: #fff;
  padding: 22px 18px 18px; margin-bottom: 18px; border-radius: var(--r-hero); border: 1px solid rgba(255, 255, 255, .16);
  background: linear-gradient(140deg, var(--hero-a) 0%, var(--hero-b) 100%);
  box-shadow: 0 26px 44px -26px var(--hero-shadow), inset 0 1px 0 rgba(255, 255, 255, .25);
}
.grand-total::before { content: ""; position: absolute; z-index: -1; top: -55%; right: -25%; width: 80%; aspect-ratio: 1; border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 255, 255, .3), transparent 66%); }
.grand-total .label { font-size: var(--fs-xs); font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: rgba(255, 255, 255, .92); margin: 0; }
.grand-total .amount { font-size: var(--fs-hero); font-weight: 760; letter-spacing: -.04em; line-height: 1.08; color: #fff; margin: 6px 0 0; text-shadow: 0 2px 22px rgba(0, 0, 0, .18); overflow-wrap: anywhere; }
.sub-stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-top: 18px; padding: 0; border: none; }
.sub-stat { min-width: 0; padding: 10px 12px; border-radius: 16px; background: rgba(3, 26, 20, .3); border: 1px solid rgba(255, 255, 255, .16);
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px); }
.sub-stat .sub-amount { font-size: .98rem; font-weight: 700; letter-spacing: -.015em; color: #fff; white-space: nowrap; }
.sub-stat .sub-amount.positive { color: #8ff0bd; }
.sub-stat .sub-label { font-size: var(--fs-2xs); font-weight: 500; color: rgba(255, 255, 255, .9); margin-top: 3px; line-height: 1.25; }
.sub-stat:nth-child(3) { grid-column: 1 / -1; display: flex; flex-direction: row-reverse; justify-content: space-between; align-items: center; gap: 12px; }
.sub-stat:nth-child(3) .sub-label { margin: 0; font-size: var(--fs-xs); }
@media (min-width: 540px) { .sub-stats { grid-template-columns: repeat(3, minmax(0, 1fr)); } .sub-stat:nth-child(3) { grid-column: auto; display: block; } .sub-stat:nth-child(3) .sub-label { margin-top: 3px; font-size: var(--fs-2xs); } }

.bank-header { align-items: center; gap: 12px; margin-bottom: 4px; }
.bank-header h2 { display: flex; align-items: center; gap: 10px; min-width: 0; margin: 0; font-size: 1.02rem; font-weight: 680; letter-spacing: -.015em; overflow-wrap: anywhere; }
.bank-avatar { flex: none; width: 34px; height: 34px; border-radius: 11px; display: grid; place-items: center; font-size: .9rem; font-weight: 760; color: #fff;
  background: linear-gradient(150deg, hsl(var(--h, 155) 58% 30%), hsl(calc(var(--h, 155) + 26) 60% 21%)); box-shadow: inset 0 1px 0 rgba(255, 255, 255, .28); }
.bank-total { flex: none; font-size: 1.05rem; font-weight: 720; letter-spacing: -.02em; color: var(--text); }
.fin-row { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; align-items: center; gap: 2px 10px; padding: 13px 0; border-bottom: 1px solid var(--border); }
.fin-label { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; font-size: .95rem; font-weight: 620; letter-spacing: -.005em; }
.fin-type { display: inline-flex; align-items: center; gap: 5px; margin: 0; padding: 2px 9px 2px 7px; border-radius: var(--r-pill); font-size: var(--fs-2xs); font-weight: 650;
  color: var(--text); background: color-mix(in srgb, var(--t, var(--accent)) 14%, transparent); }
.fin-type::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--t, var(--accent)); }
.fin-type[data-t="Compte courant"] { --t: var(--cat-courant); } .fin-type[data-t="Livret"] { --t: var(--cat-livret); }
.fin-type[data-t="Investissement"] { --t: var(--cat-invest); } .fin-type[data-t="Crypto"] { --t: var(--cat-crypto); } .fin-type[data-t="Autre"] { --t: var(--cat-autre); }
.fin-type.fin-auto { --t: var(--accent); color: var(--accent); font-weight: 700; letter-spacing: .04em; text-transform: uppercase; font-size: .62rem; background: var(--accent-soft); }
.fin-note { font-size: var(--fs-xs); margin-top: 3px; line-height: 1.35; }
.fin-value { font-size: .98rem; font-weight: 720; letter-spacing: -.015em; white-space: nowrap; text-align: right; }
.fin-actions { display: flex; gap: 6px; } /* a gap between edit and delete: delete has no confirmation, mis-taps must be hard */
.fin-actions button { width: 36px; height: 36px; padding: 0; border-radius: 10px; font-size: .95rem; line-height: 1; color: var(--muted); }
/* icon-only actions: the text glyphs (pencil / cross) are hidden and replaced by masked SVG icons that match the tab bar; theme.js adds the aria-labels */
:is(.fin-actions button, .note-del, .exp-del) { font-size: 0; display: inline-flex; align-items: center; justify-content: center; }
:is(.fin-actions button, .note-del, .exp-del)::before { content: ""; width: 18px; height: 18px; background: currentColor;
  -webkit-mask: var(--ic) center / contain no-repeat; mask: var(--ic) center / contain no-repeat; }
.fin-actions .edit-btn { --ic: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='1.9' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M16.5 3.6a2.4 2.4 0 0 1 3.4 3.4L8 18.9 3.5 20.5 5.1 16z'/%3E%3Cpath d='M14.5 5.6l3.4 3.4'/%3E%3C/svg%3E"); }
:is(.fin-actions .del-btn, .note-del, .exp-del) { --ic: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='1.9' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4.5 7h15'/%3E%3Cpath d='M9.5 7V5.2c0-.9.7-1.7 1.6-1.7h1.8c.9 0 1.6.8 1.6 1.7V7'/%3E%3Cpath d='M6.5 7l.8 11.3c.1 1 .9 1.7 1.9 1.7h5.6c1 0 1.8-.7 1.9-1.7L17.5 7'/%3E%3Cpath d='M10.3 11v5.2M13.7 11v5.2'/%3E%3C/svg%3E"); }
@media (hover: hover) { .fin-actions button:hover { background: var(--done-bg); color: var(--text); } .fin-actions .del-btn:hover { color: var(--loss); } .fin-row:hover .fin-label { color: var(--accent); } }
.fin-add { min-height: 44px; margin-top: 10px; border-radius: 14px; background: transparent; color: var(--accent); font-weight: 650; font-size: var(--fs-sm);
  border: 1.5px dashed color-mix(in srgb, var(--accent) 38%, transparent); }
@media (hover: hover) { .fin-add:hover { background: var(--accent-soft); } }
.bank-add-row { margin-bottom: 8px; }
.bank-add-row .fin-add { margin-top: 0; }
@media (max-width: 380px) {
  .fin-row { grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "info value" "info actions"; }
  .fin-row > div:first-child { grid-area: info; } .fin-value { grid-area: value; } .fin-actions { grid-area: actions; justify-self: end; }
}

/* ---------- 6. Analyse ---------- */
.analyse-grid { gap: 14px; }
.history-delta { font-size: 1.3rem; font-weight: 760; letter-spacing: -.025em; margin: 0 0 14px; }
.history-delta-pos { color: var(--positive); }
.history-delta-neg { color: var(--loss); }
.history-svg { height: 150px; overflow: visible; filter: drop-shadow(0 8px 10px color-mix(in srgb, var(--accent) 22%, transparent)); }
.hist-stop { stop-color: var(--accent); }
.history-svg polyline { vector-effect: non-scaling-stroke; stroke-width: 2px; }
.history-svg polyline:last-of-type { stroke-width: 3px; }
.history-legend { gap: 8px 16px; margin-top: 14px; }
.history-dot { box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .3), 0 1px 3px rgba(0, 0, 0, .18); } /* not currentColor: that is the (dark) text colour and smudged the dots */
.cat-donut-wrap { position: relative; margin: 4px 0 20px; }
.cat-donut-wrap svg { filter: drop-shadow(0 6px 14px color-mix(in srgb, var(--accent) 18%, transparent)); max-width: 100%; }
.donut-center { position: absolute; left: 50%; top: 80px; transform: translate(-50%, -50%); text-align: center; pointer-events: none; display: flex; flex-direction: column; gap: 1px; }
.donut-center span { font-size: var(--fs-2xs); font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.donut-center b { font-size: min(.95rem, calc(166px / var(--n, 11))); font-weight: 740; letter-spacing: -.02em; white-space: nowrap; } /* --n = characters, set by theme.js: long totals shrink to stay inside the ring */
.cat-legend { gap: 2px; }
.cat-legend-item { gap: 10px; padding: 8px 0; border-top: 1px solid var(--border); }
.cat-legend-item:first-child { border-top: none; }
.cat-dot { width: 10px; height: 10px; box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .3), 0 1px 3px rgba(0, 0, 0, .18); }

/* ---------- 7. Marches: shared structure (colours come from the neon tokens) ---------- */
.subtabs { position: relative; display: grid; grid-template-columns: repeat(var(--sub-n, 4), minmax(0, 1fr)); gap: 0; padding: 4px; margin-bottom: 16px; border-radius: 18px;
  background: var(--done-bg); border: 1px solid var(--edge); box-shadow: inset 0 1px 3px rgba(0, 0, 0, .12); }
.subtabs::before { content: ""; position: absolute; top: 4px; bottom: 4px; left: 4px; width: calc((100% - 8px) / var(--sub-n, 4)); border-radius: 14px;
  background: var(--sheen), var(--card); border: 1px solid var(--edge); box-shadow: var(--shadow-card), 0 0 20px -4px var(--glow);
  transform: translateX(calc(var(--sub-i, 0) * 100%)); transition: transform .45s var(--spring), background-color .4s ease, border-color .4s ease; }
.subtab-btn, .subtabs .subtab-btn.active { position: relative; z-index: 1; min-height: 44px; padding: 8px 2px; border-radius: 14px; background: none; font-size: .84rem; font-weight: 650; }
.subtabs .subtab-btn { color: var(--muted); }
.subtabs .subtab-btn.active { color: var(--accent); }
.market-card h2 { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.market-row { gap: 12px; padding: 13px 4px; margin: 0 -4px; border-radius: 14px; }
.market-icon { width: 40px; height: 40px; }
.market-icon-letter { font-size: .64rem; letter-spacing: .01em; font-weight: 800; }
.market-name { font-size: .95rem; font-weight: 650; letter-spacing: -.01em; }
.market-symbol { display: block; margin-top: 1px; font-weight: 600; letter-spacing: .06em; }
.market-price { font-size: .98rem; font-weight: 720; letter-spacing: -.015em; }
.market-change { display: inline-block; margin-top: 3px; padding: 1px 8px; border-radius: var(--r-pill); font-size: var(--fs-2xs); font-weight: 680; }
.market-change.history-delta-pos { background: color-mix(in srgb, var(--positive) 13%, transparent); }
.market-change.history-delta-neg { background: color-mix(in srgb, var(--loss) 13%, transparent); }
.market-spark { width: 72px; height: 32px; }
.market-spark polyline { vector-effect: non-scaling-stroke; stroke-width: 2px; }
.market-hint { margin-top: 12px; }
.market-chevron { font-size: 1.3rem; opacity: .7; }
.skel-list { display: flex; flex-direction: column; gap: 12px; }
.skel-row { display: flex; align-items: center; gap: 12px; min-height: 72.4px; padding: 13px 12px 13px 14px; border-radius: 18px; border: 1px solid var(--edge); background: var(--sheen), var(--card); box-shadow: var(--shadow-card); }
.skel { display: block; position: relative; overflow: hidden; border-radius: 8px; background: color-mix(in srgb, var(--muted) 20%, transparent); }
.skel::after { content: ""; position: absolute; inset: 0; transform: translateX(-100%); animation: shimmer 1.5s ease-in-out infinite;
  background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--text) 12%, transparent), transparent); }
.skel-av { flex: none; width: 40px; height: 40px; border-radius: 50%; }
.skel-col { display: flex; flex-direction: column; gap: 8px; flex: 1; min-width: 0; }
.skel-l1 { height: 12px; width: 62%; } .skel-l2 { height: 10px; width: 36%; }
.skel-sp { flex: none; width: 56px; height: 24px; }
.skel-end { flex: none; width: 76px; align-items: flex-end; } .skel-end .skel-l1 { width: 100%; } .skel-end .skel-l2 { width: 60%; }

/* portfolio */
.pf-summary-value { font-size: clamp(1.9rem, 8.5vw, 2.3rem); font-weight: 760; letter-spacing: -.035em; }
.pf-summary-stats { padding-top: 14px; gap: 12px; }
.pf-position-head { min-height: 60px; }
.pf-badge { width: 40px; height: 40px; font-size: .64rem; font-weight: 800; }
.pf-position-name { font-weight: 650; letter-spacing: -.01em; }
.pf-position-value { font-weight: 720; letter-spacing: -.015em; }
.pf-add-btn { border-radius: 14px; border: 1.5px dashed color-mix(in srgb, var(--accent) 38%, transparent); background: transparent; font-weight: 650; }
@media (hover: hover) { .pf-add-btn:hover, .pf-position-head:hover { background: var(--accent-soft); } }
.pf-overlay { -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px); }
.pf-dialog { background: var(--sheen), var(--card); border: 1px solid var(--edge); border-radius: 24px; box-shadow: var(--shadow-pop), 0 0 40px -12px var(--glow); animation: pop .32s var(--spring) both; }
.pf-dialog-title { font-size: 1.15rem; font-weight: 700; letter-spacing: -.02em; }
.pf-btn { border-radius: 14px; }

/* calculator */
.calc-chip { min-height: 36px; padding: 6px 14px; border-radius: var(--r-pill); font-weight: 650; border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent); }
.calc-value { font-size: clamp(1.7rem, 8vw, 2.1rem); font-weight: 780; letter-spacing: -.035em; }
.calc-results:not(:empty) { padding-top: 16px; }
.calc-submit { min-height: 48px; }
.calc-card .calc-positive { text-shadow: 0 0 14px color-mix(in srgb, var(--positive) 35%, transparent); }

/* detail screen */
.md-overlay { background: var(--bg); }
.md-sheet { padding: 14px 16px 40px; }
.md-close { width: 44px; height: 44px; background: var(--sheen), var(--card); border: 1px solid var(--edge); box-shadow: var(--shadow-card), 0 0 20px -6px var(--glow); }
.md-title { font-size: 1.25rem; font-weight: 720; letter-spacing: -.025em; }
.md-symbol { font-weight: 650; letter-spacing: .06em; }
.md-price { margin: 20px 0 22px; }
.md-price-value { font-size: clamp(2.2rem, 11vw, 2.9rem); font-weight: 780; letter-spacing: -.04em; line-height: 1.08; }
.md-price-change { font-size: 1rem; font-weight: 680; }
.md-chart-wrap { isolation: isolate; margin-bottom: 20px; }
.md-chart-wrap::before { content: ""; position: absolute; z-index: -1; inset: -12px -10px -10px -10px; border-radius: 22px; pointer-events: none;
  background: var(--sheen), var(--card); border: 1px solid var(--edge); box-shadow: var(--shadow-card), 0 0 32px -10px var(--glow); }
.md-line { stroke-width: 2.5px; }
.md-ranges { gap: 6px; padding: 6px 4px; }
.md-range { min-height: 44px; border-radius: var(--r-pill); font-weight: 650; border-color: var(--edge); }
.md-range[aria-pressed="true"] { color: var(--bg); }
.md-stats { gap: 12px; margin-top: 18px; }
.md-stat { padding: 12px 14px; }
.md-stat dd { font-size: 1.02rem; font-weight: 720; letter-spacing: -.015em; }

/* ---------- 8. Depenses ---------- */
.exp-periods { padding: 4px; gap: 2px; border-radius: 16px; background: var(--done-bg); border: 1px solid var(--edge); margin-bottom: 18px; }
.exp-period { min-height: 44px; border-radius: 12px; background: none; color: var(--muted); font-weight: 650; }
.exp-period[aria-pressed="true"] { background: var(--sheen), var(--card); color: var(--accent); box-shadow: var(--shadow-card); }
@media (prefers-color-scheme: dark) { /* in dark the selected segment must be lighter than its track, not darker */
  :root:not([data-theme="light"]) .exp-period[aria-pressed="true"] { background: var(--sheen), color-mix(in srgb, var(--accent) 17%, var(--done-bg)); }
}
.exp-total-amount { font-size: clamp(2.2rem, 11vw, 2.9rem); font-weight: 780; letter-spacing: -.04em; }
.exp-total-label { font-weight: 600; letter-spacing: .06em; text-transform: uppercase; font-size: var(--fs-2xs); }
.exp-submit { min-height: 48px; border-radius: 14px; }
#expAmount { min-height: 60px; font-size: 1.75rem; font-weight: 720; letter-spacing: -.025em; }
.exp-confirmation { border-radius: 12px; border: 1px solid color-mix(in srgb, var(--accent) 25%, transparent); font-weight: 550; }
.exp-section { border-top-color: var(--border); }
.exp-bar { height: 8px; border-radius: 4px; }
.exp-bar-fill { height: 100%; border-radius: 4px; background: linear-gradient(90deg, var(--accent), var(--loss)); }
.exp-account-name, .exp-row-label { font-weight: 620; }
.exp-day-title { font-size: var(--fs-sm); font-weight: 680; letter-spacing: -.005em; text-transform: none; color: var(--text); margin: 2px 0 2px; } /* sentence case: stays distinct from the uppercase "JOURNAL" section title above it */
.exp-day-title::first-letter { text-transform: uppercase; }
.exp-row { padding: 10px 0; }
.exp-empty::before, .pf-empty::before, .empty::before, .history-empty::before { display: grid; place-items: center; width: 56px; height: 56px; margin: 0 auto 10px; border-radius: 50%; background: var(--accent-soft); font-size: 1.6rem; line-height: 1; }
.exp-empty { padding: 18px 0 8px; } .exp-empty::before { content: "\1F9FE"; }
.pf-empty::before { content: "\1F4BC"; }
.empty { padding: 32px 0; } #list .empty::before { content: "\1F4DD"; } #categoryChartBody .empty::before { content: "\1F967"; }
.history-empty { padding: 20px 0; } #historyCardBody .history-empty::before { content: "\1F4C8"; } #marketCardBody .history-empty::before { content: "\1F4E1"; }
.exp-form-card .exp-empty::before { content: "\1F3E6"; }
/* Finances with no bank yet: the app renders nothing, so the empty state is drawn here */
#banksList:empty { padding: 20px 16px 10px; text-align: center; color: var(--muted); font-size: .88rem; line-height: 1.45; }
#banksList:empty::before { content: "\1F3E6"; display: grid; place-items: center; width: 56px; height: 56px; margin: 0 auto 10px; border-radius: 50%; background: var(--accent-soft); font-size: 1.6rem; line-height: 1; }
#banksList:empty::after { content: "Aucun compte pour l\2019instant. Ajoute ta premi\00e8re banque ci-dessous."; display: block; max-width: 30ch; margin: 0 auto; }

/* ---------- 9. Notes ---------- */
.composer { padding: 14px 14px 12px; }
.composer textarea { min-height: 84px; padding: 4px 2px; border: none; background: none; box-shadow: none; font-size: 1rem; line-height: 1.45; resize: none; }
.composer:focus-within { border-color: var(--accent); box-shadow: var(--shadow-card), var(--ring); }
.composer .btn-primary { min-height: 44px; padding: 8px 20px; }
.notes-toolbar { gap: 10px; margin-bottom: 14px; }
#noteSearch { padding-left: 38px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238a948e' stroke-width='2.2' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='6.5'/%3E%3Cpath d='M16 16l4.5 4.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: 12px 50%; background-size: 18px; }
#noteSort { color: var(--muted); flex: 1 1 100%; }
@media (min-width: 560px) { #noteSearch { flex: 1 1 0; } #noteSort { flex: 0 0 220px; } }
.note { align-items: center; gap: 6px; padding: 8px 8px 8px 4px; margin-bottom: 10px; transition: background-color .3s ease, opacity .3s ease; }
.note.done { background: var(--done-bg); box-shadow: none; }
.note-text { font-size: .95rem; line-height: 1.45; padding: 4px 0; }
.note.done .note-text { text-decoration-thickness: 1.5px; text-decoration-color: color-mix(in srgb, var(--muted) 70%, transparent); }
.note-check { -webkit-appearance: none; appearance: none; position: relative; flex: none; width: 40px; height: 40px; margin: 0; background: none; border: none; cursor: pointer; }
.note-check::before { content: ""; position: absolute; inset: 8px; border-radius: 50%; border: 2px solid color-mix(in srgb, var(--muted) 65%, transparent); transition: background-color .25s ease, border-color .25s ease, box-shadow .25s ease; }
.note-check::after { content: ""; box-sizing: content-box; position: absolute; left: 14px; top: 14px; width: 12px; height: 7px; border-left: 2.5px solid var(--bg); border-bottom: 2.5px solid var(--bg);
  transform: translateY(-1px) rotate(-45deg) scale(0); transition: transform .3s var(--spring); }
.note-check:checked::before { background: var(--accent); border-color: var(--accent); box-shadow: 0 0 14px -2px var(--glow); }
.note-check:checked::after { transform: translateY(-1px) rotate(-45deg) scale(1); }
.note-check:focus-visible { outline: none; }
.note-check:focus-visible::before { box-shadow: var(--ring); }
.note-del { width: 36px; height: 36px; padding: 0; border-radius: 10px; font-size: 1rem; }
@media (hover: hover) { .note-del:hover { background: var(--done-bg); color: var(--loss); } }

/* ---------- 10. Modal (add / edit line) ---------- */
.modal-overlay { background: rgba(4, 10, 8, .5); -webkit-backdrop-filter: blur(8px) saturate(1.2); backdrop-filter: blur(8px) saturate(1.2); overflow-y: auto; align-items: flex-start; overscroll-behavior: contain; }
.modal-overlay.open { animation: fade .22s ease both; }
.modal { margin: auto; padding: 22px 20px 20px; border-radius: 24px; background: var(--sheen), var(--card); border: 1px solid var(--edge); box-shadow: var(--shadow-pop); animation: pop .34s var(--spring) both; }
.modal h3 { font-size: 1.2rem; font-weight: 720; letter-spacing: -.025em; margin: 0 0 14px; }
.modal-actions { gap: 10px; margin-top: 10px; }
.modal-actions button { flex: 1; }
.modal-error:empty { min-height: 0; margin: 0; }

/* ---------- 11. PIN gate, loader, login: brand screens ---------- */
#gate, #loadingScreen, .auth-overlay {
  background:
    radial-gradient(95% 55% at 50% -6%, color-mix(in srgb, var(--accent) 26%, transparent), transparent 70%),
    radial-gradient(70% 40% at 105% 105%, var(--glow-b), transparent 65%), var(--bg);
  color: var(--text);
}
/* the gate scrolls instead of squashing its children when the screen is short (phone in landscape, keyboard open) */
#gate { gap: 0; overflow-y: auto; overscroll-behavior: contain; justify-content: flex-start; padding: max(24px, env(safe-area-inset-top)) max(24px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(24px, env(safe-area-inset-left)); }
#gate > * { flex-shrink: 0; }
#gate > :first-child { margin-top: auto; }
#gate > :last-child { margin-bottom: auto; }
#gate > * { animation: rise .6s var(--ease) both; }
#gate > :nth-child(2) { animation-delay: .06s; } #gate > :nth-child(3) { animation-delay: .1s; } #gate > :nth-child(4) { animation-delay: .14s; }
#gate > :nth-child(5) { animation-delay: .18s; } #gate > :nth-child(6) { animation-delay: .22s; }
.gate-icon, .auth-icon { display: grid; place-items: center; width: 88px; height: 88px; margin: 0 auto 22px; border-radius: 28px; font-size: 2.5rem; line-height: 1;
  background: linear-gradient(150deg, var(--hero-a), var(--hero-b)); box-shadow: 0 22px 40px -16px var(--hero-shadow), inset 0 1px 0 rgba(255, 255, 255, .3); }
#gate h1 { font-size: 1.7rem; font-weight: 780; letter-spacing: -.035em; }
#gate .sub { margin: 8px 0 26px; font-size: .95rem; }
#gate #pinInput { width: min(250px, 72vw); min-height: 66px; margin: 0 0 12px; padding: 12px 8px 12px calc(8px + .55em); border: 1px solid var(--edge); border-radius: 20px; font-family: inherit; font-size: 2rem; font-weight: 700;
  letter-spacing: .55em; text-align: center; color: var(--text); background-color: var(--card); box-shadow: var(--shadow-card); transition: border-color .2s ease, box-shadow .2s ease; }
#gate #pinInput:focus { outline: none; border-color: var(--accent); box-shadow: var(--shadow-card), var(--ring); }
#gate #pinInput::placeholder { letter-spacing: .4em; font-weight: 400; }
#gate #pinInput:focus::placeholder { color: transparent; } /* the caret sits mid-field: no placeholder dots underneath it */
#gate #pinBtn, #gate #bioBtn { width: min(250px, 72vw); min-height: 52px; border-radius: 16px; font-size: 1rem; }
#gate #bioBtn { margin-top: 10px; background: transparent; border: 1px solid var(--edge); color: var(--text); display: inline-flex; align-items: center; justify-content: center; gap: 9px; }
#gate #bioBtn[hidden] { display: none; }
#gate #bioBtn::before { content: ""; width: 22px; height: 22px; background: currentColor; -webkit-mask: var(--ic-face) center / contain no-repeat; mask: var(--ic-face) center / contain no-repeat;
  --ic-face: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 8.5V7a3 3 0 0 1 3-3h1.5M15.5 4H17a3 3 0 0 1 3 3v1.5M20 15.5V17a3 3 0 0 1-3 3h-1.5M8.5 20H7a3 3 0 0 1-3-3v-1.5'/%3E%3Cpath d='M9 10v1.2M15 10v1.2M12 10v3.2h-.9M9.2 15.3c.7.8 1.7 1.2 2.8 1.2s2.1-.4 2.8-1.2'/%3E%3C/svg%3E"); }
#loadingScreen[data-state="error"]::before { content: "!"; display: grid; place-items: center; width: 40px; height: 40px; border: 2px solid var(--loss); border-top-color: var(--loss); border-radius: 50%; color: var(--loss); font-size: 1.3rem; font-weight: 800; animation: none; }
#loadingScreen[data-state="error"] { line-height: 1.45; }
#gateError { font-weight: 550; margin-top: 12px; }
@media (max-height: 520px) { /* phone in landscape: compact gate */
  .gate-icon { width: 60px; height: 60px; margin-bottom: 12px; border-radius: 19px; font-size: 1.75rem; }
  #gate h1 { font-size: 1.35rem; }
  #gate .sub { margin: 4px 0 14px; font-size: .88rem; }
  #gate #pinInput { min-height: 54px; font-size: 1.7rem; margin-bottom: 8px; border-radius: 16px; }
  #gate #pinBtn, #gate #bioBtn { min-height: 46px; }
  #gate #bioBtn { margin-top: 8px; }
  #gateError { margin-top: 8px; min-height: 16px; }
}
#loadingScreen { flex-direction: column; gap: 18px; font-weight: 550; }
#loadingScreen::before { content: ""; width: 34px; height: 34px; border-radius: 50%; border: 3px solid color-mix(in srgb, var(--accent) 22%, transparent); border-top-color: var(--accent); animation: spin .8s linear infinite; }
.auth-card { border-radius: 28px; padding: 30px 22px 24px; background: var(--sheen), var(--card); border: 1px solid var(--edge); box-shadow: var(--shadow-pop); animation: pop .5s var(--spring) both; }
.auth-icon { width: 72px; height: 72px; border-radius: 24px; font-size: 2rem; margin-bottom: 16px; }
.auth-title { font-size: 1.4rem; font-weight: 760; letter-spacing: -.03em; }
.auth-submit { min-height: 50px; border-radius: 16px; }
@media (max-height: 520px) { /* phone in landscape: fewer scrolls to reach the button */
  .auth-card { padding: 16px 20px 14px; }
  .auth-icon { width: 46px; height: 46px; margin-bottom: 8px; border-radius: 15px; font-size: 1.35rem; }
  .auth-title { font-size: 1.2rem; }
  .auth-intro { margin-bottom: 12px; }
  .auth-field { margin-bottom: 10px; }
}

/* ---------- 12. NEON (Marches) ---------- */
html[data-ambiance="marches"] .brand-mark { color: #05070c; }
html[data-ambiance="marches"] .tabs::before { border-color: color-mix(in srgb, var(--accent) 60%, transparent); box-shadow: 0 0 18px -2px var(--glow), inset 0 0 14px color-mix(in srgb, var(--accent) 16%, transparent); }
html[data-ambiance="marches"] .tabs .tab-btn.active .tab-ico { filter: drop-shadow(0 0 6px var(--accent)); }
html[data-ambiance="marches"] .subtabs::before { background: color-mix(in srgb, var(--accent) 15%, var(--card)); border-color: color-mix(in srgb, var(--accent) 62%, transparent);
  box-shadow: 0 0 22px -3px var(--glow), inset 0 0 16px color-mix(in srgb, var(--accent) 14%, transparent); }
html[data-ambiance="marches"] .subtabs { box-shadow: inset 0 1px 4px rgba(0, 0, 0, .6); }
html[data-ambiance="marches"] .subtabs .subtab-btn.active { text-shadow: 0 0 12px color-mix(in srgb, var(--accent) 60%, transparent); }
html[data-ambiance="marches"] :is(h2, .pf-title) { text-shadow: 0 0 18px color-mix(in srgb, var(--accent) 35%, transparent); }
html[data-ambiance="marches"] :is(.calc-card, .pf-card, .pf-dialog, .md-overlay) { color-scheme: dark; }
html[data-ambiance="marches"] .pf-overlay { color-scheme: dark; --pf-scrim: rgba(2, 4, 8, .72); }
html[data-ambiance="marches"] :is(.calc-card, .pf-card) { border-color: var(--edge); box-shadow: var(--shadow-card), 0 0 30px -8px var(--glow), 0 0 0 1px color-mix(in srgb, var(--accent) 8%, transparent); }
html[data-ambiance="marches"] .calc-card :is(input, select) { color-scheme: dark; }
html[data-ambiance="marches"] :is(.calc-submit, .pf-btn-primary, .md-retry) { color: #05070c; box-shadow: 0 0 24px -4px var(--glow), inset 0 1px 0 rgba(255, 255, 255, .35); }
html[data-ambiance="marches"] :is(.calc-value, .pf-summary-value, .md-price-value) { text-shadow: 0 0 22px color-mix(in srgb, var(--accent) 45%, transparent); }
html[data-ambiance="marches"] :is(.history-delta-pos, .md-up, .pf-pnl[data-tone="positive"], .calc-card .calc-positive) { text-shadow: 0 0 12px color-mix(in srgb, var(--positive) 45%, transparent); }
html[data-ambiance="marches"] :is(.history-delta-neg, .md-down, .pf-pnl[data-tone="negative"], .calc-card .calc-negative) { text-shadow: 0 0 12px color-mix(in srgb, var(--loss) 40%, transparent); }
html[data-ambiance="marches"] .calc-card .calc-negative { color: var(--loss); }
html[data-ambiance="marches"] .calc-error { color: var(--loss); }

/* per-asset neon colours */
[data-asset="BTC"] { --asset: #ff9f1a; --asset-grad: linear-gradient(135deg, #ffc04d, #ff7a1a); }
[data-asset="SOL"] { --asset: #b47cff; --asset-grad: linear-gradient(135deg, #b47cff, #2dffc4); }
[data-asset="NVDA"] { --asset: #9dff2e; --asset-grad: linear-gradient(135deg, #d4ff6a, #76ff03); }
[data-asset="NBIS"] { --asset: #4d8dff; --asset-grad: linear-gradient(135deg, #86ecff, #4d8dff); }
html[data-ambiance="marches"] :is(.market-row, .pf-position, .md-overlay)[data-asset] {
  --accent: var(--asset); --accent-soft: color-mix(in srgb, var(--asset) 16%, transparent);
  --edge: color-mix(in srgb, var(--asset) 44%, transparent); --glow: color-mix(in srgb, var(--asset) 42%, transparent);
}
html[data-ambiance="marches"] .market-card { background: none; border: none; box-shadow: none; padding: 0; }
html[data-ambiance="marches"] .market-card h2 { padding: 0 4px; }
html[data-ambiance="marches"] .market-row {
  position: relative; margin: 0 0 12px; padding: 13px 12px 13px 14px; border: 1px solid var(--edge); border-radius: 18px;
  background: linear-gradient(100deg, color-mix(in srgb, var(--asset) 14%, transparent), transparent 58%), var(--sheen), var(--card);
  box-shadow: var(--shadow-card), 0 0 26px -10px var(--glow); transition: transform .25s var(--ease), box-shadow .25s ease;
}
html[data-ambiance="marches"] .market-row:last-child { border-bottom: 1px solid var(--edge); }
html[data-ambiance="marches"] .market-row:active { transform: scale(.985); }
@media (hover: hover) { html[data-ambiance="marches"] .market-row:hover { transform: translateY(-2px); box-shadow: var(--shadow-card), 0 0 34px -6px var(--glow); } }
html[data-ambiance="marches"] .market-row:hover .market-name { color: var(--text); }
html[data-ambiance="marches"] .market-icon-letter, html[data-ambiance="marches"] .pf-position .pf-badge { background: var(--asset-grad); color: #05070c; box-shadow: 0 0 16px -3px var(--glow), inset 0 1px 0 rgba(255, 255, 255, .45); }
html[data-ambiance="marches"] .market-spark { filter: drop-shadow(0 0 4px var(--glow)); }
html[data-ambiance="marches"] .market-spark polyline { stroke: var(--asset); }
html[data-ambiance="marches"] [data-asset="SOL"] .market-spark polyline { stroke: url(#grad-SOL) var(--asset); }
html[data-ambiance="marches"] .market-chevron { color: var(--asset); }
html[data-ambiance="marches"] .pf-position { position: relative; border-top-color: var(--border); }
html[data-ambiance="marches"] .pf-position::before { content: ""; position: absolute; left: -16px; top: 12px; bottom: 12px; width: 3px; border-radius: 0 3px 3px 0; background: var(--asset); box-shadow: 0 0 12px var(--asset); }
html[data-ambiance="marches"] .pf-lot { background: color-mix(in srgb, var(--asset) 8%, var(--bg)); }
html[data-ambiance="marches"] .pf-chevron { color: var(--asset); }

/* detail screen: asset-coloured frame, glow and chart.
   The corner tint sits directly under the price/meta text, so its strength is capped low enough
   that even the brightest asset (NVDA lime) keeps AA for --muted and --loss text on top of it
   (measured: 24%/10% failed NVDA at 3.74:1 and BTC at 4.48:1; 15%/6% passes every asset). */
html[data-ambiance="marches"] .md-overlay { background: var(--bg); }
/* decorative layer, separate from .md-overlay itself: lets the neon drift animate (transform only) without
   moving the real content, and inset:0 (not oversized) avoids adding to the overlay's own overflow-y:auto scroll height. */
html[data-ambiance="marches"] .md-overlay::before {
  content: ""; position: absolute; inset: 0; z-index: 0; pointer-events: none;
  background:
    radial-gradient(90% 42% at 85% -6%, color-mix(in srgb, var(--asset, var(--accent)) 15%, transparent), transparent 66%),
    radial-gradient(70% 36% at -10% 30%, color-mix(in srgb, var(--asset-2, var(--asset, var(--accent))) 6%, transparent), transparent 65%),
    linear-gradient(var(--grid) 1px, transparent 1px) 0 0 / 34px 34px, linear-gradient(90deg, var(--grid) 1px, transparent 1px) 0 0 / 34px 34px;
  animation: neonDrift 18s ease-in-out infinite;
}
html[data-ambiance="marches"] .md-sheet { position: relative; z-index: 1; }
html[data-ambiance="marches"] .md-chart-wrap::before { border-color: var(--edge); }
html[data-ambiance="marches"] .md-chart, html[data-ambiance="marches"] .md-chart[data-trend="down"] { --md-trend: var(--asset, var(--accent)); }
html[data-ambiance="marches"] .md-line { filter: drop-shadow(0 0 5px var(--glow)) drop-shadow(0 0 12px var(--glow)); }
html[data-ambiance="marches"] .md-overlay[data-asset="SOL"] .md-line { stroke: url(#grad-SOL) var(--asset); }
html[data-ambiance="marches"] .md-dot { fill: var(--asset, var(--accent)); filter: drop-shadow(0 0 6px var(--asset, var(--accent))); }
html[data-ambiance="marches"] .md-range[aria-pressed="true"] { background: color-mix(in srgb, var(--accent) 18%, var(--card)); color: var(--accent); border-color: color-mix(in srgb, var(--accent) 70%, transparent); box-shadow: 0 0 18px -3px var(--glow), inset 0 0 12px color-mix(in srgb, var(--accent) 14%, transparent); }
html[data-ambiance="marches"] .md-stat { border-color: color-mix(in srgb, var(--asset, var(--accent)) 30%, transparent); }
html[data-ambiance="marches"] .md-symbol { color: var(--asset, var(--muted)); }

/* neon motion: give the trading area life (owner's request) - ambient drift, live tick flashes, chart draw-in,
   spring-y range pills, a smoother crosshair. All GPU-only (transform/opacity), classes are toggled by theme.js,
   and every rule here folds into the existing prefers-reduced-motion block at the end of this file. */
@keyframes neonDrift { 0%, 100% { transform: translate3d(0, 0, 0) scale(1); } 50% { transform: translate3d(-1.6%, 1.2%, 0) scale(1.05); } }
html[data-ambiance="marches"] body::before { animation: neonDrift 18s ease-in-out infinite; }
@keyframes tickSweep { 0% { transform: translateX(-120%); opacity: .85; } 65% { opacity: .4; } 100% { transform: translateX(130%); opacity: 0; } }
@keyframes tickGlowUp { 0% { color: var(--positive); text-shadow: 0 0 16px var(--positive); } 100% { color: var(--text); text-shadow: none; } }
@keyframes tickGlowDown { 0% { color: var(--loss); text-shadow: 0 0 16px var(--loss); } 100% { color: var(--text); text-shadow: none; } }
html[data-ambiance="marches"] .market-row { overflow: hidden; }
html[data-ambiance="marches"] .market-row.tick-up::after, html[data-ambiance="marches"] .market-row.tick-down::after {
  content: ""; position: absolute; inset: 0; border-radius: inherit; pointer-events: none; mix-blend-mode: screen;
  background: linear-gradient(100deg, transparent, var(--tick-c), transparent 62%); animation: tickSweep .9s ease-out both;
}
html[data-ambiance="marches"] .market-row.tick-up::after { --tick-c: color-mix(in srgb, var(--positive) 45%, transparent); }
html[data-ambiance="marches"] .market-row.tick-down::after { --tick-c: color-mix(in srgb, var(--loss) 45%, transparent); }
html[data-ambiance="marches"] .market-row.tick-up .market-price { animation: tickGlowUp .9s ease-out both; }
html[data-ambiance="marches"] .market-row.tick-down .market-price { animation: tickGlowDown .9s ease-out both; }
html[data-ambiance="marches"] .md-cross-line, html[data-ambiance="marches"] .md-dot { transition: cx .09s linear, cy .09s linear, x1 .09s linear, x2 .09s linear; }
@keyframes rangePop { 45% { transform: scale(1.14); } }
html[data-ambiance="marches"] .md-range { transition: background-color .35s var(--spring), color .3s ease, border-color .3s ease, box-shadow .35s ease, transform .18s var(--ease); }
html[data-ambiance="marches"] .md-range.pop { animation: rangePop .38s var(--spring); }

/* ---------- 13. Responsive + robustness ---------- */
@media (max-width: 360px) {
  .tabs .tab-btn { font-size: .62rem; }
  .brand-mark { width: 38px; height: 38px; }
  .sub-stat { padding: 9px 10px; }
  .market-spark { width: 56px; }
  .bank-section, .history-card, .category-card, .market-card, .pf-card, .calc-card, .exp-card { padding: 16px 14px; }
  html[data-ambiance="marches"] .market-row { gap: 9px; padding: 12px 10px; }
  .market-icon { width: 36px; height: 36px; }
}
@media (min-width: 900px) { /* wide screens: the nav becomes a compact top bar */
  .wrap { padding-bottom: 56px; }
  .tabs { position: sticky; top: 12px; bottom: auto; left: auto; transform: none; width: max-content; margin: 0 auto 22px; grid-template-columns: repeat(5, 96px); }
  .status:not(:empty) { bottom: 24px; }
}
@media (max-height: 500px) and (orientation: landscape) and (max-width: 899px) { /* phones in landscape: slimmer bar, inline labels */
  .wrap { padding-bottom: calc(76px + env(safe-area-inset-bottom, 0px)); }
  .tabs { bottom: calc(6px + env(safe-area-inset-bottom, 0px)); }
  .tabs .tab-btn { flex-direction: row; justify-content: center; min-height: 44px; gap: 6px; padding: 4px 0; }
  .tab-ico .ico { width: 20px; height: 20px; }
  .status:not(:empty) { bottom: calc(66px + env(safe-area-inset-bottom, 0px)); }
}

@media (prefers-reduced-motion: reduce) {
  :root { transition: none; }
  *, *::before, *::after { animation-duration: .01ms !important; animation-delay: 0s !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
  .skel::after { display: none; }
  .live-dot, .app-header .sub::before { animation: none; }
}
