:root {
  --page: #E6E8E3; --navy: #14213D; --text: #14213D; --muted: #4A5468; --line: #C7CBC2;
  --btn: #F4F5F1; --btn-text: #14213D; --primary: #14213D; --primary-text: #E6E8E3;
  --pink: #FF48B0; --blue: #0078BF; --sun: #FFE800; --teal: #00A95C; --orange: #FF6C2F;
  --display: "Bricolage Grotesque", ui-sans-serif, system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --sat: env(safe-area-inset-top, 0px); --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px); --sar: env(safe-area-inset-right, 0px);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --page: #0E1526; --text: #E6E8E3; --muted: #9AA3B5; --line: #2A3552; --btn: #1B2640; --btn-text: #E6E8E3; --primary: #E6E8E3; --primary-text: #0E1526; }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--page); overscroll-behavior: none; }
body {
  color: var(--text); font-family: var(--display); touch-action: none;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; -webkit-text-size-adjust: 100%;
}
#root { position: fixed; inset: 0; height: 100svh; overflow: hidden; overscroll-behavior: none; touch-action: none; }
canvas#c { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
#safe { position: absolute; top: var(--sat); bottom: var(--sab); left: var(--sal); right: var(--sar); pointer-events: none; visibility: hidden; }
.hidden { display: none !important; }
.ic { display: inline-flex; width: 20px; height: 20px; }
.ic svg { width: 100%; height: 100%; }

/* Everything below is positioned by main.js from the computed layout (px). */
#hud { position: absolute; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; pointer-events: none; }
.hud-l { font-weight: 700; font-size: 17px; letter-spacing: -0.01em; white-space: nowrap; }
.hud-l small { font-family: var(--mono); font-weight: 400; font-size: 12px; color: var(--muted); margin-left: 6px; }
.hud-c { position: relative; display: flex; align-items: baseline; justify-content: center; }
.hud-c b { font-family: var(--display); font-weight: 800; font-size: 28px; font-variant-numeric: tabular-nums; line-height: 1; }
.hud-r { justify-self: end; font-family: var(--mono); font-size: 13px; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.chip { position: absolute; left: 100%; top: 50%; margin-left: 6px; transform: translateY(-50%); font-family: var(--mono); font-weight: 600; font-size: 12px;
  padding: 2px 6px; border-radius: 2px; background: var(--navy); color: #E6E8E3; white-space: nowrap; opacity: 0; transition: opacity .5s; font-variant-numeric: tabular-nums; }
@media (prefers-color-scheme: dark) { .chip { background: #E6E8E3; color: var(--navy); } }
.chip.on { opacity: 1; transition: none; }

.label { position: absolute; font-family: var(--mono); font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); pointer-events: none; }
button { font: inherit; color: inherit; touch-action: manipulation; cursor: pointer; }
.shuffle { position: absolute; display: flex; align-items: center; justify-content: center; gap: 6px; height: 44px; min-width: 64px; padding: 0 14px;
  border: 2px solid var(--navy); border-radius: 2px; background: var(--btn); color: var(--btn-text); }
@media (prefers-color-scheme: dark) { .shuffle { border-color: #E6E8E3; } }
.shuffle b { font-family: var(--mono); font-weight: 600; font-size: 17px; font-variant-numeric: tabular-nums; }
.shuffle:disabled { opacity: .38; cursor: default; }
.shuffle.pulse { animation: pulse .6s ease-out 1; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(255,72,176,.9); transform: scale(1); } 40% { transform: scale(1.08); } 100% { box-shadow: 0 0 0 14px rgba(255,72,176,0); transform: scale(1); } }
.icon-btn { position: absolute; width: 44px; height: 44px; display: flex; align-items: center; justify-content: center; border: 0; background: none; color: var(--muted); padding: 0; }
.caption { position: absolute; margin: 0; font-family: var(--mono); font-size: 13px; line-height: 18px; text-align: center; color: var(--text); pointer-events: none;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rail { position: absolute; display: flex; align-items: center; gap: 10px; pointer-events: none; font-family: var(--mono); font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.rail #rail-text { white-space: nowrap; }
.ticks { display: flex; gap: 3px; flex: 1; }
.ticks i { flex: 1; height: 6px; border-radius: 1px; background: var(--line); }
.ticks i.done { background: var(--navy); }
.ticks i.now { background: var(--pink); }
@media (prefers-color-scheme: dark) { .ticks i.done { background: #E6E8E3; } }

/* Results replace the tray area. Never a modal. */
.results { position: absolute; display: flex; flex-direction: column; gap: 8px; touch-action: manipulation; }
.res-top { display: flex; align-items: flex-end; justify-content: space-between; gap: 8px; }
.res-score { display: flex; align-items: baseline; gap: 8px; }
.res-score b { font-size: 44px; font-weight: 800; line-height: .9; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.res-score span { font-family: var(--mono); font-size: 13px; color: var(--muted); }
.res-out { display: flex; flex-direction: column; align-items: flex-end; }
.res-outcome { font-weight: 700; font-size: 17px; }
.res-rank { font-family: var(--mono); font-size: 11px; color: var(--muted); }
.squares { display: flex; gap: 3px; }
.squares i { flex: 1; max-width: 26px; height: 10px; border-radius: 1px; background: var(--line); }
.squares i.l1 { background: var(--blue); } .squares i.l2 { background: var(--teal); } .squares i.l3 { background: var(--sun); } .squares i.l4 { background: var(--orange); }
.squares i.none { background: transparent; border: 1px dashed var(--line); }
.res-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin: 0; }
.res-stats div { border-top: 2px solid var(--text); padding-top: 3px; min-width: 0; }
.res-stats dt { font-family: var(--mono); font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.res-stats dd { margin: 0; font-weight: 700; font-size: 20px; font-variant-numeric: tabular-nums; }
.res-btns { display: grid; grid-template-columns: 1.3fr 1fr 1fr; gap: 8px; }
.btn { display: flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 0 10px; border-radius: 2px; border: 2px solid var(--text);
  background: var(--btn); color: var(--btn-text); font-weight: 700; font-size: 15px; }
.btn.primary { background: var(--primary); color: var(--primary-text); border-color: var(--primary); }
.btn.small { min-height: 36px; font-size: 14px; }
.btn:active, .shuffle:active:not(:disabled) { transform: translateY(1px); }
.res-foot { margin: 0; display: flex; justify-content: space-between; align-items: center; font-family: var(--mono); font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.link { border: 0; background: none; padding: 8px 0; font-family: var(--mono); font-size: 12px; color: var(--text); text-decoration: underline; text-underline-offset: 3px; }

.past { gap: 6px; }
.past-head { display: flex; align-items: center; gap: 10px; }
.past-head .label { position: static; }
.past-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; touch-action: pan-y; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
.past-list li { border-top: 1px solid var(--line); }
.past-list button { width: 100%; display: grid; grid-template-columns: 52px 1fr auto; gap: 8px; align-items: center; min-height: 44px; border: 0; background: none; text-align: left; padding: 0 2px; }
.past-list .n { font-family: var(--mono); font-weight: 600; }
.past-list .d { font-size: 15px; }
.past-list .s { font-family: var(--mono); font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.past-empty { font-family: var(--mono); font-size: 13px; color: var(--muted); padding: 10px 0; }

#toasts { position: absolute; left: 0; right: 0; top: calc(var(--sat) + 52px); display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; z-index: 5; }
.toast { font-family: var(--mono); font-size: 14px; padding: 8px 14px; border-radius: 2px; background: var(--navy); color: #E6E8E3; box-shadow: 2px 2px 0 var(--pink); animation: tin .16s ease-out; }
@media (prefers-color-scheme: dark) { .toast { background: #E6E8E3; color: var(--navy); } }
.toast.out { opacity: 0; transition: opacity .25s; }
@keyframes tin { from { opacity: 0; transform: translateY(-4px); } }
#copy-fallback { position: absolute; left: -9999px; top: 0; width: 1px; height: 1px; opacity: 0; }

@media (prefers-reduced-motion: reduce) {
  .shuffle.pulse { animation: none; outline: 3px solid var(--pink); outline-offset: 2px; }
  .toast { animation: none; }
  .chip, .toast.out { transition: none; }
}
