:root {
  --gold: #f0c020;
  --green: #1a8f3a;
  --red: #c0202a;
  --ink: #0b0d0a;
  --panel: rgba(8, 18, 10, 0.86);
  --line: rgba(240, 192, 32, 0.55);
  --text: #f4f0e0;
  --dim: #a8a890;
  --font: "Arial Black", "Arial Bold", "Helvetica Neue", Arial, sans-serif;
  /* safe areas (notch, home bar) as variables so tests can fake a notch */
  --sat: env(safe-area-inset-top, 0px); --sar: env(safe-area-inset-right, 0px);
  --sab: env(safe-area-inset-bottom, 0px); --sal: env(safe-area-inset-left, 0px);
  --edge: #f0c020;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; -webkit-touch-callout: none; }
html, body { margin: 0; height: 100%; background: #000; overflow: hidden; color: var(--text); font-family: var(--font);
  user-select: none; -webkit-user-select: none; touch-action: none; }
#screen { position: fixed; inset: 0; width: 100%; height: 100%; image-rendering: pixelated; display: block; }
#ui { position: fixed; inset: 0; pointer-events: none; }
.screen { position: absolute; inset: var(--sat) var(--sar) var(--sab) var(--sal); display: none; pointer-events: auto; }
.screen.on { display: flex; }
button { font-family: var(--font); font-style: italic; color: var(--text); cursor: pointer; }

/* Title and menu */
#s-title, #s-menu, #s-pause { flex-direction: column; align-items: center; justify-content: center; gap: 4vh; }
#ui::before { /* dim the attract-mode race behind the title and menus so they read */
  content: ''; position: absolute; inset: 0; background: radial-gradient(ellipse at center, rgba(0,0,0,0.35) 20%, rgba(0,0,0,0.72) 100%);
  opacity: 0; transition: opacity 0.2s; }
#ui.dim::before { opacity: 1; }
.logo { display: flex; flex-direction: column; align-items: center; transform: skewX(-8deg); text-align: center; }
.logo .l1 { font-size: clamp(34px, 9vw, 96px); color: var(--gold); letter-spacing: 0.02em; line-height: 0.9;
  text-shadow: 3px 3px 0 #6a3a00, 6px 6px 0 #000, 0 0 24px rgba(240,192,32,0.4); }
.logo .l2 { font-size: clamp(30px, 8vw, 84px); color: #fff; line-height: 0.95; background: var(--green); padding: 0 0.3em;
  box-shadow: 6px 6px 0 #000; text-shadow: 3px 3px 0 #000; }
.logo .l3 { margin-top: 14px; font-size: clamp(11px, 2vw, 18px); color: var(--text); letter-spacing: 0.3em; text-transform: uppercase; text-shadow: 2px 2px 0 #000; }
.logo.small .l1 { font-size: clamp(26px, 6vw, 60px); }
.logo.small .l2 { font-size: clamp(22px, 5vw, 52px); }
.big { font-size: clamp(18px, 3.4vw, 30px); background: none; border: none; text-shadow: 3px 3px 0 #000; padding: 12px 24px; }
.blink { animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.stack { display: flex; flex-direction: column; gap: 10px; width: min(360px, 80vw); }
.stack { gap: 16px; }
/* PS1 menu bar: pixel border with notched corners, hard drop shadow, marker on the live item */
.stack button, .row button, .act {
  position: relative; font-size: clamp(16px, 2.6vw, 24px); padding: 11px 18px 11px 30px; border: none; color: var(--text);
  background: linear-gradient(180deg, #3a7a40 0%, #1f4a26 48%, #12301a 52%, #0b1c0e 100%);
  box-shadow: 0 -3px 0 var(--edge), 0 3px 0 var(--edge), -3px 0 0 var(--edge), 3px 0 0 var(--edge), 3px 6px 0 #000, 6px 3px 0 #000;
  text-align: left; letter-spacing: 0.05em; text-shadow: 2px 2px 0 #000; transform: skewX(-8deg);
}
.stack button::before, .row button::before, .act::before { /* pixel arrow marker, drawn with borders */
  content: ''; position: absolute; left: 11px; top: 50%; margin-top: -6px; border: 6px solid transparent; border-left: 8px solid var(--gold);
  border-right: 0; opacity: 0.35;
}
.stack button:hover, .stack button:focus-visible, .row button:hover, .row button:focus-visible, .act:hover:not(:disabled), .act:focus-visible {
  background: linear-gradient(180deg, #fff2a0 0%, var(--gold) 48%, #d89a00 52%, #b88000 100%); color: #111; outline: none; text-shadow: 1px 1px 0 rgba(255,255,255,0.5);
  --edge: #fff;
}
.stack button:hover::before, .stack button:focus-visible::before, .row button:hover::before, .row button:focus-visible::before, .act:hover:not(:disabled)::before { border-left-color: #111; opacity: 1; }
.stack button:active, .row button:active, .act:active:not(:disabled) { transform: skewX(-8deg) translate(3px, 3px); box-shadow: 0 -3px 0 var(--edge), 0 3px 0 var(--edge), -3px 0 0 var(--edge), 3px 0 0 var(--edge); }
.title2 { font-size: clamp(28px, 6vw, 56px); color: var(--gold); text-shadow: 3px 3px 0 #000; margin: 0; font-style: italic; }
.wallet { font-size: clamp(14px, 2.4vw, 22px); color: var(--gold); text-shadow: 2px 2px 0 #000; font-style: italic; }
.wallet b { color: #fff; }
#s-menu .wallet { position: absolute; top: 12px; right: 16px; }

/* Panel screens */
.panel-screen { flex-direction: column; background: linear-gradient(180deg, rgba(0,0,0,0.6), rgba(0,0,0,0.2) 30%, rgba(0,0,0,0.2) 70%, rgba(0,0,0,0.6)); }
.panel-screen header { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; padding: 10px 16px; gap: 8px; }
.panel-screen header .wallet { justify-self: end; }
.panel-screen h2 { margin: 0; font-size: clamp(18px, 3.6vw, 32px); font-style: italic; color: var(--gold); text-shadow: 3px 3px 0 #000; transform: skewX(-8deg); white-space: nowrap; }
.back { justify-self: start; display: inline-flex; align-items: center; gap: 8px; background: rgba(0,0,0,0.45); border: none; font-size: clamp(13px, 2vw, 18px);
  text-shadow: 2px 2px 0 #000; padding: 8px 12px 8px 10px; box-shadow: 0 -2px 0 var(--line), 0 2px 0 var(--line), -2px 0 0 var(--line), 2px 0 0 var(--line); }
.back:hover, .back:focus-visible { color: #111; background: var(--gold); outline: none; text-shadow: none; }
.ico { width: 1em; height: 1em; display: block; shape-rendering: crispEdges; fill: currentColor; filter: drop-shadow(2px 2px 0 #000); }
.back:hover .ico, .back:focus-visible .ico { filter: none; }

.cards { flex: 1; overflow-y: auto; padding: 4px 16px 20px; display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; align-content: start; touch-action: pan-y; }
.card { text-align: left; background: rgba(8, 18, 10, 0.94); border: 2px solid var(--line); padding: 12px 14px; box-shadow: 4px 4px 0 #000; font-style: normal; display: flex; flex-direction: column; gap: 4px; }
.card:hover:not(.locked), .card:focus-visible { border-color: var(--gold); background: rgba(30, 60, 30, 0.92); outline: none; }
.card .n { font-size: 12px; color: var(--gold); }
.card .t { font-size: 20px; font-style: italic; }
.card .p { font-size: 12px; color: var(--dim); font-family: Arial, sans-serif; font-weight: bold; }
.card .b { font-size: 13px; font-family: Arial, sans-serif; font-weight: normal; line-height: 1.35; color: var(--text); margin-top: 4px; }
.card .m { display: flex; justify-content: space-between; font-size: 12px; margin-top: 6px; color: var(--gold); }
.card.locked { cursor: default; background: rgba(16, 16, 14, 0.92); border-color: rgba(168,168,144,0.4); }
.card.locked .t, .card.locked .b, .card.locked .n { color: var(--dim); }
.card.locked .m { color: var(--dim); }

/* Garage */
.garage { flex: 1; display: flex; min-height: 0; padding: 0 16px 16px; gap: 16px; }
.gside { width: min(380px, 44vw); display: flex; flex-direction: column; min-height: 0; }
.tabs { display: flex; gap: 4px; }
.tabs button { flex: 1; font-size: clamp(10px, 1.5vw, 13px); padding: 8px 2px; background: #0b1c0e; border: 2px solid var(--line); border-bottom: none; }
.tabs button.on { background: var(--gold); color: #111; border-color: var(--gold); }
.plist { flex: 1; overflow-y: auto; background: var(--panel); border: 2px solid var(--line); touch-action: pan-y; }
.plist button { display: flex; justify-content: space-between; align-items: center; width: 100%; text-align: left; background: none; border: none;
  border-bottom: 1px solid rgba(240,192,32,0.18); padding: 10px 12px; font-size: clamp(13px, 1.8vw, 16px); gap: 8px; font-style: normal; }
.plist button.sel { background: rgba(240,192,32,0.18); }
.plist button .tag { font-size: 11px; color: var(--gold); white-space: nowrap; }
.plist button .tag.eq { color: #6be08a; }
.plist button .tag.lk { color: var(--dim); }
.plist .sw { display: inline-block; width: 12px; height: 12px; margin-right: 6px; border: 1px solid #000; vertical-align: -1px; }
.detail { align-self: flex-end; margin-left: auto; width: min(360px, 40vw); background: var(--panel); border: 2px solid var(--line); padding: 14px; box-shadow: 4px 4px 0 #000; }
.detail h3 { margin: 0 0 4px; font-style: italic; font-size: 20px; color: var(--gold); }
.detail p { margin: 0 0 12px; font-family: Arial, sans-serif; font-size: 13px; line-height: 1.4; }
.stat { display: grid; grid-template-columns: 96px 1fr 28px; align-items: center; gap: 8px; margin: 6px 0; font-size: 12px; }
.segs { display: flex; gap: 2px; }
.segs i { flex: 1; height: 12px; background: #2a2a24; transform: skewX(-12deg); }
.segs i.f { background: var(--gold); }
.segs i.up { background: #6be08a; }
.segs i.dn { background: #e05050; }
.stat b { text-align: right; }
.stat b.up { color: #6be08a; } .stat b.dn { color: #e05050; }
.act { width: calc(100% - 6px); margin: 14px 3px 6px; font-size: 16px; padding: 10px 10px 10px 30px; transform: none; }
.act:active:not(:disabled) { transform: translate(3px, 3px); }
.act:disabled { opacity: 0.6; cursor: default; --edge: #777; }

/* Options */
.opts { width: min(520px, 92vw); margin: 0 auto; display: flex; flex-direction: column; gap: 8px; overflow-y: auto; padding-bottom: 16px; }
.opts button { display: flex; justify-content: space-between; background: var(--panel); border: 2px solid var(--line); padding: 12px 14px; font-size: 16px; }
.opts button b { color: var(--gold); }
.opts button:hover { border-color: var(--gold); }
.opts .note { font-family: Arial, sans-serif; font-size: 12px; color: var(--text); line-height: 1.5; padding: 10px 12px; background: rgba(8, 18, 10, 0.9); border: 2px solid var(--line); }

/* HUD: drawn in the game frame by js/hud.js. Only the pause button's hit zone lives in the DOM. */
.hud { pointer-events: none; }
#bPause { position: absolute; top: 6px; left: 8px; width: 46px; height: 40px; pointer-events: auto; }

/* Results */
.results { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 12px; overflow-y: auto; padding: 0 16px 16px; }
.rside { display: flex; flex-direction: column; align-items: center; gap: 12px; }
#rTable { border-collapse: collapse; background: var(--panel); border: 2px solid var(--line); min-width: min(440px, 92vw); font-size: clamp(13px, 2vw, 17px); }
#rTable td { padding: 6px 12px; border-bottom: 1px solid rgba(240,192,32,0.18); }
#rTable td:first-child { color: var(--gold); width: 40px; }
#rTable td:last-child { text-align: right; font-family: Arial, sans-serif; font-weight: bold; }
#rTable tr.me { background: rgba(240,192,32,0.2); }
.rinfo { text-align: center; font-size: clamp(13px, 2vw, 17px); line-height: 1.6; background: var(--panel); border: 2px solid var(--line); padding: 8px 14px; text-shadow: 2px 2px 0 #000; box-shadow: 4px 4px 0 #000; }
.rinfo .prize { color: var(--gold); font-size: 1.4em; }
.rinfo .unl { color: #6be08a; }
.row { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.row button { text-align: center; }

/* Touch controls: invisible hit zones; the buttons are drawn into the game frame where these sit */
#touch { position: fixed; inset: 0; pointer-events: none; display: none; }
#touch.on { display: block; }
.tb { pointer-events: auto; position: absolute; touch-action: none; }
.tb.hit { opacity: 0; background: #000; border: none; padding: 0; margin: 0; }
.steer { bottom: calc(14px + var(--sab)); width: 19vw; max-width: 120px; height: 24vh; max-height: 150px; }
.steer[data-t="left"] { left: calc(12px + var(--sal)); }
.steer[data-t="right"] { left: calc(22px + min(19vw, 120px) + var(--sal)); }
.push { right: calc(12px + var(--sar)); bottom: calc(14px + var(--sab)); width: 22vw; max-width: 140px; height: 30vh; max-height: 190px; }
.brake { right: calc(22px + min(22vw, 140px) + var(--sar)); bottom: calc(14px + var(--sab)); width: 17vw; max-width: 104px; height: 18vh; max-height: 112px; }
@media (max-aspect-ratio: 1/1) { /* portrait: thumbs sit lower, buttons a little taller */
  .steer { width: 22vw; height: 15vh; }
  .steer[data-t="right"] { left: calc(22px + 22vw + var(--sal)); }
  .push { width: 24vw; height: 19vh; }
  .brake { right: calc(22px + 24vw + var(--sar)); width: 20vw; height: 12vh; }
}

@media (max-aspect-ratio: 1/1) {
  .garage { flex-direction: column; }
  .gside { width: 100%; flex: 0 0 auto; }
  .plist { max-height: 27vh; }
  .detail { width: 100%; align-self: stretch; margin-top: auto; }

  .stat { grid-template-columns: 80px 1fr 24px; }
  .cards { grid-template-columns: 1fr; }
}
@media (min-aspect-ratio: 1/1) {
  /* any landscape screen: results side by side, so the buttons never fall off the bottom */
  .results { flex-direction: row; justify-content: center; align-items: center; gap: 16px; }
  .rside { max-width: 320px; }
}
@media (max-height: 480px) and (min-aspect-ratio: 1/1) {
  /* landscape phones: tighter still */
  .results { gap: 12px; padding: 0 12px 8px; }
  .results #rTable, .results .cupTable { min-width: 0; font-size: 12px; }
  .results #rTable td, .results .cupTable td, .results .cupTable th { padding: 3px 8px; }
  .rside { max-width: 250px; }
  .rinfo { font-size: 12px; line-height: 1.35; padding: 6px 10px; }
  .results .row { flex-direction: column; gap: 8px; }
  .results .row button { font-size: 15px; padding: 8px 14px 8px 28px; }
  .panel-screen h2 { font-size: 20px; }
  /* the menu: logo on the left, buttons on the right */
  #s-menu { flex-direction: row; gap: 6vw; }
  #s-menu .stack { gap: 10px; width: min(300px, 44vw); }
  #s-menu .stack button { font-size: 16px; padding: 8px 14px 8px 28px; }
}
@media (max-height: 480px) {
  .gside { width: min(300px, 36vw); }
  .detail { width: min(320px, 38vw); }
  .panel-screen header { padding: 4px 12px; }
  .detail { padding: 10px; }
  .detail p { margin-bottom: 6px; font-size: 12px; }
  .stat { margin: 3px 0; }
}

.credit { margin: 0; padding: 4px 16px 8px; font: 11px Arial, sans-serif; color: var(--dim); text-shadow: 1px 1px 0 #000; text-align: center; }

/* Classes, cups, trophies */
.classTabs { display: flex; gap: 4px; padding: 0 16px 6px; }
.classTabs button { flex: 1; font-size: clamp(11px, 1.6vw, 14px); padding: 8px 2px; background: #0b1c0e; border: 2px solid var(--line); }
.classTabs button.on { background: var(--gold); color: #111; border-color: var(--gold); }
.classTabs button.lk { color: var(--dim); border-color: rgba(168,168,144,0.3); cursor: default; }
.clsBlurb { margin: 0 16px 8px; font: 12px Arial, sans-serif; color: var(--text); text-shadow: 1px 1px 0 #000; }
.tro { display: inline-block; width: 12px; height: 14px; margin-right: 6px; vertical-align: -2px;
  clip-path: polygon(0 0, 100% 0, 100% 35%, 70% 60%, 62% 80%, 85% 80%, 85% 100%, 15% 100%, 15% 80%, 38% 80%, 30% 60%, 0 35%); }
.tro.t1 { background: linear-gradient(#fff4b0, #f0c020 50%, #b88000); }
.tro.t2 { background: linear-gradient(#ffffff, #c0c8d0 50%, #808890); }
.tro.t3 { background: linear-gradient(#f8c8a0, #c87840 50%, #804820); }
.tro.big { width: 72px; height: 84px; margin: 0 auto 6px; display: block; filter: drop-shadow(4px 4px 0 #000); }
.trophy { text-align: center; text-shadow: 3px 3px 0 #000; }
.trophy b { display: block; font-size: clamp(24px, 5vw, 40px); color: var(--gold); font-style: italic; }
.trophy span { font-size: 14px; letter-spacing: 0.2em; }
#ceTable, .cupTable { border-collapse: collapse; background: var(--panel); border: 2px solid var(--line); min-width: min(360px, 92vw); font-size: clamp(13px, 2vw, 16px); }
#ceTable td, .cupTable td, .cupTable th { padding: 5px 12px; border-bottom: 1px solid rgba(240,192,32,0.18); text-align: left; }
.cupTable th { color: var(--gold); font-size: 12px; }
#ceTable tr.me, .cupTable tr.me { background: rgba(240,192,32,0.2); }
#ceTable td:last-child, .cupTable td:last-child, .cupTable th:last-child { text-align: right; }
.cupTable:empty { display: none; }

/* Quests */
.quest { display: flex; flex-direction: column; gap: 3px; background: var(--panel); border: 2px solid rgba(168,168,144,0.35); padding: 10px 14px; }
.quest b { font-style: italic; color: var(--dim); font-size: 16px; }
.quest span { font: 13px Arial, sans-serif; color: var(--text); }
.quest i { font-style: normal; font-size: 11px; color: var(--dim); letter-spacing: 0.05em; }
.quest.done { border-color: var(--gold); }
.quest.done b { color: var(--gold); }
.quest.done i { color: #6be08a; }
.plist button em { font-style: normal; font-size: 9px; color: #6be08a; margin-left: 4px; letter-spacing: 0.05em; }

/* Cheat code entry */
#s-code { align-items: center; justify-content: center; }
.codebox { display: flex; flex-direction: column; align-items: center; gap: 14px; background: var(--panel); border: 2px solid var(--line); padding: 20px 24px; box-shadow: 6px 6px 0 #000; }
#codeIn { font: italic 24px var(--font); text-transform: uppercase; letter-spacing: 0.2em; text-align: center; width: min(320px, 70vw); padding: 8px;
  background: #050805; color: var(--gold); border: 2px solid var(--gold); outline: none; -webkit-user-select: text; user-select: text; touch-action: manipulation; }
.codemsg { min-height: 18px; font-size: 14px; color: #6be08a; text-shadow: 2px 2px 0 #000; text-align: center; }

/* garage: seven tabs wrap to two rows on narrow screens */
.tabs { flex-wrap: wrap; }
.tabs button { min-width: 22%; }
#slotTabs button { font-size: clamp(9px, 1.3vw, 12px); }
.nogl { position: fixed; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; padding: 24px; text-align: center; background: #0b1c0e; color: #f4f0e0; font-family: Arial, sans-serif; }
.nogl b { font: italic 900 28px var(--font); color: #f0c020; }
/* tablets and big screens: the menus were sized for phones, so scale their content up */
@media (min-width: 700px) and (min-height: 700px) and (pointer: coarse), (min-width: 1500px) and (min-height: 900px) {
  .panel-screen > :not(.results), #s-menu > nav, #s-pause > *, #s-code > * { zoom: 1.3; }
}

/* shown from the first byte until main.js is running */
#boot { position: fixed; inset: 0; z-index: 50; display: flex; flex-direction: column; align-items: center; justify-content: center; background: #0b1c0e; transform: skewX(-8deg); }
#boot b { font: italic 900 clamp(34px, 9vw, 80px) var(--font); color: var(--gold); text-shadow: 3px 3px 0 #6a3a00, 6px 6px 0 #000; line-height: 0.9; }
#boot i { font: italic 900 clamp(30px, 8vw, 70px) var(--font); color: #fff; background: var(--green); padding: 0 0.3em; box-shadow: 6px 6px 0 #000; }
#boot span { margin-top: 24px; font: 14px var(--font); letter-spacing: 0.3em; color: var(--text); }
#boot em { animation: blink 1s steps(2) infinite; font-style: normal; }
#boot.gone { opacity: 0; transition: opacity 0.3s; pointer-events: none; }

/* Stats */
.stats { background: var(--panel); border: 2px solid var(--line); padding: 4px 14px; }
.srow { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; border-bottom: 1px solid rgba(240,192,32,0.15); font-size: 14px; }
.srow:last-child { border-bottom: none; }
.srow span { color: var(--dim); font-style: italic; }
.srow b { color: var(--text); font-family: Arial, sans-serif; text-align: right; }
.srow.head span { color: var(--gold); }
.stabs { margin-bottom: 8px; }
.stabs button { padding: 8px 4px; font-size: 13px; }
.wpick { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; background: var(--panel); border: 2px solid var(--line); padding: 4px; }
.wpick b { font-style: italic; color: var(--gold); font-size: 16px; }
.wpick button { background: #0b1c0e; border: 2px solid var(--line); color: var(--text); width: 44px; height: 36px; font-size: 18px; }
.srow.me { background: rgba(240,192,32,0.18); }

/* Support */
.suplink { background: none; border: none; color: var(--gold); font-size: 13px; letter-spacing: 0.15em; text-shadow: 2px 2px 0 #000; text-decoration: underline; text-underline-offset: 4px; padding: 6px 10px; }
.suplink:hover, .suplink:focus-visible { color: #fff; outline: none; }
.note ul { margin: 6px 0 0; padding-left: 18px; }
.note .claim { font: bold 15px monospace; color: var(--gold); letter-spacing: 0.08em; }
.mini { background: #0b1c0e; border: 2px solid var(--line); color: var(--text); font-size: 12px; padding: 4px 10px; margin-left: 6px; }
.mini:hover { border-color: var(--gold); }
.redeem { display: flex; gap: 6px; margin-top: 8px; }
.redeem input { font: bold 16px monospace; background: #0b1c0e; color: var(--gold); border: 2px solid var(--line); padding: 6px 8px; flex: 1; min-width: 0; text-transform: uppercase; }
.supme b, .supmsg { color: var(--gold); }
.supmark { display: inline-block; width: 10px; height: 10px; margin-right: 6px; background: var(--gold); clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%); }
.srow em { font-style: italic; }
.srow em.gold { color: var(--gold); }
.plist button .tag.sup { color: var(--gold); }
@media (max-height: 480px) and (min-aspect-ratio: 1/1) { .suplink { position: absolute; bottom: 6px; right: 12px; } }
.claim.big { font-size: 26px; letter-spacing: 0.25em; }
