/* Trade Lab: an editorial trading desk.
   Type: IBM Plex Sans (UI), IBM Plex Mono (numbers), Source Serif 4 (reading & headlines).

   Palette "Forest" (60 / 30 / 10):
     60  stone grey (light) or green-black (dark) surfaces
     30  green-black ink and moss grey for type, rules and structure
     10  racing green for actions and the line that matters
   Supporting chart hues: brass (--alt, also --ma50), slate (--alt-2, --ma20), rose (--ma200).
   Up/down stay green/red because traders expect it. No blue, purple, orange or cream.
   Light  bg #F1F2EE  ink #15201A  accent #1D5940  brass #A27A1C  slate #5B6D7C  rose #9A4E6E
   Dark   bg #0C120F  ink #E5EBE7  accent #6CC79B  brass #D8B25C  slate #9AADBF  rose #D68AAD */

:root {
  --bg: #f1f2ee;
  --surface: #fbfbf9;
  --surface-2: #eff0eb;
  --sunken: #e5e7e0;
  --rule: #dcdfd6;
  --rule-strong: #c2c7bb;
  --ink: #15201a;
  --ink-2: #37443c;
  --muted: #66706a;
  --faint: #9aa29c;
  --up: #2a8558;
  --down: #bd3a33;
  --accent: #1d5940;
  --accent-strong: #144430;
  --on-accent: #ffffff;
  --warn: #9c7419;
  --alt: #a27a1c;
  --alt-2: #5b6d7c;
  --up-bg: #e0efe6;
  --down-bg: #f7e3e1;
  --accent-bg: #dfeae3;
  --vol-up: rgba(42, 133, 88, 0.22);
  --vol-down: rgba(189, 58, 51, 0.22);
  --up-soft: rgba(42, 133, 88, 0.45);
  --down-soft: rgba(189, 58, 51, 0.45);
  --ma20: #5b6d7c;
  --ma50: #a27a1c;
  --ma200: #9a4e6e;
  --bb: rgba(55, 68, 60, 0.35);
  --rsi: #9a4e6e;
  --c-grid: rgba(21, 32, 26, 0.05);
  --scrim: rgba(10, 18, 14, 0.45);
  --shadow: 0 1px 2px rgba(21, 32, 26, 0.06), 0 8px 28px rgba(21, 32, 26, 0.10);

  --sans: 'IBM Plex Sans', system-ui, sans-serif;
  --mono: 'IBM Plex Mono', ui-monospace, monospace;
  --serif: 'Source Serif 4', Georgia, serif;
  --r: 3px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0c120f; --surface: #121a16; --surface-2: #17211c; --sunken: #080c0a; --rule: #212d27; --rule-strong: #304037;
    --ink: #e5ebe7; --ink-2: #b5c0b9; --muted: #7f8b84; --faint: #53605a;
    --up: #4cc08a; --down: #ec6b60; --accent: #6cc79b; --accent-strong: #8ed6b2; --on-accent: #0c120f; --warn: #d8b25c; --alt: #d8b25c; --alt-2: #9aadbf;
    --up-bg: #0f2a1d; --down-bg: #321a19; --accent-bg: #16301f;
    --vol-up: rgba(76, 192, 138, 0.22); --vol-down: rgba(236, 107, 96, 0.22); --up-soft: rgba(76, 192, 138, 0.45); --down-soft: rgba(236, 107, 96, 0.45);
    --ma20: #9aadbf; --ma50: #d8b25c; --ma200: #d68aad; --bb: rgba(181, 192, 185, 0.3); --rsi: #d68aad; --c-grid: rgba(229, 235, 231, 0.045);
    --scrim: rgba(2, 5, 4, 0.62);
    --shadow: 0 1px 2px rgba(0,0,0,.35), 0 10px 30px rgba(0,0,0,.5);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0c120f; --surface: #121a16; --surface-2: #17211c; --sunken: #080c0a; --rule: #212d27; --rule-strong: #304037;
  --ink: #e5ebe7; --ink-2: #b5c0b9; --muted: #7f8b84; --faint: #53605a;
  --up: #4cc08a; --down: #ec6b60; --accent: #6cc79b; --accent-strong: #8ed6b2; --on-accent: #0c120f; --warn: #d8b25c; --alt: #d8b25c; --alt-2: #9aadbf;
  --up-bg: #0f2a1d; --down-bg: #321a19; --accent-bg: #16301f;
  --vol-up: rgba(76, 192, 138, 0.22); --vol-down: rgba(236, 107, 96, 0.22); --up-soft: rgba(76, 192, 138, 0.45); --down-soft: rgba(236, 107, 96, 0.45);
  --ma20: #9aadbf; --ma50: #d8b25c; --ma200: #d68aad; --bb: rgba(181, 192, 185, 0.3); --rsi: #d68aad; --c-grid: rgba(229, 235, 231, 0.045);
  --scrim: rgba(2, 5, 4, 0.62);
  --shadow: 0 1px 2px rgba(0,0,0,.35), 0 10px 30px rgba(0,0,0,.5);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--ink); font: 13px/1.5 var(--sans); overflow: hidden; -webkit-font-smoothing: antialiased; font-feature-settings: 'ss02'; }
button, select, input { font: inherit; color: inherit; }
button { cursor: pointer; }
::selection { background: var(--accent-bg); }
.num, .mono { font-family: var(--mono); font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.up { color: var(--up); } .down { color: var(--down); } .muted { color: var(--muted); }
kbd { font-family: var(--mono); font-size: 10.5px; line-height: 1; padding: 2px 4px; border-radius: 2px; border: 1px solid currentColor; opacity: .55; }

/* --- controls --- */
.btn { height: 30px; padding: 0 12px; border-radius: var(--r); border: 1px solid var(--rule-strong); background: var(--surface); color: var(--ink); white-space: nowrap; transition: background-color .12s, border-color .12s; display: inline-flex; align-items: center; gap: 8px; }
.btn:hover { border-color: var(--ink-2); }
.btn:disabled { opacity: .4; cursor: default; border-color: var(--rule-strong); }
select.btn { padding: 0 6px; appearance: auto; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 500; }
.btn-primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); }
.btn-primary kbd { opacity: .6; }
.btn-buy { background: var(--up); border-color: var(--up); color: #fff; font-weight: 500; }
.btn-sell { background: var(--down); border-color: var(--down); color: #fff; font-weight: 500; }
.btn-buy:hover, .btn-sell:hover { filter: brightness(1.07); border-color: transparent; }
.btn-quiet-danger { color: var(--down); }
.btn-quiet-danger:hover { border-color: var(--down); }
.link { background: none; border: 0; padding: 0; color: var(--ink-2); text-decoration: underline; text-decoration-color: var(--rule-strong); text-underline-offset: 3px; }
.link:hover { color: var(--ink); text-decoration-color: currentColor; }
.chip { height: 24px; padding: 0 9px; border-radius: 12px; border: 1px solid var(--rule-strong); background: var(--surface); font-size: 11.5px; color: var(--ink-2); }
.chip:hover { border-color: var(--ink-2); color: var(--ink); }
input.inp, select.inp { height: 32px; width: 100%; min-width: 0; padding: 0 9px; border: 1px solid var(--rule-strong); border-radius: var(--r); background: var(--surface); outline: none; }
input.inp { font-family: var(--mono); font-variant-numeric: tabular-nums; }
input.inp:focus, select.inp:focus { border-color: var(--ink); box-shadow: 0 0 0 3px var(--accent-bg); }
input.inp::placeholder { color: var(--faint); font-family: var(--sans); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
input:focus-visible, select:focus-visible { outline: none; }

/* --- top bar --- */
.top { height: 52px; display: flex; align-items: center; gap: 24px; padding: 0 16px 0 20px; background: var(--surface); border-bottom: 1px solid var(--rule); }
.wordmark { background: none; border: 0; padding: 0; font: 600 17px/1 var(--serif); letter-spacing: -0.01em; color: var(--ink); }
.wordmark span { color: var(--accent); margin-left: 1px; }
.instrument { display: flex; align-items: baseline; gap: 10px; min-width: 0; flex: 1; white-space: nowrap; overflow: hidden; }
.instrument .sym { font-weight: 600; }
.instrument .nm { color: var(--muted); overflow: hidden; text-overflow: ellipsis; }
.instrument .px { font: 500 15px var(--mono); font-variant-numeric: tabular-nums; margin-left: 6px; }
.instrument .chg { font: 12.5px var(--mono); }
.instrument .date { color: var(--muted); padding-left: 12px; border-left: 1px solid var(--rule); }
.session-progress { display: flex; align-items: center; gap: 10px; font-size: 12px; color: var(--muted); white-space: nowrap; }
.session-progress .bar { width: 120px; height: 3px; background: var(--sunken); border-radius: 2px; overflow: hidden; }
.session-progress .bar i { display: block; height: 100%; background: var(--accent); transition: width .2s; }
.nav { display: flex; gap: 2px; }
.nav { align-items: center; }
.nav button:not(.theme-toggle) { background: none; border: 0; height: 30px; padding: 0 10px; border-radius: var(--r); color: var(--ink-2); }
.nav button:not(.theme-toggle):hover { background: var(--surface-2); color: var(--ink); }

/* theme switch: a pill track with one knob that carries the current icon */
.theme-toggle { --tt-w: 46px; --tt-h: 26px; --tt-k: 20px; --tt-pad: 3px; --tt-ease: cubic-bezier(.16, 1, .3, 1);
  position: relative; flex: none; width: var(--tt-w); height: var(--tt-h); margin-left: 10px; padding: 0; border: 0; border-radius: 999px;
  background: var(--sunken); box-shadow: inset 0 0 0 1px var(--rule-strong); transition: background-color .4s var(--tt-ease), box-shadow .4s var(--tt-ease); -webkit-tap-highlight-color: transparent; view-transition-name: theme-toggle; }
.theme-toggle::before { content: ''; position: absolute; inset: -9px -6px; } /* larger touch target */
.theme-toggle:hover { box-shadow: inset 0 0 0 1px var(--muted); }
.theme-toggle:focus-visible { outline-offset: 3px; }
.theme-toggle .tt-knob { position: absolute; top: var(--tt-pad); left: var(--tt-pad); width: var(--tt-k); height: var(--tt-k); border-radius: 50%; display: grid; place-items: center;
  background: var(--surface); box-shadow: 0 1px 2px rgba(21, 32, 26, .2), 0 2px 6px rgba(21, 32, 26, .12);
  transition: transform .5s var(--tt-ease), background-color .4s var(--tt-ease), width .25s var(--tt-ease); }
.theme-toggle:active .tt-knob { width: calc(var(--tt-k) + 4px); }
.theme-toggle svg { grid-area: 1 / 1; width: 13px; height: 13px; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; transition: opacity .3s ease, transform .5s var(--tt-ease); }
.theme-toggle .ic-sun { stroke: var(--warn); }
.theme-toggle .ic-moon { stroke: none; fill: var(--on-accent); opacity: 0; transform: rotate(-70deg) scale(.4); }
.theme-toggle[aria-checked="true"] { background: var(--accent-bg); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 35%, transparent); }
.theme-toggle[aria-checked="true"]:hover { box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 65%, transparent); }
.theme-toggle[aria-checked="true"] .tt-knob { transform: translateX(calc(var(--tt-w) - var(--tt-k) - 2 * var(--tt-pad))); background: var(--accent); box-shadow: 0 1px 2px rgba(0, 0, 0, .35), 0 0 12px color-mix(in srgb, var(--accent) 40%, transparent); }
.theme-toggle[aria-checked="true"]:active .tt-knob { transform: translateX(calc(var(--tt-w) - var(--tt-k) - 2 * var(--tt-pad) - 4px)); }
.theme-toggle[aria-checked="true"] .ic-sun { opacity: 0; transform: rotate(90deg) scale(.4); }
.theme-toggle[aria-checked="true"] .ic-moon { opacity: 1; transform: none; }
/* theme change: the new theme spreads out from the switch (see toggleTheme) */
::view-transition-old(root), ::view-transition-new(root) { animation: none; mix-blend-mode: normal; }
::view-transition-old(theme-toggle) { display: none; }
::view-transition-new(theme-toggle) { animation: none; }
@media (prefers-reduced-motion: reduce) { .theme-toggle, .theme-toggle * { transition: none !important; } }

/* collapsible details */
details.more { border-top: 1px solid var(--rule); }
details.more:last-of-type { border-bottom: 1px solid var(--rule); }
details.more summary { list-style: none; cursor: pointer; display: flex; justify-content: space-between; align-items: center; padding: 10px 0; font-weight: 500; font-size: 13px; color: var(--ink-2); user-select: none; }
details.more summary::-webkit-details-marker { display: none; }
details.more summary::after { content: ''; width: 7px; height: 7px; border-right: 1.5px solid var(--muted); border-bottom: 1.5px solid var(--muted); transform: rotate(45deg) translate(-2px, -2px); transition: transform .15s; flex: none; margin-left: 12px; }
details.more[open] summary::after { transform: rotate(-135deg) translate(-2px, -2px); }
details.more summary:hover { color: var(--ink); }
details.more .more-body { padding: 0 0 12px; color: var(--ink-2); }
details.more .more-body p { margin: 0 0 8px; }
details.more .more-body ul { margin: 0 0 8px; padding-left: 18px; }

/* --- app layout --- */
.app { display: grid; grid-template-columns: auto minmax(0, 1fr) 336px; height: calc(100% - 52px); }
.stage { display: flex; flex-direction: column; min-width: 0; background: var(--surface); }
.chartbar { display: flex; align-items: center; justify-content: space-between; gap: 8px 12px; padding: 8px 12px; border-bottom: 1px solid var(--rule); flex-wrap: wrap; }
.indicators { display: flex; gap: 2px; flex-wrap: wrap; }
.ind { height: 28px; padding: 0 8px; border: 1px solid transparent; border-radius: var(--r); background: none; color: var(--muted); font-size: 12px; display: inline-flex; align-items: center; gap: 7px; }
.ind i { width: 12px; height: 2px; background: var(--c); opacity: .35; border-radius: 1px; }
.ind:hover { color: var(--ink); background: var(--surface-2); }
.ind[aria-pressed="true"] { color: var(--ink); border-color: var(--rule); background: var(--surface-2); }
.ind[aria-pressed="true"] i { opacity: 1; }
.transport { display: flex; align-items: center; gap: 6px; }
.pending-hint { font-size: 12px; color: var(--accent); margin-right: 6px; }
.pending-hint:empty { display: none; }
.transport .btn { padding: 0 10px; }
.chart-wrap { position: relative; flex: 1; min-height: 240px; }
#chart { position: absolute; inset: 0; }
.legend { position: absolute; z-index: 3; left: 16px; top: 8px; font: 11.5px var(--mono); font-variant-numeric: tabular-nums; color: var(--muted); pointer-events: none; display: flex; flex-direction: column; gap: 2px; padding-right: 90px; }
.legend .lg-row { display: flex; gap: 12px; flex-wrap: wrap; }
.legend b { color: var(--ink); font-weight: 500; }
.legend .lg-date { color: var(--ink); font-family: var(--sans); font-weight: 500; }
.legend .lg-ma { display: inline-flex; align-items: center; gap: 5px; }
.legend .lg-ma i { width: 10px; height: 2px; }
.recent { position: absolute; z-index: 3; right: 76px; bottom: 36px; }

/* readout strip: what a trader looks at */
.readout { border-top: 1px solid var(--rule); }
.readout .cells { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); }
.readout .cell { text-align: left; background: none; border: 0; border-right: 1px solid var(--rule); padding: 9px 16px 10px; display: flex; flex-direction: column; gap: 1px; position: relative; }
.readout .cell:last-child { border-right: 0; }
.readout .cell:hover { background: var(--surface-2); }
.readout .cell[aria-expanded="true"] { background: var(--surface-2); }
.readout .cell[aria-expanded="true"]::after { content: ''; position: absolute; left: 16px; right: 16px; bottom: 0; height: 2px; background: var(--ink); }
.readout .k { font-size: 11px; color: var(--muted); }
.readout .v { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.readout .v.bull { color: var(--up); } .readout .v.bear { color: var(--down); }
.readout .explain { padding: 10px 16px 12px; border-top: 1px solid var(--rule); background: var(--surface-2); color: var(--ink-2); font-size: 12.5px; max-width: 900px; }
.readout .explain b { color: var(--ink); font-weight: 600; margin-right: 6px; }

/* bottom desk */
.desk { height: 220px; display: flex; flex-direction: column; border-top: 1px solid var(--rule); }
.desk-tabs { display: flex; align-items: center; gap: 18px; padding: 0 16px; border-bottom: 1px solid var(--rule); height: 38px; flex: none; }
.desk-tabs .spacer { flex: 1; }
.tab { background: none; border: 0; padding: 0; height: 100%; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tab:hover { color: var(--ink); }
.tab.active { color: var(--ink); border-bottom-color: var(--ink); font-weight: 500; }
.tab-body { flex: 1; overflow-y: auto; padding: 0 16px; }
.feed { list-style: none; margin: 0; padding: 0; }
.feed > li { border-bottom: 1px solid var(--rule); }
.feed > li:last-child { border-bottom: 0; }
.feed summary, .feed li.plain { list-style: none; display: grid; grid-template-columns: 76px 64px minmax(0, 1fr) 14px; gap: 12px; align-items: baseline; padding: 8px 0; }
.feed li.plain { grid-template-columns: 76px 64px minmax(0, 1fr); }
.feed summary { cursor: pointer; }
.feed summary::-webkit-details-marker { display: none; }
.feed summary::after { content: ''; width: 6px; height: 6px; border-right: 1.5px solid var(--faint); border-bottom: 1.5px solid var(--faint); transform: rotate(45deg); transition: transform .15s; justify-self: center; }
.feed details[open] summary::after { transform: rotate(-135deg); }
.feed summary:hover .h { text-decoration: underline; text-decoration-color: var(--rule-strong); text-underline-offset: 3px; }
.feed .d { font: 11.5px var(--mono); color: var(--faint); }
.feed .kind { font-size: 11px; font-weight: 500; color: var(--muted); }
.feed .kind.bull { color: var(--up); } .feed .kind.bear { color: var(--down); } .feed .kind.warn { color: var(--warn); }
.feed .h { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.feed .fb { padding: 0 0 10px 152px; color: var(--ink-2); max-width: 900px; font-size: 12.5px; }
.feed .fb p { margin: 0 0 4px; }
.feed .fb .w { color: var(--muted); }
.feed .fb .w em { font-style: normal; color: var(--ink-2); font-weight: 500; }
.feed .fb ul { margin: 0 0 4px; padding-left: 16px; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 12px; }
.tbl th { text-align: left; color: var(--muted); font-weight: 400; padding: 10px 8px 6px 0; border-bottom: 1px solid var(--rule); position: sticky; top: 0; background: var(--surface); white-space: nowrap; }
.tbl td { padding: 6px 8px 6px 0; border-bottom: 1px solid var(--rule); font-family: var(--mono); font-variant-numeric: tabular-nums; white-space: nowrap; }
.tbl td.t { font-family: var(--sans); }
.tbl .r { text-align: right; }
.journal-summary { display: flex; gap: 24px; padding: 10px 0 4px; font-size: 12px; color: var(--muted); }
.journal-summary b { color: var(--ink); font: 500 12.5px var(--mono); margin-left: 4px; }
.empty { color: var(--muted); padding: 16px 0; max-width: 520px; }

/* --- side panel --- */
.side { overflow-y: auto; background: var(--bg); border-left: 1px solid var(--rule); }
.sec { padding: 16px 18px 18px; border-bottom: 1px solid var(--rule); }
.sec:empty { display: none; }
.sec-h { display: flex; justify-content: space-between; align-items: baseline; margin: 0 0 12px; }
.sec-h h2 { margin: 0; font-size: 13px; font-weight: 600; }
.sec-h .aside { font-size: 11.5px; color: var(--muted); }
.equity { font: 500 26px/1.15 var(--mono); font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.equity-sub { font: 12.5px var(--mono); margin-top: 2px; }
.rows { display: grid; grid-template-columns: 1fr auto; gap: 5px 12px; margin-top: 12px; font-size: 12.5px; }
.rows dt { color: var(--muted); }
.rows dd { margin: 0; text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums; }
.dd { margin-top: 14px; }
.dd .lbl { display: flex; justify-content: space-between; font-size: 11.5px; color: var(--muted); margin-bottom: 5px; }
.dd .lbl b { color: var(--ink); font: 500 11.5px var(--mono); }
.dd .track { height: 4px; background: var(--sunken); border-radius: 2px; overflow: hidden; }
.dd .fill { height: 100%; background: var(--ink-2); transition: width .2s; }
.dd .fill.hot { background: var(--warn); } .dd .fill.crit { background: var(--down); }
.banner { margin-top: 14px; padding: 10px 12px; border-left: 3px solid var(--down); background: var(--down-bg); font-size: 12.5px; color: var(--ink); }

.pos-top { display: flex; justify-content: space-between; align-items: flex-end; }
.pos-side { font-weight: 600; }
.pos-side.long { color: var(--up); } .pos-side.short { color: var(--down); }
.pos-pnl { font: 500 20px/1.1 var(--mono); font-variant-numeric: tabular-nums; text-align: right; }
.pos-pnl small { display: block; font-size: 12px; text-align: right; }
.inline-field { display: grid; grid-template-columns: 1fr 96px auto; gap: 8px; align-items: center; margin-top: 8px; font-size: 12.5px; }
.inline-field label { color: var(--muted); }
.inline-field .inp { height: 28px; }
.inline-field .btn { height: 28px; padding: 0 10px; }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 14px; }
.actions .btn { justify-content: center; }
.flat-note { color: var(--muted); font-size: 12.5px; }

/* order ticket */
.sides { display: grid; grid-template-columns: 1fr 1fr; border: 1px solid var(--rule-strong); border-radius: var(--r); overflow: hidden; margin-bottom: 14px; }
.sides button { height: 34px; border: 0; background: var(--surface); color: var(--ink-2); font-weight: 500; }
.sides button + button { border-left: 1px solid var(--rule-strong); }
.sides button[aria-pressed="true"].b { background: var(--up); color: #fff; }
.sides button[aria-pressed="true"].s { background: var(--down); color: #fff; }
.sides button:not([aria-pressed="true"]):hover { background: var(--surface-2); color: var(--ink); }
.fld { margin-top: 12px; }
.fld-h { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 5px; font-size: 12px; }
.fld-h label { color: var(--ink-2); font-weight: 500; }
.fld-h .opt { color: var(--faint); font-weight: 400; }
.fld-hint { display: flex; justify-content: space-between; gap: 8px; margin-top: 5px; font-size: 11.5px; color: var(--muted); }
.fld-hint .links { display: flex; gap: 10px; }
.fld-hint .link { font-size: 11.5px; color: var(--ink-2); }
.seg { display: flex; border: 1px solid var(--rule-strong); border-radius: var(--r); overflow: hidden; height: 32px; }
.seg button { flex: 1; border: 0; background: var(--surface); color: var(--ink-2); font: 12.5px var(--mono); }
.seg button + button { border-left: 1px solid var(--rule-strong); }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--surface); }
.seg button:not([aria-pressed="true"]):hover { background: var(--surface-2); }
.seg.text button { font-family: var(--sans); }
.fld-h .links { display: flex; gap: 10px; }
.fld-h .link { font-size: 11.5px; }
.fld-hint:empty { display: none; }
.sum { display: grid; grid-template-columns: 1fr 1fr; gap: 1px; margin: 16px 0 0; background: var(--rule); border: 1px solid var(--rule); border-radius: var(--r); overflow: hidden; }
.sum div { background: var(--surface); padding: 7px 10px; }
.sum dt { font-size: 11px; color: var(--muted); }
.sum dd { margin: 0; font: 500 13px var(--mono); font-variant-numeric: tabular-nums; }
.tk-more { border-top: 0; }
.tk-more:last-of-type { border-bottom: 0; }
.tk-more > summary { padding: 0; font-size: 13px; font-weight: 600; color: var(--ink); }
.tk-more[open] > summary { margin-bottom: 12px; }
.tk-more .more-body { padding: 0; }
.checks-d { margin-top: 10px; border-bottom: 1px solid var(--rule); }
.checks-d summary { padding: 8px 0; font-size: 12.5px; }
.checks-d summary span { font-weight: 400; margin-left: auto; margin-right: 4px; font-size: 12px; }
.checks-d .checks { margin: 0 0 10px; }
.plan { margin-top: 16px; padding: 12px 14px; background: var(--surface); border: 1px solid var(--rule); border-radius: var(--r); font-size: 12.5px; color: var(--ink-2); line-height: 1.6; }
.plan b { color: var(--ink); font-weight: 600; font-family: var(--mono); font-size: 12px; }
.plan .pl-loss { color: var(--down); } .plan .pl-gain { color: var(--up); }
.checks { list-style: none; margin: 12px 0 0; padding: 0; font-size: 12.5px; }
.checks li { display: grid; grid-template-columns: 16px 1fr; gap: 6px; padding: 3px 0; }
.checks .m { font-weight: 600; text-align: center; }
.checks .ok .m { color: var(--up); } .checks .bad .m { color: var(--down); } .checks .na .m { color: var(--muted); }
.checks .why { grid-column: 2; color: var(--muted); font-size: 12px; }
.submit { width: 100%; height: 38px; justify-content: center; margin-top: 14px; font-size: 13.5px; }
.error { margin-top: 10px; padding: 8px 10px; border-left: 3px solid var(--down); background: var(--down-bg); font-size: 12.5px; }
.note-line { margin-top: 8px; font-size: 12px; color: var(--muted); }
.pending { margin-top: 16px; padding-top: 12px; border-top: 1px dashed var(--rule-strong); }
.pending h3 { margin: 0 0 6px; font-size: 12px; font-weight: 500; color: var(--ink-2); }
.pending .po { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 12.5px; padding: 3px 0; }
.ticket-off { color: var(--muted); font-size: 12.5px; }
.limit-row { margin-top: 12px; }

/* --- lesson column --- */
.lesson { width: 324px; overflow-y: auto; background: var(--bg); border-right: 1px solid var(--rule); padding: 22px 24px 28px; }
.lesson.collapsed { width: 44px; padding: 14px 0; }
.lesson .ls-top { display: flex; justify-content: space-between; align-items: baseline; font-size: 11.5px; color: var(--muted); }
.lesson h1 { font: 600 23px/1.2 var(--serif); letter-spacing: -0.01em; margin: 8px 0 14px; }
.lesson .body { font: 15px/1.6 var(--serif); color: var(--ink-2); }
.lesson .body p { margin: 0 0 12px; }
.lesson .body b { color: var(--ink); font-weight: 600; }
.lesson .body ul { margin: 0 0 12px; padding-left: 18px; }
.lesson .body li { margin-bottom: 4px; }
.lesson .body .up, .lesson .body .down { font-weight: 600; }
.lesson .body .note { display: block; margin: 16px 0; padding: 2px 0 2px 14px; border-left: 2px solid var(--accent); font: 13px/1.55 var(--sans); color: var(--ink-2); }
.lesson .body .formula { font: 13px var(--mono); padding: 10px 12px; background: var(--surface); border: 1px solid var(--rule); border-radius: var(--r); color: var(--ink); }
.lesson .body kbd { font-size: 11px; }
.ls-intro { font: 16px/1.5 var(--serif); color: var(--ink-2); margin: 0 0 16px; }
.ls-task { margin: 0 0 14px; padding: 10px 12px; background: var(--surface); border: 1px solid var(--rule); border-left: 3px solid var(--accent); border-radius: var(--r); font-size: 13px; }
.goal-list { list-style: none; margin: 0 0 20px; padding: 0; counter-reset: g; }
.goal-list li { counter-increment: g; display: grid; grid-template-columns: 26px 1fr; gap: 2px; padding: 5px 0; font-size: 13px; color: var(--ink); }
.goal-list li::before { content: counter(g); width: 18px; height: 18px; border-radius: 50%; border: 1px solid var(--rule-strong); font: 10.5px/16px var(--mono); text-align: center; color: var(--muted); margin-top: 1px; }
.goal-list li.done { color: var(--muted); text-decoration: line-through; text-decoration-color: var(--rule-strong); }
.goal-list li.done::before { content: '✓'; background: var(--up); border-color: var(--up); color: #fff; font-family: var(--sans); }
.ls-more { font-size: 13px; }
.ls-more .formula { font: 12.5px var(--mono); padding: 8px 10px; background: var(--surface); border: 1px solid var(--rule); border-radius: var(--r); color: var(--ink); }
.ls-more .up, .ls-more .down { font-weight: 600; }
.lesson-complete { margin: -8px 0 18px; padding: 8px 12px; background: var(--up-bg); color: var(--up); border-radius: var(--r); font-size: 13px; font-weight: 500; }
.lesson-nav { display: flex; justify-content: space-between; align-items: center; margin-top: 16px; gap: 8px; }
.lesson .vertical { writing-mode: vertical-rl; transform: rotate(180deg); background: none; border: 0; color: var(--ink-2); font-size: 12px; padding: 6px 0; margin: 0 auto; display: block; }

/* --- home --- */
.home { position: fixed; inset: 0; z-index: 40; background: var(--bg); overflow-y: auto; }
.home-inner { max-width: 1120px; margin: 0 auto; padding: 0 32px 48px; }
.home-top { display: flex; justify-content: space-between; align-items: center; height: 64px; border-bottom: 1px solid var(--rule); }
.home-top nav { display: flex; gap: 4px; align-items: center; }
.hero { padding: 56px 0 44px; max-width: 720px; }
.kicker { font-size: 12px; color: var(--accent); font-weight: 500; margin: 0 0 14px; }
.hero h1 { font: 600 44px/1.08 var(--serif); letter-spacing: -0.02em; margin: 0 0 18px; }
.hero .lede { font: 17px/1.6 var(--serif); color: var(--ink-2); margin: 0 0 28px; max-width: 620px; }
.cta { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.cta .btn { height: 42px; padding: 0 20px; font-size: 14px; }
.cta .meta { color: var(--muted); font-size: 12.5px; }
.home-grid { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 56px; border-top: 1px solid var(--rule); padding-top: 32px; }
.home h2 { font: 600 20px/1.2 var(--serif); margin: 0 0 6px; }
.home .h2-sub { color: var(--muted); margin: 0 0 18px; font-size: 13px; }
.toc { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--rule); }
.toc li { border-bottom: 1px solid var(--rule); }
.toc button { width: 100%; text-align: left; background: none; border: 0; padding: 14px 4px; display: grid; grid-template-columns: 44px minmax(0, 1fr) auto; gap: 14px; align-items: baseline; }
.toc button:hover { background: var(--surface); }
.toc button:hover .go { color: var(--ink); }
.toc .n { font: 13px var(--mono); color: var(--faint); }
.toc .t { font-weight: 500; font-size: 14px; }
.toc .tg { font-size: 11.5px; color: var(--muted); margin-left: 8px; font-weight: 400; }
.toc .s { display: block; color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.toc .go { font-size: 12px; color: var(--muted); white-space: nowrap; }
.toc .done .go { color: var(--up); }
.toc .done .n { color: var(--up); }
.toc .next { background: var(--surface); }
.toc .next .go { color: var(--accent); font-weight: 500; }
.modes > section { padding-bottom: 28px; margin-bottom: 28px; border-bottom: 1px solid var(--rule); }
.modes > section:last-child { border-bottom: 0; }
.modes p { color: var(--ink-2); margin: 0 0 14px; }
.form { display: grid; gap: 10px; }
.form label { display: grid; gap: 4px; font-size: 12px; color: var(--ink-2); font-weight: 500; }
.form .btn { justify-content: center; height: 34px; }
.history td, .history th { font-size: 11.5px; }
.home-foot { margin-top: 40px; padding-top: 18px; border-top: 1px solid var(--rule); color: var(--muted); font-size: 12px; max-width: 760px; }

/* --- overlays / sheets --- */
.overlay { position: fixed; inset: 0; z-index: 60; background: var(--scrim); display: grid; place-items: start center; padding: 48px 20px; overflow-y: auto; }
.overlay[hidden] { display: none; }
.sheet { background: var(--surface); border-radius: 4px; box-shadow: var(--shadow); width: min(860px, 100%); padding: 32px 36px 28px; position: relative; }
.sheet.narrow { width: min(560px, 100%); }
.sheet .close { position: absolute; right: 16px; top: 14px; background: none; border: 0; font-size: 20px; line-height: 1; color: var(--muted); padding: 6px; }
.sheet .close:hover { color: var(--ink); }
.sheet h1 { font: 600 28px/1.15 var(--serif); letter-spacing: -0.015em; margin: 0 0 6px; }
.sheet h2 { font: 600 16px var(--serif); margin: 28px 0 12px; }
.sheet .sub { color: var(--muted); margin: 0; }
.verdict { display: grid; grid-template-columns: auto 1fr; gap: 24px; align-items: center; margin-top: 24px; padding: 20px 0; border-top: 1px solid var(--rule); border-bottom: 1px solid var(--rule); }
.grade { font: 600 72px/0.9 var(--serif); width: 88px; text-align: center; }
.grade.A, .grade.B { color: var(--up); } .grade.C { color: var(--warn); } .grade.D, .grade.F { color: var(--down); } .grade.none { color: var(--faint); }
.verdict .line { font: 17px/1.45 var(--serif); margin: 0 0 4px; }
.verdict .meta { color: var(--muted); font-size: 12.5px; }
.compare { display: grid; grid-template-columns: repeat(3, 1fr); margin-top: 20px; }
.compare div { padding-right: 16px; }
.compare div + div { padding-left: 16px; border-left: 1px solid var(--rule); }
.compare .k { font-size: 12px; color: var(--muted); }
.compare .v { font: 500 22px var(--mono); font-variant-numeric: tabular-nums; }
.eq { height: 180px; position: relative; margin-top: 16px; border: 1px solid var(--rule); border-radius: var(--r); }
.eq-key { position: absolute; z-index: 2; left: 12px; top: 8px; font-size: 11.5px; color: var(--muted); display: flex; gap: 14px; }
.eq-key i { display: inline-block; width: 14px; height: 0; border-top: 2px solid var(--ink); vertical-align: middle; margin-right: 5px; }
.eq-key i.dash { border-top: 1px dashed var(--muted); }
.stat-table { display: grid; grid-template-columns: 1fr 1fr; gap: 0 32px; margin-top: 8px; }
.stat-table div { display: flex; justify-content: space-between; padding: 7px 0; border-bottom: 1px solid var(--rule); font-size: 13px; }
.stat-table dt { color: var(--muted); } .stat-table dd { margin: 0; font-family: var(--mono); font-variant-numeric: tabular-nums; }
.notes { margin: 0; padding-left: 20px; color: var(--ink-2); font: 14.5px/1.6 var(--serif); }
.notes li { margin-bottom: 6px; }
.reveal { margin-top: 18px; padding: 12px 14px; border-left: 3px solid var(--accent); background: var(--accent-bg); font-size: 13px; }
.sheet-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 28px; flex-wrap: wrap; }
.sheet-actions .btn { height: 36px; padding: 0 16px; }
.glossary { margin: 18px 0 0; }
.glossary div { display: grid; grid-template-columns: 180px 1fr; gap: 16px; padding: 9px 0; border-bottom: 1px solid var(--rule); }
.glossary dt { font-weight: 500; }
.glossary dd { margin: 0; color: var(--ink-2); }
.settings { display: grid; gap: 0; margin-top: 18px; }
.settings .row { display: grid; grid-template-columns: 1fr 150px; gap: 16px; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--rule); }
.settings .row label { font-weight: 500; }
.settings .row small { display: block; color: var(--muted); font-weight: 400; font-size: 12px; margin-top: 2px; }

.toasts { position: fixed; z-index: 80; left: 50%; bottom: 20px; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; }
.toast { background: var(--ink); color: var(--surface); border-radius: var(--r); padding: 8px 14px; font-size: 12.5px; box-shadow: var(--shadow); animation: tin .18s ease-out; }
.toast b { font-weight: 600; }
.toast.good::before { content: '✓  '; color: var(--up-soft); }
@keyframes tin { from { opacity: 0; transform: translateY(6px); } }
.loading { position: fixed; inset: 0; display: grid; place-items: center; color: var(--muted); padding: 24px; text-align: center; }

/* --- responsive --- */
@media (max-width: 1240px) { .session-progress .bar { width: 72px; } }
@media (max-width: 1180px) {
  body { overflow: auto; }
  .app { grid-template-columns: minmax(0, 1fr); height: auto; }
  .lesson, .lesson.collapsed { width: auto; border-right: 0; border-bottom: 1px solid var(--rule); }
  .lesson.collapsed { padding: 10px 16px; }
  .lesson .vertical { writing-mode: horizontal-tb; transform: none; margin: 0; }
  .chart-wrap { height: 60vh; flex: none; }
  .side { border-left: 0; border-top: 1px solid var(--rule); }
  .home-grid { grid-template-columns: minmax(0, 1fr); gap: 32px; }
  .session-progress { display: none; }
}
@media (max-width: 720px) {
  .top { height: auto; flex-wrap: wrap; gap: 6px 14px; padding: 10px 16px; }
  .instrument { order: 3; flex-basis: 100%; }
  .instrument .date { margin-left: auto; }
  .nav button:not(.theme-toggle) { padding: 0 7px; }
  .chartbar { padding: 8px 16px; }
  .transport { width: 100%; }
  .transport .pending-hint { flex-basis: 100%; order: 9; }
  #nextBtn { margin-left: auto; }
  .readout .cells { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .readout .cell { border-bottom: 1px solid var(--rule); }
  .feed summary { grid-template-columns: 58px minmax(0, 1fr) 14px; }
  .feed li.plain { grid-template-columns: 58px minmax(0, 1fr); }
  .feed .kind { display: none; }
  .feed .fb { padding-left: 70px; }
  .desk { height: 320px; }
  .home-inner { padding: 0 16px 40px; }
  .hero { padding: 36px 0 32px; }
  .hero h1 { font-size: 32px; }
  .sheet { padding: 24px 18px 20px; }
  .compare { grid-template-columns: 1fr; gap: 10px; }
  .compare div + div { padding-left: 0; border-left: 0; }
  .stat-table { grid-template-columns: 1fr; }
  .glossary div { grid-template-columns: 1fr; gap: 2px; }
  .settings .row { grid-template-columns: 1fr; gap: 6px; }
  .verdict { grid-template-columns: 1fr; gap: 8px; }
  .grade { text-align: left; }
}
