* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #151821;
  color: #f7f1df;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  touch-action: none;
  user-select: none;
}

button {
  border: 0;
  border-radius: 8px;
  background: #f5c84b;
  color: #211b12;
  cursor: pointer;
  font: inherit;
  font-weight: 800;
  min-height: 44px;
  padding: 0 22px;
  transition:
    transform 140ms ease,
    background 140ms ease;
}

button:hover {
  background: #ffd968;
  transform: translateY(-1px);
}

button:disabled {
  background: #767a84;
  color: #d4d6da;
  cursor: default;
  transform: none;
}

#game-shell,
#game {
  width: 100vw;
  height: 100vh;
}

#game {
  display: block;
}

#hud {
  inset: 0;
  pointer-events: none;
  position: fixed;
}

.hud-row {
  align-items: center;
  display: flex;
  gap: 12px;
  justify-content: space-between;
  left: 18px;
  position: absolute;
  right: 18px;
}

.hud-row.top {
  top: 16px;
}

.hud-row.bottom {
  bottom: 18px;
}

.hud-row > div,
#chapter-rule {
  background: rgba(18, 22, 31, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.13);
  border-radius: 8px;
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.24);
  min-width: 110px;
  padding: 10px 12px;
}

.eyebrow {
  color: #aeb7c5;
  display: block;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0;
  line-height: 1.2;
}

strong {
  display: block;
  font-size: 21px;
  line-height: 1.15;
  margin-top: 2px;
  white-space: nowrap;
}

#face-card {
  align-items: center;
  display: flex;
  height: 72px;
  justify-content: center;
  padding: 6px;
  position: relative;
  width: 72px;
}

#driver-face {
  border-radius: 8px;
  display: none;
  height: 60px;
  object-fit: cover;
  width: 60px;
}

#face-fallback {
  align-items: center;
  background: #344052;
  border-radius: 8px;
  display: flex;
  font-size: 14px;
  font-weight: 900;
  height: 60px;
  justify-content: center;
  line-height: 1.15;
  text-align: center;
  width: 60px;
}

#chapter-rule {
  flex: 1;
  font-size: 16px;
  font-weight: 800;
  min-height: 54px;
}

#speed-box {
  text-align: right;
}

#touch-controls {
  bottom: 108px;
  display: none;
  justify-content: space-between;
  left: 14px;
  pointer-events: none;
  position: fixed;
  right: 14px;
  z-index: 3;
}

.touch-cluster {
  display: flex;
  gap: 10px;
}

.touch-button {
  align-items: center;
  background: rgba(24, 29, 40, 0.78);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  color: #f7f1df;
  display: flex;
  font-size: 28px;
  height: 62px;
  justify-content: center;
  min-height: 0;
  padding: 0;
  pointer-events: auto;
  touch-action: none;
  width: 62px;
}

.touch-button:hover,
.touch-button.active {
  background: rgba(245, 200, 75, 0.92);
  color: #211b12;
  transform: none;
}

.touch-button.accent {
  background: rgba(45, 167, 163, 0.82);
}

.overlay {
  align-items: center;
  background: rgba(12, 15, 22, 0.56);
  display: flex;
  inset: 0;
  justify-content: center;
  padding: 18px;
  position: fixed;
}

.overlay.hidden {
  display: none;
}

.panel {
  background: rgba(24, 29, 40, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  max-width: 540px;
  padding: 24px;
  width: min(100%, 540px);
}

.panel.compact {
  max-width: 390px;
}

#result-score-card {
  background: #f5c84b;
  border-radius: 8px;
  color: #211b12;
  margin: 16px 0 10px;
  padding: 14px 16px;
}

#result-score-label {
  display: block;
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0;
}

#result-score {
  color: #211b12;
  font-size: 46px;
  line-height: 1;
  margin-top: 4px;
}

#result-stats {
  display: grid;
  gap: 10px;
  grid-template-columns: 1fr 1fr;
  margin-bottom: 12px;
}

#result-stats > div {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  padding: 10px 12px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 34px;
  line-height: 1.05;
}

h2 {
  font-size: 28px;
  line-height: 1.1;
}

p {
  color: #d6dce7;
  line-height: 1.55;
  margin: 12px 0 18px;
}

.chapter-tabs {
  display: grid;
  gap: 8px;
  margin: 22px 0;
}

.chapter-tab {
  align-items: center;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  color: #f7f1df;
  display: grid;
  grid-template-columns: 1fr auto;
  min-height: 58px;
  padding: 10px 12px;
  text-align: left;
}

.chapter-tab.active {
  border-color: #f5c84b;
  box-shadow: inset 0 0 0 1px rgba(245, 200, 75, 0.42);
}

.chapter-tab.locked {
  color: #a5acb8;
}

.chapter-tab small {
  color: #aeb7c5;
  display: block;
  font-size: 12px;
  font-weight: 700;
  margin-top: 4px;
}

@media (max-width: 680px) {
  .hud-row {
    left: 10px;
    right: 10px;
  }

  .hud-row.top {
    align-items: stretch;
    display: grid;
    grid-template-columns: 1.2fr 1fr 1fr;
  }

  .hud-row.bottom {
    display: grid;
    grid-template-columns: 72px 1fr 82px;
  }

  .hud-row > div,
  #chapter-rule {
    min-width: 0;
  }

  strong {
    font-size: 17px;
  }

  #chapter-rule {
    font-size: 13px;
  }

  h1 {
    font-size: 24px;
  }

  body.game-active #touch-controls {
    display: flex;
  }
}

@media (pointer: coarse) {
  body.game-active #touch-controls {
    display: flex;
  }
}
