:root {
  color-scheme: dark;
  --ink: #17111b;
  --plum: #281b2c;
  --cream: #fff4d5;
  --muted: #cdbca6;
  --coral: #f36b46;
  --amber: #ffc55c;
  --teal: #2e7974;
  --focus: #9ee8ff;
  font-family: "Avenir Next", "Segoe UI", sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }

html { min-width: 300px; background: var(--ink); }

body {
  min-height: 100vh;
  margin: 0;
  padding: max(0.7rem, env(safe-area-inset-top)) max(0.7rem, env(safe-area-inset-right)) max(0.8rem, env(safe-area-inset-bottom)) max(0.7rem, env(safe-area-inset-left));
  color: var(--cream);
  background:
    radial-gradient(circle at 50% -20%, #4a2b34 0, transparent 45%),
    linear-gradient(180deg, #1c141f, #100c12);
}

button { font: inherit; }
button:focus { outline: 0; }
button:focus-visible,
.game-canvas:focus-visible { outline: 3px solid var(--focus); outline-offset: 4px; }

.arcade { width: min(100%, 1280px); margin: 0 auto; }

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.55rem;
}

.title-lockup p,
.hud span,
.stage-toast,
.fail-caption,
footer,
.charge > span,
.result-card > p,
.pause-card > p {
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.title-lockup p { margin: 0 0 0.15rem; color: var(--amber); font-size: clamp(0.58rem, 1.4vw, 0.72rem); }

h1 {
  margin: 0;
  font-family: "Cooper Black", "Rockwell Extra Bold", Georgia, serif;
  font-size: clamp(2.15rem, 6vw, 4.8rem);
  line-height: 0.78;
  letter-spacing: -0.075em;
  text-wrap: balance;
}

h1 em { color: var(--coral); font-style: normal; }

.utility { display: flex; gap: 0.45rem; }

.utility button {
  min-height: 44px;
  padding: 0.45rem 0.75rem;
  border: 1px solid rgb(255 244 213 / 30%);
  border-radius: 999px;
  color: var(--cream);
  background: rgb(255 244 213 / 7%);
  cursor: pointer;
  font-size: 0.72rem;
  font-weight: 750;
}

.utility button:hover { background: rgb(255 244 213 / 13%); }

.hud {
  display: grid;
  grid-template-columns: auto minmax(8rem, 1fr) auto auto;
  align-items: center;
  gap: clamp(0.65rem, 2.5vw, 1.8rem);
  padding: 0.5rem 0.8rem;
  border: 1px solid rgb(255 244 213 / 18%);
  border-bottom: 0;
  border-radius: 16px 16px 0 0;
  background: rgb(40 27 44 / 88%);
  font-variant-numeric: tabular-nums;
}

.hud > div { display: grid; }
.hud span { color: var(--muted); font-size: 0.58rem; }
.hud strong { font-size: clamp(0.78rem, 2vw, 1.04rem); }
.route { min-width: 0; }

.progress {
  height: 0.38rem;
  margin-top: 0.22rem;
  overflow: hidden;
  border-radius: 999px;
  background: rgb(255 244 213 / 14%);
}

.progress i { display: block; width: 0; height: 100%; border-radius: inherit; background: var(--coral); transition: width 120ms linear; }

.game-shell {
  position: relative;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border: 1px solid rgb(255 244 213 / 20%);
  border-radius: 0 0 22px 22px;
  background: #271b26;
  box-shadow: 0 24px 70px rgb(0 0 0 / 48%);
  isolation: isolate;
}

.game-canvas,
.game-canvas canvas { display: block; width: 100%; height: 100%; touch-action: none; }

.loading-card,
.start-card,
.result-card,
.pause-card {
  position: absolute;
  z-index: 8;
  top: 50%;
  left: 50%;
  width: min(25rem, calc(100% - 2rem));
  padding: clamp(1rem, 3vw, 1.55rem);
  border: 1px solid rgb(255 244 213 / 40%);
  border-radius: 18px;
  color: var(--cream);
  background: rgb(28 18 29 / 91%);
  box-shadow: 0 18px 65px rgb(0 0 0 / 42%);
  backdrop-filter: blur(12px);
  transform: translate(-50%, -50%);
  text-align: center;
}

[hidden] { display: none !important; }

.loading-card { display: flex; align-items: center; justify-content: center; gap: 0.75rem; font-size: 0.78rem; }
.loader { width: 1rem; aspect-ratio: 1; border: 2px solid rgb(255 244 213 / 25%); border-top-color: var(--amber); border-radius: 50%; animation: spin 700ms linear infinite; }
@keyframes spin { to { transform: rotate(1turn); } }

.start-card p { margin: 0 0 1rem; font-family: Georgia, serif; font-size: clamp(1.05rem, 3vw, 1.55rem); font-style: italic; }
.start-card small { display: block; margin-top: 0.8rem; color: var(--muted); font-size: 0.68rem; }

.primary {
  min-height: 48px;
  padding: 0.65rem 1.15rem;
  border: 0;
  border-radius: 10px;
  color: #291721;
  background: var(--amber);
  box-shadow: 0 5px 0 #9d552f;
  cursor: pointer;
  font-weight: 850;
  text-transform: uppercase;
}

.primary:hover { filter: brightness(1.08); transform: translateY(-1px); }
.primary:active { transform: translateY(4px); box-shadow: 0 1px 0 #9d552f; }

.result-card h2,
.pause-card h2 { margin: 0.1rem 0 0.7rem; font-family: Georgia, serif; font-size: clamp(2rem, 6vw, 4rem); line-height: 1; }
.result-card > p,
.pause-card > p { margin: 0; color: var(--amber); font-size: 0.64rem; }
.result-grid { display: flex; justify-content: center; gap: 1rem; margin: 0 0 1rem; }
.result-grid span { color: var(--muted); font-size: 0.68rem; }
.result-grid b { display: block; color: var(--cream); font-size: 1rem; }

.stage-toast,
.fail-caption {
  position: absolute;
  z-index: 7;
  left: 50%;
  max-width: calc(100% - 2rem);
  opacity: 0;
  pointer-events: none;
  text-align: center;
  transform: translateX(-50%) translateY(-8px);
}

.stage-toast {
  top: 1rem;
  padding: 0.5rem 0.75rem;
  border-radius: 999px;
  color: #251722;
  background: var(--amber);
  font-size: clamp(0.62rem, 1.8vw, 0.8rem);
}

.stage-toast.show { animation: toast 1.45s cubic-bezier(.16, 1, .3, 1) both; }
@keyframes toast { 0% { opacity: 0; transform: translateX(-50%) translateY(-10px); } 12%, 72% { opacity: 1; transform: translateX(-50%) translateY(0); } 100% { opacity: 0; transform: translateX(-50%) translateY(-4px); } }

.fail-caption {
  top: 15%;
  padding: 0.4rem 0.7rem;
  border-radius: 7px;
  color: var(--cream);
  background: #d33e31;
  box-shadow: 0 5px 0 rgb(74 18 26 / 65%);
  font-size: clamp(0.72rem, 2.5vw, 1.2rem);
}

.fail-caption.show { opacity: 1; transform: translateX(-50%); }

.charge {
  position: absolute;
  z-index: 6;
  bottom: clamp(0.7rem, 2vw, 1rem);
  left: clamp(0.7rem, 2vw, 1rem);
  width: clamp(6rem, 16vw, 10rem);
  padding: 0.4rem;
  border-radius: 8px;
  background: rgb(23 17 27 / 76%);
  backdrop-filter: blur(7px);
  pointer-events: none;
}

.charge > span { display: block; margin-bottom: 0.2rem; font-size: 0.55rem; }
.charge > div { height: 0.55rem; overflow: hidden; border-radius: 999px; background: rgb(255 244 213 / 18%); }
.charge i { display: block; width: 0; height: 100%; border-radius: inherit; background: var(--coral); }

.action {
  position: absolute;
  z-index: 6;
  right: clamp(0.7rem, 2vw, 1rem);
  bottom: clamp(0.7rem, 2vw, 1rem);
  display: grid;
  min-width: clamp(8.8rem, 22vw, 13rem);
  min-height: 58px;
  padding: 0.45rem 0.85rem;
  border: 0;
  border-radius: 12px;
  color: #251722;
  background: var(--amber);
  box-shadow: 0 5px 0 #9d552f;
  cursor: pointer;
  touch-action: none;
  user-select: none;
}

.action b { font-size: clamp(0.9rem, 2.4vw, 1.2rem); line-height: 1; }
.action span { font-size: 0.6rem; font-weight: 750; letter-spacing: 0.06em; text-transform: uppercase; }
.action.charging { color: var(--cream); background: var(--coral); box-shadow: 0 2px 0 #8f3328; transform: translateY(3px); }
.action:disabled { opacity: 0; pointer-events: none; }

footer { display: flex; justify-content: space-between; gap: 1rem; padding: 0.65rem 0.25rem 0; color: var(--muted); font-size: 0.56rem; }

.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

@media (max-width: 620px) {
  body { padding-inline: 0.35rem; }
  .topbar { align-items: center; }
  .title-lockup p { display: none; }
  h1 { font-size: clamp(2rem, 10vw, 3.25rem); }
  .utility button { min-height: 40px; padding-inline: 0.58rem; font-size: 0.63rem; }
  .hud { grid-template-columns: auto 1fr auto; gap: 0.45rem; padding: 0.38rem 0.5rem; }
  .hud .best { display: none; }
  .hud span { font-size: 0.49rem; }
  .hud strong { font-size: 0.72rem; }
  .game-shell { border-radius: 0 0 14px 14px; }
  .action { min-width: 8rem; min-height: 49px; padding-block: 0.3rem; }
  .charge { bottom: 0.55rem; left: 0.55rem; }
  footer span:last-child { display: none; }
}

@media (pointer: coarse) {
  .action { min-height: 62px; }
  .utility button { min-height: 44px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}
