/* Happy Camper — styles. A bright 70s campground: cream, orange and avocado,
   with a sunset stripe under the bar. */
:root {
  --bg: #fff6e4;
  --panel: #ffffff;
  --text: #2a2420;
  --muted: #6b625a;
  --line: #eadfc8;
  --orange: #e8772e;
  --orange-dark: #b9561a;
  --avocado: #6f8f2e;
  --avocado-dark: #4f6a1c;
  --mustard: #f2b134;
  --brown: #7a4a24;
  --go: #e8772e;
  --go-dark: #b9561a;
  --right: #2fa35a;
  --wrong: #d0402e;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text); display: flex; flex-direction: column; min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
}
body.driving { height: 100dvh; overflow: hidden; }
[hidden] { display: none !important; }
button {
  font: inherit; font-weight: 700; border: 2px solid var(--line); background: var(--panel); color: var(--text);
  border-radius: 12px; padding: 8px 16px; cursor: pointer; touch-action: manipulation;
}
button:disabled { opacity: .5; cursor: default; }
button.go { background: var(--go); border-color: var(--go-dark); color: #fff; font-size: 18px; padding: 10px 22px; }
button.go:not(:disabled):hover { background: var(--go-dark); }
button.secondary { background: #fff; }
button.danger { color: var(--wrong); border-color: #f0c4be; }
button.icon { width: 42px; height: 42px; padding: 0; border-radius: 50%; font-size: 20px; }
button.plain { border: none; background: none; }
.small { color: var(--muted); font-size: 13px; }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 8px 14px; background: var(--orange); color: #fff; flex-shrink: 0;
}
.top-left { display: flex; align-items: center; gap: 12px; min-width: 0; }
.apps-link {
  display: inline-flex; align-items: center; gap: 6px; min-height: 42px; box-sizing: border-box; padding: 6px 14px;
  border-radius: 999px; background: rgba(255, 255, 255, .16); border: 1px solid rgba(255, 255, 255, .5);
  color: #fff; text-decoration: none; font-weight: 700; font-size: 16px;
}
.apps-link:hover { background: rgba(255, 255, 255, .3); }
.apps-link svg { fill: currentColor; flex: none; }
.brand { font-size: 22px; font-weight: 800; letter-spacing: .3px; display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.brand-mark { width: 40px; height: 26px; }
.top-right { display: flex; gap: 8px; align-items: center; }
.player-chip { background: rgba(255, 255, 255, .16); color: #fff; border-color: rgba(255, 255, 255, .5); padding: 6px 14px; white-space: nowrap; }
.topbar button.icon { background: rgba(255, 255, 255, .16); color: #fff; border-color: rgba(255, 255, 255, .5); }
.stripes {
  height: 10px; flex-shrink: 0;
  background: linear-gradient(var(--mustard) 0 2.5px, #f39a3a 2.5px 5px, #d9542a 5px 7.5px, var(--avocado) 7.5px 10px);
}

.update-note {
  display: flex; gap: 10px; align-items: center; justify-content: center; padding: 8px; background: #fff4d6;
  border-bottom: 1px solid #f0d58a; font-weight: 600; flex-shrink: 0;
}

/* ---------- home ---------- */
.home { max-width: 900px; width: 100%; margin: 0 auto; padding: 14px 14px 24px; display: flex; flex-direction: column; gap: 12px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 14px 16px; }
.home h2 { margin: 0 0 10px; font-size: 18px; color: var(--orange-dark); }
.players { display: flex; flex-wrap: wrap; gap: 10px; }
.player { display: flex; align-items: center; gap: 8px; padding: 8px 14px 8px 8px; border-radius: 30px; border: 3px solid var(--line); }
.player-emoji { font-size: 30px; line-height: 1; width: 40px; height: 40px; display: grid; place-items: center; border-radius: 50%; background: #f8f0dd; }
.player.on { border-color: var(--pc, var(--orange)); background: color-mix(in srgb, var(--pc, var(--orange)) 10%, #fff); }
.player.add { color: var(--muted); border-style: dashed; }
.trailers { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.trailer-pick { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 8px 10px; border-width: 3px; text-align: center; }
.trailer-pick svg { width: 100%; max-width: 130px; height: auto; max-height: 80px; }
.tr-name { font-size: 17px; }
.tr-about { font-size: 13px; font-weight: 500; color: var(--muted); line-height: 1.3; }
.trailer-pick.on { border-color: var(--orange); background: #fff1e5; }
.levels { display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px; }
.level { display: flex; flex-direction: column; align-items: center; padding: 6px 4px; border-width: 3px; min-width: 0; }
.level-n { font-size: 26px; line-height: 1.1; }
.level-name { font-size: 12px; color: var(--muted); font-weight: 600; line-height: 1.2; text-align: center; min-height: 2.4em; display: grid; place-items: center; }
.level-stars { color: #f2b705; letter-spacing: 1px; font-size: 15px; }
.level.on { border-color: var(--orange); background: #fff1e5; }
.level-about { margin: 10px 2px 0; color: var(--muted); font-weight: 600; }
.views { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.view-pick { display: flex; flex-direction: column; align-items: flex-start; text-align: left; gap: 2px; padding: 10px 14px; border-width: 3px; }
.view-name { font-size: 17px; }
.view-desc { font-size: 13px; color: var(--muted); font-weight: 500; }
.view-pick.on { border-color: var(--avocado); background: #f1f6e4; }
.home-go { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.home-go .go { font-size: 22px; padding: 12px 36px; }

/* ---------- driving ---------- */
.play { flex: 1; display: grid; grid-template-rows: auto 1fr; gap: 8px; padding: 8px 10px 10px; min-height: 0; }
.play-bar { display: flex; align-items: center; gap: 10px; min-height: 44px; }
.site-name { flex: 1; font-size: 19px; font-weight: 800; color: var(--orange-dark); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.stats { display: flex; gap: 16px; align-items: center; font-weight: 700; white-space: nowrap; }
.stat-label { color: var(--muted); font-size: 14px; }
.bumps { display: inline-flex; gap: 4px; vertical-align: middle; }
.bump { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--wrong); }
.bump.used { background: var(--wrong); }
.play-bar button { padding: 7px 12px; white-space: nowrap; }

.stage { display: grid; grid-template-columns: 1fr auto; gap: 10px; min-height: 0; }
/* the driver's panel: the wheel on top, then the speedometer, then the gears and pedals side by side */
.driver {
  display: grid; grid-template-columns: auto auto auto; column-gap: 10px; row-gap: 8px;
  grid-template-areas: "map map map" "wheel wheel wheel" "dash dash key" "brake gas shift";
  justify-items: center; align-items: end; align-content: center; min-height: 0;
  background: #f6ead0; border: 2px solid #e2d2ad; border-radius: 16px; padding: 10px 12px;
}
.driver .wheel-box { grid-area: wheel; }
.driver #btn-centre { grid-area: wheel; justify-self: end; align-self: end; z-index: 1; }
.centre-btn { width: 38px; height: 38px; padding: 0; border-radius: 50%; font-size: 20px; line-height: 1; background: #fff; }
.minimap { grid-area: map; width: 100%; min-width: 190px; height: 140px; border-radius: 10px; border: 2px solid #d9c9a6; background: #b8de7a; display: block; }
.driver .dash { grid-area: dash; }
/* the ignition key: turns to ON when the engine runs */
.ignition { grid-area: key; display: flex; flex-direction: column; align-items: center; gap: 0; padding: 2px 4px; background: none; border: none; }
.ignition svg { width: 54px; height: 54px; display: block; }
.ignition .key-turn { transform-origin: 30px 30px; transition: transform .25s; }
.ignition.on .key-turn { transform: rotate(80deg); }
.ignition.starting .key-turn { transform: rotate(95deg); }
.key-label { font-size: 12px; color: var(--brown); }
.ignition.on .key-label { color: #2f8a3c; }
.ignition kbd { margin: 1px 0 0; }
.ignition.nudge svg { animation: nudge 1s ease-in-out 2; }
@keyframes nudge { 0%, 100% { transform: rotate(0); } 25% { transform: rotate(-12deg); } 75% { transform: rotate(12deg); } }
.driver .shifter { grid-area: shift; flex-direction: column; align-self: end; }
.driver .brake { grid-area: brake; }
.driver .gas { grid-area: gas; }
kbd {
  font: 700 11px system-ui, sans-serif; background: #fff; color: #5a4636; border: 1px solid #c9b98f; border-bottom-width: 2px;
  border-radius: 4px; padding: 0 4px; margin-left: 4px;
}
html.touch kbd { display: none; }
.pedal kbd { position: absolute; top: 6px; left: 50%; transform: translateX(-50%); margin: 0; }
.view-wrap { position: relative; min-width: 0; min-height: 0; border-radius: 14px; overflow: hidden; border: 3px solid #d9c9a6; background: #8fc061; }
.view-wrap canvas { position: absolute; inset: 0; display: block; touch-action: none; width: 100%; height: 100%; }

/* the mirror view's cockpit, drawn over the 3D windshield view */
.cockpit { position: absolute; inset: 0; pointer-events: none; z-index: 1; }
.ck-roof { position: absolute; left: 0; right: 0; top: 0; height: 4%; background: #ede3cc; border-bottom: 3px solid #cbbd9b; }
.ck-dash {
  position: absolute; left: -2%; right: -2%; bottom: 0; height: 15%;
  background: repeating-linear-gradient(176deg, #8a5a32 0 7px, #7a4e2a 7px 11px, #93623a 11px 19px);
  border-top: 7px solid #3e2c1c; border-radius: 50% 50% 0 0 / 40% 40% 0 0; box-shadow: 0 -4px 10px rgba(0, 0, 0, .25);
}
.ck-vent { position: absolute; left: 5%; top: 30%; width: 12%; height: 26%; border-radius: 6px; background: repeating-linear-gradient(90deg, #2d2d2f 0 4px, #555 4px 6px); }
.ck-radio {
  position: absolute; left: 66%; top: 26%; width: 12%; height: 34%; border-radius: 6px; background: #d9dde2; border: 3px solid #9aa1a8;
  display: flex; align-items: center; justify-content: space-around; padding: 0 6%;
}
.ck-radio span { width: 14%; aspect-ratio: 1; border-radius: 50%; background: #5a4636; }
.mirror { position: absolute; border: 6px solid #2f2f31; box-shadow: 0 3px 10px rgba(0, 0, 0, .35); }
.mirror.rear { left: 33%; width: 34%; top: 6%; height: 17%; border-radius: 16px; }
.mirror.rear::before { content: ""; position: absolute; left: 50%; top: -30%; width: 10px; height: 30%; margin-left: -5px; background: #2f2f31; }
.mirror.side { top: 44%; width: 27%; height: 30%; border-radius: 22px 22px 36px 36px; border-color: #c9ced4; border-width: 7px; }
.mirror.left { left: 1.5%; }
.mirror.right { right: 1.5%; }
.msg { z-index: 3; }
/* the gauges: a little panel in the corner, or set into the dash in the Mirrors view */
.gauges {
  position: absolute; left: 8px; bottom: 8px; width: 216px; z-index: 2; pointer-events: none;
  background: rgba(90, 70, 54, .9); border-radius: 12px; padding: 3px;
}
.gauges svg { display: block; width: 100%; height: auto; }
.view-wrap.in-mirrors .gauges { left: 17%; bottom: 0.8%; width: min(250px, 32%); background: none; padding: 0; }
.lamp.lit { fill: #ff5a2a; animation: lamp 1s steps(2) infinite; }
.view-wrap.in-mirrors .msg { bottom: 17%; }
@keyframes lamp { 50% { fill: #8a2a1a; } }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.result { z-index: 4; }

/* the steering wheel */
.wheel-box { width: 190px; max-width: 100%; aspect-ratio: 1; touch-action: none; cursor: grab; user-select: none; -webkit-user-select: none; }
.wheel-box:active { cursor: grabbing; }
.wheel-box { position: relative; }
/* where your hand is on the wheel when the mouse is steering */
.grip {
  position: absolute; width: 26px; height: 26px; margin: -13px 0 0 -13px; border-radius: 50%; pointer-events: none;
  background: rgba(232, 119, 46, .85); border: 3px solid #fff; box-shadow: 0 0 0 2px var(--orange-dark), 0 2px 6px rgba(0, 0, 0, .3);
}
html.touch .mouse-only { display: none !important; }
.view-wrap.can-grab { cursor: crosshair; }
.wheel { width: 100%; height: 100%; will-change: transform; filter: drop-shadow(0 3px 3px rgba(0, 0, 0, .25)); }
.wheel svg { width: 100%; height: 100%; display: block; }
.small-btn { font-size: 13px; padding: 6px 10px; }

/* speedometer, shifter and pedals */
.dash { display: flex; flex-direction: column; align-items: center; }
.speedo { width: 120px; height: 70px; }
.speed-text { font-weight: 800; font-variant-numeric: tabular-nums; color: var(--brown); font-size: 15px; }
.shifter { display: flex; gap: 6px; background: #5a4636; padding: 6px; border-radius: 14px; }
.shifter button { width: 44px; height: 40px; padding: 0; font-size: 21px; border-radius: 10px; background: #f6efdc; border-color: #3e2f22; }
.shifter button.on[data-gear="R"] { background: #e2622c; color: #fff; }
.shifter button.on[data-gear="N"] { background: #f2b134; color: #3a2a10; }
.shifter button.on[data-gear="D"] { background: #3c9b4a; color: #fff; }
.pedal {
  --press: 0;
  position: relative; display: flex; align-items: flex-end; justify-content: center; padding-bottom: 8px;
  color: #f0e6cf; font-weight: 800; font-size: 14px; border-radius: 12px; touch-action: none; user-select: none; -webkit-user-select: none;
  background: repeating-linear-gradient(0deg, #3b3b3d 0 6px, #2a2a2c 6px 10px);
  border: 3px solid #9aa0a6; box-shadow: 0 calc(6px - var(--press) * 5px) 0 #6c7177;
  transform: translateY(calc(var(--press) * 5px)) scale(calc(1 - var(--press) * .05)); transition: transform .05s, box-shadow .05s;
  cursor: pointer;
}
.pedal span { background: rgba(0, 0, 0, .35); padding: 1px 6px; border-radius: 6px; }
.pedal.brake { width: 74px; height: 78px; }
.pedal.gas { width: 58px; height: 120px; }
.pedal.down.gas { border-color: #6fcf7a; }
.pedal.down.brake { border-color: #ff8a6a; }

/* messages over the view */
.msg {
  position: absolute; bottom: 10px; left: 50%; transform: translateX(-50%); max-width: calc(100% - 24px);
  background: rgba(255, 255, 255, .95); border-radius: 12px; padding: 8px 14px; font-weight: 700; text-align: center;
  box-shadow: 0 3px 12px rgba(0, 0, 0, .18); pointer-events: none; border: 2px solid var(--line);
}
.msg.warn { border-color: var(--mustard); background: #fff5d6; }
.msg.bad { border-color: var(--wrong); background: #ffe9e4; color: #8a2216; }
.result {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(420px, calc(100% - 24px));
  background: #fff; border-radius: 18px; padding: 16px 18px; text-align: center; box-shadow: 0 10px 40px rgba(0, 0, 0, .3);
  border: 3px solid var(--right); animation: pop .3s ease-out;
}
.result.bad { border-color: var(--wrong); }
.result-stars { font-size: 40px; color: #f2b705; letter-spacing: 4px; line-height: 1.1; }
.result-text { font-size: 21px; font-weight: 800; margin: 4px 0; }
.result-detail { color: var(--muted); font-weight: 600; font-size: 15px; }
.result-buttons { display: flex; gap: 10px; justify-content: center; margin-top: 14px; flex-wrap: wrap; }
@keyframes pop { from { transform: translate(-50%, -50%) scale(.7); } to { transform: translate(-50%, -50%) scale(1); } }

/* ---------- dialogs ---------- */
.dialog { max-width: 460px; width: calc(100% - 28px); border: none; box-shadow: 0 10px 40px rgba(0, 0, 0, .3); }
.dialog.wide { max-width: 760px; }
.dialog::backdrop { background: rgba(30, 20, 10, .45); }
.dialog h2 { margin: 0 0 12px; color: var(--orange-dark); }
.field { display: flex; flex-direction: column; gap: 6px; font-weight: 700; margin-bottom: 12px; }
.field.check { flex-direction: row; align-items: center; gap: 10px; }
.field input[type=text], .field select { font: inherit; font-weight: 500; padding: 8px 10px; border: 2px solid var(--line); border-radius: 10px; }
.field input[type=checkbox] { width: 22px; height: 22px; flex: none; }
.field-label { font-weight: 700; margin-bottom: 6px; }
.emoji-pick { display: grid; grid-template-columns: repeat(8, 1fr); gap: 6px; margin-bottom: 14px; }
.emoji-pick button { font-size: 26px; padding: 4px 0; border-radius: 10px; }
.emoji-pick button.on { border-color: var(--orange); background: #fff1e5; }
.dialog-buttons { display: flex; gap: 8px; align-items: center; margin-top: 8px; }
.spacer { flex: 1; }
.help { padding-left: 22px; }
.help li { margin-bottom: 8px; line-height: 1.45; }
.scores { border-collapse: collapse; width: 100%; font-size: 14px; }
.scores th, .scores td { padding: 6px 5px; border-bottom: 1px solid var(--line); text-align: center; }
.scores .who { text-align: left; white-space: nowrap; font-weight: 700; }
.mini-stars { color: #f2b705; font-size: 11px; letter-spacing: 0; white-space: nowrap; }
#scores { overflow-x: auto; }

/* ---------- smaller screens ---------- */

/* sideways tablets: a two-column menu so Start fits on the screen */
@media (min-aspect-ratio: 4/3) and (max-height: 820px) and (min-width: 800px) {
  .home { max-width: 1100px; display: grid; grid-template-columns: 1fr 1fr; align-items: start; gap: 10px; padding-top: 10px; }
  .home .panel { padding: 10px 14px; }
  .home h2 { font-size: 16px; margin-bottom: 8px; }
  .levels { grid-template-columns: repeat(4, 1fr); }
  .home-go { grid-column: 2; }
  .player-emoji { width: 34px; height: 34px; font-size: 26px; }
  .trailer-pick svg { max-height: 44px; }
  .trailer-pick { padding: 4px 6px 6px; }
  .tr-about { font-size: 12px; }
  .level-n { font-size: 22px; }
  .level-name { min-height: 0; }
  .home-go .go { padding: 8px 30px; }
  .players { gap: 8px; }
  .player { padding: 4px 12px 4px 4px; }
  .views { grid-template-columns: 1fr; gap: 6px; }
  .view-pick { flex-direction: row; align-items: baseline; gap: 10px; padding: 6px 12px; }
}

/* short screens (a tablet on its side): tighter driving controls */
@media (max-height: 700px) {
  .play { gap: 6px; padding: 6px 8px 8px; }
  .play-bar { min-height: 40px; }
  .site-name { font-size: 17px; }
  .wheel-box { width: 148px; }
  .minimap { height: 110px; }
  .driver { row-gap: 4px; padding: 6px 10px; }
  .speedo { width: 84px; height: 48px; }
  .speed-text { font-size: 13px; }
  .ignition svg { width: 44px; height: 44px; }
  .shifter { gap: 4px; padding: 5px; }
  .shifter button { height: 36px; }
  .pedal.gas { height: 104px; }
  .pedal.brake { height: 70px; }
}

/* upright tablets and phones: the view on top, the controls underneath */
@media (max-aspect-ratio: 1/1) {
  .stage { grid-template-columns: 1fr 1fr; grid-template-rows: auto auto; align-content: center; }
  .view-wrap { grid-column: 1 / -1; grid-row: 1; width: 100%; aspect-ratio: 3 / 2; max-height: 100%; align-self: center; }
  .driver {
    grid-column: 1 / -1; grid-row: 2; justify-content: center;
    grid-template-columns: auto auto auto auto auto; grid-template-areas: "map wheel dash dash key" "map wheel brake gas shift";
  }
  .minimap { min-width: 0; width: min(150px, 25vw); height: auto; aspect-ratio: 1; align-self: center; }
  .driver .wheel-box { align-self: center; }
  .wheel-box { width: min(170px, 29vw); }
  .driver { column-gap: 8px; padding: 8px; }
  .stats .stat-label { display: none; }
}

@media (max-width: 700px) {
  .trailers, .views { grid-template-columns: 1fr; }
  .trailer-pick { flex-direction: row; text-align: left; gap: 10px; }
  .trailer-pick svg { width: 90px; flex: none; }
  .tr-name { min-width: 90px; }
  .levels { grid-template-columns: repeat(4, 1fr); }
  .play-bar { flex-wrap: wrap; }
  .play-bar #btn-view, .play-bar #btn-restart { font-size: 13px; }
}

@media (max-width: 560px) {
  .brand { font-size: 17px; }
  .brand-mark { display: none; }
  .apps-link span { display: none; }
  .apps-link { padding: 6px 11px; }
  .top-left { gap: 8px; }
  .topbar { padding: 8px 10px; }
  .top-right { gap: 6px; }
  .player-chip { padding: 6px 10px; }
  .speedo { display: none; }
}
