:root {
  --bone: #ece4d1;
  --bone-dim: #c9c0ab;
  --ink: #16191a;
  --orange: #e2542b;
  --amber: #e8a34d;
  --display: 'Saira Condensed', 'Arial Narrow', sans-serif;
  --body: 'Barlow', 'Helvetica Neue', sans-serif;
  --mono: 'Space Mono', 'Courier New', monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #0c0e0d;
  color: var(--bone);
  font-family: var(--body);
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
}

#app { position: fixed; inset: 0; }

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

#lens { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 2; }

#hud {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  padding: max(10px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
}

#hud button, #hud .help, #hud .finish { pointer-events: auto; }
body:not(.ready) #hud > *:not(#loading) { opacity: 0; pointer-events: none; }

.title-wrap {
  position: absolute;
  left: max(12px, env(safe-area-inset-left));
  top: max(10px, env(safe-area-inset-top));
  width: auto;
  max-width: 52vw;
  filter: drop-shadow(0 5px 12px rgba(0, 0, 0, 0.45));
}
.game-title {
  margin: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  font-family: var(--display);
  font-weight: 900;
  text-transform: uppercase;
  font-size: clamp(34px, 5.1vw, 76px);
  line-height: 0.78;
  letter-spacing: 0.005em;
  color: var(--bone);
  -webkit-text-stroke: clamp(1px, 0.18vw, 2.5px) #b8481f;
  paint-order: stroke fill;
  text-shadow: 0 2px 0 #2a1a10, 0 5px 16px rgba(0, 0, 0, 0.62);
  transform: skewX(-4deg) rotate(-1.2deg);
}
.game-title span { display: block; }
.game-title span:nth-child(2) { color: #efe2c4; }

.hud-top-right {
  position: absolute;
  right: max(12px, env(safe-area-inset-right));
  top: max(10px, env(safe-area-inset-top));
}

.watch { display: flex; flex-direction: column; align-items: center; }
.watch img {
  width: clamp(62px, 8.2vw, 112px);
  height: auto;
  filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.5));
}
.watch-read {
  margin-top: -4px;
  background: rgba(14, 16, 15, 0.72);
  border-left: 2px solid var(--orange);
  padding: 2px 7px 3px;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 78px;
}
#time {
  font-family: var(--mono);
  font-weight: 700;
  font-size: clamp(13px, 1.45vw, 19px);
  letter-spacing: -0.04em;
  color: var(--bone);
  line-height: 1.1;
}
#split {
  font-family: var(--display);
  font-weight: 600;
  font-size: clamp(8px, 0.7vw, 10px);
  letter-spacing: 0.12em;
  color: var(--amber);
  min-height: 11px;
}

.hud-bottom-left {
  position: absolute;
  left: max(12px, env(safe-area-inset-left));
  bottom: max(12px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 7px;
}

.stage-card, .pace, .speed-plate, .restart {
  position: relative;
  filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.45));
}
.stage-card img, .pace img, .speed-plate img { display: block; width: 100%; height: auto; }

.stage-card { width: clamp(126px, 14.5vw, 196px); }
#stage-name {
  position: absolute;
  left: 7%;
  bottom: 18.5%;
  width: 38%;
  font-family: var(--display);
  font-weight: 700;
  font-size: clamp(7px, 0.72vw, 10px);
  letter-spacing: 0.06em;
  color: #22251f;
  white-space: nowrap;
  overflow: hidden;
}
#stage-meta {
  position: absolute;
  right: 8%;
  bottom: 22%;
  width: 26%;
  text-align: right;
  font-family: var(--mono);
  font-weight: 700;
  font-size: clamp(7px, 0.6vw, 9px);
  color: #2c2d26;
}

.pace { width: clamp(112px, 12.6vw, 158px); }
#pace-note {
  position: absolute;
  left: 27%;
  bottom: 8%;
  width: 68%;
  font-family: var(--display);
  font-weight: 700;
  font-size: clamp(7px, 0.72vw, 10px);
  letter-spacing: 0.05em;
  color: #23251f;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: clip;
}

.hud-bottom-right {
  position: absolute;
  right: max(12px, env(safe-area-inset-right));
  bottom: max(12px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}

.speed-plate { width: clamp(136px, 15.4vw, 204px); }
#speed {
  position: absolute;
  left: 21%;
  right: 21%;
  bottom: 15%;
  text-align: center;
  font-family: var(--mono);
  font-weight: 700;
  font-size: clamp(23px, 2.9vw, 40px);
  letter-spacing: -0.06em;
  color: #1a1c18;
  line-height: 1;
}
#gear {
  position: absolute;
  right: 8.5%;
  top: 12%;
  min-width: 16px;
  text-align: center;
  font-family: var(--mono);
  font-weight: 700;
  font-size: clamp(9px, 0.75vw, 11px);
  color: #23251f;
}
#unit {
  position: absolute;
  left: 24%;
  bottom: 6%;
  font-family: var(--display);
  font-weight: 600;
  font-size: clamp(6px, 0.5vw, 8px);
  letter-spacing: 0.12em;
  color: #34352c;
}

.restart {
  border: 0;
  padding: 0;
  background: none;
  color: var(--bone);
  display: flex;
  flex-direction: column;
  align-items: center;
  cursor: pointer;
  width: clamp(52px, 5.2vw, 72px);
  opacity: 0.86;
  transition: opacity 120ms ease, transform 120ms ease;
}
.restart img { width: 100%; height: auto; display: block; }
.restart span {
  font-family: var(--display);
  font-weight: 600;
  font-size: clamp(7px, 0.58vw, 9px);
  letter-spacing: 0.16em;
  color: var(--bone-dim);
  margin-top: 1px;
  text-shadow: 0 1px 3px #000;
}
.restart:hover, .restart:focus-visible { opacity: 1; transform: translateY(-1px); }

.hint {
  position: absolute;
  left: 50%;
  bottom: max(12px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 9px;
  background: rgba(12, 14, 13, 0.6);
  border: 1px solid rgba(236, 228, 209, 0.16);
  padding: 5px 10px;
  transition: opacity 500ms ease;
}
.hint.dim { opacity: 0.3; }
#hint-text {
  font-family: var(--display);
  font-weight: 600;
  font-size: clamp(8px, 0.72vw, 10px);
  letter-spacing: 0.14em;
  color: var(--bone-dim);
  white-space: nowrap;
}
#help-btn {
  border: 0;
  background: none;
  color: var(--orange);
  font-family: var(--display);
  font-weight: 700;
  font-size: clamp(8px, 0.72vw, 10px);
  letter-spacing: 0.14em;
  padding: 0;
  cursor: pointer;
}

.touch-controls {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 31%;
  display: none;
  justify-content: space-between;
  align-items: flex-end;
  padding: 0 18px 46px;
  pointer-events: none;
}
.touch-zone {
  width: 34%;
  border-bottom: 1px solid rgba(236, 228, 209, 0.22);
  padding-bottom: 5px;
  display: flex;
  justify-content: center;
  gap: 8px;
  font-family: var(--display);
  font-weight: 600;
  font-size: 9px;
  letter-spacing: 0.18em;
  color: rgba(236, 228, 209, 0.4);
  opacity: 0;
  transition: opacity 300ms ease;
}
.touch-zone em { font-style: normal; color: rgba(226, 84, 43, 0.5); }
body.touch .touch-controls { display: flex; }
body.driving .touch-zone { opacity: 1; }
body.touch #hint-text { display: none; }

.help, .finish, .loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(8, 10, 9, 0.62);
  z-index: 6;
  padding: 18px;
}
.help[hidden], .finish[hidden], .loading[hidden], .signin[hidden] { display: none; }

.help-card, .finish-card, .loading-card {
  width: min(440px, 92vw);
  background: #e8dfca;
  color: #1a1d1a;
  padding: 20px 22px 18px;
  border-top: 5px solid var(--orange);
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.55);
  position: relative;
}
.help-card::after, .finish-card::after {
  content: '';
  position: absolute;
  inset: 6px;
  border: 1px solid rgba(26, 29, 26, 0.18);
  pointer-events: none;
}
.help-card h2, .finish-card h2, .loading-card h1 {
  font-family: var(--display);
  font-weight: 800;
  letter-spacing: 0.02em;
  margin: 0 0 12px;
  line-height: 0.95;
}
.help-card h2 { font-size: 30px; }
.help-card ul { margin: 0 0 10px; padding: 0; list-style: none; }
.help-card li {
  font-family: var(--body);
  font-size: 13px;
  line-height: 1.55;
  border-bottom: 1px solid rgba(26, 29, 26, 0.12);
  padding: 5px 0;
}
.help-card b {
  font-family: var(--display);
  font-weight: 700;
  letter-spacing: 0.06em;
  color: #8c3218;
  display: inline-block;
  min-width: 104px;
}
.help-card p { font-family: var(--body); font-size: 12px; line-height: 1.5; color: #3d4036; margin: 6px 0 14px; }
.help-card button, .finish-card button {
  border: 0;
  background: #1a1d1a;
  color: var(--bone);
  font-family: var(--display);
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 0.16em;
  padding: 10px 16px;
  cursor: pointer;
}
.help-card button:hover, .finish-card button:hover { background: var(--orange); }

.loading { background: #0b0d0c; z-index: 9; }
.loading-card { text-align: center; border-top-color: var(--orange); width: min(360px, 86vw); }
.loading-card p {
  font-family: var(--display);
  font-weight: 600;
  font-size: 11px;
  letter-spacing: 0.32em;
  color: #7d3a20;
  margin: 0 0 4px;
}
.loading-card h1 { font-size: 46px; margin: 0 0 18px; color: #1a1d1a; }
.loading-card .bar { height: 5px; background: rgba(26, 29, 26, 0.16); overflow: hidden; }
.loading-card .bar i { display: block; height: 100%; width: 4%; background: var(--orange); transition: width 240ms ease; }
#load-text {
  display: block;
  margin-top: 9px;
  font-family: var(--display);
  font-weight: 600;
  font-size: 9px;
  letter-spacing: 0.2em;
  color: #56594b;
}

.finish-card h2 {
  font-family: var(--mono);
  font-weight: 700;
  font-size: clamp(38px, 8vw, 62px);
  letter-spacing: -0.06em;
  margin: 0 0 2px;
}
.finish-card .kicker {
  font-family: var(--display);
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 0.2em;
  color: #8c3218;
  margin: 0 0 4px;
}
.finish-line {
  font-family: var(--display);
  font-weight: 600;
  font-size: 13px;
  letter-spacing: 0.1em;
  color: #44473b;
  margin: 0 0 10px;
}
.splits {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  border-top: 1px solid rgba(26, 29, 26, 0.2);
  border-bottom: 1px solid rgba(26, 29, 26, 0.2);
  padding: 7px 0;
  margin-bottom: 10px;
}
.splits span { font-family: var(--mono); font-size: 11px; color: #33362c; }
.splits span b { display: block; font-family: var(--display); font-size: 9px; letter-spacing: 0.12em; color: #7c4b2a; font-weight: 600; }
.board { margin: 0 0 12px; }
.board h3 { font-family: var(--display); font-size: 11px; letter-spacing: 0.16em; margin: 0 0 4px; color: #7c4b2a; }
.board-row { display: flex; justify-content: space-between; font-family: var(--mono); font-size: 10px; color: #2c2f26; padding: 2px 0; }
.board-row a { color: #2c2f26; text-decoration: none; border-bottom: 1px solid #b59a72; }
.board-empty { font-family: var(--body); font-size: 11px; color: #6b6e5f; }

.signin {
  position: absolute;
  left: 50%;
  bottom: 84px;
  transform: translateX(-50%);
  background: rgba(14, 16, 15, 0.82);
  border-left: 3px solid var(--orange);
  padding: 7px 12px;
  font-family: var(--display);
  font-weight: 600;
  font-size: 10px;
  letter-spacing: 0.08em;
  color: var(--bone-dim);
  z-index: 5;
}
.signin p { margin: 0; }

@media (max-width: 720px), (orientation: portrait) {
  .title-wrap { width: clamp(132px, 44vw, 250px); }
  .stage-card { width: clamp(108px, 27vw, 150px); }
  .pace { width: clamp(96px, 24vw, 132px); }
  .speed-plate { width: clamp(118px, 31vw, 168px); }
  .restart { width: clamp(44px, 9vw, 58px); }
  .watch img { width: clamp(52px, 15vw, 82px); }
  .watch-read { min-width: 66px; }
  #hint-text { display: none; }
  .hint { padding: 4px 8px; }
  .help-card b { min-width: 88px; }
}

.tilt-btn {
  background: #7a421f !important;
  margin-right: 8px;
  margin-bottom: 8px;
}

@media (max-height: 470px) {
  .watch img { width: 52px; }
  .stage-card { width: 108px; }
  .pace { width: 96px; }
  .speed-plate { width: 118px; }
  #time { font-size: 12px; }
  #hint { padding: 3px 8px; }
  .title-wrap { width: 160px; }
}

#best-line {
  font-family: var(--mono);
  font-weight: 400;
  font-size: clamp(7px, 0.6vw, 9px);
  color: #b9c0b2;
  letter-spacing: -0.02em;
  line-height: 1.2;
}
#best-line:empty { display: none; }

#app::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 2;
  background:
    radial-gradient(ellipse at 50% 44%, rgba(0, 0, 0, 0) 46%, rgba(7, 9, 8, 0.36) 100%),
    linear-gradient(to bottom, rgba(9, 11, 10, 0.12), rgba(0, 0, 0, 0) 22%, rgba(0, 0, 0, 0) 78%, rgba(8, 10, 9, 0.2));
}


#app::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 1;
  background: rgba(72, 102, 118, 0.16);
  mix-blend-mode: soft-light;
}
