:root {
  color-scheme: dark;
  --ink: #f4f7ef;
  --muted: #aeb8ad;
  --panel: rgba(17, 24, 23, 0.74);
  --panel-strong: rgba(8, 13, 14, 0.88);
  --line: rgba(244, 247, 239, 0.18);
  --accent: #f0c94e;
  --accent-2: #79c7d6;
  --warning: #dd714a;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #101615;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Hiragino Sans",
    "Noto Sans JP", sans-serif;
  color: var(--ink);
}

button {
  color: inherit;
  font: inherit;
}

.game-shell {
  position: fixed;
  inset: 0;
  min-width: 320px;
  overflow: hidden;
  background: #101615;
}

#game {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.hud {
  position: absolute;
  z-index: 3;
  border: 1px solid var(--line);
  background: var(--panel);
  backdrop-filter: blur(16px);
  box-shadow: 0 16px 42px rgba(0, 0, 0, 0.22);
}

.hud-top {
  top: max(18px, env(safe-area-inset-top));
  left: max(18px, env(safe-area-inset-left));
  right: max(18px, env(safe-area-inset-right));
  min-height: 76px;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  border-radius: 8px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 220px;
}

.brand-mark {
  width: 36px;
  height: 36px;
  flex: 0 0 auto;
  border: 2px solid rgba(244, 247, 239, 0.72);
  border-radius: 50%;
  position: relative;
  background:
    linear-gradient(135deg, transparent 45%, var(--accent) 46% 55%, transparent 56%),
    radial-gradient(circle at 65% 35%, var(--accent-2) 0 4px, transparent 5px);
}

.brand-mark::after {
  content: "";
  position: absolute;
  inset: 9px 12px;
  border-left: 3px solid var(--ink);
  border-right: 3px solid var(--ink);
  transform: rotate(38deg);
  opacity: 0.9;
}

.caption {
  margin: 0 0 3px;
  color: var(--accent);
  font-size: 11px;
  line-height: 1.1;
  font-weight: 800;
  letter-spacing: 0;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 20px;
  line-height: 1.15;
  letter-spacing: 0;
}

.meter-row {
  display: grid;
  grid-template-columns: minmax(118px, 1fr) minmax(94px, 0.7fr) minmax(64px, 0.45fr);
  gap: 10px;
  width: min(520px, 48vw);
}

.meter {
  min-width: 0;
  padding: 8px 10px;
  border: 1px solid rgba(244, 247, 239, 0.14);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
}

.meter span,
.stats-grid span {
  display: block;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.1;
  font-weight: 800;
  letter-spacing: 0;
}

.meter strong {
  display: block;
  margin-top: 4px;
  font-size: 20px;
  line-height: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: clip;
}

.meter.compact strong {
  font-size: 18px;
}

.view-toggle {
  width: 88px;
  min-height: 54px;
  flex: 0 0 auto;
  border: 1px solid rgba(240, 201, 78, 0.36);
  border-radius: 8px;
  background: rgba(240, 201, 78, 0.12);
  color: var(--ink);
  cursor: pointer;
}

.view-toggle span {
  display: block;
  color: var(--muted);
  font-size: 10px;
  line-height: 1;
  font-weight: 900;
}

.view-toggle strong {
  display: block;
  margin-top: 5px;
  color: var(--accent);
  font-size: 13px;
  line-height: 1;
  font-weight: 950;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: clip;
}

.view-toggle:active {
  transform: translateY(1px);
}

.hud-side {
  left: max(18px, env(safe-area-inset-left));
  bottom: max(18px, env(safe-area-inset-bottom));
  width: min(286px, calc(100vw - 36px));
  padding: 12px;
  border-radius: 8px;
}

#minimap {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 6px;
  background: #1d2b28;
  border: 1px solid rgba(244, 247, 239, 0.14);
}

.section-readout {
  margin-top: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.section-readout span {
  min-width: 0;
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.section-readout strong {
  color: var(--accent);
  font-size: 15px;
}

.bar {
  height: 8px;
  margin-top: 9px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
}

.bar span {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent-2), var(--accent));
}

.pace-note {
  margin-top: 10px;
  padding: 10px 11px;
  border: 1px solid rgba(240, 201, 78, 0.28);
  border-radius: 8px;
  background: rgba(240, 201, 78, 0.09);
}

.pace-note span,
.pace-note small {
  display: block;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.15;
  font-weight: 800;
}

.pace-note strong {
  display: block;
  margin: 4px 0 3px;
  color: var(--accent);
  font-size: 18px;
  line-height: 1.05;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: clip;
}

.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px 12px;
  margin-top: 12px;
}

.stats-grid strong {
  font-size: 14px;
  line-height: 1.1;
}

.overlay-panel {
  position: absolute;
  z-index: 4;
  top: 50%;
  left: 50%;
  width: min(420px, calc(100vw - 38px));
  transform: translate(-50%, -50%);
  padding: 26px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-strong);
  backdrop-filter: blur(18px);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.36);
  text-align: center;
}

.overlay-panel h2 {
  margin: 5px 0 18px;
  font-size: clamp(22px, 6vw, 38px);
  line-height: 1.04;
  letter-spacing: 0;
}

.overlay-panel p:not(.caption) {
  color: var(--muted);
  font-weight: 700;
}

.primary-action {
  width: 100%;
  min-height: 48px;
  margin-top: 10px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #1d1710;
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 12px 26px rgba(240, 201, 78, 0.24);
}

.primary-action:active {
  transform: translateY(1px);
}

.setup-grid {
  display: grid;
  gap: 12px;
  margin: 0 0 12px;
  text-align: left;
}

.setup-block {
  min-width: 0;
}

.setup-label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 10px;
  line-height: 1;
  font-weight: 900;
  letter-spacing: 0;
}

.choice-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}

#directionChoices {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.choice-button,
.secondary-action {
  min-width: 0;
  min-height: 38px;
  border: 1px solid rgba(244, 247, 239, 0.17);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.07);
  color: var(--ink);
  font-size: 12px;
  font-weight: 850;
  line-height: 1.1;
  cursor: pointer;
}

.choice-button.is-selected {
  border-color: rgba(240, 201, 78, 0.82);
  background: rgba(240, 201, 78, 0.22);
  color: #fff8ce;
}

.secondary-action {
  width: 100%;
  margin-top: 10px;
  color: var(--accent-2);
}

.secondary-action.is-on {
  border-color: rgba(121, 199, 214, 0.78);
  background: rgba(121, 199, 214, 0.18);
  color: #d8f9ff;
}

.route-facts,
.leaderboard {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  margin-top: 10px;
}

.route-facts span,
.leaderboard span {
  min-width: 0;
  padding: 7px 6px;
  border: 1px solid rgba(244, 247, 239, 0.13);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.05);
  color: var(--muted);
  font-size: 11px;
  line-height: 1.1;
  font-weight: 800;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.leaderboard {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.leaderboard span {
  color: var(--ink);
}

.touch-controls {
  position: absolute;
  z-index: 5;
  right: max(18px, env(safe-area-inset-right));
  bottom: max(18px, env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: repeat(4, 58px);
  gap: 10px;
}

.touch-controls button {
  width: 58px;
  height: 58px;
  border: 1px solid rgba(244, 247, 239, 0.18);
  border-radius: 8px;
  background: rgba(15, 22, 22, 0.72);
  backdrop-filter: blur(12px);
  color: var(--ink);
  font-size: 25px;
  font-weight: 900;
  cursor: pointer;
  touch-action: none;
  user-select: none;
}

.touch-controls button[data-control="gas"] {
  color: #101615;
  background: var(--accent);
}

.touch-controls button[data-control="brake"] {
  color: #fff4ee;
  background: rgba(221, 113, 74, 0.82);
}

.touch-controls button.is-down {
  transform: translateY(1px) scale(0.98);
  filter: brightness(1.12);
}

.game-shell:has(.overlay-panel:not([hidden])) .touch-controls {
  opacity: 0;
  pointer-events: none;
}

[hidden] {
  display: none !important;
}

@media (max-width: 760px) {
  .hud-top {
    min-height: 68px;
    padding: 10px;
    align-items: stretch;
  }

  .brand {
    min-width: 0;
    max-width: 44%;
  }

  .brand-mark {
    width: 30px;
    height: 30px;
  }

  h1 {
    font-size: 15px;
  }

  .caption {
    font-size: 9px;
  }

  .meter-row {
    width: auto;
    flex: 1 1 auto;
    grid-template-columns: 1fr 0.75fr 0.58fr;
    gap: 6px;
  }

  .view-toggle {
    width: 62px;
    min-height: 46px;
    padding: 6px 4px;
  }

  .view-toggle strong {
    margin-top: 4px;
    font-size: 10px;
  }

  .meter {
    padding: 7px 6px;
  }

  .meter strong {
    font-size: 14px;
  }

  .meter.compact strong {
    font-size: 13px;
  }

  .hud-side {
    width: 204px;
    padding: 9px;
  }

  .stats-grid {
    gap: 5px 8px;
  }

  .stats-grid strong {
    font-size: 12px;
  }

  .touch-controls {
    grid-template-columns: repeat(2, 58px);
  }

  .game-shell:has(.overlay-panel:not([hidden])) .hud-side {
    display: none;
  }

  .overlay-panel {
    padding: 18px;
  }

  .overlay-panel h2 {
    margin-bottom: 14px;
  }

  .choice-row,
  #directionChoices,
  .route-facts,
  .leaderboard {
    grid-template-columns: 1fr;
  }

  .choice-button {
    min-height: 34px;
  }
}
