/* ─────────────────────────────────────────────────────────────
   Relation Candlestick · Editorial dark theme
   Inspiration: The New Yorker / Bloomberg Businessweek / Lapham's Quarterly
   Fonts: Cormorant Garamond (Latin serif) / Noto Serif SC (CJK serif)
          / DM Mono (data mono, avoiding Inter)
   Palette: warm ink black + cream + vermilion + faded gold + moss green
───────────────────────────────────────────────────────────── */

:root {
  /* ── CLASSIC palette (default on first visit) ─────────────────
     Bloomberg / NewYorker editorial: warm ink black, pure cream text,
     vermilion accent, saturated red/green candles. */
  --ink:        #0d0c0a;     /* page background, warm ink black */
  --paper:      #14110d;     /* secondary surface */
  --paper-2:    #1d1812;     /* dark card / input */
  --rule:       #3a3025;     /* gilt hairline border */
  --rule-soft:  #2a221a;     /* nearly invisible hairline */

  --cream:      #ffffff;     /* primary text */
  --cream-dim:  #d6d0bf;     /* secondary */
  --cream-mute: #8a8175;     /* tertiary */

  --accent:      #c8443c;    /* vermilion */
  --accent-rgb:  200, 68, 60;
  --accent-soft: #2e1410;
  --gold:        #c19a4a;

  --vermilion:  #c8443c;     /* alias for back-compat with existing rules */
  --warn:       #c19a4a;
  --err:        #c8443c;

  /* Candlestick (finance convention: red = up, green = down) */
  --up:         #d04841;     /* saturated red (CSS-text contexts) */
  --up-rgb:     208, 72, 65;
  --down:       #4a8a6e;     /* saturated teal-green */
  --down-rgb:   74, 138, 110;

  --chart-bg:   #0e0d0c;

  /* Font stack — Option B: Editorial Longform (Fraunces + Newsreader + IBM Plex Mono) */
  --font-display: "Fraunces", "Noto Serif SC", Georgia, serif;
  --font-body:    "Newsreader", "Noto Serif SC", Georgia, serif;
  --font-mono:    "IBM Plex Mono", "JetBrains Mono", "SFMono-Regular", Consolas, monospace;
  --font-ui:      "Newsreader", "Noto Serif SC", "PingFang SC", "Microsoft YaHei", Georgia, serif;
}

/* ── SOFT palette ─────────────────────────────────────────────
   Dusty rose + sage on warm charcoal. Triggered by the ! toggle
   in the topbar; selection persists via localStorage["rcl.theme"]. */
[data-theme="soft"] {
  --ink:        #2a1820;     /* dark cherry-blossom-tinted base (hue of #FFB7C5) */
  --paper:      #321f27;
  --paper-2:    #3a252e;
  --rule:       #4a3540;
  --rule-soft:  #2d1a22;

  --cream:      #f0e8db;
  --cream-dim:  #c0b5a3;
  --cream-mute: #7a6f60;

  --accent:      #f09ead;
  --accent-rgb:  240, 158, 173;
  --accent-soft: #2e1d22;
  --gold:        #dec9a8;     /* champagne accent (soft warm-light, low chroma) */

  --vermilion:  #f09ead;
  --warn:       #dec9a8;
  --err:        #f09ead;

  /* Chart uptick (price bars) is a soft cherry-blossom pink — slightly
     darker than the original #ffe5ec experiment so candle bodies read
     clearly against the dark canvas, but still lighter/softer than the
     UI accent #f09ead. UI accents (Apply button, brand title, hearts,
     focus rings) keep the saturated original #f09ead. */
  --up:         #fdc8d6;
  --up-rgb:     253, 200, 214;
  --down:       #b6e1f6;        /* baby blue (pastel) — was pastel green */
  --down-rgb:   182, 225, 246;

  --chart-bg:   #2c1a21;
}

/* Fraunces and Newsreader are variable fonts with optical-size axes — auto-tune
   to rendered size so headlines feel refined and body stays crisp. Tabular
   figures keep numeric columns aligned in the chart tooltip. */
html {
  font-optical-sizing: auto;
  font-feature-settings: "tnum" 1;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  background:
    radial-gradient(ellipse at 20% -10%, rgba(var(--accent-rgb),0.05), transparent 50%),
    radial-gradient(ellipse at 100% 0,  rgba(var(--down-rgb),0.03),  transparent 50%),
    var(--ink);
  color: var(--cream);
  font-family: var(--font-ui);
  font-size: 14px; line-height: 1.55;
  height: 100%;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
body { display: flex; flex-direction: column; }

/* ─── Topbar ─── */
.topbar {
  /* `position: relative` anchors .topbar-right (which is absolutely positioned
     at right: 18px to align with the APPLY button below) regardless of any
     flex/padding weirdness in the children. */
  position: relative;
  display: flex; align-items: baseline; justify-content: space-between;
  padding: 22px 44px;
  background: rgba(13,12,10,0.78);             /* classic ink-tinted glass */
  border-bottom: 1px solid var(--rule-soft);
  flex: 0 0 auto; backdrop-filter: blur(8px);
}
[data-theme="soft"] .topbar { background: rgba(42,24,32,0.78); }   /* dark cherry-blossom-tinted glass */
.brand { display: flex; align-items: baseline; gap: 16px; }
.brand .title {
  font-family: var(--font-display);
  font-size: 22px; font-weight: 500; letter-spacing: -0.005em;
  color: var(--cream-dim);     /* warm dim cream — matches the landing h1 */
}
/* In soft/pastel palette, title follows the price-bar (--up) cherry-
   blossom pink so the topbar harmonises visually with the candle
   palette. (--up is now #fdc8d6, plenty readable; the saturated UI
   accent #f09ead is reserved for buttons / toggles / focus rings.) */
[data-theme="soft"] .brand .title { color: var(--up); }
.topbar-right {
  /* Pinned to the viewport right edge with the same 18px offset as the
     APPLY button in .ind-toolbar below — guaranteed visual alignment
     independent of brand-title width or flex behaviour. */
  position: absolute;
  top: 50%; right: 18px; transform: translateY(-50%);
  display: flex; align-items: center; gap: 12px;
}
.job-pill {
  padding: 4px 12px;
  font-family: var(--font-mono); font-size: 11px;
  background: var(--paper-2); color: var(--cream-dim);
  border: 1px solid var(--rule); border-radius: 0;
  letter-spacing: 0.03em;
}
.job-pill code { color: var(--cream); }

/* ─── Theme toggle (the `!` button) ───
   Intentionally hardcoded pink #f09ead — does NOT theme. In classic mode
   it stands out as an unexpected dot of color saying "click here to bloom";
   in soft mode it blends with the rest of the pink palette. */
.theme-toggle {
  width: 28px; height: 28px;
  border: 1px solid rgba(240, 158, 173, 0.4);
  border-radius: 50%;
  background: transparent;
  color: #f09ead;
  font-family: var(--font-display);
  font-size: 16px; font-weight: 700; line-height: 1;
  cursor: pointer;
  padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  transition: transform .15s, background .15s, border-color .15s;
}
.theme-toggle:hover {
  transform: scale(1.1);
  background: rgba(240, 158, 173, 0.10);
  border-color: #f09ead;
}

/* ─── stage container ─── */
.stage { display: none; flex: 1 1 auto; padding: 36px 36px; overflow: auto; }
.stage.active { display: block; }
#stage-chart.active { display: flex; flex-direction: column; padding: 0; overflow: hidden; }
/* Force inner content to full width to avoid a dead black strip on the right */
#stage-mode { max-width: 1320px; margin: 0 auto; position: relative; }

/* ─── Decorative snowfall (pastel mode only, landing page only) ───
   Pure-CSS animation: 8 Unicode snowflake glyphs drift down across the
   landing. display:none in classic so it never paints there. Pointer-events
   off so it never blocks clicks; sits behind .hero/.mode-grid (z-index 0). */
.flakes { display: none; position: absolute; inset: 0;
  pointer-events: none; overflow: hidden; z-index: 0; }
[data-theme="soft"] #stage-mode.active .flakes { display: block; }
.flakes .flake {
  position: absolute; top: -32px;
  color: rgba(255, 255, 255, 0.78);
  text-shadow: 0 0 6px rgba(255, 255, 255, 0.25);
  user-select: none;
  animation: flake-fall linear infinite;
  will-change: transform;
}
.flakes .flake:nth-child(1) { left:  6%; font-size: 20px;
  animation-duration: 18s; animation-delay:  0s; opacity: 0.55; }
.flakes .flake:nth-child(2) { left: 20%; font-size: 26px;
  animation-duration: 24s; animation-delay:  4s; opacity: 0.65; }
.flakes .flake:nth-child(3) { left: 34%; font-size: 18px;
  animation-duration: 15s; animation-delay:  7s; opacity: 0.5;  }
.flakes .flake:nth-child(4) { left: 48%; font-size: 22px;
  animation-duration: 21s; animation-delay:  2s; opacity: 0.75; }
.flakes .flake:nth-child(5) { left: 60%; font-size: 17px;
  animation-duration: 19s; animation-delay:  9s; opacity: 0.6;  }
.flakes .flake:nth-child(6) { left: 73%; font-size: 21px;
  animation-duration: 16s; animation-delay:  3s; opacity: 0.55; }
.flakes .flake:nth-child(7) { left: 86%; font-size: 24px;
  animation-duration: 25s; animation-delay:  6s; opacity: 0.7;  }
.flakes .flake:nth-child(8) { left: 94%; font-size: 16px;
  animation-duration: 20s; animation-delay: 11s; opacity: 0.5;  }
/* Gentle drift + slow spin — snow doesn't tumble like petals. */
@keyframes flake-fall {
  0%   { transform: translate3d(0,    -32px,  0) rotate(  0deg); }
  50%  { transform: translate3d(-18px, 50vh,  0) rotate(120deg); }
  100% { transform: translate3d(-36px, 105vh, 0) rotate(240deg); }
}
/* Make sure hero/mode-grid sit above the snow layer. */
#stage-mode .hero,
#stage-mode .mode-grid,
#stage-mode .highlight-card,
#stage-mode .history-wrap,
#stage-mode .disclaimer-foot { position: relative; z-index: 1; }

/* ─── Highlight card (landing) ───
   Editorial summary of the most recent analysis. Hidden by default until
   loadAndRenderHighlight() populates it (or determines history is empty). */
.highlight-card {
  max-width: 920px; margin: 0 auto 64px;
  padding: 28px 32px;
  border: 1px solid var(--rule);
  border-top: 2px solid var(--accent);
  background: rgba(var(--accent-rgb), 0.03);
}
.highlight-card .hl-headline {
  display: flex; align-items: baseline; justify-content: center;
  gap: 14px; margin-bottom: 22px;
  font-family: var(--font-display); color: var(--cream);
}
.highlight-card .hl-stat { display: inline-flex; align-items: baseline; gap: 6px; }
.highlight-card .hl-num  { font-size: 36px; font-weight: 500; color: var(--accent); }
.highlight-card .hl-unit { font-size: 14px; color: var(--cream-mute); letter-spacing: 0.04em; }
.highlight-card .hl-sep  { color: var(--cream-mute); font-size: 22px; }
.highlight-card .hl-quotes {
  display: grid; grid-template-columns: 1fr 1fr; gap: 24px;
}
@media (max-width: 720px) {
  .highlight-card .hl-quotes { grid-template-columns: 1fr; }
}
.highlight-card .hl-quote {
  padding: 14px 16px;
  border: 1px solid var(--rule-soft);
  background: var(--paper);
}
.highlight-card .hl-quote.hl-up   { border-left: 2px solid var(--up); }
.highlight-card .hl-quote.hl-down { border-left: 2px solid var(--down); }
.highlight-card .hl-label {
  font-family: var(--font-display); font-size: 10px;
  letter-spacing: 0.16em; text-transform: uppercase;
  color: var(--cream-mute); display: block; margin-bottom: 8px;
}
.highlight-card .hl-up   .hl-label { color: var(--up); }
.highlight-card .hl-down .hl-label { color: var(--down); }
.highlight-card .hl-msg {
  font-family: var(--font-body); font-style: italic;
  font-size: 15px; line-height: 1.55; color: var(--cream);
  margin: 0 0 8px;
}
.highlight-card .hl-meta {
  font-family: var(--font-mono); font-size: 11px;
  color: var(--cream-mute); margin: 0;
  letter-spacing: 0.03em;
}

/* ─── Secret dialog (easter egg, revealed after 7 ! clicks) ─── */
.secret-dialog {
  border: 1px solid var(--rule);
  border-top: 3px solid var(--accent);
  background: var(--paper);
  color: var(--cream);
  padding: 36px 44px 32px;
  max-width: 480px;
  font-family: var(--font-body);
  box-shadow: 0 12px 40px rgba(0,0,0,0.5);
  position: relative;
}
.secret-dialog::backdrop {
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(4px);
}
.secret-dialog .secret-message {
  font-size: 19px; line-height: 1.7; margin: 0;
  font-style: italic; color: var(--cream);
  white-space: pre-wrap;
  font-family: "Newsreader", "PingFang SC", "Hiragino Sans GB",
               "Microsoft YaHei", Georgia, serif;
}
/* CJK glyphs render larger than Latin serif at the same font-size, so the
   showSecretMessage() JS wraps every Chinese run in <span class="secret-cjk">
   and we shrink it here. Tune the multiplier to taste. */
.secret-dialog .secret-cjk { font-size: 0.8em; }
/* **emphasized** runs (e.g. the punchline line) render at a bigger size and
   skip the CJK shrink, so the whole line — Latin, CJK, emoji — sits a notch
   above the body text. */
.secret-dialog .secret-emphasis { font-size: 0.95em; font-weight: 500; }
.secret-dialog .secret-close {
  position: absolute; top: 8px; right: 10px;
  background: transparent; color: var(--accent);
  /* Solid ♥ heart, scaled wider than tall via non-uniform transform —
     gives a bigger visual presence without a tall vertical footprint.
     Theme color via --accent: classic red (#d04841), pastel pink (#f09ead). */
  border: none; font-size: 26px; line-height: 1;
  cursor: pointer; padding: 4px 8px;
  outline: none;
  display: inline-block;
  transform: scaleY(0.82);
  transform-origin: center center;
}
.secret-dialog .secret-close:hover,
.secret-dialog .secret-close:focus,
.secret-dialog .secret-close:focus-visible {
  background: transparent; color: var(--accent);
  outline: none;
}

/* ─────────────────────────────────────────
   Stage 0: mode select (landing)
───────────────────────────────────────── */
.hero {
  max-width: 1080px; margin: 80px auto 96px; text-align: center;
  position: relative;
}
.hero .kicker {
  /* Demoted to a quiet eyebrow — smaller, more subtle, no all-caps shout */
  font-family: var(--font-mono); font-size: 10px;
  color: var(--cream-mute); letter-spacing: 0.24em;
  text-transform: uppercase; margin: 0 0 28px;
  font-weight: 500;
}
.hero h1 {
  font-family: var(--font-display);
  font-weight: 500; font-size: 68px; line-height: 1.05;
  margin: 0 0 32px; color: var(--cream-dim);   /* warm dim cream — softer than pure white in classic */
  letter-spacing: -0.015em;
}
.hero h1 em {
  font-style: italic; color: var(--accent);
  font-weight: 500;
}
/* In pastel mode, the whole h1 (e.g. "Ashley" + italic title) takes the
   accent pink AND italic so the name matches the rest of the line. */
[data-theme="soft"] .hero h1 { color: var(--accent); font-style: italic; }
.hero-sub {
  color: var(--cream-dim); font-size: 16px; line-height: 1.75;
  max-width: 620px; margin: 0 auto;
  font-family: var(--font-body);
}
.hero-sub + .hero-sub { margin-top: 16px; }
.hero-sub.muted {
  color: var(--cream-mute); font-style: italic; font-size: 14px;
}

.mode-grid {
  display: grid; gap: 20px;
  grid-template-columns: 1fr 1fr;
  max-width: 1180px; margin: 0 auto;
}
@media (max-width: 820px) { .mode-grid { grid-template-columns: 1fr; } }
/* Single-card variant — the second (online-analysis) card was removed for
   the gift build. Use one column and a tighter max-width so the lone card
   sits centered instead of hugging the left of a 2-column grid. */
.mode-grid--single { grid-template-columns: 1fr; max-width: 320px; }

/* Minimal CTA variant — single centered heading on a solid accent background
   so it reads clearly as a button in both palettes. Doubled-class selector
   gives higher specificity than .mode-card / .mode-card:hover below. */
.mode-card.mode-card--minimal {
  min-height: 0; padding: 12px 28px;
  align-items: center; justify-content: center;
  text-align: center; cursor: pointer;
  background: var(--accent);
  border: 1px solid var(--accent);
  transition: filter .18s, transform .18s, background .18s, border-color .18s;
}
.mode-card.mode-card--minimal:hover {
  background: var(--accent);
  border-color: var(--accent);
  filter: brightness(1.08);
  transform: translateY(-2px);
}
.mode-card.mode-card--minimal h2 {
  justify-content: center;
  font-size: 20px; letter-spacing: 0.18em;
  line-height: 1.1;
  margin: 0;
  color: #fff;                       /* high contrast on classic vermilion */
}
/* On pastel pink, white text drops below WCAG; use the dark ink instead. */
[data-theme="soft"] .mode-card.mode-card--minimal h2 { color: var(--ink); }
.mode-card {
  background: rgba(34,29,26,0.5);
  border: 1px solid var(--rule-soft);
  border-radius: 3px;
  padding: 56px 48px 44px;       /* generous editorial whitespace */
  display: flex; flex-direction: column; position: relative;
  transition: background .25s, border-color .25s, transform .25s;
  min-height: 460px;
}
@media (max-width: 820px) {
  .mode-card { padding: 36px 28px; min-height: 0; }
}
.mode-card:hover {
  background: rgba(var(--accent-rgb),0.04);
  border-color: rgba(var(--accent-rgb),0.28);
  transform: translateY(-2px);
}
.mode-num {
  font-family: var(--font-mono);
  font-size: 11px; font-weight: 500; letter-spacing: 0.22em;
  color: var(--cream-mute); margin-bottom: 24px;
}
.mode-card h2 {
  font-family: var(--font-display);
  font-size: 38px; font-weight: 500; margin: 0 0 14px;
  color: var(--cream); letter-spacing: -0.01em;
  display: flex; align-items: baseline; gap: 12px;
  flex-wrap: wrap;
}
.mode-card h2 .mode-sub {
  font-size: 15px; font-weight: 400;
  color: var(--cream-mute); font-style: italic;
  letter-spacing: 0.01em;
}
.mode-tagline {
  color: var(--cream-dim); margin: 0 0 32px;
  font-size: 15px; font-weight: 400;
  line-height: 1.7;
  font-family: var(--font-body);
}
.mode-card ul {
  padding-left: 0; list-style: none; color: var(--cream-dim);
  font-size: 14px; line-height: 1.85; flex: 1;
  font-family: var(--font-body); font-weight: 400;
}
.mode-card ul li {
  margin: 8px 0; padding-left: 22px; position: relative;
}
.mode-card ul li::before {
  content: "·"; position: absolute; left: 8px; top: -2px;
  color: var(--accent); font-size: 18px; line-height: 1;
  opacity: 0.6;
}
.mode-card ul li strong { color: var(--cream); font-weight: 600; }
.mode-card code, .form code, .hint-box code, .flow-hint code {
  background: var(--paper-2); color: var(--cream);
  padding: 1px 6px; border-radius: 0;
  font-family: var(--font-mono); font-size: 11.5px;
  border: 1px solid var(--rule-soft);
}
.flow-hint {
  background: rgba(var(--accent-rgb),0.05);
  border-left: 2px solid var(--accent);
  padding: 14px 18px; margin: 22px 0 6px;
  font-size: 13px; color: var(--cream-dim);
  font-family: var(--font-body);
  font-style: italic; line-height: 1.6;
  border-radius: 0 2px 2px 0;
}

/* History */
.history-wrap {
  max-width: 1280px; margin: 48px auto 0;
}
.history-title {
  display: flex; align-items: center; gap: 14px;
  font-family: var(--font-display);
  font-size: 16px; color: var(--cream-dim);
  letter-spacing: 0.18em; text-transform: uppercase;
  margin: 0 0 18px; text-align: center;
  justify-content: center;
}
.history-title .ht-line {
  flex: 1; height: 1px; max-width: 200px;
  background: linear-gradient(to right, transparent, var(--rule), transparent);
}
.history-list {
  display: flex; flex-direction: column;
  border-top: 1px solid var(--rule-soft);
}
.history-list .history-row {
  display: grid;
  grid-template-columns: 28px 1fr auto auto auto auto;
  gap: 14px; align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--rule-soft);
  font-size: 13px; color: var(--cream-dim);
  transition: background .15s;
}
.history-list .history-row:hover { background: rgba(var(--accent-rgb),0.03); }
.history-row .h-icon { font-size: 14px; }
.history-row .h-label {
  font-family: var(--font-display);
  font-size: 16px; color: var(--cream);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.history-row .h-meta {
  color: var(--cream-mute); font-size: 11px;
  font-family: var(--font-mono);
}
.history-row .h-id code {
  background: transparent; border: none; padding: 0;
  color: var(--cream-mute); font-size: 11px;
  font-family: var(--font-mono);
}
.history-row .h-open {
  background: transparent; color: var(--accent);
  border: 1px solid rgba(var(--accent-rgb),0.5); padding: 4px 14px;
  font: inherit; font-size: 12px; cursor: pointer;
  letter-spacing: 0.03em; border-radius: 3px;
  transition: background .15s, color .15s, border-color .15s;
}
.history-row .h-open:hover {
  background: var(--accent); color: #fff;
  border-color: var(--accent);
}
.history-row .h-del {
  background: transparent; border: none;
  color: var(--cream-mute); font-size: 16px;
  cursor: pointer; padding: 4px 8px; line-height: 1;
}
.history-row .h-del:hover { color: var(--accent); }
.history-empty {
  text-align: center; color: var(--cream-mute);
  font-style: italic; font-size: 12px;
  margin: 16px 0 0;
}
#resume-bar:not([hidden]) ~ #history-empty { display: none; }

.disclaimer-foot {
  max-width: 980px; margin: 56px auto 0;
  text-align: center;
  color: var(--cream-mute); font-size: 11px;
  font-family: var(--font-mono); letter-spacing: 0.06em;
}

/* ─────────────────────────────────────────
   Stage 1: forms (Skill / API)
───────────────────────────────────────── */
.form-wrap { max-width: 880px; margin: 0 auto; }
.form-wrap.narrow { max-width: 760px; }
.form-wrap h2 {
  margin: 18px 0 26px; font-family: var(--font-display);
  font-size: 38px; font-weight: 600; color: var(--cream);
  letter-spacing: 0.01em;
}
.back-link { margin-bottom: 18px; }
.back-link a {
  color: var(--cream-mute); text-decoration: none;
  font-size: 12px; font-family: var(--font-mono);
  letter-spacing: 0.05em;
}
.back-link a:hover { color: var(--gold); }
.ghost-link {
  display: inline-block; margin-top: 18px;
  color: var(--cream-mute); text-decoration: none;
  font-size: 12px; font-family: var(--font-mono);
}
.ghost-link:hover { color: var(--gold); }

.card {
  background: var(--paper);
  border: 1px solid var(--rule-soft);
  border-radius: 4px;
  padding: 40px 40px 32px;
  position: relative;
}
.card h2, .card h3 { margin-top: 0; }

.hint-box {
  background: rgba(var(--accent-rgb),0.04);
  border: 1px solid var(--rule-soft);
  border-left: 2px solid var(--accent);
  border-radius: 0 3px 3px 0;
  padding: 22px 26px; margin: 0 0 28px;
  font-size: 14px; color: var(--cream-dim); line-height: 1.75;
  font-family: var(--font-body);
}
.hint-box p { margin: 8px 0; }
.hint-box ol {
  padding-left: 26px; margin: 12px 0; color: var(--cream);
  font-weight: 400;
}
.hint-box ol li { margin: 7px 0; }
.hint-box code {
  background: var(--paper-2); color: var(--cream);
  padding: 2px 7px; border: 1px solid var(--rule-soft);
  font-size: 14px;
}
.hint-box strong { color: var(--cream); font-weight: 700; }

.form-section {
  margin: 22px 0 8px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--rule-soft);
  font-family: var(--font-display);
  font-size: 17px; color: var(--cream); font-weight: 500;
  letter-spacing: 0.01em;
}
.form-section:first-child { margin-top: 0; }

.form label {
  display: block; margin: 18px 0;
  font-size: 13px; color: var(--cream-dim);
  font-family: var(--font-mono); letter-spacing: 0.06em;
  text-transform: uppercase;
}
.form input, .form select {
  width: 100%; margin-top: 8px;
  background: var(--paper-2); color: var(--cream);
  border: 1px solid var(--rule); border-radius: 3px;
  padding: 12px 14px; font-size: 14px;
  font-family: var(--font-mono);
  letter-spacing: 0;
  transition: border-color .15s, box-shadow .15s;
}
.form input:focus, .form select:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(var(--accent-rgb),0.22);
}
.form select { cursor: pointer; }
.form .row { display: flex; gap: 14px; }
.form .row > label { flex: 1; }

.form label.custom-only { display: none; }
.form label.custom-only.show { display: block; }

details.advanced {
  margin: 22px 0 0;
  background: rgba(0,0,0,0.2);
  border: 1px solid var(--rule);
}
details.advanced summary {
  cursor: pointer;
  color: var(--cream); font-family: var(--font-display);
  font-size: 16px; font-weight: 500;
  list-style: none; outline: none;
  padding: 12px 16px;
}
details.advanced summary::-webkit-details-marker { display: none; }
details.advanced summary::before {
  content: "▸"; color: var(--gold); margin-right: 10px;
  display: inline-block; transition: transform .2s;
  font-size: 12px;
}
details.advanced[open] summary::before { transform: rotate(90deg); }
details.advanced .advanced-body {
  padding: 4px 16px 16px;
  border-top: 1px dashed var(--rule);
}
.kbd {
  display: inline-block; margin-left: 8px; padding: 1px 6px;
  background: var(--paper-2); color: var(--gold);
  font-size: 10px; border-radius: 0;
  font-family: var(--font-mono);
  border: 1px solid var(--rule-soft);
  text-transform: none;
}
.field-hint {
  display: block; margin-top: 6px;
  color: var(--cream-mute); font-size: 12px; line-height: 1.6;
  font-family: var(--font-body); font-weight: normal;
  text-transform: none; letter-spacing: 0;
}

/* Buttons */
button.primary {
  background: var(--accent); color: #fff;
  border: none; border-radius: 3px;
  padding: 11px 24px; cursor: pointer;
  font-size: 13px; font-family: var(--font-display);
  font-weight: 500; letter-spacing: 0.04em;
  transition: filter .15s, transform .1s, box-shadow .15s;
}
button.primary:hover {
  filter: brightness(1.08);
  box-shadow: 0 0 0 3px rgba(var(--accent-rgb),0.22);
}
button.primary:active { transform: translateY(1px); }
button.primary.big {
  width: 100%; padding: 16px;
  font-size: 15px; margin-top: 28px;
  letter-spacing: 0.06em;
  font-weight: 500;
  border-radius: 3px;
}
button.ghost {
  background: transparent;
  border: 1px solid var(--rule); color: var(--cream-dim);
  border-radius: 3px; padding: 8px 16px; cursor: pointer;
  font: inherit; font-family: var(--font-body);
  font-size: 13px; font-weight: 400; letter-spacing: 0.02em;
  transition: color .15s, border-color .15s, background .15s;
}
button.ghost:hover {
  color: var(--cream); border-color: var(--cream-mute);
  background: rgba(240,232,219,0.03);
}
button.ghost.small {
  padding: 4px 12px; font-size: 11px;
  font-family: var(--font-mono); font-weight: 400;
  letter-spacing: 0.04em; color: var(--cream-mute);
}
button.ghost.small:hover { background: transparent; color: var(--cream); border-color: var(--cream-mute); }

.error-box {
  margin-top: 16px; color: var(--err); font-size: 13px;
  font-family: var(--font-body);
}
.err-headline {
  font-size: 14px; line-height: 1.5; color: var(--err);
  margin-bottom: 12px;
}
.err-detail {
  margin: 12px 0; padding: 10px;
  background: var(--paper-2); border: 1px solid var(--rule);
  color: var(--cream-mute);
}
.err-detail summary {
  cursor: pointer; font-size: 12px; color: var(--cream-mute);
  font-family: var(--font-mono);
}
.err-detail pre {
  margin: 8px 0 0; padding: 10px;
  background: var(--ink); color: var(--cream);
  font-size: 11px; font-family: var(--font-mono);
  max-height: 200px; overflow: auto;
  white-space: pre-wrap; word-break: break-word;
  border: 1px solid var(--rule-soft);
}
.err-actions { display: flex; gap: 10px; margin-top: 14px; align-items: center; }
.err-actions a { text-decoration: none; }
.err-actions .primary {
  background: var(--vermilion); color: var(--cream);
  padding: 7px 16px; font-family: var(--font-display);
  font-weight: 600; letter-spacing: 0.05em; font-size: 12px;
}
.err-actions .ghost {
  border: 1px solid var(--rule); color: var(--cream-dim);
  padding: 7px 16px; font-size: 12px;
  font-family: var(--font-mono);
}

/* ─────────────────────────────────────────
   Stage 2: progress
───────────────────────────────────────── */
.progress-card {
  max-width: 640px; margin: 80px auto;
  text-align: center;
  background: var(--paper); border: 1px solid var(--rule-soft);
  border-radius: 4px;
  padding: 44px 44px 36px; position: relative;
}
.progress-card h2 {
  font-family: var(--font-display); font-size: 28px;
  font-weight: 500; margin: 0 0 10px; color: var(--cream);
  letter-spacing: -0.01em;
}
.bar-wrap { margin: 28px 0 14px; }
.bar {
  height: 4px; background: var(--paper-2);
  border: none; border-radius: 2px;
  overflow: hidden;
}
.bar-fill {
  height: 100%; width: 0;
  background: var(--accent);
  transition: width .4s ease;
  border-radius: 2px;
}
.bar-label {
  margin-top: 10px; color: var(--cream-mute);
  font-size: 12px; font-family: var(--font-mono);
  letter-spacing: 0.05em;
}
.stage-line {
  color: var(--cream-dim); font-size: 13px;
  margin-bottom: 8px; font-family: var(--font-body);
}
.stage-line code {
  font-family: var(--font-mono); font-size: 12px;
  background: var(--paper-2); padding: 2px 8px;
  border: 1px solid var(--rule-soft); color: var(--gold);
}
.job-info {
  display: flex; gap: 28px; justify-content: center;
  color: var(--cream-mute); font-size: 11px;
  font-family: var(--font-mono); margin: 18px 0 0;
}
.job-info code {
  background: var(--paper-2); color: var(--cream);
  padding: 2px 8px; border: 1px solid var(--rule-soft);
}

/* ─────────────────────────────────────────
   Stage 3: candlestick chart (keep all selectors)
───────────────────────────────────────── */
.chart-toolbar {
  display: flex; align-items: center; gap: 14px;
  padding: 10px 18px;
  background: var(--paper);
  border-bottom: 1px solid var(--rule);
  flex: 0 0 auto;
}
.tf-group {
  display: flex; gap: 0;
  background: var(--paper-2);
  border: 1px solid var(--rule); border-radius: 0;
}
.tf {
  background: transparent; color: var(--cream-mute);
  border: none; border-right: 1px solid var(--rule-soft);
  padding: 6px 12px; cursor: pointer;
  font-size: 11px; font-family: var(--font-mono);
  letter-spacing: 0.04em; min-width: 38px;
  transition: color .15s, background .15s;
}
.tf:last-child { border-right: none; }
.tf:hover { color: var(--cream); }
.tf.active { background: var(--vermilion); color: var(--cream); }

.meta {
  flex: 1; color: var(--cream-mute);
  font-size: 11.5px; font-family: var(--font-mono);
  letter-spacing: 0.04em;
}

.chart-host { flex: 1; position: relative; background: var(--chart-bg); }
.chart-pane { position: absolute; inset: 0; }

/* hover legend */
.legend {
  position: absolute; top: 14px; left: 18px;
  background: rgba(13,12,10,0.94);             /* classic ink-tinted */
  padding: 12px 16px;
  border: 1px solid var(--rule); border-radius: 0;
  font-size: 12px; line-height: 1.7;
  pointer-events: none;
  font-family: var(--font-mono); font-variant-numeric: tabular-nums;
  max-width: 380px; z-index: 10;
  border-left: 2px solid var(--gold);
}
[data-theme="soft"] .legend { background: rgba(42,24,32,0.94); }
.legend .row { display: flex; gap: 10px; }
.legend .k {
  color: var(--cream-mute); width: 56px; flex-shrink: 0;
  letter-spacing: 0.05em; font-size: 11px;
}
.legend .v { color: var(--cream); }
.legend .v.up { color: var(--up); }
.legend .v.down { color: var(--down); }
.legend .legend-section-title {
  margin-top: 8px; padding-top: 6px;
  border-top: 1px solid var(--rule-soft);
  color: var(--gold); font-size: 10px;
  letter-spacing: 0.18em; text-transform: uppercase;
  font-family: var(--font-display); font-weight: 500;
}
.legend .dim-row { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 4px; }
.legend .dim-chip {
  display: inline-block; padding: 1px 7px;
  background: var(--paper-2); color: var(--cream);
  font-size: 11px; border: 1px solid var(--rule-soft);
}
.legend .dim-chip.up   { color: var(--up);   border-color: rgba(var(--up-rgb),0.5); }
.legend .dim-chip.down { color: var(--down); border-color: rgba(var(--down-rgb),0.5); }
.legend .evt {
  margin-top: 5px; padding: 4px 0;
  border-bottom: 1px dashed var(--rule-soft); font-size: 11px;
}
.legend .evt:last-child { border-bottom: none; }
.legend .evt-meta { color: var(--cream-mute); margin-right: 4px; }
.legend .evt-msg  { color: var(--cream); }
.legend .evt-tail { display: flex; gap: 6px; align-items: baseline; margin-top: 2px; }
.legend .evt-rat  {
  color: var(--cream-mute); font-size: 11px; line-height: 1.4;
  font-family: var(--font-body);
}
/* Inline sub-heading inside the "Key moments" block — splits the list into
   "▲ Lifts" (positive deltas) and "▼ Hits" (negative deltas). Lighter than
   .legend-section-title because it's a sub-section, not a section. */
.legend .evt-side-label {
  margin-top: 6px; font-size: 10px;
  letter-spacing: 0.12em; text-transform: uppercase;
  font-family: var(--font-display); font-weight: 500;
}
.legend .evt-side-label.up   { color: var(--up); }
.legend .evt-side-label.down { color: var(--down); }
/* Reset the last-child rule scoped to the global list — sub-labels split it
   into two visual groups, so each group's final .evt should also drop its
   trailing dashed rule. */
.legend .evt-side-label + .evt { border-top: none; }

/* ─── Key-moments popover ───
   Floating panel for the long "Key moments" list. JS sets top/left so it
   appears next to the chart cursor (auto-flips to the left near the chart's
   right edge). pointer-events: auto means the chart's crosshair handler stops
   firing the moment the cursor enters it — the panel freezes in place and
   the user can scroll without the content shifting under them. */
.key-rail {
  position: absolute;                           /* top/left set by JS */
  width: 340px;
  display: flex; flex-direction: column;
  background: rgba(13,12,10,0.96);
  border: 1px solid var(--rule);
  border-left: 2px solid var(--gold);           /* echoes #legend's accent */
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  pointer-events: auto;
  z-index: 11;                                  /* above #legend (z:10) when they overlap */
  box-shadow: 0 6px 24px rgba(0,0,0,0.4);
}
/* Override the display:flex above when the rail is hidden — otherwise the
   HTML `hidden` attribute (which only sets `display: none` at user-agent
   priority) loses to our more-specific rule, and the "KEY MOMENTS" header
   stays visible when the popover should be closed. */
.key-rail[hidden] { display: none; }
[data-theme="soft"] .key-rail { background: rgba(42,24,32,0.96); }
.key-rail-body {
  flex: 1 1 auto; overflow-y: auto;
  padding: 14px 16px 18px;
}
.key-rail-header {
  padding-bottom: 8px;
  margin-bottom: 6px;
  border-bottom: 1px solid var(--rule-soft);
  display: flex; align-items: baseline; justify-content: space-between; gap: 10px;
}
.key-rail-title {
  font-family: var(--font-display); font-weight: 500;
  font-size: 11px; letter-spacing: 0.18em;
  text-transform: uppercase; color: var(--gold);
}
.key-rail-time {
  font-size: 10.5px; color: var(--cream-mute);
}
.key-rail-content { font-size: 12px; line-height: 1.55; }
.key-rail-content .evt { margin-top: 6px; padding: 5px 0;
  border-bottom: 1px dashed var(--rule-soft); font-size: 11.5px; }
.key-rail-content .evt:last-child { border-bottom: none; }
.key-rail-content .evt-meta { color: var(--cream-mute); margin-right: 4px; }
.key-rail-content .evt-msg  { color: var(--cream); }
.key-rail-content .evt-tail { display: flex; flex-wrap: wrap; gap: 6px;
  align-items: baseline; margin-top: 3px; }
.key-rail-content .evt-rat  { color: var(--cream-mute); font-size: 11px;
  line-height: 1.45; font-family: var(--font-body); }
.key-rail-content .evt-side-label {
  margin-top: 10px; font-size: 10px;
  letter-spacing: 0.12em; text-transform: uppercase;
  font-family: var(--font-display); font-weight: 500;
}
.key-rail-content .evt-side-label.up   { color: var(--up); }
.key-rail-content .evt-side-label.down { color: var(--down); }
.key-rail-content .evt-side-label + .evt { border-top: none; }
.key-rail-content .key-rail-empty {
  color: var(--cream-mute); font-style: italic; margin: 8px 0 0;
  font-family: var(--font-body);
}
.key-rail-content .dim-chip {
  display: inline-block; padding: 1px 7px;
  background: var(--paper-2); color: var(--cream);
  font-size: 11px; border: 1px solid var(--rule-soft);
}
.key-rail-content .dim-chip.up   { color: var(--up);   border-color: rgba(var(--up-rgb),0.5); }
.key-rail-content .dim-chip.down { color: var(--down); border-color: rgba(var(--down-rgb),0.5); }

/* Indicator toolbar */
.ind-toolbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 16px;
  padding: 8px 18px;
  background: var(--paper);
  border-bottom: 1px solid var(--rule);
  flex: 0 0 auto;
  font-size: 12px; font-family: var(--font-mono);
}
.ind-chk {
  display: inline-flex; align-items: center; gap: 6px;
  color: var(--cream); cursor: pointer; user-select: none;
  letter-spacing: 0.03em;
}
.ind-chk input[type="checkbox"] {
  accent-color: var(--vermilion); cursor: pointer;
  width: 13px; height: 13px;
}
.ind-input {
  background: var(--paper-2); color: var(--cream);
  border: 1px solid var(--rule); border-radius: 0;
  padding: 3px 7px; font: inherit; font-size: 11px;
  font-family: var(--font-mono);
}
.ind-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px rgba(var(--accent-rgb),0.22); }
.ind-apply {
  margin-left: auto;
  background: var(--accent); color: #fff;
  border: none; padding: 6px 18px; cursor: pointer;
  font: inherit; font-family: var(--font-display);
  font-weight: 500; font-size: 12px; letter-spacing: 0.04em;
  border-radius: 3px;
  transition: filter .15s, box-shadow .15s;
}
.ind-apply:hover { filter: brightness(1.08); box-shadow: 0 0 0 2px rgba(var(--accent-rgb),0.22); }

/* MACD/RSI/KDJ panes are rendered by lightweight-charts v5 natively — no extra styles needed */

/* Scrollbar styling */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--ink); }
::-webkit-scrollbar-thumb { background: var(--rule); border-radius: 0; }
::-webkit-scrollbar-thumb:hover { background: var(--gold); }
