:root {
  --ink: #1b1712;
  --paper: #f6efe2;
  --card: #c8925a;
  --tape: #ff8a1f;
  --good: #7ee08a;
  --bad: #ff6a55;
  --glass: rgba(27, 23, 18, 0.66);
  --edge: rgba(255, 226, 180, 0.32);
  font-family: "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #1b1712; color: var(--paper); user-select: none; -webkit-user-select: none; }
canvas#c { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
.hidden { display: none !important; }
button { font: inherit; }

/* ---------- screens ---------- */
.screen { position: fixed; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center; }
#menu { flex-direction: column; gap: 22px; padding: 3vh 16px calc(3vh + env(safe-area-inset-bottom));
  background: linear-gradient(180deg, rgba(21, 17, 12, 0.55) 0%, rgba(21, 17, 12, 0.35) 45%, rgba(21, 17, 12, 0.8) 100%), url(assets/art/key.jpg?v=1) center / cover no-repeat, #15110c; overflow: auto; }
#loading { z-index: 40; align-items: flex-end; background: linear-gradient(180deg, rgba(21, 17, 12, 0) 40%, rgba(21, 17, 12, 0.88) 100%), url(assets/art/key.jpg?v=1) center / cover no-repeat, #15110c; padding: 0 16px calc(5vh + env(safe-area-inset-bottom)); }
#loading .ld-card { width: min(520px, 100%); text-align: center; }
.ld-title { font-size: clamp(28px, 5vw, 44px); font-weight: 900; font-style: italic; text-transform: uppercase; color: var(--paper); text-shadow: 0 3px 0 #f58a2b, 0 6px 18px rgba(0, 0, 0, 0.6); }
.ld-bar { margin: 14px auto 10px; height: 10px; border-radius: 6px; background: rgba(0, 0, 0, 0.55); border: 1px solid var(--edge); overflow: hidden; }
.ld-bar i { display: block; width: 40%; height: 100%; border-radius: 6px; background: linear-gradient(90deg, #f58a2b, #ffb35c); animation: ldslide 1.1s ease-in-out infinite alternate; }
@keyframes ldslide { from { transform: translateX(-10%); } to { transform: translateX(150%); } }
#ldTip { margin: 0; font-size: 13px; letter-spacing: 0.1em; text-transform: uppercase; color: #f1dcbb; text-shadow: 0 2px 8px rgba(0, 0, 0, 0.8); }
.title { display: flex; align-items: center; gap: 26px; }
.doorart { position: relative; width: 110px; height: 170px; border-radius: 6px 6px 0 0; background: linear-gradient(180deg, #33676d, #244b50); border: 8px solid var(--paper); border-bottom: 0; box-shadow: 0 14px 40px rgba(0, 0, 0, 0.5); transform: rotate(-4deg); }
.doorart::after { content: ""; position: absolute; right: 14px; top: 84px; width: 11px; height: 11px; border-radius: 50%; background: #d9bf7e; }
.doorart span { position: absolute; left: 50%; top: 18px; transform: translateX(-50%); padding: 3px 10px; background: var(--paper); color: var(--ink); font-weight: 900; font-size: 22px; border: 3px solid #8a7a5a; }
h1 { margin: 0; font-size: clamp(54px, 9vw, 104px); line-height: 0.82; font-weight: 900; font-style: italic; letter-spacing: -0.01em; color: var(--paper); text-transform: uppercase;
  text-shadow: 0 5px 0 var(--tape), 0 12px 30px rgba(0, 0, 0, 0.5); }
.tagline { margin: 16px 0 0; font-size: 13px; letter-spacing: 0.14em; text-transform: uppercase; color: #e9cfa8; }
.menubar { position: relative; width: min(980px, 100%); padding: 16px; border-radius: 16px; background: rgba(20, 16, 11, 0.95); backdrop-filter: blur(6px); border: 2px solid var(--edge); box-shadow: 0 18px 50px rgba(0, 0, 0, 0.55); }
#shifts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.shift { display: flex; flex-direction: column; align-items: flex-start; gap: 3px; padding: 11px 13px; border-radius: 11px; cursor: pointer; text-align: left; color: var(--paper);
  background: linear-gradient(180deg, rgba(200, 146, 90, 0.2), rgba(200, 146, 90, 0.08)); border: 2px solid rgba(200, 146, 90, 0.35); }
.shift:hover:not(:disabled) { border-color: rgba(255, 190, 120, 0.7); }
.shift.sel { border-color: var(--tape); background: linear-gradient(180deg, rgba(255, 138, 31, 0.32), rgba(200, 146, 90, 0.14)); }
.shift.locked { opacity: 0.45; cursor: default; }
.shift .num { font-size: 11px; letter-spacing: 0.18em; text-transform: uppercase; color: #e9cfa8; }
.shift b { font-size: 19px; }
.shift .meta { font-size: 12px; color: #d8c4a6; }
.stars i { font-style: normal; color: rgba(255, 255, 255, 0.2); font-size: 15px; margin-right: 2px; }
.stars i.on { color: #ffcf4a; text-shadow: 0 0 8px rgba(255, 190, 60, 0.6); }
.stars.big i { font-size: 40px; margin: 0 4px; }
#shiftBlurb { margin: 12px 2px; min-height: 1.3em; font-size: 14px; color: #f1dcbc; }
/* the driver picker: portraits in a row above the shifts */
.drivers-head { margin: 0 2px 8px; font-size: 11px; letter-spacing: 0.18em; text-transform: uppercase; color: #e9cfa8; }
#drivers { display: flex; gap: 10px; margin-bottom: 14px; }
.drv { flex: 1 1 0; display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 6px 6px 8px; border-radius: 11px; cursor: pointer; color: var(--paper);
  background: rgba(200, 146, 90, 0.1); border: 2px solid rgba(200, 146, 90, 0.35); font: inherit; }
.drv img { width: 100%; max-width: 64px; aspect-ratio: 1; border-radius: 8px; object-fit: cover; background: #2b251e; }
.drv b { font-size: 14px; }
.drv:hover { border-color: rgba(255, 190, 120, 0.7); }
.drv.sel { border-color: var(--tape); background: linear-gradient(180deg, rgba(255, 138, 31, 0.32), rgba(200, 146, 90, 0.14)); }
.row { display: flex; gap: 10px; }
.row .big-btn { flex: 1 1 auto; }
.gear { flex: 0 0 auto; width: 58px; border-radius: 12px; border: 1px solid var(--edge); background: rgba(255, 255, 255, 0.08); color: #fff; font-size: 22px; cursor: pointer; padding: 0; }
.gear:hover, .gear[aria-expanded="true"] { background: rgba(255, 255, 255, 0.18); }
.pop { display: none; position: absolute; right: 0; bottom: calc(100% + 10px); width: min(500px, 94vw); padding: 16px 18px 12px; border-radius: 14px; background: rgba(27, 23, 18, 0.97); border: 1px solid var(--edge); box-shadow: 0 14px 44px rgba(0, 0, 0, 0.5); }
.pop.open { display: block; }
.pop-title { margin-bottom: 10px; font-size: 12px; letter-spacing: 0.2em; text-transform: uppercase; color: #e9cfa8; }
.opts { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 7px 14px; margin-bottom: 8px; }
.opts label { display: flex; flex-direction: column; gap: 4px; font-size: 11px; letter-spacing: 0.12em; text-transform: uppercase; color: #e9cfa8; }
.opts input[type=range] { padding: 0; accent-color: var(--tape); height: 24px; }
.opts select { height: 26px; border-radius: 6px; border: 1px solid var(--edge); background: #2b251e; color: var(--paper); font: inherit; font-size: 12px; text-transform: none; letter-spacing: 0; }
.controls { list-style: none; margin: 10px 0 0; padding: 0; font-size: 12px; line-height: 1.8; color: #ecdcc4; }
kbd { display: inline-block; min-width: 22px; padding: 1px 7px; border-radius: 6px; background: rgba(255, 255, 255, 0.12); border: 1px solid var(--edge); color: #fff; font: 700 12px "Trebuchet MS", sans-serif; text-align: center; }
.note { margin: 10px 0 0; font-size: 13px; color: #ffd9a6; }

#pause, #over { background: rgba(20, 16, 11, 0.55); backdrop-filter: blur(3px); }
.panel { width: min(400px, 92vw); padding: 22px 26px 18px; border-radius: 18px; background: var(--glass); border: 1px solid var(--edge); backdrop-filter: blur(10px); box-shadow: 0 18px 60px rgba(0, 0, 0, 0.45); text-align: center; max-height: 94vh; overflow: auto; }
.kicker { font-size: 12px; letter-spacing: 0.26em; text-transform: uppercase; color: #e9cfa8; margin-bottom: 6px; }
h2 { margin: 0 0 8px; font-size: 36px; font-weight: 900; font-style: italic; color: #fff; text-transform: uppercase; }
#overStats { list-style: none; margin: 12px 0 4px; padding: 0; text-align: left; }
#overStats li { display: flex; justify-content: space-between; padding: 6px 2px; border-bottom: 1px dashed rgba(255, 226, 180, 0.2); font-size: 15px; }
#overStats li.tot { border: 0; font-size: 19px; padding-top: 10px; }
#overStats b { color: #fff; }
.big-btn, .ghost-btn { display: block; width: 100%; font-weight: 800; font-size: 18px; letter-spacing: 0.06em; text-transform: uppercase; border-radius: 12px; padding: 14px 18px; cursor: pointer; border: 0; transition: transform 0.12s, filter 0.12s; }
.big-btn { color: #1b1712; background: linear-gradient(180deg, #ffab52, #f07c12); box-shadow: 0 5px 0 #a34f00, 0 10px 24px rgba(0, 0, 0, 0.4); }
.big-btn.alt { margin-top: 12px; color: #fff; background: linear-gradient(180deg, #4f8d93, #2f5d62); box-shadow: 0 5px 0 #1b3a3e, 0 10px 24px rgba(0, 0, 0, 0.4); }
.big-btn:hover { transform: translateY(-1px); filter: brightness(1.06); }
.big-btn:active { transform: translateY(3px); }
.ghost-btn { margin-top: 12px; color: #f1dcbc; background: transparent; border: 1px solid var(--edge); font-size: 14px; }
.ghost-btn:hover { background: rgba(255, 255, 255, 0.07); }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 10; text-shadow: 0 2px 6px rgba(0, 0, 0, 0.7); }
#topbar { position: absolute; top: 12px; left: 50%; transform: translateX(-50%); display: flex; align-items: center; gap: 18px; padding: 6px 18px; border-radius: 40px; background: var(--glass); border: 1px solid var(--edge); }
#clock { font-size: 30px; font-weight: 900; min-width: 82px; text-align: center; font-variant-numeric: tabular-nums; }
#clock.low { color: var(--bad); animation: pulse 0.8s infinite; }
@keyframes pulse { 50% { transform: scale(1.08); } }
#left { font-size: 13px; color: #ecdcc4; min-width: 120px; text-align: right; }
#scoreBox { min-width: 120px; font-size: 20px; }
#scoreBox #combo { margin-left: 8px; color: #ffcf4a; font-weight: 800; }
#scanArrow { position: absolute; top: 74px; left: 50%; transform: translateX(-50%); width: 64px; height: 64px; transform-origin: 50% 50%; }
#scanArrow i { position: absolute; left: 50%; top: 2px; transform: translateX(-50%); width: 0; height: 0; border-left: 16px solid transparent; border-right: 16px solid transparent; border-bottom: 34px solid var(--tape); filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.6)); }
#scanTxt { position: absolute; left: 50%; top: 40px; transform: translateX(-50%); white-space: nowrap; font-weight: 800; font-size: 13px; }
#big { position: absolute; top: 30%; width: 100%; text-align: center; font-size: 96px; font-weight: 900; font-style: italic; }
#bigSub { position: absolute; top: calc(30% + 118px); width: 100%; padding: 0 20px; text-align: center; font-size: 18px; color: #f6e6cc; }
#toast { position: absolute; top: 22%; left: 50%; transform: translateX(-50%) scale(0.9); padding: 9px 18px; border-radius: 12px; background: var(--glass); font-size: 20px; font-weight: 800; opacity: 0; transition: opacity 0.18s, transform 0.18s; white-space: nowrap; }
#toast.show { opacity: 1; transform: translateX(-50%) scale(1); }
#toast.good { color: var(--good); } #toast.bad { color: var(--bad); }
#hint { position: absolute; bottom: 120px; left: 50%; transform: translateX(-50%); padding: 7px 16px; border-radius: 10px; background: rgba(255, 138, 31, 0.9); color: #1b1712; font-weight: 900; font-size: 16px; text-shadow: none; }
#trayBox { position: absolute; left: 14px; bottom: 14px; }
#tray { display: flex; gap: 7px; align-items: flex-end; }
.card { position: relative; width: 74px; padding: 7px 6px 6px; border-radius: 6px; background: var(--card); color: var(--ink); text-shadow: none; box-shadow: 0 4px 10px rgba(0, 0, 0, 0.45); border-top: 6px solid #e9d8b4; text-align: center; }
.card b { display: block; font-size: 26px; line-height: 1; }
.card span { display: block; font-size: 10px; margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card i { position: absolute; left: 4px; top: 1px; font-style: normal; font-size: 10px; opacity: 0.6; }
.card.cur { transform: translateY(-10px) scale(1.12); outline: 3px solid var(--tape); }
#trayMeta { margin-top: 8px; display: flex; gap: 14px; font-size: 13px; color: #ecdcc4; }
#scans { color: var(--tape); font-weight: 800; }
#stam { position: absolute; bottom: 96px; left: 50%; transform: translateX(-50%); width: 180px; height: 6px; border-radius: 4px; background: rgba(0, 0, 0, 0.4); overflow: hidden; }
#stamFill { height: 100%; width: 100%; background: linear-gradient(90deg, #ffcf4a, #7ee08a); }
#stam.tired #stamFill { background: var(--bad); }
#keys { position: absolute; bottom: 12px; right: 14px; font-size: 12px; color: rgba(246, 239, 226, 0.75); }

/* ---------- touch ---------- */
#touchUI, #rotate { display: none; }
body.touch.playing #touchUI { display: block; }
body.touch #keys { display: none; }
#stickBase { display: none; position: fixed; width: 124px; height: 124px; margin: -62px 0 0 -62px; border-radius: 50%; background: rgba(255, 255, 255, 0.12); border: 2px solid rgba(255, 255, 255, 0.3); z-index: 15; pointer-events: none; }
#stickKnob { position: absolute; left: 37px; top: 37px; width: 50px; height: 50px; border-radius: 50%; background: rgba(255, 255, 255, 0.45); }
.tb { position: fixed; z-index: 15; width: 74px; height: 74px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, 0.45); background: rgba(27, 23, 18, 0.5); color: #fff; font-weight: 900; font-size: 13px; letter-spacing: 0.04em; }
.tb.on, .tb.lit { background: rgba(255, 138, 31, 0.75); color: #1b1712; }
.tb.big { width: 96px; height: 96px; right: calc(22px + env(safe-area-inset-right)); bottom: 26px; font-size: 17px; background: rgba(255, 138, 31, 0.45); }
#tbNext { right: calc(132px + env(safe-area-inset-right)); bottom: 24px; }
.tb.small { width: 60px; height: 60px; font-size: 11px; }
#tbScan { right: calc(40px + env(safe-area-inset-right)); bottom: 136px; }
#tbRun { right: calc(116px + env(safe-area-inset-right)); bottom: 110px; }
#tbPause { position: fixed; z-index: 15; top: 12px; right: calc(12px + env(safe-area-inset-right)); width: 44px; height: 44px; border-radius: 10px; border: 1px solid var(--edge); background: var(--glass); color: #fff; }
body.touch #trayBox { left: calc(12px + env(safe-area-inset-left)); bottom: auto; top: 64px; }
body.touch .card { width: 58px; } body.touch .card b { font-size: 20px; }
body.touch #hint { bottom: 140px; }
@media (orientation: portrait) { body.touch.playing #rotate { display: flex; position: fixed; inset: 0; z-index: 40; align-items: center; justify-content: center; text-align: center; background: #1b1712; font-size: 22px; font-weight: 800; } }
@media (max-width: 760px) {
  #shifts { grid-template-columns: 1fr 1fr; }
  .title { gap: 16px; } .doorart { width: 74px; height: 116px; } .doorart span { font-size: 16px; top: 10px; } .doorart::after { top: 58px; }
}
@media (max-height: 520px) {
  #menu { gap: 10px; padding-top: 10px; } h1 { font-size: 46px; } .doorart { display: none; } .tagline { margin-top: 8px; }
  .shift { padding: 6px 10px; } .shift b { font-size: 15px; } #shiftBlurb { margin: 6px 2px; font-size: 12px; }
  #drivers { margin-bottom: 8px; } .drv { flex-direction: row; padding: 4px 6px; } .drv img { width: 34px; } .drivers-head { display: none; }
  .big-btn { padding: 10px; font-size: 15px; }
  #big { font-size: 64px; } #bigSub { top: calc(30% + 80px); font-size: 14px; }
}

/* ---------- the handheld's route map (shown during the countdown) ---------- */
#device { position: absolute; right: 4vw; top: 50%; width: min(44vw, 460px); transform: translateY(-50%) rotate(2.5deg); padding: 10px 10px 8px; border-radius: 26px;
  background: linear-gradient(160deg, #2b2f36, #14161a); border: 2px solid #4a505a; box-shadow: 0 24px 60px rgba(0, 0, 0, 0.6), inset 0 0 0 3px #0b0c0e; opacity: 0; transition: opacity 0.25s; text-shadow: none; }
#device.on { opacity: 1; }
.dev-top { display: flex; align-items: center; gap: 8px; padding: 2px 8px 8px; font-size: 12px; letter-spacing: 0.18em; font-weight: 800; color: #9fe2b0; }
.dev-top i { width: 7px; height: 7px; border-radius: 50%; background: #7ee08a; box-shadow: 0 0 8px #7ee08a; }
.dev-top em { margin-left: auto; font-style: normal; color: var(--tape); }
#deviceMap { display: block; width: 100%; height: auto; border-radius: 12px; background: #101a14; }
#devStops { padding: 8px 8px 2px; font-size: 13px; line-height: 1.5; color: #f6efe2; font-weight: 700; }
#devStops b { display: inline-block; margin-right: 10px; white-space: nowrap; }
#devStops b u { text-decoration: none; display: inline-block; min-width: 18px; padding: 0 4px; margin-right: 4px; border-radius: 9px; background: var(--tape); color: var(--ink); text-align: center; font-size: 11px; }
#devStops b.val u { background: #ffd84a; }
.dev-foot { display: flex; justify-content: space-between; align-items: baseline; padding: 4px 8px 2px; font-size: 11px; color: #9aa3ad; }
.dev-foot b { font-size: 22px; color: var(--paper); }
.card.val { border-top-color: #ffd84a; outline: 2px solid #ffd84a; background: #d9a85e; }
.card.val::after { content: "★"; position: absolute; right: 5px; top: 1px; font-size: 12px; color: #7a4a00; }
body.touch #device { right: 2vw; width: 40vw; }
@media (max-width: 760px) { #device { width: 46vw; } #devStops { font-size: 11px; } }