:root {
  color-scheme: light;
  --ink: #172033;
  --muted: #526078;
  --panel: rgba(255, 255, 255, 0.9);
  --panel-strong: #fffaf1;
  --line: rgba(23, 32, 51, 0.12);
  --sun: #ffd166;
  --orange: #f47c48;
  --green: #2fbf71;
  --blue: #3a86ff;
  --shadow: 0 24px 70px rgba(75, 50, 20, 0.2);
}

* {
  box-sizing: border-box;
}

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

body {
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 15% 10%, rgba(255, 209, 102, 0.5), transparent 28rem),
    radial-gradient(circle at 85% 25%, rgba(58, 134, 255, 0.18), transparent 22rem),
    linear-gradient(135deg, #fff3d9 0%, #f8fbff 54%, #e8fff3 100%);
  overflow-x: hidden;
}

button {
  font: inherit;
  -webkit-tap-highlight-color: transparent;
}

.game-shell {
  width: min(1180px, calc(100vw - 28px));
  min-height: 100vh;
  margin: 0 auto;
  padding: 22px 0;
  display: grid;
  align-items: center;
}

.hero-panel {
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
  padding: 18px;
}

.topbar,
.score-row,
.controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.topbar {
  margin-bottom: 14px;
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.logo-mark {
  flex: 0 0 auto;
  width: 78px;
  height: 78px;
  object-fit: contain;
  image-rendering: pixelated;
  filter: drop-shadow(4px 5px 0 rgba(23, 32, 51, 0.16));
}

.eyebrow,
.kicker {
  margin: 0 0 6px;
  color: var(--orange);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(1.9rem, 4.2vw, 4rem);
  line-height: 0.95;
  letter-spacing: 0;
}

.sound-toggle,
.touch-controls button,
.overlay-card button {
  min-height: 44px;
  border: 0;
  border-radius: 999px;
  cursor: pointer;
  transition: transform 180ms ease, box-shadow 180ms ease, background 180ms ease;
}

.sound-toggle {
  padding: 0 18px;
  color: #fff;
  background: #172033;
}

.score-row {
  margin-bottom: 14px;
}

.metric {
  flex: 1;
  min-width: 0;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.72);
}

.metric span,
.control-copy span {
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
}

.metric strong {
  display: block;
  margin-top: 4px;
  font-size: clamp(1.25rem, 3vw, 2rem);
  line-height: 1;
}

.pulse-target.is-popping {
  animation: score-pop 260ms ease-out;
}

@keyframes score-pop {
  0% {
    transform: translateY(0) scale(1);
    color: inherit;
  }
  45% {
    transform: translateY(-2px) scale(1.14);
    color: #f47c48;
  }
  100% {
    transform: translateY(0) scale(1);
    color: inherit;
  }
}

.flag-metric strong {
  color: var(--green);
}

.canvas-wrap {
  position: relative;
  overflow: hidden;
  border-radius: 18px;
  border: 1px solid rgba(23, 32, 51, 0.16);
  background: #91dcff;
  touch-action: manipulation;
}

.progress-track {
  position: absolute;
  z-index: 5;
  top: 12px;
  left: 14px;
  right: 14px;
  height: 12px;
  overflow: hidden;
  border: 2px solid rgba(23, 32, 51, 0.26);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.72);
}

.progress-fill {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #2fbf71, #ffd166, #f47c48);
  transition: width 120ms linear;
}

canvas {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  touch-action: none;
}

.overlay {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: linear-gradient(135deg, rgba(23, 32, 51, 0.62), rgba(47, 191, 113, 0.24));
}

.overlay.is-visible {
  display: flex;
}

.overlay-card {
  width: min(430px, 100%);
  border-radius: 20px;
  padding: 26px;
  color: var(--ink);
  background: var(--panel-strong);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.22);
  text-align: center;
}

.overlay-card h2 {
  margin-bottom: 10px;
  font-size: clamp(1.6rem, 5vw, 2.6rem);
  line-height: 1.05;
}

.overlay-card p:not(.kicker) {
  color: var(--muted);
  line-height: 1.6;
}

.character-select {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin: 16px 0 12px;
}

.character-card {
  display: grid;
  justify-items: center;
  gap: 5px;
  min-height: auto;
  padding: 10px 8px;
  border: 2px solid rgba(23, 32, 51, 0.14);
  border-radius: 14px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.72);
  cursor: pointer;
  transition: transform 160ms ease, border-color 160ms ease, box-shadow 160ms ease;
}

.character-card.is-selected {
  border-color: var(--orange);
  box-shadow: 0 10px 24px rgba(244, 124, 72, 0.22);
  background: #fff8e8;
}

.character-card img {
  width: 58px;
  height: 58px;
  object-fit: contain;
  image-rendering: pixelated;
}

.character-card strong {
  font-size: 1rem;
}

.character-card span {
  color: var(--muted);
  font-size: 0.78rem;
}

.overlay-card > button {
  margin-top: 8px;
  padding: 0 28px;
  color: #fff;
  background: linear-gradient(135deg, var(--orange), #ffb703);
  box-shadow: 0 14px 34px rgba(244, 124, 72, 0.34);
}

.controls {
  margin-top: 14px;
}

.control-copy {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 18px;
}

.touch-controls {
  display: flex;
  gap: 10px;
}

.touch-controls button {
  padding: 0 18px;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  user-select: none;
}

button:focus-visible {
  outline: 3px solid rgba(58, 134, 255, 0.75);
  outline-offset: 3px;
}

@media (hover: hover) {
  .sound-toggle:hover,
  .touch-controls button:hover,
  .character-card:hover,
  .overlay-card > button:hover {
    transform: translateY(-1px);
  }
}

@media (max-width: 720px) {
  body {
    background: linear-gradient(180deg, #fff4dc 0%, #e8fff3 100%);
  }

  .game-shell {
    width: 100vw;
    min-height: 100dvh;
    padding: 0 0 76px;
    align-items: start;
  }

  .hero-panel {
    min-height: 100dvh;
    padding: 10px;
    border-width: 0;
    border-radius: 0;
  }

  .topbar,
  .score-row,
  .controls {
    align-items: stretch;
  }

  .topbar,
  .controls {
    flex-direction: row;
    gap: 10px;
  }

  .topbar {
    margin-bottom: 9px;
  }

  .brand-lockup {
    width: auto;
    flex: 1;
    gap: 9px;
  }

  .logo-mark {
    width: 44px;
    height: 44px;
  }

  .eyebrow {
    margin-bottom: 2px;
    font-size: 0.62rem;
    letter-spacing: 0.08em;
  }

  h1 {
    font-size: clamp(1.45rem, 8vw, 2.15rem);
    line-height: 1;
  }

  .score-row {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 7px;
    margin-bottom: 9px;
  }

  .metric {
    padding: 8px 9px;
    border-radius: 10px;
  }

  .metric span {
    font-size: 0.7rem;
  }

  .metric strong {
    margin-top: 2px;
    font-size: 1.12rem;
  }

  .sound-toggle {
    width: auto;
    min-width: 86px;
    min-height: 40px;
    padding: 0 12px;
    font-size: 0.86rem;
  }

  .canvas-wrap {
    border-radius: 12px;
  }

  .progress-track {
    top: 8px;
    left: 10px;
    right: 10px;
    height: 10px;
    border-width: 1px;
  }

  canvas {
    aspect-ratio: 4 / 3;
  }

  .controls {
    position: fixed;
    z-index: 20;
    right: 10px;
    bottom: calc(10px + env(safe-area-inset-bottom));
    left: 10px;
    margin-top: 0;
    align-items: end;
    pointer-events: none;
  }

  .control-copy {
    display: none;
  }

  .touch-controls {
    justify-content: flex-end;
    width: 100%;
    pointer-events: auto;
  }

  .touch-controls button {
    width: min(45vw, 190px);
    min-height: 62px;
    border: 0;
    border-radius: 999px;
    color: #fff;
    font-size: 1.08rem;
    font-weight: 900;
    background: linear-gradient(135deg, #172033, #3a86ff);
    box-shadow: 0 14px 30px rgba(23, 32, 51, 0.28);
  }

  .overlay {
    padding: 10px;
    align-items: flex-start;
  }

  .overlay-card {
    width: min(390px, 100%);
    max-height: calc(100dvh - 26px);
    overflow: auto;
    padding: 16px;
    border-radius: 16px;
  }

  .overlay-card h2 {
    margin-bottom: 8px;
    font-size: 1.55rem;
  }

  .overlay-card p:not(.kicker) {
    margin-bottom: 10px;
    font-size: 0.9rem;
    line-height: 1.45;
  }

  .character-select {
    gap: 8px;
    margin: 10px 0;
  }

  .character-card {
    padding: 8px 6px;
    border-radius: 12px;
  }

  .character-card img {
    width: 44px;
    height: 44px;
  }

  .character-card strong {
    font-size: 0.94rem;
  }

  .character-card span {
    font-size: 0.68rem;
  }

  .overlay-card > button {
    width: 100%;
    min-height: 48px;
  }
}

@media (max-width: 420px) {
  .hero-panel {
    padding: 8px;
  }

  .score-row {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .metric {
    padding: 7px 5px;
    text-align: center;
  }

  .metric strong {
    font-size: 0.98rem;
  }

  .metric span {
    font-size: 0.64rem;
  }

  canvas {
    aspect-ratio: 10 / 13;
  }
}

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