/* ============================================
   TRADING JOURNAL — Design Tokens
   fbfrr-inspired · dark slate · purple accent
   ============================================ */

:root {
  /* ---------- DARK — fbfrr exact: #171f2e / #1a2231 ---------- */
  --bg-0: #171f2e;           /* dark-primary (fbfrr exact) */
  --bg-1: #1a2231;           /* dark-secondary (fbfrr exact) */
  --bg-2: #1e2840;           /* raised panel */
  --bg-3: #243050;           /* hover / selected row */
  --bg-4: #2d3a60;           /* chip bg */

  --line-1: rgba(255,255,255,0.07);  /* subtle hairline — gray-800 fbfrr */
  --line-2: rgba(255,255,255,0.10);  /* stronger divider */
  --line-3: rgba(255,255,255,0.15);  /* input border */

  --ink-0: rgba(255,255,255,0.92);   /* primary text — white/92 */
  --ink-1: rgba(255,255,255,0.72);   /* body — white/72 */
  --ink-2: #9ca3af;          /* muted — gray-400 (fbfrr exact) */
  --ink-3: #6b7280;          /* dimmer — gray-500 (fbfrr exact) */
  --ink-4: #4b5563;          /* disabled — gray-600 */

  --pos: #12b76a;            /* green — fbfrr success-600 */
  --pos-bg: rgba(18, 183, 106, 0.10);
  --pos-dim: #054f31;
  --neg: #f04438;            /* red — fbfrr error-500 */
  --neg-bg: rgba(240, 68, 56, 0.10);
  --neg-dim: #7a271a;
  --warn: #f59e0b;
  --warn-bg: rgba(245, 158, 11, 0.10);
  --info: #3b82f6;           /* blue — data viz only */
  --info-bg: rgba(59, 130, 246, 0.10);

  --accent: #7a5af8;         /* purple — primary accent (fbfrr) */
  --accent-dim: #6938ef;
  --accent-bg: rgba(122, 90, 248, 0.08);
  --accent-border: rgba(122, 90, 248, 0.25);
  --accent-ink: #ffffff;

  /* Type */
  --ff-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --ff-sans: 'Onest', 'Inter', system-ui, -apple-system, sans-serif;
  --ff-serif: 'Onest', system-ui, sans-serif;
  --ff-display: 'Onest', system-ui, sans-serif;
  --ff-jp: 'Onest', system-ui, sans-serif;

  --fs-9: 11px;
  --fs-10: 12px;
  --fs-11: 13px;
  --fs-12: 14px;
  --fs-13: 15px;
  --fs-14: 16px;
  --fs-15: 17px;
  --fs-16: 18px;
  --fs-18: 20px;
  --fs-20: 22px;
  --fs-24: 26px;
  --fs-28: 30px;
  --fs-36: 38px;
  --fs-48: 50px;
  --fs-64: 66px;

  --lh-tight: 1.08;
  --lh-snug: 1.25;
  --lh-body: 1.5;

  /* Spacing (4px base) */
  --s-1: 2px;
  --s-2: 4px;
  --s-3: 6px;
  --s-4: 8px;
  --s-5: 10px;
  --s-6: 12px;
  --s-7: 14px;
  --s-8: 16px;
  --s-10: 20px;
  --s-12: 24px;
  --s-16: 32px;
  --s-20: 40px;
  --s-24: 48px;

  /* Density knob — compact by default for desk use */
  --row-h: 28px;
  --panel-pad: 12px;

  /* Radii — soft but sharp */
  --r-0: 0px;
  --r-1: 4px;
  --r-2: 8px;
  --r-3: 10px;
  --r-pill: 999px;

  /* Elevation */
  --sh-1: 0 1px 0 rgba(255,255,255,0.02) inset, 0 1px 2px rgba(0,0,0,0.45);
  --sh-2: 0 10px 30px rgba(0,0,0,0.65);
  --glow-accent: 0 0 0 1px rgba(122,90,248,0.25), 0 0 20px rgba(122,90,248,0.18);
  --glow-neg:    0 0 0 1px rgba(255,59,92,0.25),  0 0 20px rgba(255,59,92,0.18);

  /* Motion */
  --ease: cubic-bezier(.2,.6,.2,1);
  --dur-1: 120ms;
  --dur-2: 240ms;

  /* Chart */
  --grid: rgba(255,255,255,0.04);

  /* Material Design 3 aliases → fbfrr tokens (for pages that use --md-sys-color-*) */
  --md-sys-color-secondary-container: var(--accent-bg);
  --md-sys-color-on-secondary-container: var(--accent);
  --md-sys-color-error: var(--neg);
  --md-sys-color-error-container: var(--neg-bg);
  --md-sys-color-on-error-container: var(--neg);
  --md-sys-color-on-surface-variant: var(--ink-2);
  --md-sys-color-surface-bright: var(--bg-2);
}

/* ---------- LIGHT ---------- */
[data-theme="light"] {
  --bg-0: #F8FAFC;
  --bg-1: #FFFFFF;
  --bg-2: #F4F3FF;           /* fbfrr primary-50 tint */
  --bg-3: #E8EBEE;
  --bg-4: #DEE2E6;

  --line-1: #E6E9EC;
  --line-2: #D4D9DE;
  --line-3: #BAC0C7;

  --ink-0: #0A0C0F;
  --ink-1: #1C2128;
  --ink-2: #4E545D;
  --ink-3: #7A828D;
  --ink-4: #B2B9C2;

  --pos: #027A48;            /* fbfrr success dark */
  --pos-bg: rgba(2, 122, 72, 0.10);
  --pos-dim: #014838;
  --neg: #B42318;            /* fbfrr error dark */
  --neg-bg: rgba(180, 35, 24, 0.08);
  --neg-dim: #7A2318;
  --warn: #B87300;
  --warn-bg: rgba(184, 115, 0, 0.10);
  --info: #0070D4;
  --info-bg: rgba(0, 112, 212, 0.08);

  --accent: var(--info);
  --accent-ink: #FFFFFF;

  --grid: rgba(0,0,0,0.05);

  --sh-1: 0 1px 0 rgba(0,0,0,0.02), 0 1px 3px rgba(0,0,0,0.06);
  --sh-2: 0 12px 32px rgba(0,0,0,0.10);
  --glow-accent: 0 0 0 2px rgba(0,112,212,0.18);
}

/* Density variants */
[data-density="compact"] {
  --row-h: 26px;
  --panel-pad: 10px;
}
[data-density="comfortable"] {
  --row-h: 40px;
  --panel-pad: 22px;
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }
html, body, #app { height: 100%; }
body {
  margin: 0;
  background-color: var(--bg-0);
  /* Subtle global grid — 48px, very low opacity */
  background-image:
    linear-gradient(rgba(255,255,255,0.018) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.018) 1px, transparent 1px);
  background-size: 48px 48px;
  color: var(--ink-1);
  font-family: var(--ff-sans);
  font-size: var(--fs-13);
  line-height: var(--lh-body);
  /* Match Hyperliquid-style rendering: cv11 (alt 4/6/9), ss01 (alt a), tnum for numbers */
  font-feature-settings: "cv11", "ss01", "ss03";
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  font-feature-settings: "ss01", "cv11", "tnum";
  position: relative;
}

/* ============================================
   AMBIENT CYBERPUNK BACKGROUND
   Layered: city grid + magenta/teal glow + noise
   Sits behind everything via body::before
   ============================================ */
/* ============================================
   Ambient now painted on body{} directly for
   robust cross-renderer capture. Pseudo kept empty.
   ============================================ */
body::before { content: none; }

@keyframes bg-drift {
  0%   { background-position: 0 0, 0 0, 0 0, 0 0, 0 0, 0 0, 0 0, 0 0; }
  100% { background-position: 0 0, 0 0, 0 0, 96px 96px, 96px 96px, 96px 96px, 96px 96px, 0 0; }
}

/* Scan lines removed — they add visual noise that tires eyes on long sessions */
body::after { content: none; }

@keyframes sweep {
  0%, 100% { background-position: 0% 0; }
  50%      { background-position: 100% 0; }
}

/* Light mode: softer, warmer ambient */
[data-theme="light"] body::before {
  background:
    radial-gradient(ellipse 80vw 60vh at 85% -5%, rgba(255, 0, 170, 0.06), transparent 55%),
    radial-gradient(ellipse 70vw 50vh at 15% 105%, rgba(0, 112, 212, 0.08), transparent 55%),
    linear-gradient(rgba(0, 0, 0, 0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0, 0, 0, 0.025) 1px, transparent 1px),
    var(--bg-0);
  background-size: auto, auto, 16px 16px, 16px 16px, auto;
}

/* Ensure app chrome sits above ambient bg */
#app { position: relative; z-index: 1; }

/* Keep main transparent so ambient bg shows through negative space,
   but DO NOT force section/aside transparent — let Tailwind bg utilities work. */
main { background: transparent !important; }

/* Explicit framework panel containers stay solid dark for readability */
.panel, .panel-body, [data-opaque] {
  background-color: var(--bg-1);
}

.mono { font-family: var(--ff-mono); font-feature-settings: "tnum", "zero"; }
.serif { font-family: var(--ff-serif); }
.num { font-family: var(--ff-mono); font-variant-numeric: tabular-nums; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.warn { color: var(--warn); }
.ink-0 { color: var(--ink-0); }
.ink-1 { color: var(--ink-1); }
.ink-2 { color: var(--ink-2); }
.ink-3 { color: var(--ink-3); }

.up::before { content: '▲ '; font-size: 0.8em; }
.dn::before { content: '▼ '; font-size: 0.8em; }

.label {
  font-family: var(--ff-mono);
  font-size: var(--fs-10);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-3);
  font-weight: 500;
}
.label-sm { font-size: var(--fs-9); }

.h-display {
  font-family: var(--ff-display);
  font-weight: 800;
  font-size: var(--fs-48);
  line-height: 0.95;
  letter-spacing: -0.035em;
  color: var(--ink-0);
}
.h-display em { font-style: italic; color: var(--ink-2); }

.h-1 { font-family: var(--ff-display); font-size: var(--fs-24); font-weight: 800; color: var(--ink-0); letter-spacing: -0.025em; line-height: 1.05; }
.h-2 { font-family: var(--ff-display); font-size: var(--fs-18); font-weight: 700; color: var(--ink-0); letter-spacing: -0.02em; line-height: 1.1; }
.h-3 { font-family: var(--ff-display); font-size: var(--fs-14); font-weight: 700; color: var(--ink-0); letter-spacing: -0.01em; }

/* ---------- Panel ---------- */
.panel {
  background: var(--bg-1);
  border: 1px solid var(--line-1);
  border-radius: var(--r-2);
}
.panel-pad { padding: var(--panel-pad); }
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-8);
  padding: var(--s-6) var(--panel-pad);
  border-bottom: 1px solid var(--line-1);
  min-height: 40px;
}
.panel-head .title {
  font-family: var(--ff-mono);
  font-size: var(--fs-11);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-2);
  font-weight: 500;
}

/* ---------- Button — Fluent 2 design system (dark mode) ---------- */
/* ref: github.com/x-316/fbfgf — border-radius 4px, flat solid, inner stroke */
:root {
  --btn-acc-rest:    #7a5af8;
  --btn-acc-hover:   #8b6ef9;
  --btn-acc-press:   #6038ef;
  --btn-acc-ink:     #ffffff;
  --btn-sec-bg:      var(--bg-2);
  --btn-sec-border:  var(--line-3);
  --btn-sec-hover:   var(--bg-3);
  --btn-sec-press:   var(--bg-4);
  --btn-r:           4px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 32px;
  padding: 0 12px;
  border: 1px solid var(--btn-sec-border);
  background: var(--btn-sec-bg);
  color: var(--ink-0);
  font-family: 'Onest', system-ui, sans-serif;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0;
  text-transform: none;
  border-radius: var(--btn-r);
  cursor: pointer;
  transition: background 100ms ease, border-color 100ms ease, color 100ms ease;
  user-select: none;
  text-decoration: none;
  white-space: nowrap;
  position: relative;
}
.btn:hover  { background: var(--btn-sec-hover); border-color: var(--line-3); }
.btn:active { background: var(--btn-sec-press); border-color: var(--line-2); }

/* Primary — accent solid + inner stroke (Fluent 2 signature) */
.btn-primary {
  background: var(--btn-acc-rest);
  border: 1px solid transparent;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.12);
  color: var(--btn-acc-ink);
  font-weight: 600;
}
.btn-primary:hover  { background: var(--btn-acc-hover); border-color: transparent; }
.btn-primary:active { background: var(--btn-acc-press); border-color: transparent; }

/* Ghost / subtle — no border at rest */
.btn-ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn-ghost:hover  { background: rgba(255,255,255,0.06); color: var(--ink-0); border-color: var(--line-2); }
.btn-ghost:active { background: rgba(255,255,255,0.10); border-color: var(--line-2); }

/* Danger */
.btn-danger { color: var(--neg); border-color: var(--neg-dim); background: transparent; }
.btn-danger:hover  { background: var(--neg-bg); border-color: var(--neg); }
.btn-danger:active { background: rgba(240,68,56,0.18); }

/* Success */
.btn-success { background: var(--pos); color: #fff; border-color: transparent; box-shadow: inset 0 0 0 1px rgba(255,255,255,0.1); }
.btn-success:hover  { background: #14cc78; border-color: transparent; }
.btn-success:active { background: #0e9a5a; }

/* Warn */
.btn-warn { background: var(--warn-bg); color: var(--warn); border-color: rgba(245,158,11,0.30); }
.btn-warn:hover  { background: rgba(245,158,11,0.18); border-color: var(--warn); }
.btn-warn:active { background: rgba(245,158,11,0.25); }

/* Sizes — Fluent 2: sm=26px, md=32px (default), lg=40px */
.btn-xs   { height: 24px; padding: 0  8px; font-size: 12px; gap: 4px; }
.btn-sm   { height: 26px; padding: 0 10px; font-size: 12px; }
.btn-lg   { height: 40px; padding: 0 20px; font-size: 14px; }
.btn-icon { width: 32px; height: 32px; padding: 0; }
.btn-icon.btn-sm { width: 26px; height: 26px; }
.btn-icon.btn-lg { width: 40px; height: 40px; }
.btn-full { width: 100%; height: 40px; font-size: 14px; }

/* Focus ring — Fluent 2: 2px solid outside */
.btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Disabled */
.btn:disabled, .btn[disabled], .btn[aria-disabled="true"] {
  opacity: 0.38;
  cursor: not-allowed;
  pointer-events: none;
}

/* Loading spinner */
.btn.is-loading { color: transparent !important; pointer-events: none; }
.btn.is-loading::after {
  content: '';
  position: absolute;
  inset: 0;
  margin: auto;
  width: 14px;
  height: 14px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: btn-spin 0.6s linear infinite;
}
.btn-primary.is-loading::after { border-color: #fff; border-top-color: transparent; }
@keyframes btn-spin { to { transform: rotate(360deg); } }

/* Touch: expand hit area */
@media (pointer: coarse) {
  .btn      { min-height: 44px; }
  .btn-xs   { min-height: 36px; }
  .btn-icon { min-width: 44px; min-height: 44px; }
}

/* ---------- Pill / tag ---------- */
.pill {
  display: inline-flex;
  align-items: center;
  gap: var(--s-3);
  height: 18px;
  padding: 0 var(--s-5);
  font-family: var(--ff-mono);
  font-size: var(--fs-10);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  background: var(--bg-4);
  color: var(--ink-1);
  border-radius: var(--r-1);
  font-weight: 500;
}
.pill.pos { background: var(--pos-bg); color: var(--pos); }
.pill.neg { background: var(--neg-bg); color: var(--neg); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.info { background: var(--info-bg); color: var(--info); }
.pill .dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 0 2px currentColor;
  opacity: .9;
}
.dot-live { animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(0.85); }
}

/* ---------- Input ---------- */
.input, .select, .textarea {
  background: var(--bg-2);
  border: 1px solid var(--line-2);
  color: var(--ink-0);
  font-family: var(--ff-mono);
  font-size: var(--fs-12);
  padding: 0 var(--s-8);
  height: 32px;
  border-radius: var(--r-1);
  outline: none;
  transition: all var(--dur-1) var(--ease);
  width: 100%;
}
.textarea {
  padding: var(--s-8);
  height: auto;
  min-height: 80px;
  font-family: var(--ff-sans);
  font-size: var(--fs-13);
  line-height: 1.5;
  resize: vertical;
}
.input:focus, .select:focus, .textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}
.input::placeholder, .textarea::placeholder { color: var(--ink-3); }

/* Segmented control */
.seg {
  display: inline-flex;
  border: 1px solid var(--line-2);
  border-radius: var(--r-1);
  background: var(--bg-2);
  padding: 2px;
  gap: 2px;
}
.seg button {
  appearance: none;
  background: transparent;
  border: 0;
  color: var(--ink-2);
  font-family: var(--ff-mono);
  font-size: var(--fs-10);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 4px 10px;
  cursor: pointer;
  border-radius: var(--r-1);
  transition: all var(--dur-1) var(--ease);
}
.seg button.active {
  background: var(--bg-4);
  color: var(--ink-0);
}

/* ---------- Table ---------- */
.tbl {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-12);
}
.tbl th {
  text-align: left;
  font-family: var(--ff-mono);
  font-size: var(--fs-10);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-3);
  font-weight: 500;
  padding: var(--s-5) var(--s-8);
  border-bottom: 1px solid var(--line-1);
  background: var(--bg-1);
  position: sticky;
  top: 0;
  z-index: 1;
  white-space: nowrap;
}
.tbl td {
  padding: var(--s-5) var(--s-8);
  border-bottom: 1px solid var(--line-1);
  height: var(--row-h);
  vertical-align: middle;
  color: var(--ink-1);
}
.tbl tbody tr { transition: background var(--dur-1) var(--ease); }
.tbl tbody tr:hover { background: var(--bg-2); cursor: pointer; }
.tbl tbody tr.sel { background: var(--bg-3); }
.tbl .num, .tbl td.num { text-align: right; }
.tbl .num { font-family: var(--ff-mono); font-variant-numeric: tabular-nums; }

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: var(--r-pill); }
::-webkit-scrollbar-thumb:hover { background: rgba(122,90,248,0.30); }

/* Utility */
.row { display: flex; align-items: center; }
.col { display: flex; flex-direction: column; }
.gap-2 { gap: var(--s-2); } .gap-3 { gap: var(--s-3); }
.gap-4 { gap: var(--s-4); } .gap-6 { gap: var(--s-6); }
.gap-8 { gap: var(--s-8); } .gap-12 { gap: var(--s-12); } .gap-16 { gap: var(--s-16); }
.grow { flex: 1; } .shrink-0 { flex-shrink: 0; }
.between { justify-content: space-between; }
.center { justify-content: center; align-items: center; }
.end { justify-content: flex-end; }
.wrap { flex-wrap: wrap; }

/* Ticker */
.ticker {
  overflow: hidden;
  position: relative;
  border-bottom: 1px solid var(--line-1);
  background: var(--bg-1);
  height: 26px;
  display: flex;
  align-items: center;
}
.ticker-track {
  display: flex;
  gap: var(--s-16);
  padding-left: var(--s-8);
  animation: ticker 80s linear infinite;
  white-space: nowrap;
}
@keyframes ticker {
  from { transform: translateX(0); }
  to { transform: translateX(-50%); }
}
.ticker-item {
  display: inline-flex;
  gap: var(--s-4);
  align-items: center;
  font-family: var(--ff-mono);
  font-size: var(--fs-11);
  color: var(--ink-2);
}
.ticker-item .sym { color: var(--ink-0); font-weight: 500; letter-spacing: 0.04em; }

/* Bar series (equity curve style) */
.spark-wrap { position: relative; width: 100%; height: 100%; }
.spark-wrap svg { display: block; width: 100%; height: 100%; overflow: visible; }

/* Soft divider between cells */
.vr { width: 1px; align-self: stretch; background: var(--line-1); }
.hr { height: 1px; width: 100%; background: var(--line-1); }

/* Selection */
::selection { background: var(--accent); color: var(--accent-ink); }

/* Focus rings for a11y */
:focus-visible { outline: 1px solid var(--accent); outline-offset: 2px; }

/* Kbd */
kbd {
  font-family: var(--ff-mono);
  font-size: var(--fs-10);
  background: var(--bg-3);
  border: 1px solid var(--line-2);
  border-bottom-width: 2px;
  padding: 1px 5px;
  border-radius: var(--r-1);
  color: var(--ink-1);
}

/* Bot status dot with glow */
.status-dot {
  width: 8px; height: 8px; border-radius: 50%;
  display: inline-block; flex-shrink: 0;
}
.status-dot.live { background: var(--pos); box-shadow: 0 0 0 2px var(--pos-bg); }
.status-dot.paper { background: var(--info); box-shadow: 0 0 0 2px var(--info-bg); }
.status-dot.paused { background: var(--warn); box-shadow: 0 0 0 2px var(--warn-bg); }
.status-dot.off { background: var(--ink-4); }
.status-dot.error { background: var(--neg); box-shadow: 0 0 0 2px var(--neg-bg); animation: pulse 1.6s infinite; }

/* Dense grid lines helper */
.grid-bg {
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 24px 24px;
}

/* ============================================
   CYBERPUNK / GHOST IN THE SHELL ACCENTS
   ============================================ */

/* Display type — Eva-style condensed bold */
.h-display-jp {
  font-family: var(--ff-display);
  font-weight: 700;
  font-size: 56px;
  line-height: 0.92;
  letter-spacing: -0.02em;
  text-transform: uppercase;
  color: var(--ink-0);
}
.h-display-jp em {
  font-style: normal;
  color: var(--accent);
  font-family: var(--ff-display);
}

.display-cond {
  font-family: var(--ff-display);
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  line-height: 1;
}

/* Japanese katakana label — small accent text */
.jp {
  font-family: var(--ff-jp);
  font-weight: 500;
  letter-spacing: 0.04em;
}
.jp-sm {
  font-family: var(--ff-jp);
  font-size: 10px;
  color: var(--ink-3);
  letter-spacing: 0.08em;
  font-weight: 500;
}

/* City-grid background — for hero / login / empty states */
.city-grid {
  position: relative;
  background-color: var(--bg-0);
  background-image:
    linear-gradient(rgba(122,90,248,0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(122,90,248,0.04) 1px, transparent 1px),
    linear-gradient(rgba(105,56,239,0.02) 1px, transparent 1px),
    linear-gradient(90deg, rgba(105,56,239,0.02) 1px, transparent 1px);
  background-size: 64px 64px, 64px 64px, 16px 16px, 16px 16px;
  background-position: 0 0, 0 0, 0 0, 0 0;
}
.city-grid::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse at 80% 20%, rgba(255, 77, 0, 0.06), transparent 50%),
    radial-gradient(ellipse at 20% 80%, rgba(122,90,248,0.08), transparent 50%);
  pointer-events: none;
}

/* Scan-line overlay — subtle CRT flicker */
.scan-lines {
  position: relative;
}
.scan-lines::after {
  content: '';
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    to bottom,
    transparent 0,
    transparent 2px,
    rgba(122,90,248,0.018) 2px,
    rgba(122,90,248,0.018) 3px
  );
  pointer-events: none;
  mix-blend-mode: screen;
  z-index: 2;
}

/* ============================================
   GRAIN TEXTURE + AMBIENT ORBS
   ============================================ */

/* Grain texture — denser film noise for authentic feel */
.grain-overlay {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9998;
  opacity: 0.05;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23n)' opacity='1'/%3E%3C/svg%3E");
  background-repeat: repeat;
  background-size: 160px 160px;
}

/* Ambient glow orbs — warm orange, asymmetric placement */
.bg-orb {
  position: fixed;
  border-radius: 50%;
  pointer-events: none;
  z-index: 0;
}
/* Top-left: large purple orb — main glow */
.bg-orb-1 {
  width: 600px; height: 440px;
  background: radial-gradient(ellipse, rgba(122,90,248,0.09) 0%, transparent 70%);
  top: -280px; left: -120px;
  filter: blur(60px);
}
/* Bottom-right: smaller dim green — stay within viewport edges */
.bg-orb-2 {
  width: 320px; height: 280px;
  background: radial-gradient(ellipse, rgba(105,56,239,0.06) 0%, transparent 70%);
  bottom: -60px; right: -40px;
  filter: blur(80px);
}
/* Mid-left slim streak: asymmetry */
.bg-orb-3 {
  width: 200px; height: 140px;
  background: radial-gradient(ellipse, rgba(122,90,248,0.04) 0%, transparent 70%);
  top: 50vh; left: -40px;
  filter: blur(90px);
}

/* Global ambient scan lines — now baked into body::after sweep instead.
   Kept as a no-op for back-compat. */
body.scan-on { /* reserved */ }

/* Glitch text effect */
.glitch {
  position: relative;
  display: inline-block;
}
.glitch::before,
.glitch::after {
  content: attr(data-text);
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  opacity: 0.85;
  pointer-events: none;
}
.glitch::before {
  color: var(--accent);
  transform: translate(-1px, 0);
  clip-path: polygon(0 0, 100% 0, 100% 45%, 0 45%);
}
.glitch::after {
  color: var(--info);
  transform: translate(1px, 0);
  clip-path: polygon(0 55%, 100% 55%, 100% 100%, 0 100%);
}

/* Corner brackets — HUD frame */
.hud-frame {
  position: relative;
}
.hud-frame::before,
.hud-frame::after,
.hud-frame > .hud-bl,
.hud-frame > .hud-br {
  content: '';
  position: absolute;
  width: 10px;
  height: 10px;
  border: 1px solid var(--accent);
}
.hud-frame::before { top: -1px; left: -1px; border-right: 0; border-bottom: 0; }
.hud-frame::after  { top: -1px; right: -1px; border-left: 0; border-bottom: 0; }
.hud-frame > .hud-bl { bottom: -1px; left: -1px; border-right: 0; border-top: 0; }
.hud-frame > .hud-br { bottom: -1px; right: -1px; border-left: 0; border-top: 0; }

/* Accent utility classes */
.mag { color: var(--accent); }
.bg-mag { background: var(--accent-bg); color: var(--accent); }

/* Hazard stripe — corner ornament */
.hazard-stripe {
  background: repeating-linear-gradient(
    -45deg,
    var(--accent) 0,
    var(--accent) 6px,
    var(--bg-0) 6px,
    var(--bg-0) 12px
  );
  height: 4px;
}
.hazard-stripe.mag {
  background: repeating-linear-gradient(
    -45deg,
    var(--accent) 0,
    var(--accent) 6px,
    var(--bg-0) 6px,
    var(--bg-0) 12px
  );
}

/* Section eyebrow with katakana */
.eyebrow-jp {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 4px;
}
.eyebrow-jp .en {
  font-family: var(--ff-mono);
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-3);
}
.eyebrow-jp .jp {
  font-family: var(--ff-jp);
  font-size: 10px;
  color: var(--accent);
  letter-spacing: 0.08em;
}
.eyebrow-jp .bar {
  flex: 1;
  height: 1px;
  background: linear-gradient(to right, var(--line-2), transparent);
}

/* Editorial serif number for big display */
.big-num {
  font-family: var(--ff-mono);
  font-size: var(--fs-36);
  font-weight: 500;
  letter-spacing: -0.02em;
  line-height: 1;
  color: var(--ink-0);
  font-variant-numeric: tabular-nums;
}
.big-num.pos { color: var(--pos); }
.big-num.neg { color: var(--neg); }


/* ============================================
   UX PASS 2 — clarity, contrast, consistency
   Appended 2026-04-22. Non-breaking: pure additions
   + inheritable defaults. No existing rules modified.
   ============================================ */

/* ---------- Readable base ---------- */
html { -webkit-text-size-adjust: 100%; text-rendering: optimizeLegibility; }
body {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  letter-spacing: 0.003em;  /* micro-tracking for legibility on dark */
}

/* ---------- Typography baseline — condensed + bold hierarchy ---------- */
h1:where(:not([class*=" "]):not([class])),
h2:where(:not([class*=" "]):not([class])),
h3:where(:not([class*=" "]):not([class])),
h4:where(:not([class*=" "]):not([class])),
h5:where(:not([class*=" "]):not([class])),
h6:where(:not([class*=" "]):not([class])) {
  font-family: var(--ff-display);
  color: var(--ink-0);
  font-weight: 800;
  letter-spacing: -0.025em;
  line-height: 1.12;
}
h1:where(:not([class])) { font-size: var(--fs-28); margin: 0 0 var(--s-6); }
h2:where(:not([class])) { font-size: var(--fs-20); margin: 0 0 var(--s-5); }
h3:where(:not([class])) { font-size: var(--fs-16); margin: 0 0 var(--s-4); }

p:where(:not([class])) { line-height: var(--lh-body); color: var(--ink-1); }

/* Global page section header — used across all pages */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: var(--s-8);
  flex-wrap: wrap;
}
.page-title {
  font-family: var(--ff-display);
  font-size: var(--fs-24);
  font-weight: 800;
  letter-spacing: -0.025em;
  color: var(--ink-0);
  line-height: 1;
}
.page-sub {
  font-family: var(--ff-mono);
  font-size: var(--fs-10);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-3);
  margin-top: 5px;
}

/* ---------- Selection & caret ---------- */
::selection { background: rgba(122,90,248,0.20); color: var(--ink-0); }
::-moz-selection { background: rgba(122,90,248,0.20); color: var(--ink-0); }
:root { caret-color: var(--accent); }

/* ---------- Focus rings (a11y) ---------- */
:where(a, button, [role=button], input, select, textarea, [tabindex]):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--r-1);
}
/* Remove default Chrome focus ring when we handle it */
:where(a, button, [role=button]):focus:not(:focus-visible) { outline: none; }

/* ---------- Scrollbars — warm tinted ---------- */
* { scrollbar-width: thin; scrollbar-color: var(--line-2) transparent; }
*::-webkit-scrollbar { width: 6px; height: 6px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
  background: var(--line-2);
  border-radius: var(--r-pill);
}
*::-webkit-scrollbar-thumb:hover { background: rgba(122,90,248,0.30); }

/* ---------- Links — default polished ---------- */
a:where(:not([class])) {
  color: var(--accent);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
  transition: color var(--dur-1) var(--ease);
}
a:where(:not([class])):hover { color: var(--ink-0); }

/* ---------- Buttons — disabled state (deduplicated) ---------- */
.btn:active { transform: none; }

/* ---------- Input — error state ---------- */
.input[aria-invalid="true"],
.input.is-error,
.select[aria-invalid="true"],
.textarea[aria-invalid="true"] {
  border-color: var(--neg);
  box-shadow: 0 0 0 3px rgba(237, 112, 136, 0.15);
}

/* ---------- Tables — default hover + stronger header ---------- */
table:where(:not([class])) { border-collapse: collapse; width: 100%; }
table:where(:not([class])) th {
  text-align: left;
  font-weight: 600;
  color: var(--ink-1);
  font-size: var(--fs-10);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: var(--s-6) var(--s-8);
  border-bottom: 1px solid var(--line-2);
}
table:where(:not([class])) td {
  padding: var(--s-6) var(--s-8);
  border-bottom: 1px solid var(--line-1);
  color: var(--ink-1);
}
table:where(:not([class])) tbody tr { transition: background var(--dur-1) var(--ease); }
table:where(:not([class])) tbody tr:hover { background: var(--bg-2); }

/* ---------- Card primitive ---------- */
.card {
  background: var(--bg-1);
  border: 1px solid var(--line-1);
  border-radius: var(--r-2);
  transition: border-color var(--dur-1) var(--ease), background var(--dur-1) var(--ease);
}
.card-pad   { padding: var(--s-12); }
.card-pad-lg{ padding: var(--s-16); }
.card-hover:hover { border-color: var(--line-3); background: var(--bg-2); }
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--s-8) var(--s-12);
  border-bottom: 1px solid var(--line-1);
  font-size: var(--fs-10);
  text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--ink-2);
}

/* ---------- KPI primitive ---------- */
.kpi {
  display: flex; flex-direction: column; gap: var(--s-3);
  padding: var(--s-12);
  background: var(--bg-1);
  border: 1px solid var(--line-1);
  border-radius: var(--r-2);
  min-width: 0;
}
.kpi .kpi-label {
  font-size: var(--fs-9);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-2);
  font-weight: 600;
}
.kpi .kpi-value {
  font-family: var(--ff-mono);
  font-variant-numeric: tabular-nums;
  font-size: var(--fs-24);
  font-weight: 600;
  color: var(--ink-0);
  line-height: var(--lh-tight);
}
.kpi .kpi-sub {
  font-size: var(--fs-10);
  color: var(--ink-2);
}
.kpi.kpi-pos .kpi-value { color: var(--pos); }
.kpi.kpi-neg .kpi-value { color: var(--neg); }
.kpi.kpi-warn .kpi-value { color: var(--warn); }

/* ---------- Chip variants ---------- */
.chip-good    { border: 1px solid var(--pos-dim); color: var(--pos); background: var(--pos-bg); }
.chip-bad     { border: 1px solid var(--neg-dim); color: var(--neg); background: var(--neg-bg); }
.chip-warn    { border: 1px solid rgba(242,177,68,.35); color: var(--warn); background: var(--warn-bg); }
.chip-info    { border: 1px solid rgba(151,252,228,.35); color: var(--info); background: var(--info-bg); }
.chip-muted   { border: 1px solid var(--line-2); color: var(--ink-2); background: var(--bg-2); }
.chip-solid-good { background: var(--pos); color: #001a0d; border: none; }
.chip-solid-bad  { background: var(--neg); color: #1a0009; border: none; }

/* ---------- Empty state ---------- */
.empty-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: var(--s-6);
  padding: var(--s-20) var(--s-12);
  color: var(--ink-2);
  font-size: var(--fs-11);
  text-align: center;
}
.empty-state .empty-title {
  color: var(--ink-1); font-weight: 600; font-size: var(--fs-13);
}

/* ---------- Skeleton loader ---------- */
.skel {
  background: linear-gradient(90deg, var(--bg-2), var(--bg-3), var(--bg-2));
  background-size: 200% 100%;
  animation: skel-shimmer 1.4s var(--ease) infinite;
  border-radius: var(--r-1);
}
@keyframes skel-shimmer {
  from { background-position: 200% 0; }
  to   { background-position: -200% 0; }
}

/* ---------- Stack & cluster utilities (vertical/horizontal spacing) ---------- */
.stack-2 > * + * { margin-top: var(--s-2); }
.stack-3 > * + * { margin-top: var(--s-3); }
.stack-4 > * + * { margin-top: var(--s-4); }
.stack-6 > * + * { margin-top: var(--s-6); }
.stack-8 > * + * { margin-top: var(--s-8); }
.stack-12 > * + * { margin-top: var(--s-12); }
.cluster  { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-4); }
.cluster-6 { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-6); }
.cluster-8 { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-8); }

/* ---------- Section heading (H2 look) ---------- */
.section-head {
  display: flex; align-items: baseline; gap: var(--s-8);
  margin: var(--s-10) 0 var(--s-6);
}
.section-head h2 { margin: 0; }
.section-head .section-count {
  font-family: var(--ff-mono);
  font-size: var(--fs-10);
  color: var(--ink-3);
}

/* ---------- Divider between content groups ---------- */
.divider {
  height: 1px; background: var(--line-1); margin: var(--s-10) 0;
}

/* ---------- Motion: respect user preference ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

/* ---------- Nav polish (applies to existing .nav-link) ---------- */
.nav-link {
  border-radius: var(--r-1) var(--r-1) 0 0;
  position: relative;
}
.nav-link:hover { background: var(--bg-2); }
.nav-active {
  box-shadow: inset 0 -2px 0 var(--accent);
}
.nav-link:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

/* ---------- Light theme: stronger body text for WCAG AA ---------- */
[data-theme="light"] body { color: #1A1F26; }
[data-theme="light"] .ink-1, [data-theme="light"] p:where(:not([class])) { color: #353A43; }
[data-theme="light"] h1, [data-theme="light"] h2, [data-theme="light"] h3,
[data-theme="light"] h4, [data-theme="light"] h5, [data-theme="light"] h6 { color: #0F1217; }
[data-theme="light"] .card { background: #FFFFFF; border-color: #DEE2E6; }
[data-theme="light"] .kpi { background: #FFFFFF; border-color: #DEE2E6; }
[data-theme="light"] table:where(:not([class])) th { color: #353A43; border-bottom-color: #BAC0C7; }
[data-theme="light"] table:where(:not([class])) td { border-bottom-color: #E6E9EC; color: #353A43; }
[data-theme="light"] table:where(:not([class])) tbody tr:hover { background: #F1F3F5; }
[data-theme="light"] *::-webkit-scrollbar-thumb { background: #C4CAD1; border-color: #F6F7F8; }
[data-theme="light"] *::-webkit-scrollbar-thumb:hover { background: #9FA6AE; }

/* ---------- Tight number formatting everywhere ---------- */
.tabular, .num-tab { font-variant-numeric: tabular-nums; font-family: var(--ff-mono); }

/* ---------- Visually hidden but accessible (avoid duplicating .sr-only) ---------- */
.visually-hidden {
  position: absolute !important;
  width: 1px !important; height: 1px !important;
  padding: 0 !important; margin: -1px !important;
  overflow: hidden !important; clip: rect(0,0,0,0) !important;
  white-space: nowrap !important; border: 0 !important;
}


/* ============================================
   UX PASS 3 — Light-mode contrast overhaul
   Fixes washed-out text & hard-to-read badges
   appended 2026-04-22
   ============================================ */

[data-theme="light"] {
  /* Darker ink palette to meet WCAG AA on near-white bg */
  --ink-2: #3E444C;  /* was #4E545D — was ok, push darker for muted labels  */
  --ink-3: #5E656F;  /* was #7A828D — now 6.4:1 on bg-0 (AA+)               */
  --ink-4: #8A919B;  /* was #B2B9C2 — passes AA for disabled/placeholder    */

  /* Line colors slightly stronger so card borders visible */
  --line-1: #D9DDE2;
  --line-2: #C4CAD1;
}

/* ---------- Button light mode overrides ---------- */
[data-theme="light"] .btn          { background: #f5f5f5; border-color: #d1d1d1; color: #242424; }
[data-theme="light"] .btn:hover    { background: #ebebeb; border-color: #bdbdbd; }
[data-theme="light"] .btn:active   { background: #e0e0e0; }
[data-theme="light"] .btn-primary  { background: var(--accent); border-color: transparent; color: #fff; box-shadow: none; }
[data-theme="light"] .btn-primary:hover  { background: var(--btn-acc-hover); }
[data-theme="light"] .btn-ghost:hover    { background: rgba(0,0,0,0.05); border-color: rgba(0,0,0,0.08); color: #242424; }

/* ---------- Tailwind *-400 text colors → darker on light for AA ---------- */
[data-theme="light"] .text-slate-400,
[data-theme="light"] .text-gray-400,
[data-theme="light"] .text-zinc-400,
[data-theme="light"] .text-neutral-400,
[data-theme="light"] .text-stone-400 { color: #475569 !important; }

[data-theme="light"] .text-slate-500,
[data-theme="light"] .text-gray-500,
[data-theme="light"] .text-zinc-500 { color: #334155 !important; }

[data-theme="light"] .text-slate-300,
[data-theme="light"] .text-gray-300,
[data-theme="light"] .text-zinc-300 { color: #64748b !important; }

/* ---------- Semantic *-400 → *-600/700 on light (readable) ---------- */
[data-theme="light"] .text-emerald-400,
[data-theme="light"] .text-green-400  { color: #047857 !important; }
[data-theme="light"] .text-emerald-300,
[data-theme="light"] .text-green-300  { color: #059669 !important; }
[data-theme="light"] .text-red-400,
[data-theme="light"] .text-rose-400   { color: #B91C1C !important; }
[data-theme="light"] .text-red-300    { color: #DC2626 !important; }
[data-theme="light"] .text-amber-400,
[data-theme="light"] .text-yellow-400 { color: #B45309 !important; }
[data-theme="light"] .text-sky-400,
[data-theme="light"] .text-blue-400   { color: #1D4ED8 !important; }
[data-theme="light"] .text-cyan-400   { color: #0E7490 !important; }
[data-theme="light"] .text-violet-400,
[data-theme="light"] .text-purple-400 { color: #6D28D9 !important; }
[data-theme="light"] .text-orange-400 { color: #C2410C !important; }
[data-theme="light"] .text-teal-400   { color: #0F766E !important; }
[data-theme="light"] .text-indigo-400 { color: #4338CA !important; }

/* ---------- Common inline-style muted classes used across templates ---------- */
[data-theme="light"] .tiny-muted,
[data-theme="light"] .feed-sub,
[data-theme="light"] .apc-sub,
[data-theme="light"] .pos-meta,
[data-theme="light"] .apc-px-lbl,
[data-theme="light"] .apc-px-hint,
[data-theme="light"] .kanji,
[data-theme="light"] .section-count,
[data-theme="light"] .kpi .kpi-sub,
[data-theme="light"] .kpi .kpi-label,
[data-theme="light"] .empty-state,
[data-theme="light"] .sig-divider.divider-archived { color: var(--ink-2); }

/* Place-holders darker */
[data-theme="light"] input::placeholder,
[data-theme="light"] textarea::placeholder,
[data-theme="light"] select::placeholder { color: var(--ink-3); opacity: 1; }

/* ---------- Chips — ensure text legible on light bg chips ---------- */
[data-theme="light"] .chip-muted  { color: #3E444C; background: #EDF0F3; border-color: #C4CAD1; }
[data-theme="light"] .chip-good   { color: #065F46; background: rgba(5,150,105,.10); border-color: #059669; }
[data-theme="light"] .chip-bad    { color: #991B1B; background: rgba(220,38,38,.08);  border-color: #DC2626; }
[data-theme="light"] .chip-warn   { color: #92400E; background: rgba(217,119,6,.10);  border-color: #D97706; }
[data-theme="light"] .chip-info   { color: #1E40AF; background: rgba(29,78,216,.08);  border-color: #1D4ED8; }
[data-theme="light"] .fresh-chip  { color: #9A3412; background: rgba(234,88,12,.10);  border-color: #EA580C; }
[data-theme="light"] .recent-chip { color: #065F46; background: rgba(5,150,105,.10);  border-color: #059669; }
[data-theme="light"] .old-chip    { color: #92400E; background: rgba(217,119,6,.10);  border-color: #D97706; }
[data-theme="light"] .archived-chip { color: #475569; background: #EDF0F3;            border-color: #94A3B8; }
[data-theme="light"] .trail-chip  { color: #92400E; background: rgba(245,158,11,.12); border-color: #D97706; }

/* Battle-specific */
[data-theme="light"] .pos-sltp .sl { color: #B91C1C; }
[data-theme="light"] .pos-sltp .tp { color: #047857; }
[data-theme="light"] .pos-sltp     { color: var(--ink-2); }
[data-theme="light"] .apc-px-move.fav   { background: rgba(5,150,105,.12); color: #047857; }
[data-theme="light"] .apc-px-move.unfav { background: rgba(220,38,38,.10); color: #B91C1C; }

/* ---------- Positive/negative text — darker variants on light ---------- */
[data-theme="light"] .pos, [data-theme="light"] .positive, [data-theme="light"] .good {
  color: #047857 !important;
}
[data-theme="light"] .neg, [data-theme="light"] .negative, [data-theme="light"] .bad,
[data-theme="light"] .danger {
  color: #B91C1C !important;
}

/* ---------- Nav subtitles (JP labels) — readable on light ---------- */
[data-theme="light"] .nav-link .jp { color: #64748B; }
[data-theme="light"] .nav-active .jp { color: var(--info) !important; }

/* ---------- Code / kbd blocks ---------- */
[data-theme="light"] code,
[data-theme="light"] kbd,
[data-theme="light"] pre {
  background: #EDF0F3;
  color: #0A0C0F;
  border: 1px solid var(--line-1);
}

/* ---------- Link contrast ---------- */
[data-theme="light"] a:where(:not([class])) { color: #1D4ED8; }
[data-theme="light"] a:where(:not([class])):hover { color: #0A0C0F; }

/* ---------- Opacity Tailwind utilities — disable on light (they fade too much) ---------- */
[data-theme="light"] .text-on-surface-variant\/60,
[data-theme="light"] .text-on-surface-variant\/70 { color: var(--ink-2) !important; }
[data-theme="light"] [class*="bg-opacity-"],
[data-theme="light"] .opacity-60 { opacity: 1; }

/* ---------- Scrollbar light contrast ---------- */
[data-theme="light"] *::-webkit-scrollbar-thumb {
  background: #B2B9C2;
  border: 2px solid #F6F7F8;
}
[data-theme="light"] *::-webkit-scrollbar-thumb:hover { background: #7A828D; }

/* ---------- Table rows hover on light ---------- */
[data-theme="light"] table:where(:not([class])) tbody tr:hover { background: #EDF0F3; }

/* ---------- Button disabled readable ---------- */
[data-theme="light"] .btn:disabled, [data-theme="light"] .btn[aria-disabled="true"] {
  opacity: 0.55;  /* slightly more visible than dark's 0.45 */
}


/* ============================================
   UX PASS 4 — Aggressive light-mode legibility
   Force dark ink anywhere that still falls through
   2026-04-22 iter
   ============================================ */

[data-theme="light"] {
  /* Push ink darker still — some environments were borderline on paper-white */
  --ink-2: #2E3339;   /* was #3E444C — now 11:1 on #F6F7F8 */
  --ink-3: #4A5058;   /* was #5E656F — now 7.9:1 */
  --ink-4: #7A828D;   /* was #8A919B — now 4.8:1 for disabled/placeholder */
}

/* Kill Tailwind text-opacity fade in light theme — the biggest
   legibility killer for text-*/70 and text-on-surface-variant/60 */
[data-theme="light"] * {
  --tw-text-opacity: 1 !important;
  --tw-bg-opacity: 1 !important;
}
[data-theme="light"] :is(.text-on-surface-variant,
                         .text-on-surface,
                         .text-on-background) { color: var(--ink-1) !important; }

/* Opacity utilities (Tailwind) — reserve them for active interactive states,
   don't let them dim static body text on light */
[data-theme="light"] :not(:hover):not(:focus):is(
  .opacity-50, .opacity-60, .opacity-70, .opacity-75, .opacity-80
) { opacity: 1 !important; }

/* Catch-all muted classes commonly used in templates */
[data-theme="light"] :is(
  .muted, .subtle, .dim, .hint, .quiet,
  .text-muted, .text-subtle, .text-dim, .text-hint,
  .meta, .sub, .caption, .helper,
  .text-caption, .text-helper, .text-meta
) { color: var(--ink-2) !important; }

/* Small text that often gets ignored — scale up minimum contrast */
[data-theme="light"] :is(.text-\[10px\], .text-\[11px\], .text-\[12px\],
                         .text-xs, .text-\[9px\]) {
  /* Let it keep its own color IF explicitly set, else ensure ≥ ink-2 */
}

/* Tailwind *-600/700 are fine but *-500 sometimes too light on white */
[data-theme="light"] .text-gray-500,
[data-theme="light"] .text-slate-500,
[data-theme="light"] .text-zinc-500,
[data-theme="light"] .text-neutral-500,
[data-theme="light"] .text-stone-500 { color: #2E3339 !important; }

[data-theme="light"] .text-gray-600,
[data-theme="light"] .text-slate-600,
[data-theme="light"] .text-zinc-600 { color: #1A1F26 !important; }

/* Any pale status/positive/negative text that slipped past pass 3 */
[data-theme="light"] .text-emerald-500, [data-theme="light"] .text-green-500 { color: #047857 !important; }
[data-theme="light"] .text-red-500,     [data-theme="light"] .text-rose-500  { color: #B91C1C !important; }
[data-theme="light"] .text-amber-500,   [data-theme="light"] .text-yellow-500 { color: #92400E !important; }
[data-theme="light"] .text-blue-500,    [data-theme="light"] .text-sky-500   { color: #1E40AF !important; }
[data-theme="light"] .text-cyan-500                                            { color: #155E75 !important; }
[data-theme="light"] .text-violet-500,  [data-theme="light"] .text-purple-500 { color: #5B21B6 !important; }
[data-theme="light"] .text-indigo-500                                          { color: #3730A3 !important; }
[data-theme="light"] .text-orange-500                                          { color: #9A3412 !important; }
[data-theme="light"] .text-teal-500                                            { color: #115E59 !important; }

/* Semantic classes ported from dark palette with lowered alpha backgrounds —
   ensure text stays readable even if bg is very faint */
[data-theme="light"] :is(
  .bg-pos-bg, .bg-neg-bg, .bg-warn-bg, .bg-info-bg,
  .bg-accent-bg
) { color: var(--ink-1); }

/* Table data cells that inherit via custom classes */
[data-theme="light"] :is(td, th, .td, .th) { color: var(--ink-1); }

/* Feed/card timestamps and tertiary labels that templates style inline */
[data-theme="light"] :is(
  .feed-sub, .pos-meta, .tiny-muted, .apc-sub,
  .stat-val-sub, .chart-label, .legend, .axis-label,
  .panel-sub, .section-sub, .pill-sub, .chip-sub
) { color: var(--ink-2) !important; }

/* Any element that STILL inherits a light gray via --ink-3 for body text */
[data-theme="light"] :where(p, div, span) {
  /* no blanket override — too risky, respect explicit ink-3 where designer
     intended. Instead force ink-3 itself to our darker value (done above) */
}

/* High contrast mode support */
@media (prefers-contrast: more) {
  [data-theme="light"] {
    --ink-1: #000000;
    --ink-2: #1A1F26;
    --ink-3: #353A43;
  }
  [data-theme="light"] * { font-weight: 500; }
}


/* ============================================
   UX PASS 5 — Insight-specific chip/divider fixes
   Targets hex colors hardcoded in insight.html inline <style>
   that bypassed generic overrides
   ============================================ */

/* .chip.good / .chip.bad / .chip.warn (insight uses dot-chain pattern, not chip-good) */
[data-theme="light"] .chip.good {
  color: #065F46 !important;
  background: rgba(5,150,105,.14) !important;
  border-color: #059669 !important;
}
[data-theme="light"] .chip.bad {
  color: #991B1B !important;
  background: rgba(220,38,38,.10) !important;
  border-color: #DC2626 !important;
}
[data-theme="light"] .chip.warn {
  color: #92400E !important;
  background: rgba(217,119,6,.12) !important;
  border-color: #D97706 !important;
}
[data-theme="light"] .chip.primary {
  color: #1E40AF !important;
  background: rgba(29,78,216,.10) !important;
  border-color: #1D4ED8 !important;
}

/* Generic .chip (pass without variant) — visible border + ink-1 text */
[data-theme="light"] .chip {
  color: var(--ink-1);
  border-color: var(--line-3);
  background: var(--bg-1);
}

/* Freshness dividers (insight-specific, insight.html defines these) */
[data-theme="light"] .divider-fresh    { color: #9A3412 !important; border-color: #EA580C !important; }
[data-theme="light"] .divider-recent   { color: #065F46 !important; border-color: #059669 !important; }
[data-theme="light"] .divider-old      { color: #92400E !important; border-color: #D97706 !important; }
[data-theme="light"] .divider-archived { color: #475569 !important; border-color: #94A3B8 !important; opacity: 1 !important; }

/* Archived sig card dim — undo the 60% opacity on light so still readable */
[data-theme="light"] .sig-card.bucket-archived { opacity: 1 !important; }
[data-theme="light"] .sig-card.bucket-archived .chip:not(.archived-chip) { opacity: 0.85; }

/* Insight sig-card left border (direction) stays vivid — but add bg tint for separation */
[data-theme="light"] .sig-card.long  { background: linear-gradient(90deg, rgba(5,150,105,.04), transparent 50%); }
[data-theme="light"] .sig-card.short { background: linear-gradient(90deg, rgba(220,38,38,.04), transparent 50%); }

/* text-emerald-400 / text-red-400 used for "Bull"/"Bear" labels in insight */
[data-theme="light"] .text-emerald-400 { color: #047857 !important; }
[data-theme="light"] .text-red-400     { color: #B91C1C !important; }

/* Insight history table event colors — override whatever "evColor" class computed at render */
[data-theme="light"] tr [class*="text-amber"],
[data-theme="light"] tr [class*="text-emerald"],
[data-theme="light"] tr [class*="text-red"],
[data-theme="light"] tr [class*="text-slate"] {
  /* handled by pass 3 remap; ensure they still win over table row hover */
  font-weight: 600;
}

/* Macro digest "refreshed X ago" and other tertiary info on white bg */
[data-theme="light"] [class*="text-[10px]"][class*="on-surface-variant"],
[data-theme="light"] [class*="text-[11px]"][class*="on-surface-variant"],
[data-theme="light"] [class*="text-[12px]"][class*="on-surface-variant"] {
  color: var(--ink-1) !important;  /* was ink-2, bump up for small text */
}

/* Filter button — Fluent 2 (4px radius) */
.filter-btn {
  border-radius: 4px;
  transition: background 100ms ease, border-color 100ms ease, color 100ms ease;
}
.filter-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: transparent;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.12);
}
[data-theme="light"] .filter-btn:not(.active) {
  color: var(--ink-2);
  border-color: var(--line-3);
  background: var(--bg-1);
}
[data-theme="light"] .filter-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: transparent;
}

/* PnL card text shadow: dark mode only */
.pnl-txt {
  text-shadow: 0 1px 6px rgba(0,0,0,0.85), 0 0 14px rgba(0,0,0,0.4);
}
[data-theme="light"] .pnl-txt {
  text-shadow: none;
}


/* ============================================
   REDESIGN v2 — Premium SaaS Upgrade
   Inspired by Visuo/Ngulis: clean premium,
   generous spacing, glass depth, bold type.
   Green-black palette preserved.
   ============================================ */

/* ── Enhanced design tokens ── */
:root {
  --r-2: 10px;          /* was 8px — softer cards */
  --r-3: 14px;          /* was 10px */
  --r-card: 12px;

  --sh-card: 0 1px 0 rgba(255,255,255,0.03) inset,
             0 4px 24px rgba(0,0,0,0.55),
             0 1px 3px rgba(0,0,0,0.4);
  --sh-card-hover: 0 1px 0 rgba(255,255,255,0.05) inset,
                   0 8px 32px rgba(0,0,0,0.65),
                   0 0 0 1px rgba(122,90,248,0.12);
  --sh-btn-primary: none;
  --sh-btn-primary-hover: none;

  --gradient-card-top: linear-gradient(180deg,
    rgba(255,255,255,0.035) 0px,
    rgba(255,255,255,0) 1px);
  --gradient-btn-primary: var(--accent);
  --gradient-accent-text: linear-gradient(97deg, #7a5af8 0%, #9b8afb 100%);
}

/* ── Body ambient upgrade ── */
body {
  background-image:
    linear-gradient(rgba(255,255,255,0.012) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.012) 1px, transparent 1px);
  background-size: 64px 64px;
}

/* ── Ambient orbs — stay within viewport edges on mobile ── */
.bg-orb-1 {
  width: 600px; height: 440px;
  background: radial-gradient(ellipse, rgba(122,90,248,0.07) 0%, transparent 65%);
  top: -280px; left: -120px;
  filter: blur(80px);
}
.bg-orb-2 {
  width: 400px; height: 320px;
  background: radial-gradient(ellipse, rgba(0,212,255,0.045) 0%, transparent 65%);
  bottom: -60px; right: -40px;
  filter: blur(100px);
}

/* ── Card ── */
.card, .panel {
  border-radius: var(--r-card) !important;
  border-color: rgba(255,255,255,0.07) !important;
  box-shadow: var(--sh-card) !important;
  transition: box-shadow var(--dur-2) var(--ease),
              border-color var(--dur-2) var(--ease),
              transform var(--dur-2) var(--ease) !important;
  position: relative;
}
.card::before, .panel::before {
  content: '';
  position: absolute;
  inset: 0 0 auto 0;
  height: 1px;
  background: linear-gradient(90deg,
    transparent 0%,
    rgba(255,255,255,0.06) 30%,
    rgba(122,90,248,0.12) 50%,
    rgba(255,255,255,0.06) 70%,
    transparent 100%);
  border-radius: var(--r-card) var(--r-card) 0 0;
  pointer-events: none;
  z-index: 1;
}
.card-hover:hover, .panel:hover {
  box-shadow: var(--sh-card-hover) !important;
  border-color: rgba(122,90,248,0.14) !important;
  transform: translateY(-1px);
}

/* ── KPI cards ── */
.kpi {
  border-radius: var(--r-card);
  background: var(--bg-1);
  border-color: rgba(255,255,255,0.07);
  box-shadow: var(--sh-card);
  position: relative;
  overflow: hidden;
}
.kpi::before {
  content: '';
  position: absolute;
  inset: 0 0 auto 0;
  height: 1px;
  background: linear-gradient(90deg,
    transparent, rgba(122,90,248,0.18), transparent);
  pointer-events: none;
}
.kpi .kpi-value {
  font-size: var(--fs-28);
  font-weight: 700;
  letter-spacing: -0.03em;
}
.kpi .kpi-label {
  font-size: 10px;
  letter-spacing: 0.1em;
  color: var(--ink-3);
}

/* ── Buttons — defined in base section above ── */

/* ── Tables ── */
.tbl th {
  background: var(--bg-0);
  border-bottom-color: var(--line-1);
  color: var(--ink-2);
  padding: var(--s-6) var(--s-10);
  font-size: 10px;
  letter-spacing: 0.1em;
}
.tbl td {
  padding: var(--s-6) var(--s-10);
  border-bottom-color: rgba(255,255,255,0.03);
}
.tbl tbody tr:hover {
  background: rgba(122,90,248,0.04);
  box-shadow: inset 3px 0 0 rgba(122,90,248,0.35);
}

/* ── Inputs ── */
.input, .select, .textarea {
  border-radius: 8px;
  background: var(--bg-0);
  border-color: var(--line-2);
  transition: all var(--dur-2) var(--ease);
}
.input:focus, .select:focus, .textarea:focus {
  background: rgba(122,90,248,0.03);
  border-color: rgba(122,90,248,0.4);
  box-shadow: 0 0 0 3px rgba(122,90,248,0.08), 0 0 0 1px rgba(122,90,248,0.4);
}

/* ── Page title — premium ── */
.page-title {
  font-size: clamp(18px, 2.5vw, 24px);
  font-weight: 800;
  letter-spacing: -0.03em;
  background: var(--gradient-accent-text);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  line-height: 1;
  padding-bottom: 2px;
}
.page-sub {
  color: var(--ink-3);
  font-size: 10px;
  letter-spacing: 0.12em;
  margin-top: 4px;
}

/* ── Section headers — accent left bar ── */
.panel-head, .card-head {
  background: linear-gradient(90deg,
    rgba(122,90,248,0.04) 0%, transparent 60%);
  border-bottom-color: rgba(255,255,255,0.05);
  border-left: 2px solid rgba(122,90,248,0.35);
  border-radius: var(--r-card) var(--r-card) 0 0;
  padding-left: calc(var(--panel-pad) - 2px);
}
.panel-head .title, .card-head {
  color: var(--ink-1);
  font-size: 10px;
  letter-spacing: 0.1em;
  font-weight: 600;
}

/* ── Pills — rounded ── */
.pill {
  border-radius: var(--r-pill);
  height: 20px;
  padding: 0 var(--s-6);
  font-size: 10px;
}
.pill.pos { box-shadow: 0 0 8px rgba(122,90,248,0.15); }
.pill.neg { box-shadow: 0 0 8px rgba(255,59,92,0.12); }

/* ── Scrollbar — refined ── */
*::-webkit-scrollbar { width: 4px; height: 4px; }
*::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.08);
  border-radius: var(--r-pill);
}
*::-webkit-scrollbar-thumb:hover { background: rgba(122,90,248,0.25); }

/* ── Toast ── */
.tj-toast {
  border-radius: 10px;
  background: var(--bg-0);
  border-color: var(--line-1);
}

/* ── Status dot glow ── */
.status-dot.live {
  box-shadow: 0 0 0 3px rgba(122,90,248,0.12),
              0 0 8px rgba(122,90,248,0.4);
}

/* ── Chip — rounded premium ── */
.chip-good, .chip-bad, .chip-warn, .chip-info, .chip-muted {
  border-radius: var(--r-pill);
  font-size: 10px;
  padding: 0 8px;
  height: 20px;
  display: inline-flex;
  align-items: center;
}

/* ── Nav link — pill active state ── */
.nav-link {
  border-radius: 6px;
  margin-bottom: 0;
  padding: 7px 10px;
  border-bottom: none;
  position: relative;
  font-size: 11px;
  letter-spacing: 0.05em;
}
.nav-link::after {
  content: '';
  position: absolute;
  bottom: -1px;
  left: 50%;
  transform: translateX(-50%) scaleX(0);
  width: 80%;
  height: 2px;
  background: var(--accent);
  border-radius: var(--r-pill);
  transition: transform var(--dur-2) var(--ease);
}
.nav-link:hover {
  background: rgba(122,90,248,0.07);
  color: var(--ink-0);
}
.nav-link:hover::after {
  transform: translateX(-50%) scaleX(0.5);
}
.nav-active {
  background: rgba(122,90,248,0.08) !important;
  color: var(--accent) !important;
  border-bottom: none !important;
  box-shadow: 0 0 0 1px rgba(122,90,248,0.14) inset;
}
.nav-active::after {
  transform: translateX(-50%) scaleX(1) !important;
}

/* ── Brand mark — premium ── */
.brand-mark {
  width: 32px; height: 32px;
  border-radius: 8px;
  border: 1px solid rgba(122,90,248,0.22);
  background: linear-gradient(135deg, rgba(122,90,248,0.06), rgba(0,0,0,0));
  box-shadow: 0 0 12px rgba(122,90,248,0.1);
}

/* ── Navbar ── */
nav.fixed.top-0 {
  background: var(--bg-0) !important;
  border-bottom: 1px solid var(--line-1) !important;
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
  box-shadow: none !important;
}

/* ── Fade-in animation — smoother ── */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
.fade-up   { animation: fadeUp 0.3s cubic-bezier(.2,.8,.2,1) forwards; }
.fade-up-d1 { animation: fadeUp 0.3s cubic-bezier(.2,.8,.2,1) 0.06s forwards; opacity: 0; }
.fade-up-d2 { animation: fadeUp 0.3s cubic-bezier(.2,.8,.2,1) 0.12s forwards; opacity: 0; }
.fade-up-d3 { animation: fadeUp 0.3s cubic-bezier(.2,.8,.2,1) 0.18s forwards; opacity: 0; }

/* ── Empty state — premium ── */
.empty-state {
  border: 1px dashed rgba(255,255,255,0.07);
  border-radius: var(--r-card);
  background: rgba(255,255,255,0.01);
}

/* ── Divider — accent gradient ── */
.divider, .hr {
  background: linear-gradient(90deg,
    transparent 0%,
    rgba(255,255,255,0.06) 30%,
    rgba(255,255,255,0.06) 70%,
    transparent 100%);
}

/* ── EXECUTE button in nav ── */
.btn.btn-primary[href="/trades/new"] {
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
}

/* Grain overlay — slightly less for cleaner premium look */
.grain-overlay { opacity: 0.03; }

/* ── Light mode overrides for redesign ── */
[data-theme="light"] .card,
[data-theme="light"] .panel {
  background: linear-gradient(180deg, #ffffff 0%, #fafafa 100%);
  border-color: rgba(0,0,0,0.07);
  box-shadow: 0 1px 0 rgba(255,255,255,0.8) inset,
              0 4px 24px rgba(0,0,0,0.06);
}
[data-theme="light"] .card::before,
[data-theme="light"] .panel::before {
  background: linear-gradient(90deg,
    transparent, rgba(0,0,0,0.04), transparent);
}
[data-theme="light"] .kpi {
  background: #fff;
  box-shadow: 0 2px 12px rgba(0,0,0,0.06);
}
[data-theme="light"] .page-title {
  background: none;
  -webkit-background-clip: unset;
  -webkit-text-fill-color: unset;
  background-clip: unset;
  color: var(--ink-0);
}
[data-theme="light"] .tbl th {
  background: #fafafa;
  border-bottom-color: #e5e7eb;
}
[data-theme="light"] .tbl tbody tr:hover {
  background: rgba(0,0,0,0.03);
  box-shadow: inset 3px 0 0 rgba(0,112,212,0.4);
}
[data-theme="light"] nav.fixed.top-0 {
  box-shadow: 0 1px 0 rgba(0,0,0,0.05), 0 4px 16px rgba(0,0,0,0.06) !important;
}
[data-theme="light"] .nav-link:hover {
  background: rgba(0,0,0,0.05);
}
[data-theme="light"] .nav-active {
  background: rgba(29,78,216,0.08) !important;
  box-shadow: 0 0 0 1px rgba(29,78,216,0.15) inset !important;
}
[data-theme="light"] .nav-active::after {
  background: var(--info);
}
[data-theme="light"] .panel-head, [data-theme="light"] .card-head {
  background: rgba(0,0,0,0.02);
  border-left-color: rgba(0,112,212,0.4);
}
[data-theme="light"] .input,
[data-theme="light"] .select,
[data-theme="light"] .textarea {
  background: #fff;
  border-color: #d1d5db;
}
[data-theme="light"] .input:focus,
[data-theme="light"] .select:focus,
[data-theme="light"] .textarea:focus {
  border-color: var(--info);
  box-shadow: 0 0 0 3px rgba(0,112,212,0.1);
  background: #fff;
}
