/* Trading Game: dark theme only, mobile first. No external fonts. */

:root {
  --bg: #0e1116;
  --panel: #161b24;
  --panel-2: #1d2430;
  --line: #2a3342;
  --text: #e6ebf2;
  --muted: #9aa4b2;
  --up: #26a69a;
  --down: #ef5350;
  --accent: #4f8cff;
  --warn: #f5c542;
  --ctl-h: 44px;
  color-scheme: dark;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.35 system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
  overflow-x: hidden;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
}

button,
select,
input {
  font: inherit;
  color: inherit;
}

/* Practice status on the Home PRACTICE button: a small row of values, coloured by result. */
.practice-status {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  text-align: left;
}

.ps {
  white-space: nowrap;
  color: var(--muted);
}

.ps b {
  font-weight: 700;
  color: var(--text);
}

.ps.ps-up b {
  color: var(--up);
}

.ps.ps-down b {
  color: var(--down);
}

.pos {
  color: var(--up);
}

.neg {
  color: var(--down);
}

/* ---------- screens ---------- */

.screen {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  width: 100%;
}

.screen.game {
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  min-height: 56px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  padding-top: max(6px, env(safe-area-inset-top));
}

.brand {
  font-weight: 700;
  letter-spacing: 0.02em;
  padding: 6px 2px;
}

.title {
  flex: 1 1 auto;
  min-width: 0;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.equity-block {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  justify-content: center;
  flex: 0 0 auto;
  min-width: 0;
  text-align: right;
}

.equity {
  font-weight: 700;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.total {
  font-size: 12px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}

.total.pos {
  color: var(--up);
}

.total.neg {
  color: var(--down);
}

/* ---------- home ---------- */

.home-body {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 16px;
  padding-bottom: 8px;
  max-width: 520px;
  width: 100%;
  margin: 0 auto;
}

.lead {
  margin: 4px 0 4px;
  color: var(--muted);
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.card-title {
  margin: 0;
  font-size: 18px;
  letter-spacing: 0.04em;
}

.sub {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.msg {
  margin: 0;
  color: var(--warn);
  font-size: 14px;
  min-height: 0;
}

.msg:empty {
  display: none;
}

.footer {
  padding: 14px 16px;
  padding-bottom: max(14px, env(safe-area-inset-bottom));
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.mode-btn {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: 4px;
  width: 100%;
  min-height: 64px;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  text-align: left;
  cursor: pointer;
}

.mode-btn.primary {
  border-color: var(--accent);
}

.mode-btn:disabled {
  opacity: 0.5;
}

.mode-name {
  font-weight: 800;
  font-size: 17px;
  letter-spacing: 0.05em;
}

.mode-sub {
  color: var(--muted);
  font-size: 13px;
  font-weight: 400;
}

.row2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

/* ---------- game ---------- */

.stats {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 30px;
  padding: 4px 12px;
  font-size: 13px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
}

.chart-wrap {
  position: relative;
  flex: 1 1 auto;
  min-height: 120px;
  overflow: hidden;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.chart-wrap canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

/* >> button: bottom right of the plot, just left of the price scale */
.jump {
  position: absolute;
  right: 70px;
  bottom: 8px;
  min-width: 44px;
  min-height: 44px;
  background: rgba(22, 27, 36, 0.92);
  font-size: 16px;
}

.jump:disabled {
  opacity: 0.35;
}

.bar {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 56px;
  padding: 6px 8px;
  background: var(--panel);
  border-top: 1px solid var(--line);
  flex: 0 0 auto;
}

.bar.end {
  min-height: 56px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--ctl-h);
  min-width: 44px;
  padding: 0 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  font-weight: 600;
  font-size: 15px;
  line-height: 1;
  text-align: center;
  cursor: pointer;
  touch-action: manipulation;
  white-space: nowrap;
}

.btn:disabled {
  opacity: 0.4;
  cursor: default;
}

a.btn {
  text-decoration: none;
  color: inherit;
}

a.btn[hidden] {
  display: none;
}

.btn.primary {
  border-color: var(--accent);
}

.btn.buy {
  background: var(--up);
  border-color: var(--up);
  color: #04110f;
}

.btn.sell {
  background: var(--down);
  border-color: var(--down);
  color: #1a0505;
}

.btn.big {
  flex: 1 1 0;
  min-height: 52px;
  font-size: 17px;
  font-weight: 800;
}

.btn.x {
  min-width: 44px;
  padding: 0;
  font-size: 18px;
}

.btn.toggle[aria-pressed="true"] {
  border-color: var(--warn);
  color: var(--warn);
}

.speed,
.risk-field {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
}

.speed-label,
.cap {
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
}

.select,
.risk-input {
  min-height: var(--ctl-h);
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bg);
  padding: 0 8px;
  font-size: 16px; /* at least 16px so iOS does not zoom */
  font-variant-numeric: tabular-nums;
}

.risk-input {
  width: 76px;
  text-align: center;
}

.risk-input.wide {
  width: 120px;
}

.risk-bar .risk-field {
  margin-left: 0;
}

.risk-bar .btn.toggle {
  margin-left: auto;
}

/* open position row */
.pos-row {
  gap: 4px;
}

.pos-side {
  flex: 0 0 auto;
  min-width: 52px;
  padding: 4px 6px;
  border-radius: 6px;
  text-align: center;
  font-weight: 800;
  font-size: 13px;
  letter-spacing: 0.04em;
  background: var(--panel-2);
}

.pos-side.buy {
  color: var(--up);
}

.pos-side.sell {
  color: var(--down);
}

.pos-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1 1 0;
  min-width: 0;
  line-height: 1.15;
}

.pos-cell .val {
  font-weight: 700;
  font-size: 13px;
  white-space: nowrap;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  font-variant-numeric: tabular-nums;
}

/* order bar */
.actions {
  flex-wrap: wrap;
}

.order-info {
  flex: 1 0 100%;
  margin: 0;
  font-size: 13px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  line-height: 1.3;
}

.order-info.hint {
  color: var(--muted);
}

.order-row {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1 1 100%;
}

.order-row[hidden] {
  display: none !important;
}

.bar.end .btn {
  flex: 1 1 0;
}

/* compact history at the bottom */
.history {
  flex: 0 0 auto;
  background: var(--panel);
  border-top: 1px solid var(--line);
}

.hist-sum {
  display: flex;
  align-items: center;
  min-height: 44px;
  padding: 0 12px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  list-style: none;
}

.hist-sum::-webkit-details-marker {
  display: none;
}

.hist-sum::after {
  content: "+";
  margin-left: auto;
  color: var(--muted);
  font-size: 18px;
}

.history[open] .hist-sum::after {
  content: "-";
}

.hist-list {
  list-style: none;
  margin: 0;
  padding: 0 8px 8px;
  max-height: 18dvh;
  max-height: 18vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.hist-row {
  display: grid;
  grid-template-columns: 44px 1fr auto;
  align-items: center;
  gap: 2px 8px;
  padding: 6px 4px;
  border-top: 1px solid var(--line);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.hist-row .hist-side {
  font-weight: 800;
}

.hist-row .hist-prices {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
}

.hist-row .hist-pnl {
  font-weight: 700;
  text-align: right;
}

.hist-row .hist-reason {
  grid-column: 2 / 4;
  font-size: 12px;
  color: var(--muted);
}

.hist-row.selectable {
  cursor: pointer;
}

.hist-row.selectable:focus-visible {
  outline: 2px solid var(--accent, #4a9eff);
  outline-offset: -2px;
}

.hist-row.selected {
  background: rgba(127, 170, 230, 0.16);
  box-shadow: inset 3px 0 0 var(--accent, #4a9eff);
}

.hist-tag {
  margin-left: 8px;
  padding: 0 5px;
  border: 1px solid var(--line);
  border-radius: 4px;
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
}

.hist-empty {
  padding: 8px 4px;
  font-size: 13px;
  color: var(--muted);
}

/* ---------- dialogs (overlay + centred panel) ---------- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(5, 7, 10, 0.72);
}

.dialog {
  width: 100%;
  max-width: 420px;
  max-height: calc(100vh - 32px);
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}

.result-card {
  width: 100%;
}

.big-number {
  margin: 0;
  font-size: 34px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.big-number.pos {
  color: var(--up);
}

.big-number.neg {
  color: var(--down);
}

.res-rows {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 14px;
  margin: 0;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

.res-rows dt {
  color: var(--muted);
}

.res-rows dd {
  margin: 0;
  text-align: right;
}

.close-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.close-input-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.close-result {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  min-height: 1.3em;
}

/* ---------- game layout: one column on phones, two panes from 900 px ----------
 * Phone: the panes are transparent (display: contents) and `order` keeps the sequence the phone has always had:
 * header, stats, chart, position row, replay, risk, order, finish, history.
 * Wide: CSS grid, chart pane on the left, splitter, control pane on the right. The breakpoint is the media query
 * below; ui_logic.js reads the same query (TGUI.WIDE_QUERY) so the script and the CSS switch together.
 */
.pane {
  display: contents;
}

.splitter {
  display: none;
}

.pane-right > .topbar {
  order: 1;
}

.stats {
  order: 2;
}

#chart-wrap {
  order: 3;
}

#pos-row {
  order: 4;
}

.bar.replay {
  order: 5;
}

.bar.risk-bar {
  order: 6;
}

.bar.actions {
  order: 7;
}

.bar.end {
  order: 8;
}

#history {
  order: 9;
}

@media (min-width: 900px) {
  .screen.game {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 12px var(--split-right, clamp(280px, 30%, 50%));
    grid-template-rows: minmax(0, 1fr);
  }

  .pane {
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
  }

  .pane-left {
    grid-column: 1;
    grid-row: 1;
  }

  .pane-right {
    grid-column: 3;
    grid-row: 1;
    overflow-x: hidden;
    overflow-y: auto;
    border-left: 1px solid var(--line);
    background: var(--bg);
  }

  .pane-right > * {
    flex: 0 0 auto;
  }

  .pane-right > .topbar,
  .pane-right > .stats,
  .pane-right > #pos-row,
  .pane-right > .bar.risk-bar,
  .pane-right > .bar.actions,
  .pane-right > .bar.end,
  .pane-right > #history {
    order: 0;
  }

  .pane-right > .topbar {
    flex-wrap: wrap;
  }

  .pane-left .chart-wrap {
    flex: 1 1 0;
    min-height: 0;
    border-top: 0;
  }

  .pane-left .speed {
    margin-left: 0;
  }

  .pane-right #history {
    flex: 1 1 0;
    min-height: 140px;
    display: flex;
    flex-direction: column;
    border-top: 1px solid var(--line);
  }

  .pane-right .hist-list {
    flex: 1 1 0;
    min-height: 0;
    max-height: none;
  }

  .splitter {
    display: flex;
    grid-column: 2;
    grid-row: 1;
    align-items: center;
    justify-content: center;
    background: var(--panel-2);
    border-left: 1px solid var(--line);
    border-right: 1px solid var(--line);
    cursor: col-resize;
    touch-action: none;
    user-select: none;
    outline: none;
  }

  .splitter:hover,
  .splitter:focus-visible,
  .screen.splitting .splitter {
    background: #2b3a55;
    border-color: var(--accent);
  }

  .splitter .grip {
    width: 6px;
    height: 48px;
    background: radial-gradient(circle, var(--muted) 1.5px, transparent 2px) 0 0 / 6px 12px;
  }

  .splitter:hover .grip,
  .splitter:focus-visible .grip,
  .screen.splitting .splitter .grip {
    background: radial-gradient(circle, #ffffff 1.5px, transparent 2px) 0 0 / 6px 12px;
  }

  .screen.splitting {
    user-select: none;
    cursor: col-resize;
  }

  .screen.splitting * {
    cursor: col-resize !important;
  }
}

/* ---------- replay row: a cassette-deck look. Always one line: Play, Step, Speed, Reset ---------- */

.bar.replay {
  flex-wrap: nowrap;
  justify-content: flex-start;
  gap: 8px;
  padding: 8px 10px;
  background: linear-gradient(180deg, #1c2330 0%, #10141c 100%);
  border-top: 1px solid #05070a;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05), inset 0 -2px 8px rgba(0, 0, 0, 0.5);
}

/* Transport keys: raised metal, pressed down when touched. */
.bar.replay .btn {
  min-height: 44px;
  min-width: 56px;
  padding: 0 8px;
  border-radius: 6px;
  border: 1px solid #05070a;
  background: linear-gradient(180deg, #5a6373 0%, #323947 50%, #282e3a 51%, #343c4b 100%);
  color: #eef2f8;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2), 0 2px 0 #06080b, 0 4px 8px rgba(0, 0, 0, 0.5);
  transition: transform 60ms ease, box-shadow 60ms ease;
}

.bar.replay .btn:active:not(:disabled) {
  transform: translateY(2px);
  box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.7), 0 0 0 #06080b;
}

.bar.replay .btn:disabled {
  opacity: 0.45;
}

/* Speed sits right after Step. Reset is the red eject key, pushed to the far right so it is not hit by accident. */
.bar.replay .speed {
  margin-left: 0;
}

.bar.replay .btn.reset {
  margin-left: auto;
  background: linear-gradient(180deg, #c94a4c 0%, #8a2628 50%, #7a2123 51%, #9a2c2e 100%);
  color: #fff4f4;
}

/* Speed: a small LCD window for the value and a tape-slider with a knob. */
.speed {
  gap: 6px;
}

.speed-out {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 46px;
  height: 28px;
  padding: 0 6px;
  border-radius: 4px;
  border: 1px solid #000;
  background: #05080b;
  box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.95);
  color: #7dffa0;
  font-family: ui-monospace, Consolas, monospace;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 0 6px rgba(125, 255, 160, 0.55);
  white-space: nowrap;
}

.speed .slider {
  -webkit-appearance: none;
  appearance: none;
  width: 96px;
  height: 24px;
  margin: 0;
  background: transparent;
  cursor: pointer;
}

.speed .slider:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.speed .slider::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 3px;
  background: linear-gradient(180deg, #05080b, #1a1f29);
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.9), 0 1px 0 rgba(255, 255, 255, 0.08);
}

.speed .slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 22px;
  height: 22px;
  margin-top: -8px;
  border-radius: 4px;
  border: 1px solid #05070a;
  background: linear-gradient(180deg, #f4f6fa 0%, #a3acbb 55%, #5b6476 100%);
  box-shadow: 0 2px 3px rgba(0, 0, 0, 0.6), inset 0 1px 0 #fff;
}

.speed .slider::-moz-range-track {
  height: 6px;
  border-radius: 3px;
  background: #0b0f15;
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.9);
}

.speed .slider::-moz-range-thumb {
  width: 22px;
  height: 22px;
  border-radius: 4px;
  border: 1px solid #05070a;
  background: linear-gradient(180deg, #f4f6fa 0%, #a3acbb 55%, #5b6476 100%);
  box-shadow: 0 2px 3px rgba(0, 0, 0, 0.6);
}

/* Phones: the row must fit 360 px, so the speed name is read by screen readers only. */
@media (max-width: 899px) {
  .bar.replay {
    gap: 5px;
    padding: 8px 6px;
  }

  .bar.replay .btn {
    min-width: 50px;
    padding: 0 4px;
    font-size: 11px;
  }

  .speed .slider {
    width: 68px;
  }

  .speed-out {
    min-width: 38px;
    padding: 0 3px;
    font-size: 12px;
  }

  .speed .speed-label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }
}

@media (min-width: 900px) {
  .pane-left .bar.replay {
    min-height: 0;
    padding: 6px 8px;
  }

  .pane-left .bar.replay .btn {
    min-height: 36px;
  }

  .pane-left .speed .slider {
    height: 22px;
  }
}

/* ---------- chart help button and manual ---------- */

/* Only the button takes pointer events; the rest of the chart keeps panning. The hit area is 44 px on phones and
 * 36 px on desktop, the visible circle is 28 px. */
.help-btn {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 3;
  width: 44px;
  height: 44px;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;
  display: flex;
  align-items: center;
  justify-content: center;
}

.help-btn::before {
  content: "";
  position: absolute;
  z-index: -1;
  left: 50%;
  top: 50%;
  width: 28px;
  height: 28px;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  border: 1px solid var(--line);
  background: rgba(22, 27, 36, 0.92);
}

.help-btn:hover,
.help-btn:focus-visible {
  color: var(--text);
  outline: none;
}

.help-btn:hover::before,
.help-btn:focus-visible::before {
  border-color: var(--accent);
}

@media (min-width: 900px) {
  .help-btn {
    width: 36px;
    height: 36px;
  }
}

.help-card {
  max-width: 460px;
}

.help-body {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.help-h {
  margin: 6px 0 0;
  font-size: 15px;
  letter-spacing: 0.03em;
}

.help-list {
  margin: 0;
  padding-left: 18px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 14px;
  line-height: 1.35;
}

.help-foot {
  margin-top: 6px;
}

.toast {
  position: fixed;
  top: 64px;
  top: calc(64px + env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: 20;
  max-width: calc(100% - 24px);
  padding: 10px 14px;
  border-radius: 10px;
  background: #242d3b;
  border: 1px solid var(--line);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
  font-size: 14px;
  text-align: center;
}

/* ---------- accounts, leaderboard and auth screens ---------- */

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.acct-area {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
  min-width: 0;
}

.acct-area .btn {
  min-width: 44px;
  padding: 0 10px;
}

.btn.chip {
  max-width: 150px;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 700;
}

.btn.wide,
.big-btn {
  width: 100%;
  min-height: 52px;
  font-size: 17px;
  font-weight: 700;
}

.btn.danger {
  background: var(--down);
  border-color: var(--down);
  color: #1a0505;
}

.link-btn {
  text-decoration: none;
}

.banner {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--warn);
  background: rgba(245, 197, 66, 0.08);
}

.banner-text {
  margin: 0;
  font-weight: 600;
}

.banner-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
}

.banner-msg {
  margin: 0;
  font-size: 14px;
  color: var(--muted);
}

.banner-msg:empty {
  display: none;
}

.page {
  max-width: 560px;
  width: 100%;
  margin: 0 auto;
}

.page-body {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 16px;
  padding-bottom: 24px;
}

.page-body.narrow {
  max-width: 440px;
  width: 100%;
  margin: 0 auto;
}

.page-title {
  margin: 4px 0 0;
  font-size: 22px;
  outline: none;
}

.section-title {
  margin: 4px 0 0;
  font-size: 14px;
  letter-spacing: 0.04em;
  color: var(--muted);
  text-transform: uppercase;
}

.notice {
  margin: 0;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  font-size: 15px;
}

.hint {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
}

.links {
  margin: 0;
  font-size: 15px;
  color: var(--muted);
}

.links a {
  color: var(--accent);
  padding: 10px 0;
  display: inline-block;
}

.form,
.done,
.stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.stack .btn {
  width: 100%;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field label {
  font-size: 14px;
  color: var(--muted);
}

.field input {
  width: 100%;
  min-height: var(--ctl-h);
  padding: 0 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bg);
  font-size: 16px; /* at least 16px so iOS does not zoom */
}

.field input[aria-invalid="true"] {
  border-color: var(--down);
}

.field input:focus-visible,
.btn:focus-visible,
.tab:focus-visible,
a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.pw-row {
  display: flex;
  align-items: stretch;
  gap: 6px;
}

.pw-row input {
  flex: 1 1 auto;
  min-width: 0;
}

.pw-toggle {
  min-width: 64px;
  font-size: 14px;
}

.field-error,
.form-error {
  margin: 0;
  font-size: 14px;
  color: var(--down);
}

.field-error:empty,
.form-error:empty,
.lb-status:empty {
  display: none;
}

.form-error:empty {
  display: none;
}

.acc-verify {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.acc-verify .sub:empty {
  display: none;
}

/* leaderboard */

.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.tabs.three {
  grid-template-columns: 1fr 1fr 1fr;
}

.tab {
  min-height: var(--ctl-h);
  padding: 0 6px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  touch-action: manipulation;
}

.tab[aria-pressed="true"] {
  border-color: var(--accent);
  color: var(--text);
  box-shadow: inset 0 -3px 0 var(--accent);
}

.lb-table {
  width: 100%;
  table-layout: fixed;
  border-collapse: collapse;
  font-size: 15px;
  font-variant-numeric: tabular-nums;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
}

.lb-table th,
.lb-table td {
  padding: 10px 8px;
  text-align: left;
  border-top: 1px solid var(--line);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lb-table thead th {
  border-top: 0;
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
  letter-spacing: 0.04em;
}

/* column widths: the board has rank, player, trades, % P&L, DD and Review (100%); Completed Sessions swaps rank
   for league and gives the player 20% (100%) */
.lb-table .c-rank {
  width: 10%;
}

.lb-table .c-nick {
  width: 26%;
}

.lb-table .c-trades {
  width: 12%;
  text-align: right;
}

.lb-table .c-total {
  width: 16%;
  text-align: right;
}

.lb-table .c-dd {
  width: 14%;
  text-align: right;
}

.lb-table .c-date {
  width: 22%;
  text-align: right;
}

.lb-table .c-league {
  width: 16%;
}

.lb-table .c-narrow {
  width: 20%;
}

/* a date wraps onto two lines (date, then time) rather than being cut off on a phone */
.lb-table td.c-date {
  white-space: normal;
  font-size: 13px;
  line-height: 1.25;
}

/* a session row can be opened by double click or double tap, or with Enter */
.lb-table tr.openable {
  cursor: pointer;
}

.lb-table tr.openable:hover td {
  background: rgba(255, 255, 255, 0.03);
}

.lb-table tr.openable:focus-visible {
  outline: 2px solid var(--accent, #4aa3ff);
  outline-offset: -2px;
}

.lb-hint {
  margin: 0 0 12px;
}

/* Review: the controls are gone; the statistics sit above the history */
.game.reviewing .bar,
.game.reviewing #btn-latest {
  display: none !important;
}

.review-stats {
  margin: 0 0 8px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
}

.review-stats-title {
  margin: 0 0 6px;
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 0.04em;
  font-weight: 600;
}

.rs-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  column-gap: 18px;
  row-gap: 4px;
  margin: 0;
}

/* live statistics: WR, DD and PF in one row */
.rs-grid-3 {
  grid-template-columns: repeat(3, 1fr);
}

.game.reviewing .live-stats {
  display: none !important;
}

.rs-item {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

.rs-label {
  color: var(--muted);
}

.rs-value {
  text-align: right;
  white-space: nowrap;
}

.review-note {
  margin: 0 0 6px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 13px;
}

.lb-table td.c-total {
  font-weight: 700;
}

.lb-table td.c-nick {
  text-overflow: ellipsis;
}

.lb-table tfoot td {
  position: sticky;
  bottom: 0;
  background: var(--panel-2);
  color: var(--text);
  border-top: 2px solid var(--accent);
  font-weight: 600;
}

.lb-table .you-tag {
  font-size: 12px;
  color: var(--accent);
  margin-left: 4px;
}

/* dialogs used by the account panel are the same overlay pattern as the game dialogs */

.dialog .form {
  gap: 12px;
}

.dialog .row2 {
  margin-top: 4px;
}

/* Sign in with Google: a link styled as a full-width button, and the "or" line between it and the form */
.google-btn {
  display: block;
  width: 100%;
  margin: 0 0 12px;
  text-align: center;
  text-decoration: none;
  box-sizing: border-box;
}

.or {
  margin: 0 0 12px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
}
