/* Powder Peak. The mountain fills the screen; the readouts sit along the top
   edge and the thumbs' controls in the bottom corners, so the middle — where
   the snow ahead is — stays clear. */
:root {
  --kGlow1: rgba(0, 0, 0, .6);

  /* R-C40: colours that were written out in rules, as tokens (theme-derive.py) */
  --kBg1: #10213a;
  --kBg10: #24344a;
  --kBg11: #ffd34b;
  --kBg12: #ff5b4b;
  --kBg13: rgba(8, 18, 34, .5);
  --kBg14: #4d9eff;
  --kBg15: rgba(8, 18, 34, .8);
  --kBg16: rgba(10, 30, 60, .16);
  --kBg17: rgba(255, 255, 255, .45);
  --kBg18: rgba(14, 32, 60, .5);
  --kBg19: rgba(3, 10, 22, .5);
  --kBg2: #1b3252;
  --kBg20: rgba(14, 28, 50, .9);
  --kBg3: #284873;
  --kBg4: #12233c;
  --kBg5: #0f1d33;
  --kBg6: #1d3a60;
  --kBg7: #cfe3f7;
  --kBg8: #172d4b;
  --kBg9: #9fc4ea;
  --kInk1: #ffffff;
  --kInk2: #ffe2a6;
  --kLine1: #24406a;
  --kLine2: #ffd27a;
  --kLine3: #ffffff;

  --bg: #0c1a2e;
  --ink: #f2f7fd;
  --dim: #a9bcd2;
  --card: #14263f;
  --line: #2c4a70;
  /* The controls' one accent is the house amber. Pink is Amelia's and the player's,
     never the chrome's (the game-ui-colour standard). */
  --accent: #ffb338;
  --accentInk: #3a2204;
  --me: #ff5ca8;
  --picked: #bfe3ff;
  --good: #57d68d;
  --bad: #ff6b5b;
  --glass: rgba(8, 18, 34, .66);
}

/* R-C40: the light look. This product's own is dark; the other is chosen with the switch beside Home. */
:root[data-theme="light"] {
  --kGlow1: rgba(255, 255, 255, .6);

  --kBg1: #cddbef;
  --kBg10: #bac6d7;
  --kBg11: #9f7c00;
  --kBg12: #dd4f41;
  --kBg13: rgba(227, 236, 251, .5);
  --kBg14: #2f81e0;
  --kBg15: rgba(227, 236, 251, .8);
  --kBg16: rgba(205, 221, 246, .16);
  --kBg17: rgba(31, 31, 31, .45);
  --kBg18: rgba(204, 219, 242, .5);
  --kBg19: rgba(239, 248, 255, .5);
  --kBg2: #b7c8e0;
  --kBg20: rgba(212, 224, 243, .9);
  --kBg3: #9cb2cf;
  --kBg4: #cbd8ec;
  --kBg5: #d3dff1;
  --kBg6: #abc0dc;
  --kBg7: #2b343d;
  --kBg8: #bdcde5;
  --kBg9: #384b5e;
  --kInk1: #000000;
  --kInk2: #090000;
  --kLine1: #a5b9d7;
  --kLine2: #493300;
  --kLine3: #1f1f1f;

  --bg: #ecf8ff;
  --ink: #1d1f22;
  --dim: #454e5a;
  --card: #dae8fc;
  --line: #a9bed8;
  --accent: #a26a00;
  --accentInk: #ffffff;
  --me: #e65d9b;
  --picked: #223340;
  --good: #02a25d;
  --bad: #ef6051;
  --glass: rgba(237, 246, 255, .66);
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg); color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none; overflow: hidden;
  -webkit-text-size-adjust: 100%;
  -webkit-user-select: none; user-select: none;
}
#app { display: flex; flex-direction: column; height: 100%; }

#hdr {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
  padding: calc(env(safe-area-inset-top, 0px) + 6px) 8px 6px;
  background: var(--kBg1); border-bottom: 1px solid var(--kLine1);
}
#hdrTitle { flex: 1 1 0; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
            font-weight: 700; font-size: 15px; }
@media (max-width: 380px) { #hdrTitle { visibility: hidden; } }
/* R-C26: [hidden] loses to any display of our own */
[hidden] { display: none !important; }
.pill {
  min-width: 44px; min-height: 44px; border: 0; border-radius: 12px;
  background: var(--kBg2); color: var(--ink); font-size: 18px; cursor: pointer;
}
.pill:active { background: var(--kBg3); }

.scr { display: none; flex: 1; overflow-y: auto; padding: 12px; }
.scr.on { display: block; }
#scr-play.on { display: flex; padding: 0; overflow: hidden; }
#scr-menu, #scr-how { max-width: 720px; margin: 0 auto; width: 100%; }

h1 { font-size: 30px; margin: 8px 0 4px; }
.sub { color: var(--dim); font-size: 14px; line-height: 1.45; margin-bottom: 12px; }
.stat { color: var(--dim); font-size: 13px; }
.goal { color: var(--ink); font-size: 14px; line-height: 1.45; margin: 8px 2px 8px; min-height: 20px; }
.endBest { grid-column: 1 / -1; color: var(--ink); font-size: 15px; margin: 4px 2px 6px; font-variant-numeric: tabular-nums; }
.rowLbl { color: var(--dim); font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; margin: 12px 2px 4px; }

.big {
  display: block; width: 100%; min-height: 52px; margin: 8px 0;
  border: 1px solid var(--line); border-radius: 14px; background: var(--kBg2);
  color: var(--ink); font-size: 17px; font-weight: 600; cursor: pointer;
}
.big.primary { background: var(--accent); border-color: var(--kLine2); color: var(--accentInk); }

#custom { margin: 10px 0; border: 1px solid var(--line); border-radius: 14px; background: var(--kBg4); }
#custom > summary { list-style: none; }
#custom > summary::-webkit-details-marker { display: none; }
#custom > summary::after { content: "▾"; margin-left: auto; color: var(--dim); }
#custom[open] > summary::after { content: "▴"; }
summary { min-height: 48px; display: flex; align-items: center; padding: 0 12px; cursor: pointer; font-weight: 600; }
.setBody { padding: 10px 12px 14px; }
.setRow { display: flex; align-items: center; gap: 10px; margin: 10px 0; flex-wrap: wrap; }
.setLbl { flex: 1 1 110px; font-size: 14px; }
.setNote { color: var(--dim); font-size: 12px; line-height: 1.4; }
.knob { display: flex; gap: 6px; flex-shrink: 0; flex-wrap: wrap; }
.knobBtn {
  min-height: 44px; min-width: 56px; border-radius: 10px; padding: 0 10px;
  border: 1px solid var(--line); background: var(--kBg5); color: var(--dim);
  font-size: 13px; cursor: pointer;
}
.knobBtn.on { background: var(--kBg6); color: var(--ink); border-color: var(--picked); font-weight: 700; }

/* R-C12b: the rungs */
.pickRow { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; width: 100%; margin: 6px 0 4px; }
.pick {
  min-width: 0; min-height: 72px;
  background: var(--kBg2); color: var(--ink); border: 2px solid transparent;
  border-radius: 14px; padding: 8px 4px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 2px; text-align: center;
}
.pick .te { font-size: 24px; }
.pick b { font-size: 14px; }
.pick small { color: var(--dim); font-size: 11px; font-variant-numeric: tabular-nums; }
.pick.sel { border-color: var(--picked); background: var(--kBg6); }
/* the rungs set the rival: outside Match Race they change nothing, and say so by stepping back */
.pickRow.idle { opacity: .6; }

/* R22: the rider as picked. It stays at the top of the screen while the three rows under it are in view. */
#lookBox {
  position: sticky; top: 0; z-index: 3; height: 210px; margin: 12px 0 2px; touch-action: pan-y; cursor: grab; border-radius: 14px; overflow: hidden;
  border: 1px solid var(--line); background: var(--kBg7); box-shadow: 0 0 0 8px var(--bg), 0 6px 14px rgba(4, 10, 22, .45);   /* the ring of page colour hides the edge of a swatch scrolling behind */
}
#lookBox.none { height: auto; background: var(--kBg4); box-shadow: none; }
#lookBox.none #look { display: none; }
#look { display: block; width: 100%; height: 100%; }
#lookName {
  position: absolute; left: 8px; top: 6px; padding: 3px 9px; border-radius: 9px; background: var(--glass);
  color: var(--ink); font-size: 13px; font-weight: 700; max-width: calc(100% - 16px); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
#lookBox.none #lookName { position: static; display: block; background: none; padding: 8px 10px; }
@media (max-height: 480px) { #lookBox { height: 120px; } }
/* R29: three tabs under the rider; one panel at a time. A picked tab is an outline, like every other pick. */
#kitTabs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin: 8px 0 6px; }
#kitTabs button {
  min-height: 48px; border-radius: 12px; border: 2px solid transparent; background: var(--kBg2); color: var(--ink);
  font-size: 15px; font-weight: 700; cursor: pointer;
}
#kitTabs button.on { border-color: var(--picked); background: var(--kBg6); }
#kitTabs button[hidden] { display: none; }
.kitPanel[hidden] { display: none; }
.kitLbl { margin: 10px 2px 4px; color: var(--dim); font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
.swRow { display: flex; flex-wrap: wrap; gap: 6px; }
/* a row of named choices (hat, jacket pattern, the board's print): tiles side by side, like the boards */
.optRow, #graphicRow { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; margin-top: 6px; }
/* a swatch is content, not chrome: it is the colour it offers. 44 px to tap; the picked one wears the ice ring. */
.swb {
  width: 44px; height: 44px; flex: 0 0 44px; border-radius: 50%; border: 3px solid var(--bg); padding: 0; cursor: pointer;
  box-shadow: 0 0 0 2px var(--line);
}
.swb.sel { box-shadow: 0 0 0 3px var(--picked); }
.swb.own { border-style: dashed; border-color: rgba(255, 255, 255, .7); }
/* the modes, the runs and the riders: grids that wrap, never rows that scroll sideways */
#modeRow { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; }
#boardRow { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; }
#designRow { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 6px; margin-top: 6px; }
.opt.dz { min-height: 56px; }
.opt .sw { display: block; width: 34px; height: 14px; border-radius: 7px; border: 2px solid var(--kLine3); }
#courseRow { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
#riderRow { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 6px; }
@media (max-width: 460px) {
  #modeRow { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  #boardRow { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  #designRow { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  #riderRow { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
.opt {
  min-height: 72px; min-width: 0; border-radius: 12px; border: 2px solid transparent;
  background: var(--kBg8); color: var(--ink); cursor: pointer; padding: 6px 4px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: 12px; line-height: 1.2; text-align: center;
}
.opt .ic { font-size: 22px; line-height: 1; }
.opt .n { font-size: 11px; color: var(--dim); min-height: 13px; }
.opt.sel { border-color: var(--picked); background: var(--kBg6); }
.opt.locked { opacity: .45; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px; margin: 8px 0; font-size: 14px; line-height: 1.5; }
.card h2 { font-size: 17px; margin: 0 0 4px; }

/* ---- the mountain -------------------------------------------------------------- */
#stage { position: relative; flex: 1; width: 100%; overflow: hidden; touch-action: none; background: var(--kBg9); }
#cvs { display: block; width: 100%; height: 100%; touch-action: none; }
#glFail {
  position: absolute; inset: 20% 12% auto; padding: 14px; border-radius: 12px; z-index: 30;
  background: var(--kBg1); color: var(--ink); font-size: 14px; line-height: 1.5;
}

#hud {
  position: absolute; top: 6px; left: 6px; right: 6px; pointer-events: none; z-index: 5;
  display: flex; align-items: flex-start; justify-content: space-between; gap: 6px;
}
#hudL, #hudR { display: flex; flex-direction: column; gap: 4px; }
#hudL { align-items: flex-start; }
#hudR { align-items: flex-end; }
#hudC { flex: 1 1 0; display: flex; flex-direction: column; align-items: center; gap: 4px; min-width: 0; }
.meter { display: flex; align-items: center; gap: 5px; background: var(--glass); border-radius: 10px; padding: 4px 8px; font-size: 14px; }
.meter .bar { width: 72px; height: 10px; border-radius: 5px; background: var(--kBg10); overflow: hidden; }
.meter i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--kBg11), var(--kBg12)); transition: width .2s; }
.chip { background: var(--glass); border-radius: 10px; padding: 4px 8px; font-size: 14px; white-space: nowrap; }
.chip b { font-variant-numeric: tabular-nums; }
.chip.big2 { font-size: 17px; font-weight: 700; }
#goalChip {
  background: var(--glass); border-radius: 12px; padding: 5px 10px; font-size: 14px; font-weight: 700; max-width: 100%;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
#goalChip:empty, #goalText:empty { display: none; }
#progress { position: relative; width: min(100%, 220px); height: 8px; border-radius: 4px; background: var(--kBg13); }
#progress i { position: absolute; top: -3px; width: 14px; height: 14px; margin-left: -7px; border-radius: 50%; border: 2px solid var(--kLine3); left: 0; }
#progMe { background: var(--me); }
#progRival { background: var(--kBg14); }
#countdown {
  font-size: 64px; font-weight: 900; color: var(--kInk1); text-shadow: 0 0 14px rgba(120, 190, 255, .9), 0 3px 6px var(--kGlow1);
  font-variant-numeric: tabular-nums; margin-top: 12vh;
}

#toast {
  position: absolute; left: 50%; top: 30%; transform: translate(-50%, -50%); z-index: 6;
  background: var(--kBg15); border-radius: 14px; padding: 8px 16px; font-size: 18px; font-weight: 800;
  text-align: center; max-width: 86%; pointer-events: none; opacity: 0; transition: opacity .3s;
}
#toast.on { opacity: 1; }
#toast small { display: block; color: var(--kInk2); font-size: 14px; font-weight: 700; }

/* ---- the thumbs (R15) ---- */
#touch { position: absolute; inset: 0; z-index: 4; touch-action: none; }
.stickBase {
  position: absolute; width: 120px; height: 120px; margin: -60px 0 0 -60px; border-radius: 50%;
  background: var(--kBg16); border: 2px solid rgba(255, 255, 255, .55); pointer-events: none;
}
.stickKnob {
  position: absolute; left: 50%; top: 50%; width: 52px; height: 52px; margin: -26px 0 0 -26px; border-radius: 50%;
  background: var(--kBg17); border: 2px solid rgba(255, 255, 255, .85);
}
#rightBtns {
  position: absolute; right: calc(env(safe-area-inset-right, 0px) + 12px); bottom: calc(env(safe-area-inset-bottom, 0px) + 22px);
  display: flex; flex-direction: column; align-items: flex-end; gap: 14px;
}
body.lefty #touchHint { left: auto; right: 12px; }
body.lefty #rightBtns { right: auto; left: calc(env(safe-area-inset-left, 0px) + 12px); align-items: flex-start; }
.tb {
  width: 68px; height: 68px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, .7);
  background: var(--kBg18); color: var(--kInk1); font-size: 28px; cursor: pointer; touch-action: none;
}
.tb.jump { width: 92px; height: 92px; font-size: 38px; border-width: 3px; border-color: var(--kLine3); }
.tb.down { background: var(--kBg17); }
#touchHint {
  position: absolute; left: 12px; bottom: calc(env(safe-area-inset-bottom, 0px) + 24px);
  background: var(--glass); border-radius: 12px; padding: 6px 12px; font-size: 13px; color: var(--kInk1); text-align: left;
  max-width: calc(100% - 136px); pointer-events: none; transition: opacity .6s;
}
#touchHint.gone { opacity: 0; }
#keysHint {
  position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%); z-index: 4;
  background: var(--glass); border-radius: 12px; padding: 6px 12px; font-size: 12px; color: var(--kInk1);
  max-width: 92%; text-align: center; pointer-events: none; transition: opacity .6s;
}
#keysHint.gone { opacity: 0; }
/* a mouse needs none of the thumb controls */
body.mouse #rightBtns, body.mouse #touchHint { display: none; }
/* nothing to press while the sign is up or the run is over */
#stage.quiet #touch, #stage.quiet #keysHint { display: none; }

/* ---- overlays ---- */
.ovl {
  position: absolute; inset: 0; z-index: 20; display: none;
  align-items: flex-start; justify-content: center; padding: 16px; overflow-y: auto;
  background: var(--kBg19);
}
.ovl.on { display: flex; }
.ovlCard {
  margin: auto; width: 100%; max-width: 420px; background: var(--card); border: 1px solid var(--line);
  border-radius: 18px; padding: 16px; text-align: center; box-shadow: 0 10px 30px rgba(0, 0, 0, .5);
}
.ovlCard h2 { margin: 0 0 6px; font-size: 22px; }
.ovlCard p { color: var(--dim); font-size: 14px; line-height: 1.5; margin: 6px 0 10px; white-space: pre-line; }
#brief { background: none; padding: 0; }
#briefBar {
  position: absolute; left: 50%; bottom: calc(env(safe-area-inset-bottom, 0px) + 8px); transform: translateX(-50%);
  width: calc(100% - 16px); max-width: 720px; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px;
  background: var(--kBg20); border: 1px solid var(--line); border-radius: 16px; padding: 8px 10px;
}
#briefWords { flex: 1 1 260px; min-width: 0; }
#briefWords h2 { margin: 0; font-size: 19px; }
#briefWords p { margin: 2px 0 0; color: var(--dim); font-size: 13px; line-height: 1.35; white-space: pre-line; }
#briefBtns { flex: 0 0 auto; display: flex; gap: 8px; margin-left: auto; }
#briefBtns .big { width: auto; margin: 0; padding: 0 16px; min-height: 48px; }
#doneMedal { font-size: 44px; letter-spacing: 6px; margin: 4px 0; min-height: 10px; }
/* the shared runtime's notices (a newer version is ready) */
.toast-host { position: fixed; left: 0; right: 0; bottom: 12px; display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; z-index: 40; }
@media (prefers-reduced-motion: reduce) { #toast { transition: none; } }
/* a phone on its side: the cards put their buttons in a row, so all fit without scrolling */
@media (max-height: 480px) {
  .ovlCard { padding: 10px 12px; max-width: 560px; }
  .ovlCard h2 { font-size: 19px; margin-bottom: 2px; }
  .ovlCard p { margin: 4px 0 6px; font-size: 13px; }
  #doneMedal { font-size: 30px; margin: 0; }
  #done .big, #paused .big { display: inline-block; width: calc(33% - 8px); min-width: 120px; min-height: 46px; margin: 4px 2px; padding: 0 8px; font-size: 15px; }
  #rightBtns { bottom: calc(env(safe-area-inset-bottom, 0px) + 10px); gap: 8px; }
  .tb.jump { width: 80px; height: 80px; }
  #countdown { margin-top: 4vh; }
}
