/* Safe Driver — interface styling. The look borrows from the road itself:
   asphalt panels, centre-line yellow, guide-sign green, white regulatory signs. */
:root {
  --asphalt: #15171a;
  --panel: rgba(21, 23, 27, 0.88);
  --panel-solid: #1e2125;
  --line: rgba(255, 255, 255, 0.13);
  --ink: #f3f3ee;
  --ink-2: #b4b8bf;
  --yellow: #f4c20d;
  --green: #0b6b43;
  --green-2: #0e7e50;
  --red: #e0453a;
  --orange: #ff9a2e;
  --blue: #6aa8ff;
  --good: #5fd68b;
  --paper: #f6f2e7;
  --paper-ink: #24211b;
  --display: "Arial Narrow", "Roboto Condensed", "Helvetica Neue", Arial, sans-serif;
  --body: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; overflow: hidden; background: var(--asphalt); color: var(--ink);
  font: 15px/1.45 var(--body); -webkit-font-smoothing: antialiased;
  -webkit-user-select: none; user-select: none; touch-action: manipulation;
}
#game { position: fixed; inset: 0; width: 100vw; height: 100vh; height: 100dvh; display: block; }
.hidden { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
kbd {
  display: inline-block; min-width: 1.7em; padding: 1px 6px; margin: 0 2px; text-align: center;
  font: 600 12px/1.5 var(--body); color: var(--ink); background: #2c3036; border: 1px solid #454a52;
  border-bottom-width: 2px; border-radius: 5px;
}
h1, h2, h3, p { margin: 0; }
.step {
  margin: 22px 0 9px; font: 700 12px/1 var(--body); letter-spacing: 0.12em; text-transform: uppercase; color: var(--ink-2);
}

/* ---------- buttons ---------- */
.btn {
  border: 0; border-radius: 10px; padding: 14px 26px;
  font: 700 19px/1 var(--display); letter-spacing: 0.06em; text-transform: uppercase;
  transition: transform 0.12s, filter 0.12s;
}
.btn:hover { filter: brightness(1.08); transform: translateY(-1px); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible, .state-card:focus-visible, .seg button:focus-visible, .chip:focus-visible, .icon-btn:focus-visible, summary:focus-visible {
  outline: 3px solid #fff; outline-offset: 2px;
}
.btn.primary { background: var(--yellow); color: #17150c; box-shadow: 0 4px 0 #a98400; }
.btn.ghost { background: transparent; border: 1px solid var(--line); color: var(--ink); }

/* ---------- start screen and trip report ---------- */
.screen {
  position: fixed; inset: 0; z-index: 20; overflow-y: auto; -webkit-overflow-scrolling: touch;
  background: linear-gradient(180deg, rgba(13, 15, 18, 0.9), rgba(13, 15, 18, 0.95));
  display: flex; justify-content: center;
}
.menu-inner, .end-inner { width: min(1040px, 100% - 32px); padding: 34px 0 44px; }
.title .stripe {
  width: 150px; height: 7px; margin-bottom: 14px;
  background: repeating-linear-gradient(90deg, var(--yellow) 0 34px, transparent 34px 54px);
}
.title h1 { font: 800 clamp(44px, 8vw, 78px)/0.95 var(--display); letter-spacing: 0.03em; text-transform: uppercase; }
.title p { margin-top: 12px; font-size: 18px; color: var(--ink-2); max-width: 46ch; }

.cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.state-card {
  position: relative; text-align: left; padding: 20px 20px 16px; border: 0; border-radius: 13px;
  background: var(--green); color: #fff; outline: 2px solid rgba(255, 255, 255, 0.92); outline-offset: -8px;
  display: flex; flex-direction: column; gap: 3px; transition: transform 0.15s, background 0.15s, box-shadow 0.15s;
}
.state-card:hover { transform: translateY(-3px); }
.state-card.on { background: var(--green-2); box-shadow: 0 0 0 4px var(--yellow); }
.state-card.on::after {
  content: "✓"; position: absolute; top: 16px; right: 18px; width: 26px; height: 26px; border-radius: 50%;
  background: var(--yellow); color: #17150c; font: 800 16px/26px var(--body); text-align: center;
}
.state-card .abbr { font: 800 46px/1 var(--display); letter-spacing: 0.04em; }
.state-card .name { font: 700 19px/1.2 var(--body); }
.state-card .guide { font-size: 12.5px; opacity: 0.86; }
.state-card ul { margin: 10px 0 8px; padding-left: 17px; font-size: 13.5px; line-height: 1.4; }
.state-card li + li { margin-top: 3px; }
.state-card .best { margin-top: auto; padding-top: 8px; border-top: 1px solid rgba(255, 255, 255, 0.28); font-size: 12.5px; opacity: 0.9; }

.options { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.seg button {
  text-align: left; padding: 11px 13px; border-radius: 10px; background: var(--panel); border: 1px solid var(--line);
  font-weight: 700; font-size: 15.5px;
}
.seg button small { display: block; margin-top: 2px; font-weight: 400; font-size: 12.5px; color: var(--ink-2); }
.seg button.on { border-color: var(--yellow); background: rgba(244, 194, 13, 0.13); box-shadow: inset 0 0 0 1px var(--yellow); }

.go { display: flex; align-items: center; gap: 22px; flex-wrap: wrap; margin-top: 26px; }
.controls-help { display: flex; flex-wrap: wrap; gap: 8px 16px; font-size: 13px; color: var(--ink-2); }
.controls-help.col { flex-direction: column; margin: 14px 0 18px; }
.how { margin-top: 26px; max-width: 74ch; color: var(--ink-2); }
.fine { margin-top: 12px; max-width: 86ch; font-size: 12.5px; color: #8b9098; }

.end-head { display: flex; align-items: center; gap: 22px; flex-wrap: wrap; }
.grade {
  flex: none; width: 104px; height: 104px; border-radius: 16px; display: grid; place-items: center;
  font: 800 58px/1 var(--display); color: #fff; outline: 3px solid rgba(255, 255, 255, 0.92); outline-offset: -9px; background: var(--green);
}
.grade.gB { background: #2866b3; } .grade.gC { background: #c56f12; } .grade.gD, .grade.gF { background: #b3342b; }
.end-head h1 { font: 800 clamp(28px, 4.6vw, 44px)/1.05 var(--display); text-transform: uppercase; letter-spacing: 0.03em; }
.end-head p { margin-top: 6px; color: var(--ink-2); }
.end-score { margin-left: auto; text-align: right; }
.end-score b { display: block; font: 800 50px/1 var(--display); color: var(--yellow); font-variant-numeric: tabular-nums; }
.end-score small { color: var(--ink-2); text-transform: uppercase; letter-spacing: 0.1em; font-size: 11.5px; }
.end-score span { display: block; margin-top: 4px; font-size: 13px; color: var(--ink-2); }
.end-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-top: 22px; }
.end-stats div { padding: 12px 14px; border-radius: 10px; background: var(--panel); border: 1px solid var(--line); }
.end-stats b { display: block; font: 800 24px/1.1 var(--display); }
.end-stats span { font-size: 12.5px; color: var(--ink-2); }

.end-list { display: grid; gap: 8px; }
.result { border-radius: 10px; background: var(--panel); border: 1px solid var(--line); border-left: 5px solid var(--good); }
.result.partial { border-left-color: var(--orange); }
.result.crash { border-left-color: var(--red); }
.result summary { display: flex; align-items: center; gap: 12px; padding: 12px 14px; cursor: pointer; list-style: none; }
.result summary::-webkit-details-marker { display: none; }
.r-icon { font-size: 22px; width: 30px; text-align: center; }
.r-title { font-weight: 700; font-size: 16px; }
.r-chip { margin-left: auto; padding: 3px 9px; border-radius: 20px; font-size: 12px; font-weight: 700; background: rgba(95, 214, 139, 0.16); color: var(--good); }
.result.partial .r-chip { background: rgba(255, 154, 46, 0.16); color: var(--orange); }
.result.crash .r-chip { background: rgba(224, 69, 58, 0.18); color: #ff8076; }
.r-pts { min-width: 78px; text-align: right; font: 700 16px var(--display); font-variant-numeric: tabular-nums; color: var(--ink-2); }
.r-body { padding: 0 14px 14px 56px; }
.r-body ul { list-style: none; margin: 0 0 12px; padding: 0; font-size: 14px; }
.r-body li.ok { color: var(--good); } .r-body li.no { color: #ff8076; }

/* ---------- best-practice card ---------- */
.lesson {
  background: var(--paper); color: var(--paper-ink); border-radius: 10px; padding: 15px 18px 16px;
  border-left: 7px solid var(--green); -webkit-user-select: text; user-select: text;
}
.lesson-from { font: 700 11.5px/1.3 var(--body); letter-spacing: 0.08em; text-transform: uppercase; color: var(--green); }
.lesson h3 { margin: 5px 0 6px; font: 800 21px/1.15 var(--display); letter-spacing: 0.02em; text-transform: uppercase; }
.lesson p { font-size: 15px; line-height: 1.5; }
.lesson .lesson-rule { margin-bottom: 8px; font-weight: 700; font-size: 16px; line-height: 1.4; }
.lesson cite { display: block; margin-top: 10px; padding-top: 8px; border-top: 1px solid rgba(0, 0, 0, 0.14); font-style: normal; font-size: 12.5px; color: #5d584d; }
.lesson.small { padding: 12px 15px; }
.lesson.small h3 { font-size: 16px; margin-top: 0; }
.lesson.small p { font-size: 14px; }
.lesson.small .lesson-rule { font-size: 14.5px; }
.lesson.small cite { font-size: 12px; }
.step span { font-weight: 400; letter-spacing: 0.04em; text-transform: none; }

/* ---------- dialogs ---------- */
.modal { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; padding: 16px; background: rgba(8, 9, 11, 0.74); overflow-y: auto; }
.card { width: min(590px, 100%); padding: 22px; border-radius: 15px; background: var(--panel-solid); border: 1px solid var(--line); box-shadow: 0 24px 70px rgba(0, 0, 0, 0.55); animation: pop 0.22s ease-out; }
@keyframes pop { from { transform: scale(0.94); opacity: 0; } to { transform: none; opacity: 1; } }
.crash-head { display: flex; align-items: center; gap: 16px; }
.diamond {
  flex: none; width: 46px; height: 46px; margin: 8px; transform: rotate(45deg); border-radius: 6px;
  background: var(--yellow); outline: 2px solid #17150c; outline-offset: -5px; display: grid; place-items: center;
  font: 800 28px/1 var(--display); color: #17150c;
}
.diamond span { transform: rotate(-45deg); }
.crash-head h2 { font: 800 28px/1.05 var(--display); letter-spacing: 0.04em; text-transform: uppercase; color: #ff7a6f; }
.crash-head p { margin-top: 4px; font-size: 17px; }
.crash-dmg { display: flex; align-items: center; gap: 12px; margin: 14px 0 16px; font-size: 13px; color: var(--ink-2); }
.crash-dmg .track { flex: 1; }
.crash-card .btn { margin-top: 18px; width: 100%; }
.pause-card { width: min(380px, 100%); }
.pause-card h2 { font: 800 30px/1 var(--display); text-transform: uppercase; letter-spacing: 0.05em; }
.pause-card .btn { width: 100%; margin-top: 8px; }

.track { height: 8px; border-radius: 5px; background: rgba(255, 255, 255, 0.15); overflow: hidden; }
.track i { display: block; height: 100%; width: 0; background: var(--yellow); border-radius: 5px; transition: width 0.35s; }
.track.dmg i { background: var(--red); }

/* ---------- in-drive display ---------- */
.hud { position: fixed; inset: 0; z-index: 10; pointer-events: none; }
.hud button { pointer-events: auto; }
.hud-left, .hud-right { position: absolute; top: 14px; display: flex; flex-direction: column; gap: 8px; }
.hud-left { left: 14px; width: 212px; padding: 12px 14px; border-radius: 12px; background: var(--panel); border: 1px solid var(--line); }
.hud-right { right: 14px; align-items: flex-end; }
.tag { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--ink-2); }
.tag b { padding: 2px 7px; border-radius: 5px; background: var(--green); color: #fff; font: 800 13px/1.4 var(--display); letter-spacing: 0.06em; }
.score span { font: 800 40px/1 var(--display); color: var(--yellow); font-variant-numeric: tabular-nums; }
.score small { margin-left: 6px; font-size: 11.5px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink-2); }
.trip span { display: block; margin-top: 4px; font-size: 12px; color: var(--ink-2); }

.dash { display: flex; align-items: stretch; gap: 8px; }
.limit {
  width: 62px; padding: 6px 0 4px; border-radius: 7px; background: #fbfbf8; color: #111; text-align: center;
  outline: 2px solid #111; outline-offset: -4px; display: flex; flex-direction: column;
}
.limit small { font: 800 9px/1.15 var(--display); letter-spacing: 0.05em; }
.limit b { font: 800 31px/1 var(--display); margin-top: 1px; }
.speedo { min-width: 104px; padding: 6px 14px; border-radius: 12px; background: var(--panel); border: 1px solid var(--line); text-align: right; }
.speedo b { font: 800 46px/1 var(--display); font-variant-numeric: tabular-nums; }
.speedo small { margin-left: 4px; font-size: 12px; color: var(--ink-2); }
.speedo.over { border-color: var(--red); } .speedo.over b { color: #ff6c61; }
.speedo.fast { border-color: var(--orange); } .speedo.fast b { color: var(--orange); }
.cond { padding: 4px 10px; border-radius: 6px; background: var(--orange); color: #1b1203; font: 800 12.5px/1.3 var(--display); letter-spacing: 0.07em; text-transform: uppercase; animation: blink 0.9s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0.45; } }
.chip {
  display: flex; align-items: baseline; gap: 10px; justify-content: space-between; min-width: 174px;
  padding: 6px 12px; border-radius: 9px; background: var(--panel); border: 1px solid var(--line);
}
.chip label { font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-2); pointer-events: none; }
.chip span { font: 800 17px/1.2 var(--display); font-variant-numeric: tabular-nums; }
.chip.ok span { color: var(--good); } .chip.warn span { color: var(--orange); } .chip.bad span { color: #ff6c61; } .chip.hi span { color: var(--blue); }

.top-stack { position: absolute; top: 14px; left: 50%; transform: translateX(-50%); width: min(560px, 100vw - 500px); min-width: 300px; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.banner {
  display: flex; align-items: center; gap: 14px; width: 100%; padding: 11px 16px; border-radius: 12px;
  background: var(--panel); border: 1px solid var(--line); border-left: 7px solid var(--yellow); animation: drop 0.3s ease-out;
}
.banner.danger { border-left-color: var(--red); } .banner.info { border-left-color: var(--green-2); }
@keyframes drop { from { transform: translateY(-14px); opacity: 0; } to { transform: none; opacity: 1; } }
.b-icon { font-size: 30px; line-height: 1; }
.banner strong { display: block; font: 800 21px/1.1 var(--display); letter-spacing: 0.05em; text-transform: uppercase; }
.banner p { margin-top: 3px; font-size: 14px; line-height: 1.35; color: #d9dbdf; }
.mirror { display: flex; align-items: center; gap: 10px; padding: 6px 14px; border-radius: 30px; background: #0d0e10; border: 2px solid #3a3e45; font-weight: 700; font-size: 14px; }
.mirror i { width: 12px; height: 12px; border-radius: 50%; background: #ff3b30; animation: flash 0.4s steps(2) infinite; }
.mirror i:last-child { background: #3f7bff; animation-delay: 0.2s; }
@keyframes flash { 50% { opacity: 0.15; } }

.toasts { position: absolute; left: 14px; top: 196px; width: min(350px, 100vw - 28px); display: flex; flex-direction: column; gap: 6px; }
.toast {
  display: flex; gap: 10px; align-items: baseline; padding: 7px 11px; border-radius: 9px; background: var(--panel);
  border: 1px solid var(--line); font-size: 13.5px; line-height: 1.35; animation: slide 0.25s ease-out; transition: opacity 0.35s, transform 0.35s;
}
@keyframes slide { from { transform: translateX(-16px); opacity: 0; } to { transform: none; opacity: 1; } }
.toast.out { opacity: 0; transform: translateX(-14px); }
.toast b { flex: none; min-width: 46px; font: 800 15px/1.2 var(--display); font-variant-numeric: tabular-nums; }
.toast.good b { color: var(--good); } .toast.bad b { color: #ff6c61; } .toast.miss b { color: var(--orange); } .toast.info b { color: var(--blue); }

.bottom-stack { position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%); width: min(640px, 100vw - 28px); display: flex; flex-direction: column; align-items: center; gap: 8px; }
.hint { display: flex; gap: 10px; align-items: baseline; padding: 8px 14px; border-radius: 10px; background: var(--panel); border: 1px solid var(--line); font-size: 14px; line-height: 1.35; }
.hint b { flex: none; font: 800 12px/1.6 var(--display); letter-spacing: 0.1em; text-transform: uppercase; color: var(--yellow); }
.keys { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 14px; padding: 6px 12px; border-radius: 9px; background: rgba(21, 23, 27, 0.7); font-size: 12.5px; color: var(--ink-2); }

.corner { position: absolute; right: 14px; bottom: 14px; display: flex; gap: 8px; }
.icon-btn { width: 40px; height: 40px; border-radius: 10px; background: var(--panel); border: 1px solid var(--line); font-size: 15px; }
.icon-btn.off { opacity: 0.45; text-decoration: line-through; }

/* phone temptation */
.phone { position: absolute; left: 14px; bottom: 14px; pointer-events: auto; animation: buzz 0.5s 3; }
@keyframes buzz { 0%, 100% { transform: none; } 25% { transform: translateX(-3px) rotate(-1.2deg); } 75% { transform: translateX(3px) rotate(1.2deg); } }
.phone-body { width: 218px; padding: 16px 14px 14px; border-radius: 22px; background: #0b0c0e; border: 3px solid #3a3e45; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5); }
.phone-notch { width: 56px; height: 6px; margin: 0 auto 12px; border-radius: 4px; background: #2a2d33; }
.phone-from { font-weight: 700; font-size: 13px; color: var(--ink-2); }
.phone-msg { margin: 6px 0 12px; padding: 9px 11px; border-radius: 4px 14px 14px 14px; background: #262a31; font-size: 14.5px; }
.phone button { width: 100%; padding: 9px; border-radius: 10px; border: 0; background: #2f7df6; color: #fff; font-weight: 700; }
.phone-typing { display: none; gap: 6px; justify-content: flex-end; margin-bottom: 12px; }
.phone-typing i { width: 9px; height: 9px; border-radius: 50%; background: #2f7df6; animation: flash 0.6s infinite; }
.phone-typing i:nth-child(2) { animation-delay: 0.15s; } .phone-typing i:nth-child(3) { animation-delay: 0.3s; }
.phone.typing { left: 50%; bottom: auto; top: 7vh; transform: translateX(-50%); animation: none; }
.phone.typing .phone-body { width: min(470px, 86vw); height: 66vh; border-radius: 34px; padding: 26px 22px; }
.phone.typing .phone-msg { font-size: 19px; }
.phone.typing .phone-typing { display: flex; }
.phone.typing button { display: none; }

/* touch controls */
.touch .pad { position: absolute; bottom: 18px; display: flex; gap: 12px; }
.touch .pad.left { left: 16px; } .touch .pad.right { right: 16px; }
.touch button { width: 78px; height: 78px; border-radius: 18px; background: rgba(21, 23, 27, 0.72); border: 2px solid rgba(255, 255, 255, 0.28); font: 800 15px var(--display); letter-spacing: 0.06em; text-transform: uppercase; touch-action: none; }
.touch button.gas { border-color: var(--good); height: 104px; } .touch button.brake { border-color: var(--red); }
.touch button.down { background: rgba(255, 255, 255, 0.25); }
.touching .keys { display: none; }
.touching .corner { bottom: auto; top: 196px; right: 14px; }
.touching .bottom-stack { bottom: 136px; }
.touching .phone { bottom: 112px; }

@media (max-width: 860px) {
  .cards, .options { grid-template-columns: 1fr; }
  .end-stats { grid-template-columns: 1fr 1fr; }
  .end-score { margin-left: 0; text-align: left; }
  .top-stack { top: 150px; width: calc(100vw - 28px); }
  .hud-left { width: 168px; padding: 9px 11px; }
  .score span { font-size: 30px; }
  .toasts { top: auto; bottom: 230px; }
  .chip { min-width: 150px; }
  .r-body { padding-left: 14px; }
  .keys { display: none; }
}
/* Phones: the road fills the screen, so keep the display small and see-through. */
@media (max-width: 560px) {
  .hud-left, .speedo, .chip, .banner, .hint { background: rgba(21, 23, 27, 0.72); }
  .hud-left { top: 8px; left: 8px; width: 132px; padding: 7px 9px; gap: 5px; }
  .hud-left .tag span, .hud-left .trip span { display: none; }
  .score span { font-size: 26px; }
  .score small { display: none; }
  .hud-right { top: 8px; right: 8px; gap: 5px; }
  .limit { width: 46px; padding: 4px 0 3px; }
  .limit small { font-size: 7px; }
  .limit b { font-size: 22px; }
  .speedo { min-width: 74px; padding: 4px 9px; }
  .speedo b { font-size: 30px; }
  .chip { min-width: 0; padding: 4px 9px; gap: 7px; }
  .chip label { font-size: 9px; }
  .chip span { font-size: 14px; }
  .top-stack { top: 112px; }
  .banner { padding: 8px 12px; gap: 10px; }
  .banner strong { font-size: 17px; }
  .b-icon { font-size: 22px; }
  .hint { font-size: 12.5px; padding: 6px 10px; }
  .touching .corner { top: 112px; right: 8px; }
  .toasts { left: 8px; bottom: 250px; font-size: 12.5px; }
}
@media (max-height: 560px) {
  .toasts { top: 150px; }
  .hud-left .trip:last-child { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
