:root {
  color-scheme: light;
  --bg: #f7fbfc;
  --bg-alt: #f0f9ff;
  --bg-lime: #f6fff8;
  --panel: rgba(255, 255, 255, 0.72);
  --panel-strong: rgba(255, 255, 255, 0.88);
  --stroke: rgba(255, 255, 255, 0.76);
  --stroke-strong: rgba(15, 23, 42, 0.08);
  --text: #111827;
  --muted: #4b5563;
  --ink: #0f172a;
  --coral: #ff7f50;
  --azure: #0ea5e9;
  --sage: #84cc16;
  --sand: #f8fafc;
  --shadow: 0 28px 72px rgba(15, 23, 42, 0.12);
  --shadow-soft: 0 12px 28px rgba(15, 23, 42, 0.08);
  --accent-gradient: linear-gradient(90deg, var(--coral), var(--azure), var(--sage));
  --display: "Iowan Old Style", "Baskerville", "Palatino Linotype", Georgia, serif;
  --mono: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  overflow: hidden;
  background:
    radial-gradient(circle at 18% 14%, rgba(14, 165, 233, 0.16), transparent 28%),
    radial-gradient(circle at 78% 16%, rgba(255, 127, 80, 0.14), transparent 24%),
    radial-gradient(circle at 50% 88%, rgba(132, 204, 22, 0.13), transparent 24%),
    linear-gradient(135deg, #ffffff 0%, #f0f9ff 42%, #f6fff8 100%);
  color: var(--text);
  font-family: var(--mono);
  line-height: 1.5;
}

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

button {
  border: 0;
  color: inherit;
  cursor: pointer;
}

button:focus-visible {
  outline: 2px solid rgba(14, 165, 233, 0.42);
  outline-offset: 3px;
}

[hidden] {
  display: none !important;
}

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

.button,
.pad,
.stage-footer {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.stage {
  position: relative;
  width: 100vw;
  height: 100vh;
  isolation: isolate;
}

#scene {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.stage__grain,
.stage__vignette {
  position: fixed;
  inset: 0;
  pointer-events: none;
}

.stage__grain {
  opacity: 0.08;
  background-image:
    linear-gradient(rgba(15, 23, 42, 0.02) 1px, transparent 1px),
    linear-gradient(90deg, rgba(15, 23, 42, 0.02) 1px, transparent 1px);
  background-size: 4px 4px;
  mix-blend-mode: multiply;
}

.stage__vignette {
  background:
    radial-gradient(circle at center, transparent 40%, rgba(15, 23, 42, 0.05) 100%),
    linear-gradient(180deg, transparent 68%, rgba(15, 23, 42, 0.035));
}

.ui-shell {
  position: fixed;
  top: clamp(0.9rem, 2vw, 1.35rem);
  left: clamp(0.9rem, 2vw, 1.35rem);
  display: inline-grid;
  grid-template-columns: max-content;
  align-items: start;
  gap: 0.6rem;
  pointer-events: none;
  z-index: 2;
}

.stage-footer {
  position: fixed;
  left: clamp(1rem, 2vw, 1.8rem);
  bottom: clamp(1rem, 2vw, 1.8rem);
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  min-height: 2.55rem;
  margin: 0;
  padding: 0.65rem 0.9rem;
  border-radius: 999px;
  color: var(--muted);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.82), rgba(255, 255, 255, 0.64));
  border: 1px solid rgba(255, 255, 255, 0.74);
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  pointer-events: none;
  z-index: 3;
  line-height: 1;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 0.7rem;
  font-weight: 700;
}

.stage-footer strong {
  color: var(--ink);
  font-size: 1rem;
  letter-spacing: 0.04em;
  font-variant-numeric: tabular-nums;
}

.hero {
  position: relative;
  pointer-events: auto;
  padding: 0.8rem 1rem;
  border-radius: 1.1rem 1.7rem 1.1rem 1.4rem;
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.78), rgba(255, 255, 255, 0.6));
  border: 1px solid rgba(255, 255, 255, 0.78);
  box-shadow: var(--shadow-soft);
}

.hero__title {
  position: relative;
  z-index: 1;
  margin: 0;
  font-family: var(--display);
  font-weight: 800;
  font-size: clamp(2rem, 4vw, 3.25rem);
  line-height: 0.88;
  letter-spacing: -0.05em;
  background: linear-gradient(90deg, var(--ink) 0%, var(--azure) 54%, var(--sage) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  text-shadow: 0 12px 30px rgba(15, 23, 42, 0.06);
}

.button {
  min-height: 3.25rem;
  padding: 0 1rem;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-size: 0.76rem;
  font-weight: 700;
  transition:
    transform 180ms ease,
    box-shadow 180ms ease,
    background 180ms ease,
    color 180ms ease;
}

.button:hover {
  transform: translateY(-1px);
}

.button:active {
  transform: translateY(1px) scale(0.99);
}

.button--secondary {
  color: var(--text);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.84), rgba(255, 255, 255, 0.66));
  border: 1px solid rgba(15, 23, 42, 0.08);
}

.overlay__button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 10rem;
}

body[data-phase="playing"] .ui-shell {
  opacity: 0.95;
}

body[data-phase="playing"] .hero__title {
  font-size: clamp(2rem, 4vw, 3.2rem);
}

.touch-pad {
  position: absolute;
  right: clamp(1rem, 2vw, 1.8rem);
  bottom: clamp(1rem, 2vw, 1.8rem);
  display: none;
  grid-template-columns: repeat(3, 3.75rem);
  grid-template-rows: repeat(3, 3.75rem);
  gap: 0.7rem;
  z-index: 3;
  pointer-events: auto;
}

.pad {
  display: grid;
  place-items: center;
  border-radius: 1.15rem;
  color: var(--ink);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.84), rgba(255, 255, 255, 0.64));
  border: 1px solid rgba(255, 255, 255, 0.7);
  box-shadow: var(--shadow-soft);
  font-size: 1.08rem;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  transition:
    transform 160ms ease,
    background 160ms ease,
    border-color 160ms ease,
    box-shadow 160ms ease;
}

.pad:hover {
  transform: translateY(-1px);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.95), rgba(255, 255, 255, 0.72));
  box-shadow: 0 16px 34px rgba(15, 23, 42, 0.12);
}

.pad:active {
  transform: translateY(1px) scale(0.98);
}

.pad--up {
  grid-column: 2;
  grid-row: 1;
}

.pad--left {
  grid-column: 1;
  grid-row: 2;
}

.pad--center {
  grid-column: 2;
  grid-row: 2;
  color: white;
  background: var(--accent-gradient);
}

.pad--right {
  grid-column: 3;
  grid-row: 2;
}

.pad--down {
  grid-column: 2;
  grid-row: 3;
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  z-index: 1;
  pointer-events: auto;
  transition:
    opacity 220ms ease,
    transform 220ms ease;
}

.overlay__stack {
  display: grid;
  justify-items: center;
  gap: 1rem;
}

.overlay__card {
  width: min(34rem, calc(100vw - 2rem));
  border-radius: 1.65rem 2.5rem 1.65rem 2rem;
  padding: 1.4rem 1.45rem 1.35rem;
  text-align: center;
  transform: translateY(0);
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.28);
  box-shadow: var(--shadow);
  opacity: 0.76;
  pointer-events: auto;
  cursor: pointer;
}

.overlay__card:focus-visible {
  outline: 2px solid rgba(14, 165, 233, 0.28);
  outline-offset: 4px;
}

.overlay__kicker {
  margin: 0 0 0.65rem;
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  text-transform: uppercase;
  letter-spacing: 0.32em;
  font-size: 0.72rem;
  font-weight: 700;
}

.overlay__title {
  margin: 0;
  font-family: var(--display);
  font-weight: 800;
  font-size: clamp(2.2rem, 6vw, 3.9rem);
  line-height: 0.92;
  letter-spacing: -0.05em;
  background: linear-gradient(90deg, var(--ink) 0%, var(--azure) 55%, var(--sage) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.overlay__body {
  margin: 0.85rem auto 0;
  max-width: 28ch;
  color: var(--muted);
  line-height: 1.55;
}

body[data-phase="playing"] .overlay {
  opacity: 0;
  transform: translateY(1rem) scale(0.98);
}

body[data-phase="ready"] .overlay,
body[data-phase="paused"] .overlay,
body[data-phase="gameover"] .overlay,
body[data-phase="levelup"] .overlay,
body[data-phase="victory"] .overlay {
  opacity: 1;
}

body[data-phase="playing"] .overlay__card {
  transform: translateY(1.2rem);
}

body[data-phase="levelup"] .overlay__card {
  border-color: rgba(14, 165, 233, 0.18);
}

@media (pointer: coarse), (max-width: 840px) {
  .ui-shell {
    top: 0.5rem;
    left: 0.5rem;
  }

  .hero {
    padding: 0.65rem 0.85rem;
  }

  .touch-pad {
    display: grid;
  }

  .stage-footer {
    left: 0.5rem;
    bottom: calc(0.5rem + env(safe-area-inset-bottom));
    max-width: calc(100vw - 1rem);
    font-size: 0.64rem;
  }
}

@media (max-width: 840px) {
  .hero__title {
    font-size: clamp(1.8rem, 11vw, 3rem);
  }

  .touch-pad {
    right: 50%;
    transform: translateX(50%);
    bottom: calc(1rem + env(safe-area-inset-bottom));
  }
}

@media (prefers-reduced-motion: reduce) {
  .button,
  .pad,
  .overlay,
  .stage-footer {
    transition-duration: 1ms;
  }
}
