:root {
  color-scheme: dark;
  --ink: #f7f0e3;
  --muted: #b9c6c5;
  --panel: rgba(10, 13, 18, 0.58);
  --line: rgba(255, 236, 178, 0.3);
  --gold: #f3b85b;
  --cyan: #75e0d4;
  --rose: #ff6f8e;
  --void: #05060a;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  background: linear-gradient(180deg, #21120d 0%, #171110 45%, #070606 100%);
  color: var(--ink);
  font-family:
    "Yu Gothic UI", "Hiragino Kaku Gothic ProN", "Meiryo", system-ui,
    sans-serif;
  letter-spacing: 0;
  user-select: none;
}

button,
input {
  font: inherit;
}

.game-shell {
  position: relative;
  width: 100vw;
  height: 100vh;
  min-height: 520px;
  overflow: hidden;
  background: #120d0b;
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.hud,
.lower-hud {
  position: absolute;
  left: clamp(14px, 3vw, 34px);
  right: clamp(14px, 3vw, 34px);
  z-index: 3;
  pointer-events: none;
}

.hud {
  top: clamp(12px, 2.3vw, 24px);
  display: grid;
  grid-template-columns: minmax(88px, 1fr) minmax(160px, 360px) minmax(88px, 1fr);
  gap: 14px;
  align-items: start;
}

.metric {
  display: grid;
  gap: 2px;
  color: white;
  text-shadow: 0 0 18px rgba(243, 184, 91, 0.36);
}

.metric strong {
  font-size: clamp(18px, 3vw, 28px);
  line-height: 1;
}

.metric span,
.track-status {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.align-right {
  justify-items: end;
}

.track-status {
  display: grid;
  gap: 8px;
  justify-items: center;
  text-align: center;
  min-width: 0;
}

.track-status strong {
  width: 100%;
  overflow: hidden;
  color: var(--ink);
  font-size: clamp(13px, 2vw, 17px);
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.progress {
  width: min(100%, 340px);
  height: 4px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
}

.progress i {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--cyan), var(--gold), var(--rose));
  box-shadow: 0 0 16px rgba(117, 224, 212, 0.45);
}

.lower-hud {
  bottom: clamp(14px, 3vw, 28px);
  display: grid;
  grid-template-columns: minmax(98px, 1fr) auto minmax(160px, 1fr);
  gap: 16px;
  align-items: end;
}

.timebox {
  display: grid;
  gap: 5px;
  width: fit-content;
  min-width: 96px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  text-shadow: 0 0 16px rgba(0, 0, 0, 0.65);
}

#passCount {
  color: var(--cyan);
  letter-spacing: 0;
}

.button-row {
  display: flex;
  gap: 8px;
  pointer-events: auto;
}

.button-row button,
.title-card button {
  display: inline-grid;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.18);
  color: var(--ink);
  background: rgba(7, 9, 14, 0.7);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.04),
    0 12px 38px rgba(0, 0, 0, 0.32);
  cursor: pointer;
}

.button-row button {
  width: 42px;
  height: 42px;
  border-radius: 999px;
  font-weight: 900;
}

.button-row button:hover,
.title-card button:hover {
  border-color: rgba(243, 184, 91, 0.6);
  background: rgba(31, 24, 22, 0.82);
}

.mobile-joystick {
  position: absolute;
  left: max(16px, env(safe-area-inset-left));
  bottom: max(132px, calc(env(safe-area-inset-bottom) + 132px));
  z-index: 4;
  display: none;
  width: 132px;
  height: 132px;
  touch-action: none;
  pointer-events: auto;
}

.joystick-base {
  position: relative;
  width: 100%;
  height: 100%;
  border: 1px solid rgba(117, 224, 212, 0.32);
  border-radius: 999px;
  background:
    radial-gradient(circle at center, rgba(117, 224, 212, 0.12) 0 30%, transparent 31%),
    rgba(7, 9, 14, 0.5);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.05),
    inset 0 0 34px rgba(117, 224, 212, 0.13),
    0 14px 34px rgba(0, 0, 0, 0.36);
}

.joystick-base::before,
.joystick-base::after {
  position: absolute;
  content: "";
  background: rgba(255, 255, 255, 0.12);
  pointer-events: none;
}

.joystick-base::before {
  top: 50%;
  left: 18px;
  right: 18px;
  height: 1px;
}

.joystick-base::after {
  top: 18px;
  bottom: 18px;
  left: 50%;
  width: 1px;
}

.joystick-knob {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 58px;
  height: 58px;
  border: 1px solid rgba(243, 184, 91, 0.58);
  border-radius: 999px;
  background:
    radial-gradient(circle at 35% 28%, rgba(255, 255, 255, 0.42), transparent 26%),
    linear-gradient(135deg, rgba(117, 224, 212, 0.82), rgba(243, 184, 91, 0.9));
  box-shadow:
    inset 0 0 18px rgba(5, 6, 10, 0.22),
    0 8px 22px rgba(0, 0, 0, 0.42),
    0 0 20px rgba(117, 224, 212, 0.2);
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.mobile-joystick.is-active .joystick-base {
  border-color: rgba(243, 184, 91, 0.72);
  box-shadow:
    inset 0 0 22px rgba(117, 224, 212, 0.18),
    0 0 26px rgba(243, 184, 91, 0.24);
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  padding: 28px;
  background:
    linear-gradient(180deg, rgba(45, 23, 15, 0.3), rgba(0, 0, 0, 0.48)),
    rgba(0, 0, 0, 0.34);
  backdrop-filter: blur(5px);
}

.overlay.is-hidden {
  opacity: 0;
  pointer-events: none;
  transition: opacity 240ms ease;
}

.title-card {
  display: grid;
  justify-items: center;
  gap: 18px;
  width: min(440px, 92vw);
  padding: 34px 28px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  background: rgba(5, 6, 10, 0.72);
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.52);
  text-align: center;
}

.title-card p {
  margin: 0;
  color: var(--cyan);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0;
}

.title-card h1 {
  margin: 0;
  font-size: clamp(32px, 8vw, 58px);
  line-height: 1.04;
  text-shadow:
    0 0 22px rgba(243, 184, 91, 0.42),
    0 6px 34px rgba(0, 0, 0, 0.7);
}

.title-card button {
  min-width: 148px;
  min-height: 48px;
  padding: 0 28px;
  border-radius: 999px;
  color: #120d08;
  background: linear-gradient(135deg, #fff0b8, #f3b85b 52%, #ff8a68);
  font-weight: 950;
}

.result-line {
  min-height: 20px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

@media (max-width: 720px) {
  .game-shell {
    min-height: 100svh;
  }

  .hud {
    grid-template-columns: 1fr 1fr;
  }

  .track-status {
    grid-column: 1 / -1;
    grid-row: 2;
  }

  .lower-hud {
    grid-template-columns: 1fr auto;
  }

  .mobile-joystick {
    display: block;
  }
}

@media (pointer: fine) {
  .mobile-joystick {
    display: none;
  }
}

@media (pointer: coarse) and (max-width: 900px) {
  .mobile-joystick {
    display: block;
  }
}
