/* Tradermath: layout and components matched to the Mental Math Trainer. Loaded after app.css. */
:root { --shadow: 0 1px 2px rgba(20,20,20,.04), 0 2px 10px rgba(20,20,20,.05); }
:root[data-theme=dark] { --shadow: none; }
body { font: 14px/1.45 Inter, ui-sans-serif, system-ui, -apple-system, Segoe UI, sans-serif; }
kbd { font: 500 11px/1 Inter, system-ui, sans-serif; padding: 3px 6px; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 6px; background: var(--surface); color: var(--text-2); }
.dim { color: var(--muted); }

/* ---------- shell + header ---------- */
.app { max-width: 1120px; padding: 16px 18px 60px; min-height: 100vh; }
.top { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 0; margin-bottom: 18px; }
.brand { flex: 1; min-width: 0; }
.logo { font-size: 20px; font-weight: 700; letter-spacing: -.01em; }
.tabs { position: static; display: flex; gap: 4px; background: var(--surface-2); padding: 4px; border-radius: 12px; margin: 0; border: 0; overflow-x: auto; }
.tabs .tab { border: 0; background: transparent; padding: 7px 14px; border-radius: 9px; color: var(--text-2); font-weight: 500; cursor: pointer; white-space: nowrap; flex: none; }
.tabs .tab:hover { color: var(--text); }
.tabs .tab.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
:root[data-theme=dark] .tabs .tab.on { background: var(--text); color: var(--bg); }
.theme-btn { width: 40px; height: 40px; flex: none; display: inline-flex; align-items: center; justify-content: center; border: 1px solid var(--line); background: var(--surface); border-radius: 10px; cursor: pointer; color: var(--text); padding: 0; }
.theme-btn:hover { background: var(--surface-2); }
.theme-btn svg { width: 18px; height: 18px; }
.stats-top { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.io { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.sync { font-size: 12.5px; }
.sync.s-local { color: var(--warn); }
.sync.s-local i { background: var(--warn); }
.sync.s-ok { color: var(--ok); }
.sync.s-ok i { background: var(--ok); }
.view { gap: 14px; padding-top: 0; }

/* ---------- panels / headings ---------- */
.card { padding: 20px 22px; border-radius: var(--radius); box-shadow: var(--shadow); }
.card.tight { padding: 14px 16px; }
.grid4 > .card, .grid3 > .card { padding: 16px 18px; }
.card h3 { font-size: 15px; font-weight: 600; }
.h { font-size: 13px; font-weight: 600; color: var(--text-2); margin: 22px 0 10px; }
.h:first-child { margin-top: 0; }
.h.small { margin-top: 0; font-size: 15px; color: var(--text); }
.col > .h { margin: 8px 0 0; }
.col > .h:first-child { margin-top: 0; }
.sec-h { margin: 10px 0 0; }
.sec-h h2 { font-size: 13px; font-weight: 600; color: var(--text-2); letter-spacing: 0; }
.lead { color: var(--text-2); margin: 0 0 4px; }
.note { color: var(--muted); font-size: 12.5px; margin: 10px 0 0; line-height: 1.5; }
.muted { color: var(--muted); }
.stat-lbl { font-size: 11px; font-weight: 600; letter-spacing: .06em; }
.stat-big { font-family: inherit; font-variant-numeric: tabular-nums; }

/* ---------- buttons ---------- */
.btn { padding: 10px 16px; border-radius: 10px; font-weight: 500; border: 1px solid var(--line); background: var(--surface); color: var(--text); }
.btn.sm { padding: 7px 12px; font-size: 13px; border-radius: 9px; }
.btn.xs { padding: 4px 9px; font-size: 12px; border-radius: 8px; }
.btn.icon { width: 40px; height: 40px; padding: 0; }
.btn.primary, .start { background: var(--accent); color: var(--on-accent); border: 0; padding: 11px 24px; border-radius: 10px; font-weight: 600; font-size: 15px; cursor: pointer; box-shadow: 0 2px 8px #1f3a5f38; display: inline-flex; align-items: center; justify-content: center; gap: 7px; line-height: 1.2; }
:root[data-theme=dark] .btn.primary, :root[data-theme=dark] .start { box-shadow: none; }
.btn.primary.sm { padding: 8px 16px; font-size: 13px; }
.btn.primary.xs { padding: 5px 10px; font-size: 12px; }
.btn.primary:hover:not(:disabled), .start:hover:not(:disabled) { filter: brightness(1.08); background: var(--accent); }
.btn.primary:disabled, .start:disabled { opacity: .45; cursor: not-allowed; box-shadow: none; }
.start svg, .ghost svg { width: 16px; height: 16px; flex: none; }
.ghost { background: var(--surface); color: var(--text); border: 1px solid var(--line); padding: 10px 16px; border-radius: 10px; font-weight: 500; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; line-height: 1.2; }
.ghost.sm { padding: 7px 12px; font-size: 13px; border-radius: 9px; }
.ghost:hover:not(:disabled) { background: var(--surface-2); }
.ghost:disabled { opacity: .45; cursor: not-allowed; }
.link { background: none; border: 0; padding: 4px 0; color: var(--accent); cursor: pointer; font-weight: 500; font-size: 13px; display: inline-flex; align-items: center; gap: 4px; }
.link svg { width: 14px; height: 14px; }
.link:hover { text-decoration: underline; }
.link.danger-link { color: var(--err); }
.danger-btn, .start.danger-btn { background: var(--err); color: #fff; box-shadow: none; }
:root[data-theme=dark] .danger-btn { color: #1a0d0d; }
.start-row { display: flex; align-items: center; gap: 10px; margin-top: 14px; flex-wrap: wrap; }
.start-row .hint, .hint:not(.box) { color: var(--muted); font-size: 12.5px; }

/* ---------- chips (option pickers) ---------- */
.pills, .pills.dark { display: flex; flex-wrap: wrap; gap: 8px; background: none; border: 0; padding: 0; border-radius: 0; }
.pills button, :root[data-theme=dark] .pills button { background: var(--surface); border: 1px solid var(--line); color: var(--text-2); padding: 6px 13px; border-radius: 999px; font-size: 13px; font-weight: 500; cursor: pointer; min-width: 40px; transition: all .1s; box-shadow: none; }
.pills button:hover { border-color: var(--muted); color: var(--text); }
.pills button.on, .pills.dark button.on, :root[data-theme=dark] .pills button.on, :root[data-theme=dark] .pills.dark button.on { background: var(--accent); border-color: var(--accent); color: var(--on-accent); box-shadow: none; }
.tag { font-size: 12px; font-weight: 600; padding: 3px 10px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); white-space: nowrap; }
.tag.dim { background: var(--surface-2); color: var(--text-2); }

/* ---------- form fields ---------- */
.inp { border-radius: 8px; padding: 7px 10px; }
.inp.sm { padding: 6px 9px; }
.inp.num { font-family: inherit; font-variant-numeric: tabular-nums; }
.fld { font-size: 11.5px; font-weight: 500; color: var(--muted); }
.frow .flbl { font-size: 13px; font-weight: 600; color: var(--text-2); }
.tm-fields { gap: 10px; margin-top: 4px; }
.tm-custom { align-self: flex-start; }

/* ---------- stat tiles ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.cards > .stat { display: block; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; box-shadow: var(--shadow); }
.stat-v { font-size: 26px; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; line-height: 1.15; }
.stat-l { color: var(--muted); font-size: 12px; margin-top: 4px; }
.results .cards > .stat, .panel .cards > .stat { box-shadow: none; background: var(--surface-2); border-color: transparent; }
.metric { padding: 9px 13px; border-radius: 12px; }
.metric span { font-size: 12px; }
.metric b { font-family: inherit; font-variant-numeric: tabular-nums; font-size: 17px; font-weight: 700; }

/* ---------- tables ---------- */
.tbl-wrap { overflow: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; }
.tbl-wrap.tall { max-height: 420px; }
.tbl { font-size: 13px; }
.tbl th, .tbl td { padding: 8px 12px; white-space: nowrap; }
.tbl th { color: var(--muted); font-weight: 500; font-size: 12px; background: var(--surface); }
.tbl-wrap .tbl th { position: sticky; top: 0; z-index: 1; }
.tbl td { font-family: inherit; font-variant-numeric: tabular-nums; }
.tbl .num { text-align: right; }
.del-cell { width: 1%; }
.del { background: none; border: 1px solid transparent; color: var(--muted); cursor: pointer; padding: 3px 7px; border-radius: 7px; font-size: 13px; filter: grayscale(1); opacity: .7; }
.del:hover { border-color: var(--line); filter: none; opacity: 1; background: var(--err-soft); }
.group-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 6px; }
.group-head .h { margin: 0; }

/* ---------- confirm dialog (trainer style) ---------- */
.tm-scrim { position: fixed; inset: 0; background: #14141459; display: flex; align-items: center; justify-content: center; z-index: 60; padding: 20px; animation: tm-fade .15s ease-out; }
:root[data-theme=dark] .tm-scrim { background: #0009; }
.modal-in { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 20px; width: min(560px, 100%); box-shadow: 0 20px 50px #0003; animation: tm-pop .2s cubic-bezier(.22,1,.36,1); }
.modal-in .h { margin: 0 0 12px; }
.del-summary { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; color: var(--text-2); font-size: 13px; line-height: 1.7; }
.del-summary .big-line { color: var(--text); font-weight: 600; }
@keyframes tm-fade { from { opacity: 0; } to { opacity: 1; } }

/* existing app dialogs: same look */
.scrim { background: #14141459; align-items: center; }
:root[data-theme=dark] .scrim { background: #0009; }
.scrim > .modal { border-radius: 16px; box-shadow: 0 20px 50px #0003; }
.modal-h { padding: 18px 20px 12px; }
.modal-b { padding: 16px 20px 20px; }

/* ---------- game setup ---------- */
.tm-titlebar { gap: 10px; }
.tm-gname { font-size: 20px; font-weight: 700; letter-spacing: -.01em; }

/* ---------- in-game HUD (trainer style) ---------- */
.hud { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 10px; }
.hud-l { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.hud-l .ghost { margin-right: 4px; }
.hud-r { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; }
.clock { font-size: 44px; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; line-height: 1; min-height: 44px; transition: color .2s; }
.clock.low { color: var(--err); animation: tm-tick 1s ease-in-out infinite; }
@keyframes tm-tick { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.05); } }
.score-lbl { font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); text-align: right; }
.score { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--text); line-height: 1.1; text-align: right; }
.score.pos { color: var(--ok); } .score.neg { color: var(--err); }
.tm-bar { height: 5px; background: var(--surface-2); border-radius: 5px; overflow: hidden; margin-top: -4px; visibility: hidden; }
.tm-bar.on { visibility: visible; }
.tm-bar .bar-fill { height: 100%; width: 100%; background: var(--accent); border-radius: 5px; transition: width .12s linear, background-color .2s; }
.tm-bar.low .bar-fill { background: var(--err); }
.playing-view .timer { display: none !important; }

/* ---------- results (trainer style) ---------- */
.results { display: flex; flex-direction: column; gap: 14px; border-color: var(--line); }
.res-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; font-size: 13px; color: var(--muted); }
.res-title { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; color: var(--text-2); }
.res-title svg { width: 16px; height: 16px; color: var(--warn); }
.big-result { display: flex; flex-direction: column; align-items: center; margin: 6px 0 10px; }
.big { font-size: 96px; font-weight: 700; letter-spacing: -.04em; line-height: 1; font-variant-numeric: tabular-nums; }
.big.pos { color: var(--ok); } .big.neg { color: var(--err); }
.big-lbl { color: var(--muted); font-size: 13px; margin-top: 6px; }
.results .start-row { margin-top: 4px; }

@media (max-width: 720px) {
  .app { padding: 12px 12px 40px; }
  .logo { font-size: 18px; }
  .top { gap: 10px; }
  .tabs { order: 3; width: 100%; }
  .clock { font-size: 36px; min-height: 36px; }
  .score { font-size: 22px; }
  .big { font-size: 64px; }
  .hud { grid-template-columns: 1fr auto; }
  .hud-l { grid-column: 1 / -1; }
}

/* pager: chip style */
.pager button { font-family: inherit; font-variant-numeric: tabular-nums; }
.pager button.on { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
/* theme menu: Light / Dark / System */
.theme-dd { position: relative; flex: none; }
.theme-btn.open { background: var(--surface-2); }
.theme-menu { position: absolute; top: calc(100% + 6px); right: 0; z-index: 40; min-width: 170px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 6px; box-shadow: 0 10px 30px #00000024; animation: tm-pop .18s var(--tm-out) both; transform-origin: top right; }
.theme-opt { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 9px; border: 0; background: none; border-radius: 8px; cursor: pointer; color: var(--text); font: inherit; font-size: 14px; text-align: left; }
.theme-opt span { flex: 1; }
.theme-opt svg { width: 18px; height: 18px; flex: none; }
.theme-opt:hover { background: var(--surface-2); }
.theme-opt.on { color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, var(--surface)); }
/* theme switch: one cross-fade of the whole page (View Transitions), so text, backgrounds and borders change together */
::view-transition-old(root), ::view-transition-new(root) { animation-duration: .25s; animation-timing-function: ease; }
/* sliding pill for the top tabs (positioned by motion.js) */
.tabs.has-pill { position: relative; }
.tabs.has-pill::before { content: ""; position: absolute; left: 0; top: 0; width: var(--pill-w, 0); height: var(--pill-h, 0); transform: translate(var(--pill-x, 0), var(--pill-y, 0)); opacity: var(--pill-o, 0); border-radius: 9px; background: var(--surface); box-shadow: var(--shadow); transition: transform .28s cubic-bezier(.3,.7,.3,1), width .28s cubic-bezier(.3,.7,.3,1), height .28s, opacity .15s; pointer-events: none; z-index: 0; }
:root[data-theme=dark] .tabs.has-pill::before { background: var(--text); }
.tabs.pill-still::before { transition: none; }
.tabs.has-pill .tab { position: relative; z-index: 1; transition: color .2s; }
.tabs.has-pill .tab.on, :root[data-theme=dark] .tabs.has-pill .tab.on { background: transparent; box-shadow: none; }
/* filter chips: quick press and colour change */
.pills button, :root[data-theme=dark] .pills button, .tip-seg button { transition: background-color .18s, border-color .18s, color .18s, transform .12s var(--tm-out); }
.pills button:active, .tip-seg button:active { transform: scale(.94); }
@media (prefers-reduced-motion: reduce) { .tabs.has-pill::before { transition: none; } }

/* mock: "Finish now?" box sits at the top of the window so the close button visibly does something (24 Nov) */
.tip-confirm.tip-confirm-top { position: sticky; top: 0; z-index: 3; margin: 0 0 10px; box-shadow: 0 6px 18px rgba(0,0,0,.25); }

/* top-tab pill as a real element (motion.js, 24 Nov); the ::before pill is retired */
.tabs.has-pill2::before { content: none !important; display: none !important; }
.tabs.has-pill2 .mo-pill { position: absolute; left: 0; top: 0; z-index: 0; border-radius: 9px; background: var(--surface); box-shadow: var(--shadow); pointer-events: none; will-change: transform, width; }
:root[data-theme=dark] .tabs.has-pill2 .mo-pill { background: var(--text); }

/* mobile dashboard (24 Nov): streak flame sits inline before its text at laptop size; week strip letters never run into the button */
.stat:has(> .streak-ic) { display: flex !important; flex-direction: row !important; align-items: center !important; justify-content: flex-start !important; gap: 12px !important; }
.stat > .streak-ic { order: 0 !important; position: static !important; flex: none; width: 44px !important; height: 44px !important; margin: 0 !important; }
.stat > .streak-ic + div { order: 1; min-width: 0; }
.rd-daily .rd-week { align-items: start; margin-bottom: 4px; }
.rd-daily .rd-day { min-width: 0; height: auto !important; }
.rd-daily .rd-day i { height: auto !important; }
.rd-daily .rd-day em { line-height: 1.2; }
.rd-daily .rd-week { flex: none; }
.stats .stat > span.gicon.streak-ic, .stat > span.gicon.streak-ic.streak-ic { width: 44px !important; height: 44px !important; min-width: 44px; border-radius: 12px; }
.stat > span.gicon.streak-ic.streak-ic svg { width: 22px !important; height: 22px !important; }
.hero .grid4 > .stat:nth-child(4) > .gicon.streak-ic { position: static !important; width: 44px !important; height: 44px !important; border-radius: 12px; }
.rd-daily .rd-week { height: auto !important; min-height: max-content; contain: none !important; overflow: visible; }
.rd-daily .rd-day i { height: 38px !important; width: 100%; max-width: 38px; aspect-ratio: auto; }
.rd-daily .rd-day.future i { opacity: .45; }

/* text size (27 Nov): Normal or Big, kept on this device, beside the theme button (same as the Maths Workbook) */
.tip-aa { font-weight: 700; font-size: 16px; line-height: 1; letter-spacing: -.02em; }
.tip-aa small { font-size: 11px; margin-right: 1px; }
.tip-size.on { background: var(--accent-soft); color: var(--accent); }
html[data-size=big] body { zoom: 1.15; }

/* layout audit fixes (27 Nov) */
.hero .grid4 > .stat:nth-child(2) > .gicon.streak-ic { position: static !important; width: 44px !important; height: 44px !important; border-radius: 12px; }
@media (max-width: 600px) {
  .top { gap: 8px; }
  .top .theme-btn { width: 36px; height: 36px; border-radius: 9px; }   /* title + Aa + theme fit on one line, big text too */
  .tip-key-i { min-height: 32px; }
  .btn.xs, .btn.sm, .hud .link { min-height: 32px; }
  .mm-quote input { min-height: 38px; font-size: 16px; }              /* 16px also stops iOS zooming in on focus */
}
@media (max-width: 600px) {
  /* P&L and streak tiles: icon above the text, like the ring and gauge in the row above */
  .hero .grid4 > .stat:has(> .streak-ic) { flex-direction: column !important; align-items: flex-start !important; gap: 10px !important; }
  html[data-size=big] .top .logo { font-size: 16px; }
  html[data-size=big] .top { gap: 6px; }
}

/* no blue flash when tapping buttons on phones (27 Nov) */
*{-webkit-tap-highlight-color:transparent}

/* Android app (27 Nov): everything runs edge to edge; the app passes the status and button bar heights as --sat / --sab */
html{--sat:0px;--sab:0px}
body{padding-top:var(--sat)!important;padding-bottom:var(--sab)!important}
.scrim{padding-top:calc(var(--sat) + 12px)!important;padding-bottom:calc(var(--sab) + 12px)!important}

.tip-gloss-search{top:calc(var(--sat) + 8px)}

/* stacked plain-text fractions (frac.js, 27 Nov): numerator over denominator, full size */
.sfrac{display:inline-flex;flex-direction:column;align-items:center;vertical-align:middle;line-height:1.05;margin:0 .1em;text-align:center}
.sfrac > span{display:block;padding:0 .12em}.sfrac > span + span{border-top:max(1px,.06em) solid currentColor;padding-top:.06em}
/* mid widths: title, tabs and the two header buttons stay on one line; the tabs scroll (27 Nov) */
@media (min-width: 901px) { .top { flex-wrap: nowrap; } .top .tabs { min-width: 0; flex: 1 1 auto; overflow-x: auto; scrollbar-width: none; } .top .tabs::-webkit-scrollbar { display: none; } }
