:root {
  color-scheme: dark;
  --bg: #09090a;
  --panel: #101013;
  --line: rgba(245, 241, 232, 0.16);
  --text: #f4f1e8;
  --muted: rgba(244, 241, 232, 0.58);
  --red: #c83232;
  --red-dark: #861d22;
  --white: #fffaf0;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 50% 18%, rgba(255, 250, 240, 0.05), transparent 34rem),
    var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: max(16px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
  touch-action: manipulation;
  user-select: none;
}

button {
  font: inherit;
}

.shell {
  width: min(94vw, 860px);
  display: grid;
  gap: 16px;
}

.topbar,
.hud-row {
  width: min(100%, 760px);
  justify-self: center;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.stat {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 92px;
  color: var(--muted);
  font-size: clamp(0.72rem, 2vw, 0.78rem);
  font-weight: 700;
}

.stat strong {
  color: var(--text);
  font-size: clamp(0.96rem, 2.6vw, 1.08rem);
}

.icon-button,
.focus-button,
.overlay button {
  border: 1px solid rgba(244, 241, 232, 0.2);
  background: rgba(244, 241, 232, 0.07);
  color: var(--text);
  border-radius: 8px;
  cursor: pointer;
  transition: transform 130ms ease, background 130ms ease, border-color 130ms ease;
}

.icon-button {
  min-height: 38px;
  padding: 0 13px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
}

.icon-button[aria-pressed="false"] {
  color: rgba(244, 241, 232, 0.35);
}

.stage-wrap {
  position: relative;
  width: min(100%, 760px);
  aspect-ratio: 1.52 / 1;
  min-height: 310px;
  max-height: min(68vh, 520px);
  justify-self: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #0d0d10;
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.38);
}

canvas {
  width: 100%;
  height: 100%;
  display: block;
  cursor: crosshair;
  touch-action: none;
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 14px;
  padding: 24px;
  text-align: center;
  background: linear-gradient(180deg, rgba(9, 9, 10, 0.1), rgba(9, 9, 10, 0.42));
  opacity: 1;
  pointer-events: auto;
  transition: opacity 160ms ease;
}

.overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.overlay.compact {
  background: rgba(9, 9, 10, 0.38);
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(1.72rem, 5.5vw, 3.35rem);
  font-weight: 900;
  line-height: 0.95;
}

h2 {
  font-size: clamp(1.35rem, 4vw, 2.2rem);
  font-weight: 900;
}

.overlay p {
  color: var(--muted);
  font-size: clamp(0.95rem, 2.8vw, 1.08rem);
}

.overlay small {
  color: rgba(244, 241, 232, 0.48);
  font-size: 0.78rem;
  font-weight: 700;
}

.overlay button {
  min-width: 116px;
  min-height: 44px;
  padding: 0 20px;
  background: var(--text);
  color: #0d0d10;
  border-color: transparent;
  font-weight: 900;
}

.icon-button:hover,
.focus-button:hover,
.overlay button:hover {
  transform: translateY(-1px);
}

.icon-button:focus-visible,
.focus-button:focus-visible,
.overlay button:focus-visible {
  outline: 2px solid rgba(255, 250, 240, 0.9);
  outline-offset: 3px;
}

.hud-row {
  min-height: 44px;
}

.score {
  min-width: 94px;
  font-size: clamp(2rem, 8vw, 4rem);
  font-weight: 900;
  line-height: 0.9;
  font-variant-numeric: tabular-nums;
}

.focus-button {
  min-width: 122px;
  min-height: 46px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  padding: 0 14px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 900;
}

.focus-button.available {
  color: var(--text);
  border-color: rgba(244, 241, 232, 0.38);
}

.focus-button b {
  color: var(--white);
  font-size: 1rem;
  letter-spacing: 2px;
}

.result-time {
  font-size: clamp(3.2rem, 15vw, 7.5rem);
  font-weight: 950;
  line-height: 0.82;
  font-variant-numeric: tabular-nums;
}

.result-message {
  min-height: 1.3em;
  color: var(--text);
  font-weight: 900;
}

#resultStats {
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 800;
}

.toast {
  position: fixed;
  left: 50%;
  top: 18%;
  transform: translate(-50%, 8px);
  opacity: 0;
  color: var(--text);
  font-size: clamp(1rem, 3vw, 1.6rem);
  font-weight: 950;
  pointer-events: none;
  text-align: center;
  text-shadow: 0 6px 28px rgba(0, 0, 0, 0.7);
  transition: opacity 180ms ease, transform 180ms ease;
}

.toast.visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (max-width: 640px) {
  body {
    align-items: start;
    padding-top: max(12px, env(safe-area-inset-top));
  }

  .shell {
    width: 100%;
    gap: 12px;
  }

  .stage-wrap {
    aspect-ratio: 0.82 / 1;
    min-height: min(68vh, 610px);
    max-height: 70vh;
  }

  .hud-row {
    align-items: center;
  }

  .focus-button {
    min-width: 116px;
    min-height: 52px;
  }
}

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