/* ==========================================================================
   Design tokens. Two styles (minimal, glass) x two modes (light, dark).
   js/theme.js sets data-style and data-mode on <html> before first paint.
   Rules are attribute-based (not only :root) so a section can preview another
   theme by carrying its own data-style/data-mode (see design.html).
   ========================================================================== */
:root,
[data-mode="light"] {
  --bg: #f7f7f5;
  --bg-image: none;
  --surface: #ffffff;
  --surface-2: #f1f2f0;
  --input: #ffffff;
  --text: #141a17;
  --muted: #5d6a64;
  --border: #e3e6e3;
  --accent: #1f6f5c;
  --accent-text: #ffffff;
  --accent-soft: #e3f1ec;
  --success: #1b7a43;
  --danger: #b3261e;
  --warning: #9a5b00;
  --trade-bg: #dff3e6; --trade-fg: #145c33;
  --caution-bg: #fbefd5; --caution-fg: #7a4a00;
  --pause-bg: #f8e1df; --pause-fg: #8c1f17;
  --neutral-bg: #eceeec; --neutral-fg: #3c4843;
  --radius: 14px;
  --shadow: none;
  --blur: none;
  color-scheme: light;
}
[data-mode="dark"] {
  --bg: #0e1211;
  --bg-image: none;
  --surface: #151b19;
  --surface-2: #1c2421;
  --input: #11171a;
  --text: #e8ede9;
  --muted: #9aa8a1;
  --border: #26302c;
  --accent: #4fb596;
  --accent-text: #06120d;
  --accent-soft: #15302a;
  --success: #5cc98a;
  --danger: #ff8a80;
  --warning: #f0b84f;
  --trade-bg: #163a26; --trade-fg: #8fe0b0;
  --caution-bg: #3d2f12; --caution-fg: #f3c86f;
  --pause-bg: #3f1c19; --pause-fg: #ffaaa3;
  --neutral-bg: #232d29; --neutral-fg: #c3cec8;
  --radius: 14px;
  --shadow: none;
  --blur: none;
  color-scheme: dark;
}
/* No JavaScript: follow the system setting. */
@media (prefers-color-scheme: dark) {
  :root:not([data-mode]) {
    --bg: #0e1211; --surface: #151b19; --surface-2: #1c2421; --input: #11171a; --text: #e8ede9; --muted: #9aa8a1;
    --border: #26302c; --accent: #4fb596; --accent-text: #06120d; --accent-soft: #15302a;
    --success: #5cc98a; --danger: #ff8a80; --warning: #f0b84f;
    --trade-bg: #163a26; --trade-fg: #8fe0b0; --caution-bg: #3d2f12; --caution-fg: #f3c86f;
    --pause-bg: #3f1c19; --pause-fg: #ffaaa3; --neutral-bg: #232d29; --neutral-fg: #c3cec8;
    color-scheme: dark;
  }
}

/* Glass: translucent, blurred tiles floating over soft colour light. */
[data-style="glass"][data-mode="light"] {
  --bg: #eaf1ee;
  --bg-image:
    radial-gradient(42rem 32rem at 8% -5%, rgb(79 181 150 / .45), transparent 60%),
    radial-gradient(38rem 30rem at 98% 8%, rgb(124 108 214 / .32), transparent 60%),
    radial-gradient(44rem 30rem at 50% 108%, rgb(240 184 79 / .28), transparent 62%),
    linear-gradient(160deg, #eef5f2, #e7ecf6);
  --surface: rgb(255 255 255 / .58);
  --surface-2: rgb(255 255 255 / .42);
  --input: rgb(255 255 255 / .72);
  --text: #0f1a16;
  --muted: #3f4d47;
  --border: rgb(255 255 255 / .78);
  --accent-soft: rgb(31 111 92 / .12);
  --neutral-bg: rgb(255 255 255 / .55);
  --radius: 18px;
  --shadow: 0 10px 30px rgb(20 40 35 / .10), inset 0 1px 0 rgb(255 255 255 / .65);
  --blur: blur(18px) saturate(160%);
}
[data-style="glass"][data-mode="dark"] {
  --bg: #0a100f;
  --bg-image:
    radial-gradient(42rem 32rem at 8% -5%, rgb(79 181 150 / .32), transparent 60%),
    radial-gradient(38rem 30rem at 98% 8%, rgb(124 108 214 / .28), transparent 60%),
    radial-gradient(44rem 30rem at 50% 108%, rgb(240 184 79 / .16), transparent 62%),
    linear-gradient(160deg, #0b1312, #10121c);
  --surface: rgb(22 30 28 / .55);
  --surface-2: rgb(255 255 255 / .06);
  --input: rgb(0 0 0 / .28);
  --text: #eef3f0;
  --muted: #aab7b1;
  --border: rgb(255 255 255 / .12);
  --accent-soft: rgb(79 181 150 / .16);
  --neutral-bg: rgb(255 255 255 / .08);
  --radius: 18px;
  --shadow: 0 10px 30px rgb(0 0 0 / .35), inset 0 1px 0 rgb(255 255 255 / .06);
  --blur: blur(18px) saturate(150%);
}
/* No blur support, or the user asked for less transparency: make glass solid enough to read. */
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  [data-style="glass"][data-mode="light"] { --surface: rgb(255 255 255 / .9); --surface-2: rgb(255 255 255 / .75); }
  [data-style="glass"][data-mode="dark"] { --surface: rgb(22 30 28 / .92); --surface-2: rgb(255 255 255 / .08); }
}
@media (prefers-reduced-transparency: reduce) {
  [data-style="glass"][data-mode="light"] { --surface: #ffffff; --surface-2: #f1f2f0; --blur: none; }
  [data-style="glass"][data-mode="dark"] { --surface: #151b19; --surface-2: #1c2421; --blur: none; }
}

/* ==========================================================================
   Base
   ========================================================================== */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100vh; color: var(--text);
  background-color: var(--bg); background-image: var(--bg-image); background-attachment: fixed;
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); }
h1 { font-size: 1.6rem; line-height: 1.25; margin: 0 0 .25rem; letter-spacing: -.01em; }
h2 { font-size: 1.2rem; margin: 0 0 .5rem; letter-spacing: -.005em; }
h3 { font-size: 1rem; margin: 1rem 0 .5rem; }
p { margin: .4rem 0; }
.small { font-size: .875rem; }
.muted { color: var(--muted); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.skip { position: absolute; left: -999px; }
.skip:focus { left: 8px; top: 8px; z-index: 30; background: var(--surface); padding: 8px; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.row { display: flex; gap: .5rem; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.row.between { justify-content: space-between; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }

/* Every raised surface shares one look, so a theme change restyles them all. */
.surface, .card, .tile, .market-card, .topbar, .tabs, .steps li, .honest, .dialog, .toast-host-surface {
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  -webkit-backdrop-filter: var(--blur);
  backdrop-filter: var(--blur);
}

.topbar { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: .75rem 16px; border-width: 0 0 1px; border-radius: 0; flex-wrap: wrap; position: relative; z-index: 6; }
.topbar nav a:not(.btn) { color: var(--text); text-decoration: none; padding: .25rem .5rem; }
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 700; color: var(--text); text-decoration: none; font-size: 1.1rem; }

.tabs { display: flex; gap: .25rem; overflow-x: auto; padding: 0 16px; border-width: 0 0 1px; border-radius: 0; scrollbar-width: thin; position: sticky; top: 0; z-index: 5; }
.tabs a { padding: .7rem .9rem; color: var(--muted); text-decoration: none; white-space: nowrap; border-bottom: 3px solid transparent; }
.tabs a[aria-current="page"] { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }

main { max-width: 1100px; margin: 0 auto; padding: 20px 16px; }
main:focus { outline: none; }
main.wide { max-width: 1400px; }
.view-head { margin: .5rem 0 1.25rem; }
.footer { max-width: 1100px; margin: 2rem auto 0; padding: 16px; color: var(--muted); border-top: 1px solid var(--border); }

.card { border-radius: var(--radius); padding: 20px; margin: 0 0 16px; }
.card.warn { border-color: var(--warning); }
.mode-real { border: 2px solid var(--danger); }
.mode-demo { border-left: 4px solid var(--accent); }

/* ==========================================================================
   Tiles: the building block for dashboards and the home page bento grid.
   ========================================================================== */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; margin: 0 0 16px; }
.tile { border-radius: var(--radius); padding: 16px; display: flex; flex-direction: column; gap: .35rem; min-width: 0; color: var(--text); text-decoration: none; }
a.tile:hover, button.tile:hover { border-color: var(--accent); }
.tile-kicker { font-size: .75rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.tile-value { font-size: 1.9rem; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.tile-value.v-trade, .tile-value.v-caution, .tile-value.v-pause { background: none; }
.tile-value.v-trade { color: var(--success); }
.tile-value.v-caution { color: var(--warning); }
.tile-value.v-pause { color: var(--danger); }
.tile-note { font-size: .85rem; color: var(--muted); }
.tile-accent { background: var(--accent-soft); }

/* Bento grid for the home page: a 4-column canvas where tiles span 1–2 cells. */
.bento { display: grid; grid-template-columns: repeat(4, 1fr); grid-auto-rows: minmax(150px, auto); gap: 14px; }
.bento .tile { padding: 20px; }
.span-2 { grid-column: span 2; }
.rows-2 { grid-row: span 2; }
.bento h3 { margin: .25rem 0; font-size: 1.1rem; }

/* ==========================================================================
   Controls
   ========================================================================== */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .35rem; min-height: 40px; padding: .45rem .95rem; border-radius: calc(var(--radius) - 4px); border: 1px solid var(--border); background: var(--surface-2); color: var(--text); font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; }
.btn:hover { border-color: var(--muted); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.btn.danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn.warning { background: var(--warning); color: #fff; border-color: var(--warning); }
.btn.ghost { background: transparent; }
.btn.big { min-height: 48px; padding: .6rem 1.25rem; font-size: 1.05rem; }
.small-btn { min-height: 34px; padding: .3rem .7rem; }
.btn.kill { border-color: var(--danger); color: var(--danger); background: transparent; }
.btn.kill.on { background: var(--danger); color: #fff; }

.badge { display: inline-block; padding: .15rem .55rem; border-radius: 999px; font-size: .8rem; font-weight: 700; background: var(--neutral-bg); color: var(--neutral-fg); white-space: nowrap; }
.v-trade { background: var(--trade-bg); color: var(--trade-fg); }
.v-caution { background: var(--caution-bg); color: var(--caution-fg); }
.v-pause { background: var(--pause-bg); color: var(--pause-fg); }
.v-collecting { background: var(--neutral-bg); color: var(--neutral-fg); }
.r-low { background: var(--trade-bg); color: var(--trade-fg); }
.r-medium { background: var(--caution-bg); color: var(--caution-fg); }
.r-high { background: var(--pause-bg); color: var(--pause-fg); }
p.verdict-msg { padding: .6rem .8rem; border-radius: calc(var(--radius) - 6px); }

.chip { padding: .3rem .7rem; border-radius: 999px; font-weight: 700; font-size: .85rem; text-decoration: none; }
.chip.demo { background: var(--trade-bg); color: var(--trade-fg); }
.chip.real { background: var(--pause-bg); color: var(--pause-fg); }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); display: inline-block; }
.dot.s-open { background: var(--success); }
.dot.s-reconnecting, .dot.s-connecting { background: var(--warning); }
.banner { background: var(--caution-bg); color: var(--caution-fg); padding: .6rem 16px; font-size: .9rem; text-align: center; }

/* Theme switcher (header). A <details> menu: works with keyboard and without JS errors. */
.theme-menu { position: relative; }
.theme-menu > summary { list-style: none; }
.theme-menu > summary::-webkit-details-marker { display: none; }
.theme-panel { position: absolute; right: 0; top: calc(100% + 8px); width: 240px; padding: 14px; border-radius: var(--radius); z-index: 20; display: grid; gap: 10px;
  background: var(--surface); border: 1px solid var(--border); box-shadow: 0 12px 32px rgb(0 0 0 / .18); -webkit-backdrop-filter: var(--blur); backdrop-filter: var(--blur); }
[data-style="glass"] .theme-panel { background: var(--surface); }
.segmented { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; padding: 4px; border-radius: calc(var(--radius) - 4px); background: var(--surface-2); border: 1px solid var(--border); }
.segmented button { min-height: 34px; border: 0; border-radius: calc(var(--radius) - 8px); background: transparent; color: var(--muted); font: inherit; font-weight: 600; font-size: .85rem; cursor: pointer; }
.segmented button[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); }

/* ==========================================================================
   Markets, digits, tables, stats
   ========================================================================== */
.market-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; margin-bottom: 16px; }
.market-card { display: flex; flex-direction: column; align-items: flex-start; gap: .35rem; padding: 12px 14px; border-radius: var(--radius); color: var(--text); font: inherit; text-align: left; cursor: pointer; }
.market-card:hover { border-color: var(--accent); }
.market-card.selected { border: 2px solid var(--accent); }
.market-name { font-weight: 600; }

.digits { display: grid; grid-template-columns: repeat(10, 1fr); gap: 6px; align-items: end; margin: .5rem 0; }
.digit-col { display: flex; flex-direction: column; align-items: center; gap: 4px; min-width: 0; }
.digit-track { width: 100%; height: 110px; background: var(--surface-2); border-radius: 8px; display: flex; align-items: flex-end; overflow: hidden; }
.digit-bar { width: 100%; background: var(--accent); border-radius: 8px 8px 0 0; min-height: 2px; transition: height .3s; }
.digit-pct { font-size: .72rem; color: var(--muted); }
.digit-label { font-weight: 700; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: .55rem .6rem; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--muted); font-weight: 600; }

.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin: .5rem 0 1rem; }
.stat { background: var(--surface-2); border: 1px solid var(--border); border-radius: calc(var(--radius) - 4px); padding: 10px 12px; }
.stat-label { font-size: .8rem; color: var(--muted); }
.stat-value { font-size: 1.2rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat.up .stat-value { color: var(--success); }
.stat.down .stat-value { color: var(--danger); }

.digit-strip { display: flex; flex-wrap: wrap; gap: 4px; list-style: none; padding: 0; margin: .25rem 0; }
.dchip { width: 28px; height: 28px; display: grid; place-items: center; border-radius: 8px; font-weight: 700; font-size: .85rem; font-variant-numeric: tabular-nums; }
.dchip.even { background: var(--accent); color: var(--accent-text); }
.dchip.odd { border: 2px solid var(--accent); color: var(--text); }
.dchip.newest { outline: 2px solid var(--text); outline-offset: 1px; }
@media (prefers-reduced-motion: no-preference) { .dchip.newest { animation: pop .25s ease-out; } }
@keyframes pop { from { transform: scale(.6); } to { transform: scale(1); } }
.start-here { border: 2px solid var(--accent); }
.checks li.todo::before { content: "○"; color: var(--muted); }

.curve { width: 100%; height: auto; display: block; background: var(--surface-2); border-radius: calc(var(--radius) - 4px); }
.curve-zero { stroke: var(--muted); stroke-dasharray: 4 4; stroke-width: 1; }
.curve-line { fill: none; stroke-width: 2.5; }
.curve-line.up { stroke: var(--success); }
.curve-line.down { stroke: var(--danger); }

.bot-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; margin: 16px 0; }
.bot-grid .card { margin: 0; display: flex; flex-direction: column; gap: .25rem; }
.bot h3 { margin: 0; }
.evidence { border-top: 1px solid var(--border); margin-top: .5rem; padding-top: .5rem; flex: 1; }

/* ==========================================================================
   Forms
   ========================================================================== */
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px 16px; margin: .75rem 0; }
.field { display: flex; flex-direction: column; gap: .25rem; }
.field[hidden] { display: none; }
.field-label { font-weight: 600; font-size: .9rem; }
.field-hint { font-size: .8rem; color: var(--muted); }
input, select { font: inherit; color: var(--text); background: var(--input); border: 1px solid var(--border); border-radius: calc(var(--radius) - 6px); padding: .5rem .65rem; min-height: 40px; max-width: 100%; }
select option { background: var(--bg); color: var(--text); }
input[type="search"] { flex: 1; min-width: 200px; }
input[type="checkbox"] { min-height: auto; width: 18px; height: 18px; }
.check { display: flex; align-items: center; gap: .5rem; margin: .5rem 0; }
.errors p { color: var(--danger); margin: .25rem 0; }
details { margin: .75rem 0; }
summary { cursor: pointer; font-weight: 600; }
progress { width: 100%; height: 12px; accent-color: var(--accent); }

.checks { list-style: none; padding: 0; margin: .5rem 0; }
.checks li { padding: .4rem 0 .4rem 1.8rem; position: relative; }
.checks li::before { position: absolute; left: 0; font-weight: 700; }
.checks li.ok::before { content: "✓"; color: var(--success); }
.checks li.bad::before { content: "✕"; color: var(--danger); }
.checks li.bad { color: var(--danger); }

.log { list-style: none; padding: 0; margin: 0; max-height: 360px; overflow-y: auto; font-size: .875rem; }
.log li { padding: .35rem 0; border-bottom: 1px solid var(--border); }
.log time { color: var(--muted); font-variant-numeric: tabular-nums; }
.log-win { color: var(--success); }
.log-loss, .log-error { color: var(--danger); }
.log-wait { color: var(--warning); }

.dialog { border-radius: var(--radius); color: var(--text); max-width: min(480px, calc(100vw - 32px)); padding: 22px; }
[data-style="glass"] .dialog { background: var(--surface); }
.dialog::backdrop { background: rgb(0 0 0 / .45); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); }
#toasts { position: fixed; bottom: 16px; right: 16px; left: 16px; display: flex; flex-direction: column; align-items: flex-end; gap: 8px; pointer-events: none; z-index: 40; }
.toast { pointer-events: auto; max-width: 420px; padding: .6rem .9rem; border-radius: calc(var(--radius) - 4px); background: var(--text); color: var(--bg); box-shadow: 0 8px 24px rgb(0 0 0 / .2); }
.t-success { background: var(--success); color: #fff; }
.t-error { background: var(--danger); color: #fff; }

/* ==========================================================================
   Landing and content pages
   ========================================================================== */
.hero { display: grid; grid-template-columns: 1.2fr 1fr; gap: 32px; align-items: center; padding: 40px 0 32px; }
.hero h1 { font-size: clamp(1.9rem, 4.2vw, 2.8rem); letter-spacing: -.025em; }
.lead { font-size: 1.15rem; color: var(--muted); }
.preview { margin: 0; }
.section { padding: 32px 0; border-top: 1px solid var(--border); }
.section > h2 { margin-bottom: 1rem; }
.steps { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; padding: 0; counter-reset: s; list-style: none; }
.steps li { border-radius: var(--radius); padding: 16px 16px 16px 52px; position: relative; counter-increment: s; }
.steps li::before { content: counter(s); position: absolute; left: 16px; top: 16px; width: 24px; height: 24px; border-radius: 50%; background: var(--accent); color: var(--accent-text); font-weight: 700; font-size: .85rem; display: grid; place-items: center; }
.honest { border-radius: var(--radius); padding: 22px; margin: 24px 0; }
.prose { max-width: 720px; }
.unfilled { background: var(--caution-bg); color: var(--caution-fg); padding: 0 .3rem; border-radius: 4px; }
.setup-row { display: grid; grid-template-columns: 28px 1fr; gap: .25rem .75rem; padding: .75rem 0; border-bottom: 1px solid var(--border); }
.setup-row:last-child { border-bottom: 0; }
.setup-icon { font-weight: 700; font-size: 1.1rem; line-height: 1.4; }
.setup-icon.ok { color: var(--success); }
.setup-icon.warn { color: var(--warning); }
.setup-icon.fail { color: var(--danger); }
.setup-icon.wait { color: var(--muted); }
.setup-fix { grid-column: 2; font-size: .875rem; color: var(--muted); }
.copy-row { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; margin: .5rem 0; }
.copy-row code { flex: 1; min-width: 0; overflow-wrap: anywhere; background: var(--surface-2); padding: .45rem .6rem; border-radius: 6px; }

/* Design board (design.html): each panel renders in its own theme. */
.board { display: grid; grid-template-columns: repeat(auto-fit, minmax(460px, 1fr)); gap: 16px; }
.board-panel { border-radius: 20px; padding: 18px; background-color: var(--bg); background-image: var(--bg-image); color: var(--text); border: 1px solid var(--border); min-width: 0; }
.board-panel > h2 { font-size: 1rem; margin-bottom: 12px; }

@media (max-width: 900px) {
  .bento { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 760px) {
  .hero { grid-template-columns: 1fr; padding: 16px 0; }
  .topbar nav a:not(.btn) { display: none; }
  .digit-track { height: 80px; }
  .digit-pct { font-size: .62rem; }
  .bot-grid { grid-template-columns: 1fr; }
  .board { grid-template-columns: 1fr; }
}
@media (max-width: 520px) {
  .bento { grid-template-columns: 1fr; }
  .span-2, .rows-2 { grid-column: auto; grid-row: auto; }
  .tile-value { font-size: 1.6rem; }
}
