:root {
  --bg: #faf7f2;
  --surface: #ffffff;
  --ink: #1f2430;
  --muted: #6b7280;
  --line: #e8e2d8;
  --radius: 16px;
  --sh1: 0 1px 2px rgba(31, 36, 48, 0.06), 0 4px 12px rgba(31, 36, 48, 0.06);
  --sh2: 0 2px 4px rgba(31, 36, 48, 0.06), 0 14px 32px rgba(31, 36, 48, 0.12);
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --a1: #0e7490;
  --a2: #7c3aed;
  --tint: #0e74901f;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  --pad: max(10px, 2.4vmin);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  color-scheme: light;
}

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

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100svh;
  padding:
    calc(var(--pad) + var(--safe-top))
    calc(var(--pad) + var(--safe-right))
    calc(var(--pad) + var(--safe-bottom))
    calc(var(--pad) + var(--safe-left));
  overflow-x: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button {
  min-height: 44px;
  margin: 0;
  border: 0;
  background: none;
  font: inherit;
  color: var(--ink);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
[tabindex]:focus-visible,
[role="link"]:focus-visible {
  outline: 3px solid var(--ink);
  outline-offset: 3px;
}

[hidden] {
  display: none !important;
}

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

/* Shared surfaces */
.app {
  position: relative;
  z-index: 1;
  width: 100%;
}

.glass {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--sh1);
}

.home-screen {
  animation: home-in 350ms var(--ease) both;
}

.intro-screen,
.play-screen {
  animation: screen-side-in 350ms var(--ease) both;
}

@keyframes home-in {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes screen-side-in {
  from {
    opacity: 0;
    transform: translateX(24px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 11px 22px;
  border-radius: 999px;
  font-size: 16px;
  font-weight: 700;
  line-height: 1.2;
  transition:
    transform 200ms var(--ease),
    box-shadow 200ms var(--ease),
    background-color 200ms var(--ease),
    color 200ms var(--ease);
}

.btn--primary {
  min-width: 140px;
  background: var(--a1);
  color: #ffffff;
  box-shadow: var(--sh1);
}

.btn--secondary {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--sh1);
}

.btn:hover {
  transform: translateY(-2px);
  box-shadow: var(--sh2);
}

.btn:active {
  transform: scale(0.97);
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  flex: 0 0 40px;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink);
  transition:
    background-color 200ms var(--ease),
    color 200ms var(--ease),
    border-color 200ms var(--ease);
}

.icon-btn:hover {
  background: var(--tint);
  border-color: var(--a1);
  color: var(--a1);
}

.icon-btn svg {
  display: block;
  width: 20px;
  height: 20px;
}

.sound-stack {
  position: relative;
  display: block;
  width: 20px;
  height: 20px;
}

.sound-layer {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  opacity: 0;
  transition: opacity 150ms var(--ease);
}

.sound-layer.is-active {
  opacity: 1;
}

.sound-layer svg {
  display: block;
  width: 20px;
  height: 20px;
}

/* Home */
.home-screen {
  display: flex;
  flex-direction: column;
  gap: clamp(12px, 2.8vmin, 30px);
  min-height: calc(100vh - var(--pad) - var(--pad) - var(--safe-top) - var(--safe-bottom));
  min-height: calc(100svh - var(--pad) - var(--pad) - var(--safe-top) - var(--safe-bottom));
}

.home-header {
  padding-top: 0;
}

.brand {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: clamp(9px, 1.8vmin, 14px);
}

.brand-copy {
  flex: 1 1 0;
  min-width: 0;
}

.logo-mark {
  flex: 0 0 auto;
  width: clamp(30px, 4vmin, 44px);
  height: clamp(30px, 4vmin, 44px);
  color: var(--ink);
}

.logo-mark svg {
  display: block;
  width: 100%;
  height: 100%;
}

.brand-name {
  margin: 0;
  color: var(--ink);
  font-size: clamp(1.55rem, 3.4vmin, 2.5rem);
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.05;
}

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: clamp(5px, 1vmin, 8px);
}

.filter-chip {
  min-height: 38px;
  padding: 0 clamp(12px, 2vmin, 18px);
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink);
  font-size: clamp(0.8rem, 1.4vmin, 0.95rem);
  font-weight: 650;
  transition:
    background-color 200ms var(--ease),
    color 200ms var(--ease),
    border-color 200ms var(--ease);
}

.filter-chip:hover {
  border-color: var(--ink);
}

.filter-chip[aria-pressed="true"] {
  border-color: var(--ink);
  background: var(--ink);
  color: #ffffff;
  font-weight: 700;
}

.game-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(clamp(170px, 18vw, 250px), 1fr));
  gap: clamp(10px, 1.8vmin, 20px);
}

.card {
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: clamp(155px, 20vmin, 210px);
  padding: clamp(14px, 2vmin, 20px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--sh1);
  cursor: pointer;
  transition:
    transform 300ms var(--ease),
    box-shadow 300ms var(--ease),
    border-color 300ms var(--ease);
  animation: card-in 380ms var(--ease) both;
  animation-delay: calc(var(--i) * 40ms);
  -webkit-user-select: none;
  user-select: none;
}

.card:hover,
.card:focus-visible {
  transform: translateY(-4px);
  border-color: var(--a1);
  box-shadow: var(--sh2);
}

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

.card-icon {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: clamp(48px, 6.4vmin, 64px);
  height: clamp(48px, 6.4vmin, 64px);
  padding: clamp(8px, 1.2vmin, 12px);
  border-radius: 50%;
  background: var(--tint);
  color: var(--a1);
  transition: transform 400ms var(--spring);
}

.card:hover .card-icon,
.card:focus-visible .card-icon {
  transform: rotate(-4deg) scale(1.06);
}

.card-icon svg {
  display: block;
  width: 100%;
  height: 100%;
}

.card-title {
  margin: clamp(12px, 2vmin, 18px) 0 0;
  color: var(--ink);
  font-size: clamp(1.05rem, 1.9vmin, 1.35rem);
  font-weight: 700;
  letter-spacing: -0.015em;
  line-height: 1.15;
}

.card-tagline {
  margin: clamp(5px, 0.9vmin, 7px) 0 0;
  color: var(--muted);
  font-size: clamp(0.82rem, 1.4vmin, 0.95rem);
  line-height: 1.4;
}

.card-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: clamp(6px, 1vmin, 10px);
  margin-top: auto;
  padding-top: clamp(12px, 2vmin, 18px);
}

.card-genre {
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--tint);
  color: var(--a1);
  font-size: clamp(0.68rem, 1.1vmin, 0.78rem);
  font-weight: 700;
  letter-spacing: 0.08em;
  line-height: 1.4;
  text-transform: uppercase;
}

.card-best {
  color: var(--ink);
  font-size: clamp(0.78rem, 1.3vmin, 0.88rem);
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

@keyframes card-in {
  from {
    opacity: 0;
    translate: 0 16px;
  }
  to {
    opacity: 1;
    translate: 0 0;
  }
}

/* Intro */
.intro-screen {
  display: grid;
  place-items: center;
  min-height: calc(100vh - var(--pad) - var(--pad) - var(--safe-top) - var(--safe-bottom));
  min-height: calc(100svh - var(--pad) - var(--pad) - var(--safe-top) - var(--safe-bottom));
}

.intro-card {
  display: flex;
  flex-direction: column;
  gap: clamp(14px, 2.4vmin, 24px);
  width: min(820px, 100%);
  padding: clamp(18px, 3.6vmin, 40px);
}

.intro-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: clamp(14px, 2.6vmin, 24px);
}

.intro-icon {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: clamp(64px, 10vmin, 112px);
  height: clamp(64px, 10vmin, 112px);
  padding: clamp(12px, 1.8vmin, 20px);
  border-radius: 50%;
  background: var(--tint);
  color: var(--a1);
}

.intro-icon svg {
  display: block;
  width: 100%;
  height: 100%;
}

.intro-copy {
  min-width: 0;
}

.intro-genre {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--tint);
  color: var(--a1);
  font-size: clamp(0.68rem, 1.1vmin, 0.82rem);
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.intro-title {
  margin: 8px 0 0;
  color: var(--ink);
  font-size: clamp(1.6rem, 3.6vmin, 2.5rem);
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.05;
}

.intro-tagline {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: clamp(0.9rem, 1.8vmin, 1.1rem);
}

.intro-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: clamp(16px, 2.6vmin, 30px);
  align-items: start;
}

.intro-section h2 {
  margin: 0 0 clamp(8px, 1.2vmin, 12px);
  color: var(--ink);
  font-size: clamp(0.85rem, 1.5vmin, 1rem);
  font-weight: 750;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.help-list {
  display: flex;
  flex-direction: column;
  gap: clamp(6px, 1vmin, 9px);
  margin: 0;
  padding: 0;
  list-style: none;
}

.help-list li {
  position: relative;
  padding-left: 1.3em;
  color: var(--muted);
  font-size: clamp(0.85rem, 1.45vmin, 1rem);
  line-height: 1.45;
}

.help-list li::before {
  content: "";
  position: absolute;
  top: 0.58em;
  left: 0;
  width: 0.52em;
  height: 0.52em;
  border-radius: 2px;
  background: var(--a1);
}

.control-list {
  display: flex;
  flex-direction: column;
  margin: 0;
}

.control-row {
  display: grid;
  grid-template-columns: minmax(80px, 0.36fr) minmax(0, 1fr);
  gap: clamp(8px, 1.4vmin, 14px);
  padding: clamp(6px, 1.2vmin, 10px) 0;
  border-bottom: 1px solid var(--line);
}

.control-row:last-child {
  border-bottom: 0;
}

.control-label {
  color: var(--ink);
  font-size: clamp(0.8rem, 1.35vmin, 0.92rem);
  font-weight: 700;
}

.control-value {
  color: var(--muted);
  font-size: clamp(0.8rem, 1.35vmin, 0.92rem);
  line-height: 1.4;
}

.intro-best {
  margin: 0;
  color: var(--ink);
  font-size: clamp(0.9rem, 1.7vmin, 1.05rem);
  font-weight: 750;
  font-variant-numeric: tabular-nums;
}

.intro-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: clamp(8px, 1.4vmin, 12px);
  padding-top: clamp(12px, 2vmin, 20px);
  border-top: 1px solid var(--line);
}

/* Play */
.play-screen {
  display: flex;
  flex-direction: column;
  gap: clamp(5px, 1vmin, 9px);
  height: calc(100vh - var(--pad) - var(--pad) - var(--safe-top) - var(--safe-bottom));
  height: calc(100svh - var(--pad) - var(--pad) - var(--safe-top) - var(--safe-bottom));
  min-height: 0;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  flex: 0 0 auto;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  background: var(--surface);
  box-shadow: var(--sh1);
}

.games-btn {
  justify-self: start;
  min-width: 0;
  padding-right: clamp(12px, 1.6vmin, 16px);
  padding-left: clamp(12px, 1.6vmin, 16px);
}

.play-title {
  justify-self: center;
  max-width: 100%;
  margin: 0;
  overflow: hidden;
  color: var(--ink);
  font-size: clamp(0.9rem, 1.7vmin, 1.2rem);
  font-weight: 750;
  line-height: 1.2;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
  pointer-events: none;
}

.topbar-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  justify-self: end;
  gap: clamp(4px, 1vmin, 10px);
}

.stats {
  display: flex;
  flex: 0 0 auto;
  flex-wrap: wrap;
  gap: clamp(5px, 1vmin, 8px);
}

.stat-chip {
  display: inline-flex;
  align-items: baseline;
  gap: 0.5em;
  min-height: 38px;
  padding: 0 clamp(10px, 1.6vmin, 14px);
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  box-shadow: none;
  font-variant-numeric: tabular-nums;
}

.stat-label {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  line-height: 1.2;
  text-transform: uppercase;
}

.stat-value {
  color: var(--ink);
  font-size: clamp(0.95rem, 1.8vmin, 1.15rem);
  font-weight: 800;
  line-height: 1.2;
}

.stage-wrap {
  position: relative;
  display: flex;
  flex: 1 1 auto;
  align-items: center;
  justify-content: center;
  min-height: 0;
  overflow: hidden;
}

.stage {
  position: relative;
  flex: 0 0 auto;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--sh2);
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

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

.fx-flash {
  position: absolute;
  inset: 0;
  z-index: 5;
  pointer-events: none;
}

/* Overlays */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(10px, 2vmin, 20px);
  background: rgba(250, 247, 242, 0.82);
  animation: overlay-fade 200ms var(--ease) both;
}

.overlay-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(9px, 1.5vmin, 14px);
  width: min(520px, 100%);
  max-height: 100%;
  overflow: auto;
  padding: clamp(18px, 3.2vmin, 32px);
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: var(--sh2);
  text-align: center;
  animation: overlay-panel-in 300ms var(--ease) both;
}

.overlay-title {
  margin: 0;
  color: var(--ink);
  font-size: clamp(1.4rem, 3vmin, 2.2rem);
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.1;
}

.overlay-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: clamp(10px, 2vmin, 16px);
  width: 100%;
  padding-top: clamp(4px, 1vmin, 8px);
}

.go-score {
  margin: 0;
  color: var(--ink);
  font-size: clamp(2.5rem, 9vmin, 5rem);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.03em;
  line-height: 1;
}

.go-best {
  margin: 0;
  color: var(--muted);
  font-size: clamp(0.9rem, 1.7vmin, 1.05rem);
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

.best-badge {
  position: relative;
  display: inline-flex;
  padding: 5px 13px;
  border-radius: 999px;
  background: var(--a1);
  color: #ffffff;
  font-size: clamp(0.75rem, 1.4vmin, 0.9rem);
  font-weight: 800;
  line-height: 1.3;
  animation: badge-in 450ms var(--spring) both;
}

.go-line {
  margin: 0;
  color: var(--muted);
  font-size: clamp(0.85rem, 1.6vmin, 1rem);
  line-height: 1.45;
}

@keyframes overlay-fade {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes overlay-panel-in {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes badge-in {
  from {
    opacity: 0;
    transform: scale(0.6);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

/* Responsive */
@media (max-width: 700px) {
  .intro-body {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 480px) {
  .intro-card {
    gap: 12px;
    padding: 16px;
  }

  .intro-head {
    gap: 14px;
  }

  .intro-icon {
    width: 56px;
    height: 56px;
    padding: 11px;
    border-radius: 50%;
  }

  .intro-title {
    margin-top: 5px;
    font-size: clamp(1.5rem, 6vmin, 1.9rem);
  }

  .intro-tagline {
    margin-top: 4px;
    font-size: 0.95rem;
  }

  .intro-section h2 {
    margin-bottom: 8px;
    font-size: 0.9rem;
  }

  .help-list {
    gap: 5px;
  }

  .help-list li {
    font-size: 0.9rem;
    line-height: 1.4;
  }

  .control-row {
    grid-template-columns: 76px minmax(0, 1fr);
    gap: 7px;
    padding: 5px 0;
  }

  .control-label,
  .control-value {
    font-size: 0.84rem;
    line-height: 1.35;
  }

  .intro-best {
    font-size: 0.95rem;
  }

  .intro-actions {
    gap: 8px;
    padding-top: 12px;
  }
}

@media (max-width: 519px) {
  .play-title {
    display: none;
  }
}

/* Motion preferences */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0s !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0s !important;
  }

  .home-screen,
  .intro-screen,
  .play-screen,
  .card,
  .overlay,
  .overlay-panel,
  .best-badge {
    animation: none !important;
    translate: none !important;
  }

  .card:hover,
  .card:focus-visible,
  .card:active,
  .btn:hover,
  .btn:active {
    transform: none !important;
  }

  .card:hover .card-icon,
  .card:focus-visible .card-icon {
    transform: none !important;
  }
}
