/* Daylight instrument panel. The track canvas keeps its own surface palette. */
:root {
  color-scheme: light;
  --bg: #f3f5f6;
  --card: #fff;
  --line: #d3dbde;
  --muted: #52626a;
  --light: #18252b;
  --acid: #a13b04;
  --action: #b84207;
  --action-hover: #963603;
  --warm: #fff0e6;
  --panel-soft: #eff3f4;
  --instrument-shadow: 0 2px 7px #283c4726;
}
body.embedded { background: #fff; }
.top, .game-area, .keybar, .race-board, dialog {
  color: var(--light);
  background: var(--card);
  border-color: var(--line);
}
.brand, .keytitle, .help-button { color: var(--light); }
.brand b span { color: #b43c00; }
.brand-bars i { background: #ef630d; }
.brand-divider { background: var(--line); }
.brand-section, .keypair, .arrow-note { color: var(--muted); }
kbd {
  color: var(--light);
  background: var(--panel-soft);
  border-color: #bbc7cb;
}

.garage {
  background: linear-gradient(90deg,#e5edf1a6, #e5edf140 46%,transparent 76%);
}
.start-card {
  color: var(--light);
  background: #fffffff7;
  border: 1px solid #bfcbd0;
  box-shadow: 0 8px 32px #22343d2b;
}
.start-card h1 span { color: #be4509; }
.drive-display {
  background: radial-gradient(ellipse at 49% 43%,#fff 0%,#f1f4f3 58%,#e5ebed 100%);
  border: 1px solid var(--line);
}
.setting-label, .garage-fields label { color: var(--muted); }
.drive-choice, #garageDemo, #backToGarage, #demoButton, #finishNew,
.menu-actions button, #menuDialog select, .garage select {
  background: #fff;
  color: var(--light);
  border: 1px solid #adbbc0;
}
.drive-choice:hover, .drive-choice:focus-visible { border-color: var(--action); }
.drive-choice[aria-pressed=true] {
  background: var(--warm);
  color: #843003;
  border-color: #b84207;
  box-shadow: inset 0 0 0 1px #b84207;
}
#enterTrack, #finishAgain, .pause-overlay button {
  color: #fff;
  border-color: var(--action);
  background: var(--action);
}
@media (hover:hover) {
  #enterTrack:hover, #finishAgain:hover, .pause-overlay button:hover { background: var(--action-hover); }
  #garageDemo:hover, #backToGarage:hover, #demoButton:hover, #finishNew:hover,
  .menu-actions button:hover { background: var(--panel-soft); border-color: #8b9da5; }
}

.stage-label, .square, .stage-hud .time, .minimap {
  background: #fffffff5;
  color: var(--light);
  border: 1px solid #b3c1c8;
  box-shadow: var(--instrument-shadow);
}
.stage-label i { background: #397947; box-shadow: 0 0 0 3px #39794718; }
.stage-hud .time output { color: var(--light); }
.stage-hud .time .ico { color: var(--acid); }
.square:hover, .track-tag:hover, .square:focus-visible { background: #f2f5f6; }
.minimap { width: clamp(100px, 16vw, 126px); height: auto; aspect-ratio: 1.6; }
.minimap canvas { filter: brightness(.62) saturate(1.45); }
#gameMenu {
  order: -1;
  display: inline-flex;
  justify-content: center;
  align-items: center;
  gap: 4px;
  width: auto;
  height: var(--tool-height);
  padding: 0 7px;
  font-family: inherit;
  font-size: 12px;
  font-weight: 650;
  line-height: 1.1;
  white-space: nowrap;
}
#gameMenu .ico { display: block; width: 14px; height: 14px; }
#gameMenu span { display: inline; }
#gameMenu[hidden] { display: none; }

.checkers { background: repeating-conic-gradient(#49595e 0 25%,#fff 0 50%) 0 0/6px 6px; }
.live-meters { color: var(--muted); }
.live-meters output { color: var(--light); }
.gear-lamp { background: #fff; color: #8e3504; border-color: #c28d65; }
.driving-pad .steering-wheel {
  background: transparent;
  filter: drop-shadow(0 1px 2px #ffffffed);
}
.wheel-rim { stroke: #53656e; }
.wheel-spokes { fill: #899aa2; stroke: #4a5b65; }
.wheel-hub { fill: #ebeff0; stroke: #6e8088; }
.wheel-marker { stroke: #ff711b; }
.steering-wheel.held .wheel-rim { stroke: #344953; }
.driving-pad .pedal-bank :is(.hand,.brake) {
  color: #26373d;
  background: #fff;
  border-color: #afbec4;
}
.driving-pad .pedal-bank .brake { background: #e5ecee; }
.driving-pad .pedal-bank .gas {
  color: #672703;
  background: #ffe2c7;
  border-color: #c5723a;
  box-shadow: inset 0 -3px 0 #bc773f;
}
.driving-pad .pedal-bank .gas::after { background: #ffad66; }

.pause-overlay, .finish-overlay { background: #18282f61; }
dialog {
  color: var(--light);
  border-color: #afbdc4;
  background: #fff;
  box-shadow: 0 12px 40px #192a3455;
}
dialog::backdrop { background: #19292f70; }
dialog p, dialog .model-note, .finish-message, .finish-places span,
.board-heading p, .board-note, .board-footer { color: var(--muted); }
.menu-actions { display: grid; gap: 8px; margin-top: 14px; }
.menu-actions button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  border-radius: 7px;
  padding: 7px 12px;
  font-weight: 650;
}
#menuDialog select { width: 100%; min-height: 44px; border-radius: 6px; padding-inline: 9px; }
.board-heading { flex-wrap: wrap; }
.board-config { display: flex; flex-wrap: wrap; align-items: center; gap: 7px 12px; }
.race-board table { table-layout: fixed; }
.race-board th, .race-board td { border-color: var(--line); }
.race-board th { color: var(--muted); }
.race-board th:first-child, .race-board td:first-child { width: clamp(40px,11%,76px); }
.race-board th:last-child, .race-board td:last-child { width: clamp(93px,34%,185px); }
.player-login, .player-team, .row-discipline { display: block; overflow-wrap: anywhere; }
.player-login { font-weight: 650; }
.player-team, .row-discipline { color: var(--muted); font: 400 12px/1.35 system-ui,sans-serif; }
.row-discipline { margin-top: 2px; white-space: normal; }
.row-discipline .ico { width: 13px; height: 13px; margin-right: 4px; vertical-align: -2px; }
.self-tag { color: #823605; font: 600 12px/1.4 system-ui,sans-serif; }
#gameMenu {
  color: #604431;
  background: #fff5ebf5;
  border: 1px solid #c9b8a8;
  border-radius: 7px;
  box-shadow: var(--instrument-shadow);
}
#gameMenu:hover { background: #fffaf5; }
.race-board tr.mine td { background: var(--warm); color: #762c05; }
.race-board tr.mine .player-team, .race-board tr.mine .row-discipline { color: #754429; }
.race-board tr.mine td:first-child { box-shadow: inset 3px 0 #bf4b13; }
:where(button,select,a):focus-visible { outline-color: var(--action); outline-offset: 2px; }

@media (max-width:535px) {
  .garage { background: #e4ecee80; }
  #playView .stage-top {
    display: grid;
    grid-template-columns: minmax(81px,auto) minmax(0,1fr);
    align-items: start;
  }
  .stage-tools { flex-wrap: wrap; justify-content: flex-end; justify-self: end; }
  .stage-hud { max-width: 118px; }
  #playView .runbar { flex-wrap: wrap; }
}
@media (max-width:375px) {
  #playView .stage-top { left: 7px; right: 7px; gap: 4px; }
  .stage-tools { gap: 3px; }
  .stage-hud { max-width: 94px; row-gap: 5px; }
  .race-board th:first-child, .race-board td:first-child { width: 40px; }
  .race-board:not(.finish-board) { padding-inline: 10px; }
}

#playView.before-start .driving-pad { display: none; }
#menuDialog .menu-actions button {
  min-width: 0;
  height: auto;
  width: 100%;
  font: 650 14px/1.25 system-ui,sans-serif;
}
#menuDialog #menuResume {
  background: var(--action);
  border-color: var(--action);
  color: #fff;
}
@media (max-width:720px) {
  #playView.before-start .garage { padding-top: 58px; }
}
@media (min-width:610px) and (max-width:800px) and (max-height:530px) and (orientation:landscape) {
  #playView.before-start .garage { padding: 8px 52px; justify-items: start; }
}
@media (min-width:610px) and (max-width:800px) {
  .in-frame.host-landscape #playView.before-start .garage { padding: 8px 52px; justify-items: start; }
}


.stage {
  --hud-inset: clamp(8px, 1.8vw, 16px);
  --tool-height: 32px;
  --tool-gap: 8px;
  --tool-step: calc(var(--tool-height) + 12px);
  --fullscreen-width: 66px;
  --retry-width: 78px;
  --screen-tools-width: calc(var(--retry-width) + var(--tool-gap) + var(--fullscreen-width));
}
.stage-top #soundButton { width: 36px; height: var(--tool-height); border-radius: 7px; }
#soundButton .ico { width: 18px; height: 18px; }
.stage :is(#soundButton, #gameMenu, #cameraButton, #trackAgain, #fullScreenButton) { position: relative; }
/* Keep the compact controls easy to tap without extending into the adjacent button. */
.stage :is(#soundButton, #gameMenu, #cameraButton, #trackAgain, #fullScreenButton)::after {
  content: ""; position: absolute; inset: -7px 0;
}
.stage #soundButton::after { inset-inline: -5px; }
#playView:not(.before-start) .stage-top {
  top: max(var(--hud-inset), env(safe-area-inset-top));
  left: max(var(--hud-inset), env(safe-area-inset-left));
  right: max(var(--hud-inset), env(safe-area-inset-right));
  gap: 4px;
  display: flex;
}
.stage-tools { margin-right: calc(var(--screen-tools-width) + var(--tool-gap)); gap: var(--tool-gap); flex-wrap: nowrap; align-items: flex-start; }
#playView .stage-hud { max-width: none; flex: 0 1 auto; gap: 4px; }
#playView .stage-bottom {
  top: calc(max(var(--hud-inset), env(safe-area-inset-top)) + var(--tool-step));
  right: max(var(--hud-inset), env(safe-area-inset-right));
  bottom: auto;
}
.instruments { display: grid; justify-items: start; gap: 4px; }
.instruments .live-meters {
  width: fit-content;
  margin: 0;
  padding: 4px 7px;
  background: #fffffff0;
  border-radius: 5px;
  color: #233238;
}
.instruments .live-meters { gap: 8px; }
.instruments #demoButton { pointer-events: auto; }
@media (max-width:535px) {
  .instruments .live-meters { font-size: 10px; gap: 5px; }
  .instruments .live-meters output { font-size: 12px; }
  .minimap { width: 86px; }
}

@media (max-width:535px) {
  /* Keep retry and fullscreen together, with the smaller tools on the next row. */
  .stage-tools { position: absolute; top: var(--tool-step); right: 0; margin-right: 0; }
  #playView .stage-bottom {
    right: max(var(--hud-inset), env(safe-area-inset-right));
    top: calc(max(var(--hud-inset), env(safe-area-inset-top)) + var(--tool-step) + var(--tool-step));
  }
  #playView .stage-hud { max-width: calc(100% - var(--screen-tools-width) - var(--tool-gap)); }
  .stage-hud .stage-label { height: auto; min-height: 28px; padding: 4px 6px; gap: 5px; }
  .stage-hud #runLabel { white-space: normal; line-height: 1.15; text-wrap: balance; }
}

.stage-bottom .minimap { display: block; border-radius: 7px; }
.stage-tools .camera-switch {
  display: inline-flex; align-items: center; justify-content: center; gap: 4px;
  min-width: 46px; height: var(--tool-height); padding: 0 6px;
  border: 1px solid #b3c1c8; border-radius: 7px; background: #fffffff2;
  color: #293d45; font: 650 11px/1 system-ui,sans-serif; white-space: nowrap;
  box-shadow: var(--instrument-shadow); cursor: pointer; touch-action: manipulation;
}
.camera-switch .ico { width: 15px; height: 15px; }
.camera-switch:hover { background: #f2f5f6; }
@media (max-width:420px) {
  .stage-tools { gap: 5px; }
  .stage-tools #gameMenu { width: 46px; min-width: 46px; padding: 0 2px; }
  #gameMenu .ico, .camera-switch .ico { display: none; }
  .stage-tools .camera-switch { width: 57px; padding: 0 2px; white-space: normal; }
}
@media (max-width:360px) {
  .stage-tools { gap: 4px; }
  .stage-tools .camera-switch { width: 47px; font-size: 10px; }
  .instruments { margin-top: 12px; }
  #playView .stage-hud .time { padding-inline: 5px; }
}
.race-board tr.mine.new-record td { background: #e2f5e8; color: #174e2d; }
.race-board tr.mine.new-record td:first-child { box-shadow: inset 3px 0 #258346; }
.race-board tr.mine.new-record :is(.player-team,.row-discipline,.self-tag) { color: #236239; }

#leaderboard .board-heading { flex-wrap: wrap; align-items: center; }
.drive-chips { display: flex; flex-wrap: wrap; gap: 5px; }
.drive-chips button {
  display: inline-flex; align-items: center; justify-content: center; gap: 5px;
  min-height: 36px; border: 1px solid #c9d4d8; border-radius: 999px;
  padding: 5px 12px; color: #374c55; background: #fff; font: 600 13px/1.2 system-ui,sans-serif;
}
.drive-chips button[aria-pressed=true] { border-color: #9c4113; color: #85350f; background: #fff1e5; }
.drive-chips .ico { width: 15px; height: 15px; flex: none; }
.board-pair { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: clamp(6px, 1.4vw, 16px); margin-top: 12px; align-items: start; }
.period-card {
  container: period / inline-size;
  min-width: 0; padding: clamp(5px, 1vw, 12px); border: 1px solid #d5dfe2; border-radius: 14px; background: #fff;
}
.period-card > :is(h3,h4) { margin: 0; padding: 3px 4px; color: #273b43; font: 700 16px/1.25 system-ui,sans-serif; }
.period-card .board-note:not(:empty) { margin: 8px 4px; color: #52656e; overflow-wrap: anywhere; }
.period-card table { border-collapse: separate; border-spacing: 0 4px; margin: 2px 0 0; }
.period-card table th, .period-card table td { padding: 6px; border: 0; }
.period-card table th:first-child, .period-card table td:first-child { width: 12%; }
.period-card table th:last-child, .period-card table td:last-child { width: 32%; }
.period-card tbody td { background: #f2f5f6; }
.period-card tbody td:first-child { border-radius: 9px 0 0 9px; }
.period-card tbody td:last-child { border-radius: 0 9px 9px 0; }
.period-card table[hidden] { display: none; }
@container period (max-width: 265px) {
  .period-card table, .period-card tbody { display: block; }
  .period-card thead { position: absolute; width: 1px; height: 1px; clip-path: inset(50%); overflow: hidden; }
  .period-card tbody tr {
    display: grid; grid-template-columns: auto minmax(0,1fr); align-content: start; align-items: baseline;
    gap: 3px; margin-top: 5px; padding: 6px; border-radius: 9px; background: #f2f5f6;
  }
  .period-card tr.mine { background: var(--warm); box-shadow: inset 3px 0 #bf4b13; }
  .period-card tr.mine.new-record { background: #e2f5e8; box-shadow: inset 3px 0 #258346; }
  .period-card table tbody tr td, .race-board .period-card tr.mine td { width: auto; padding: 0; border-radius: 0; background: transparent; box-shadow: none; }
  .period-card table tbody td:is(:first-child,:last-child) { width: auto; }
  .period-card table tbody td:first-child { font-size: 13px; }
  .period-card tbody td:nth-child(2) { min-width: 0; font-size: 12px; line-height: 1.3; }
  .period-card table tbody td:last-child { grid-column: 1/-1; text-align: left; font-size: 14px; }
  .period-card :is(.player-team,.self-tag,.row-discipline) { font-size: 11px; }
  .period-card .row-discipline .ico { width: 11px; height: 11px; margin-right: 2px; }
}
@media (max-width:535px) {
  .drive-chips { gap: 4px; }
  .drive-chips button { min-height: 44px; padding: 5px 8px; font-size: 12px; }
  .board-pair { gap: 6px; }
}
