@font-face {
  font-family: "CrashGame";
  src: url("./assets/fonts/クラッシュ風フォント.ttf") format("truetype");
  font-display: swap;
}

:root {
  --panel: rgba(255, 255, 255, 0.75);
  --ink: #e8eefc;
  --muted: #c5d0ec;
  --line: rgba(255, 255, 255, 0.45);
  --stage-u: min(1vw, 1dvh);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  font-family: "CrashGame", sans-serif;
  background:
    radial-gradient(circle at 18% 10%, rgba(57, 98, 180, 0.5), transparent 35%),
    radial-gradient(circle at 78% 20%, rgba(73, 128, 212, 0.4), transparent 34%),
    linear-gradient(160deg, #090f1a 0%, #111a2f 55%, #0b1222 100%);
  overflow: hidden;
}

button,
input,
select,
textarea {
  font-family: inherit;
}

.screen {
  display: grid;
  place-items: center;
  width: 100vw;
  height: 100dvh;
}

.stage {
  position: relative;
  width: min(100vw, 100dvh);
  aspect-ratio: 1 / 1;
  overflow: hidden;
  background: #070d16;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  padding: calc(env(safe-area-inset-top, 0px) + 8px) 10px 10px;
  background: transparent;
  pointer-events: none;
  z-index: 2;
}

.corner-hud {
  position: absolute;
  top: calc(env(safe-area-inset-top, 0px) + 8px);
  z-index: 3;
  padding: 0;
  border-radius: 0;
  font-size: calc(var(--stage-u) * 8.4);
  font-weight: 700;
  color: #ffb347;
  background: transparent;
  border: 0;
  text-shadow: none;
  -webkit-text-stroke: 1px #000;
}

.corner-hud,
.corner-hud strong {
  color: #ffb347;
}

@supports ((-webkit-background-clip: text) or (background-clip: text)) {
  .corner-hud,
  .corner-hud strong {
    background-image: linear-gradient(180deg, #ffe24a 0%, #c2185b 100%);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    -webkit-text-fill-color: transparent;
    -webkit-text-stroke: 1px #000;
  }
}

.corner-left {
  left: 10px;
}

.corner-right {
  right: 10px;
}

.apple-hud {
  position: absolute;
  right: calc(env(safe-area-inset-right, 0px) + 24px);
  bottom: calc(env(safe-area-inset-bottom, 0px) + 24px);
  z-index: 3;
  display: flex;
  align-items: center;
  gap: calc(var(--stage-u) * 1.3);
}

.apple-dot,
.apple-total {
  width: calc(var(--stage-u) * 6);
  height: calc(var(--stage-u) * 6);
  border-radius: 999px;
  border: calc(var(--stage-u) * 0.3) solid rgba(255, 255, 255, 0.8);
  background: rgba(255, 255, 255, 0.2);
  box-shadow: 0 0 0 rgba(255, 255, 255, 0);
}

.apple-dot.is-on {
  background: radial-gradient(circle at 35% 30%, #ffd6df, #ff5a79 55%, #c2183e 100%);
  border-color: #ff9db0;
  box-shadow: 0 0 12px rgba(255, 74, 116, 0.65);
}

.apple-hud.is-upgrade .apple-dot {
  animation: appleSpark 0.45s ease-out;
}

.apple-total {
  width: calc(var(--stage-u) * 10);
  display: grid;
  place-items: center;
  color: #fff5cf;
  font-size: calc(var(--stage-u) * 2);
  font-weight: 700;
  background: rgba(28, 20, 48, 0.56);
}

@keyframes appleSpark {
  0% {
    transform: scale(1);
    box-shadow: 0 0 0 rgba(255, 255, 255, 0);
    filter: brightness(1);
  }
  45% {
    transform: scale(1.25);
    box-shadow: 0 0 18px rgba(255, 255, 255, 0.95);
    filter: brightness(1.5);
  }
  100% {
    transform: scale(1);
    box-shadow: 0 0 0 rgba(255, 255, 255, 0);
    filter: brightness(1);
  }
}

.row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.top-row {
  justify-content: center;
}

h1 {
  margin: 0;
  font-size: calc(var(--stage-u) * 1.8);
}

.link-btn {
  pointer-events: auto;
  text-decoration: none;
  border: 1px solid rgba(255, 255, 255, 0.5);
  background: rgba(255, 255, 255, 0.12);
  color: #eff4ff;
  border-radius: 8px;
  padding: 6px 10px;
  font-size: calc(var(--stage-u) * 0.95);
}

.stat-pill {
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 999px;
  padding: 5px 10px;
  font-size: calc(var(--stage-u) * 1.1);
}

.top-row h1 {
  margin-right: 4px;
}

#mode-pill {
  position: static;
  top: auto;
  left: auto;
  transform: none;
  z-index: auto;
  font-size: calc(var(--stage-u) * 2);
  padding: 8px 16px;
}

.center-panel {
  position: absolute;
  left: 50%;
  top: 54%;
  transform: translate(-50%, -50%);
  width: min(90vw, 560px);
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(8, 12, 28, 0.78);
  backdrop-filter: blur(5px);
  text-align: center;
  z-index: 3;
}

.center-panel h2 {
  margin: 0;
  font-size: calc(var(--stage-u) * 3);
}

#title-screen h2 {
  font-size: calc(var(--stage-u) * 12);
}

#title-screen p {
  font-size: calc(var(--stage-u) * 4.2);
}

#title-screen {
  width: min(96vw, 980px);
  border: 1px solid rgba(255, 255, 255, 0.8);
  background:
    radial-gradient(circle at 18% 16%, rgba(255, 255, 255, 0.65), transparent 36%),
    radial-gradient(circle at 82% 18%, rgba(255, 236, 247, 0.62), transparent 34%),
    linear-gradient(145deg, rgba(255, 209, 236, 0.86), rgba(189, 236, 255, 0.84) 52%, rgba(225, 206, 255, 0.84));
  box-shadow:
    0 16px 34px rgba(150, 120, 195, 0.26),
    inset 0 0 0 1px rgba(255, 255, 255, 0.45);
}

#stage-label {
  white-space: nowrap;
}

.center-panel p {
  margin: 10px 0;
  color: var(--muted);
}

.start-btn {
  cursor: pointer;
  border: 1px solid rgba(255, 255, 255, 0.6);
  border-radius: 10px;
  padding: 10px 20px;
  font-size: calc(var(--stage-u) * 2.4);
  font-weight: 700;
  color: #081124;
  background: linear-gradient(180deg, #f8fbff 0%, #cddfff 100%);
}

.stage-select-line {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: #f3f7ff;
  font-weight: 700;
  font-size: calc(var(--stage-u) * 4.8);
}

.stage-arrow {
  cursor: pointer;
  width: 108px;
  height: 108px;
  border: 1px solid rgba(255, 255, 255, 0.55);
  border-radius: 999px;
  color: #eaf2ff;
  background: rgba(255, 255, 255, 0.08);
}

.countdown-panel {
  width: min(70vw, 260px);
  top: 50%;
  background: rgba(4, 8, 20, 0.68);
}

.loading-panel {
  background: rgba(6, 11, 25, 0.9);
}

.progress-slider {
  width: min(72vw, 360px);
  accent-color: #86b8ff;
}

.countdown-panel h2 {
  font-size: calc(var(--stage-u) * 10);
}

.small {
  font-size: calc(var(--stage-u) * 1.05);
}

.result-total {
  font-size: calc(var(--stage-u) * 5.6);
  color: #eff5ff;
}

#result-screen h2 {
  font-size: calc(var(--stage-u) * 6);
}

#result-screen .small {
  font-size: calc(var(--stage-u) * 4.2);
}

#result-screen {
  left: auto;
  right: 4%;
  transform: translate(0, -50%);
}

.lap-times {
  margin: 12px auto;
  width: min(72vw, 360px);
  text-align: left;
  color: #d7e6ff;
  font-size: calc(var(--stage-u) * 4);
}

.lap-times li {
  padding: 2px 0;
}

.hidden {
  display: none;
}
