:root {
  /* the night look (this product's own): a floodlit dirt arena; the light look is chosen with the switch beside Home */
  --bg: #1a1712;
  --bg2: #2a251d;
  --ink: #f5efe4;
  --inkDim: #bfb29b;
  --line: #4a4134;
  --accent: #ffb338;
  --accentInk: #3a2204;
  --sel: #3a3226;
  --stageBg: #0d0c0a;
  --hudBg: rgba(16, 13, 9, 0.62);
  --hudInk: #fff7e6;
  --stick: rgba(255, 255, 255, 0.28);
  --knob: rgba(255, 255, 255, 0.55);
  --shade: rgba(20, 17, 12, 0.92);
  --toastBg: #fbf6ea;
  --toastInk: #20180c;
  --danger: #f87171;
  --gold: #ffd166;
}
:root[data-theme="light"] {
  --bg: #f4ecdf;
  --bg2: #e6dac6;
  --ink: #221a0e;
  --inkDim: #5a4a32;
  --line: #b9a888;
  --accent: #8a5200;
  --accentInk: #ffffff;
  --sel: #d8c8ad;
  --stageBg: #2a2418;
  --hudBg: rgba(255, 250, 240, 0.78);
  --hudInk: #20180c;
  --stick: rgba(32, 24, 12, 0.22);
  --knob: rgba(32, 24, 12, 0.45);
  --shade: rgba(244, 236, 223, 0.94);
  --toastBg: #221a0e;
  --toastInk: #ffffff;
  --danger: #b91c1c;
  --gold: #a86b00;
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; overflow: hidden; overscroll-behavior: none; }
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; background: linear-gradient(180deg, var(--bg) 0%, var(--bg2) 100%); color: var(--ink); user-select: none; -webkit-user-select: none; overflow: hidden; }
#app { height: 100%; display: flex; flex-direction: column; max-width: min(100%, 900px); margin: 0 auto; }

#hdr { display: flex; align-items: center; gap: 8px; padding: 8px 12px; padding-top: max(8px, env(safe-area-inset-top)); }
#hdr .pill { background: var(--bg2); border: 2px solid var(--line); border-radius: 999px; padding: 6px 11px; font-weight: 800; font-size: 15px; min-width: 44px; min-height: 44px; display: flex; align-items: center; cursor: pointer; justify-content: center; color: inherit; font-family: inherit; }
#hdrHome { border: none; background: var(--accent); color: var(--accentInk); font-size: 18px; }
#hdrStatus { flex: 1; min-width: 0; text-align: center; font-weight: 800; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--inkDim); }

.scr { flex: 1; display: none; flex-direction: column; overflow-y: auto; padding: 6px 14px 18px; gap: 10px; min-height: 0; overscroll-behavior: contain; }
.scr.on { display: flex; }
#scr-menu { align-items: center; text-align: center; justify-content: center; }
#scr-menu h1 { font-size: clamp(28px, 8vw, 44px); }
#scr-menu .sub { color: var(--inkDim); font-weight: 600; }
.menuGrid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; width: 100%; }
button.big { width: 100%; border-radius: 16px; min-height: 52px; font-size: 18px; font-weight: 800; background: var(--bg2); color: var(--ink); border: 3px solid var(--line); cursor: pointer; font-family: inherit; padding: 6px 10px; }
button.big:active { transform: translateY(2px); }
button.big.primary { background: var(--accent); border-color: var(--accent); color: var(--accentInk); }
button.big.danger { border-color: var(--danger); color: var(--danger); }
button.big:disabled { opacity: 0.45; cursor: default; }
#statsLine { color: var(--inkDim); font-weight: 700; }
.scrTitle { text-align: center; }
.seg { display: flex; flex-wrap: wrap; gap: 6px; width: 100%; }
.seg button { flex: 1; min-height: 44px; min-width: 64px; border-radius: 12px; border: 3px solid var(--line); background: var(--bg); color: var(--ink); font-family: inherit; font-weight: 800; font-size: 15px; cursor: pointer; }
.seg button.sel { border-color: var(--accent); background: var(--sel); }

/* the course list: the next new course one tap, every course reached to play again */
#courseGrid, #freeRows { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
button.tile { min-height: 68px; border-radius: 14px; border: 3px solid var(--line); background: var(--bg2); color: var(--ink); font-family: inherit; display: flex; flex-direction: column; align-items: flex-start; gap: 2px; padding: 6px 10px; cursor: pointer; text-align: left; }
button.tile.next { border-color: var(--accent); }
button.tile.free { border-style: dashed; }          /* a saved surprise course, not one of the numbered ten */
button.tile .tn { font: 800 13px ui-monospace, Menlo, monospace; color: var(--inkDim); }
button.tile .tname { font-weight: 800; font-size: 15px; overflow-wrap: anywhere; }
button.tile .ts { font-size: 13px; font-weight: 700; color: var(--inkDim); }

/* play: the picture fills the screen, the HUD over it */
#scr-play { padding: 0 0 max(0px, env(safe-area-inset-bottom)); }
#stageWrap { position: relative; flex: 1; min-height: 0; background: var(--stageBg); overflow: hidden; touch-action: none; }
#stage { display: block; width: 100%; height: 100%; }
#hud { position: absolute; left: 8px; right: 60px; top: 8px; display: flex; gap: 8px; flex-wrap: wrap; pointer-events: none; }
#hud span { background: var(--hudBg); color: var(--hudInk); border-radius: 10px; padding: 4px 9px; font: 800 15px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; min-width: 4.5em; text-align: center; }
#hud span:empty { visibility: hidden; }
#btnPause { position: absolute; right: 8px; top: 8px; min-width: 44px; min-height: 44px; border-radius: 999px; background: var(--hudBg); color: var(--hudInk); border: 2px solid var(--line); font-size: 17px; cursor: pointer; }
#trick { position: absolute; left: 0; right: 0; top: 28%; text-align: center; font-weight: 900; font-size: clamp(20px, 6vw, 32px); color: var(--gold); text-shadow: 0 2px 6px rgba(0, 0, 0, 0.6); opacity: 0; transition: opacity 0.2s; pointer-events: none; padding: 0 12px; }
#trick.on { opacity: 1; }
#count { position: absolute; left: 0; right: 0; top: 36%; text-align: center; font-weight: 900; font-size: 72px; color: var(--hudInk); text-shadow: 0 3px 10px rgba(0, 0, 0, 0.6); pointer-events: none; }
#stick { position: absolute; width: 120px; height: 120px; margin: -60px 0 0 -60px; border-radius: 50%; border: 3px solid var(--stick); visibility: hidden; pointer-events: none; }
#stick.on { visibility: visible; }
#knob { position: absolute; left: 35px; top: 35px; width: 50px; height: 50px; border-radius: 50%; background: var(--knob); }
#pauseCard { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(90%, 340px); background: var(--shade); border: 3px solid var(--line); border-radius: 18px; padding: 16px; display: flex; flex-direction: column; gap: 10px; }
#pauseCard[hidden] { display: none; }
.pcTitle { text-align: center; font-weight: 900; font-size: 22px; }
#glFail { position: absolute; left: 12px; right: 12px; top: 30%; background: var(--shade); border: 3px solid var(--line); border-radius: 16px; padding: 14px; font-weight: 700; line-height: 1.5; text-align: center; }
#glFail[hidden] { display: none; }
#fpsNow { position: absolute; left: 8px; bottom: 8px; background: var(--hudBg); color: var(--hudInk); border-radius: 8px; padding: 2px 6px; font: 700 12px ui-monospace, Menlo, monospace; }
#fpsNow[hidden] { display: none; }

/* the result */
#scr-done { align-items: center; justify-content: center; text-align: center; }
#doneStars { font-size: 40px; letter-spacing: 4px; color: var(--gold); min-height: 1.2em; }
.card { background: var(--bg2); border: 3px solid var(--line); border-radius: 16px; padding: 14px; display: flex; flex-direction: column; gap: 8px; font-size: 15px; line-height: 1.55; font-weight: 600; width: 100%; text-align: left; }
.setRow { display: flex; flex-direction: column; gap: 6px; }
.setNote { font-size: 13.5px; color: var(--inkDim); }

#toast { position: fixed; left: 50%; bottom: 78px; transform: translateX(-50%); background: var(--toastBg); color: var(--toastInk); font-weight: 800; padding: 9px 16px; border-radius: 999px; opacity: 0; transition: opacity 0.25s; pointer-events: none; z-index: 40; max-width: 90vw; text-align: center; }
#toast.on { opacity: 1; }
/* R10.3 a lasting note while a write has not gone in (the toast says it once; this stays until a save goes in) */
#saveNote { position: fixed; left: 50%; top: 8px; transform: translateX(-50%); background: var(--toastBg); color: var(--toastInk); font-weight: 800; font-size: 14px; padding: 8px 14px; border-radius: 12px; pointer-events: none; z-index: 41; max-width: 90vw; text-align: center; box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3); }
#saveNote[hidden] { display: none; }

@media (prefers-reduced-motion: reduce) { #trick, #toast { transition: none; } }
