:root {
  color-scheme: light;
  --bg: #f5fbff;
  --ink: #0b1720;
  --muted: #5e7180;
  --panel: #ffffff;
  --line: #cad9e3;
  --water: #0f8f9a;
  --deep: #064257;
  --sun: #f7c948;
  --coral: #ff6f61;
  --sand: #f6df9f;
  --shadow: 0 18px 46px rgb(6 66 87 / 14%);
  --radius: 8px;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  min-width: 320px;
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgb(119 209 238 / 42%), transparent 330px),
    var(--bg);
}

body,
button,
input {
  font: inherit;
}

button,
input {
  color: inherit;
}

a {
  color: inherit;
}

.skip-link {
  position: fixed;
  top: 1rem;
  left: 1rem;
  z-index: 10;
  padding: 0.65rem 0.85rem;
  border-radius: var(--radius);
  background: var(--ink);
  color: white;
  transform: translateY(-150%);
}

.skip-link:focus {
  transform: translateY(0);
}

.app-shell {
  width: min(1180px, calc(100% - 2rem));
  margin: 0 auto;
  padding: 1rem 0 2rem;
}

.topbar,
.nav,
.game-layout,
.stage-header,
.score-strip,
.player-bar,
.panel-heading,
.site-footer {
  display: flex;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 3;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: 72px;
  background: color-mix(in srgb, var(--bg), transparent 10%);
  backdrop-filter: blur(16px);
}

.topbar h1,
.play-stage h2,
.scores-panel h2 {
  margin: 0;
  line-height: 1.05;
  letter-spacing: 0;
}

.topbar h1 {
  font-size: clamp(1.5rem, 4vw, 2.1rem);
}

.eyebrow {
  margin: 0 0 0.28rem;
  color: var(--coral);
  font-size: 0.75rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.nav {
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgb(255 255 255 / 76%);
}

.nav a {
  min-width: 4.75rem;
  padding: 0.55rem 0.75rem;
  border-radius: calc(var(--radius) - 2px);
  color: var(--muted);
  font-weight: 800;
  text-align: center;
  text-decoration: none;
}

.nav a:hover,
.nav a:focus-visible,
.nav a[aria-current="page"] {
  background: var(--deep);
  color: white;
  outline: none;
}

.game-layout {
  align-items: flex-start;
  gap: 1rem;
}

.play-stage,
.scores-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.play-stage {
  display: flex;
  flex-direction: column;
  flex: 1 1 720px;
  min-width: 0;
  padding: clamp(0.85rem, 2vw, 1.25rem);
}

.scores-panel {
  position: sticky;
  top: 88px;
  flex: 0 0 340px;
  padding: 1rem;
}

.stage-header,
.panel-heading {
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.9rem;
}

.stage-header {
  order: 1;
}

.play-stage h2 {
  max-width: 16ch;
  font-size: clamp(1.7rem, 5vw, 3.5rem);
}

.scores-panel h2 {
  font-size: 1.65rem;
}

.score-strip {
  gap: 0.55rem;
}

.score-strip div {
  display: grid;
  min-width: 84px;
  padding: 0.7rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #f4fbff;
  text-align: center;
}

.score-strip span,
.panel-heading span,
.player-bar label {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 900;
  text-transform: uppercase;
}

.score-strip strong {
  font-size: 2rem;
  line-height: 1;
}

canvas {
  order: 3;
  display: block;
  width: 100%;
  max-width: min(720px, 51vh);
  aspect-ratio: 3 / 4;
  height: auto;
  margin: 0 auto;
  border: 3px solid var(--deep);
  border-radius: var(--radius);
  background: #87d6f4;
  box-shadow: inset 0 -16px 0 rgb(0 0 0 / 10%);
  cursor: pointer;
  touch-action: manipulation;
}

.player-bar {
  order: 2;
  align-items: center;
  gap: 0.65rem;
  margin: 0 0 0.9rem;
}

.player-bar label {
  flex: 0 0 auto;
}

input {
  width: 100%;
  min-height: 2.8rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fbfdff;
  padding: 0.65rem 0.75rem;
  font-weight: 800;
}

button {
  min-height: 2.8rem;
  padding: 0.65rem 1.1rem;
  border: 1px solid var(--deep);
  border-radius: var(--radius);
  background: var(--deep);
  color: white;
  font-weight: 900;
  cursor: pointer;
}

button:hover,
button:focus-visible {
  background: var(--water);
  border-color: var(--water);
}

input:focus,
button:focus-visible,
a:focus-visible,
canvas:focus {
  outline: 3px solid rgb(247 201 72 / 64%);
  outline-offset: 2px;
}

.status-line {
  order: 4;
  min-height: 1.5rem;
  margin: 0.65rem 0 0;
  color: var(--muted);
  font-weight: 800;
}

.leaderboard {
  display: grid;
  gap: 0.55rem;
  margin: 0;
  padding: 0;
  list-style: none;
  counter-reset: score-rank;
}

.leaderboard li {
  counter-increment: score-rank;
  display: grid;
  grid-template-columns: 2rem 1fr auto;
  align-items: center;
  gap: 0.6rem;
  min-height: 3.25rem;
  padding: 0.65rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #f8fcff;
}

.leaderboard li::before {
  content: counter(score-rank);
  display: grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  background: var(--sun);
  color: var(--ink);
  font-weight: 900;
}

.leaderboard span {
  min-width: 0;
  overflow-wrap: anywhere;
  font-weight: 850;
}

.leaderboard strong {
  color: var(--deep);
  font-size: 1.25rem;
}

.leaderboard time {
  grid-column: 2 / 4;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 750;
}

.leaderboard .empty-score {
  grid-template-columns: 1fr;
  color: var(--muted);
  font-weight: 800;
  text-align: center;
}

.leaderboard .empty-score::before {
  content: none;
}

.site-footer {
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 1rem;
  color: var(--muted);
  font-size: 0.9rem;
}

@media (max-width: 880px) {
  .game-layout,
  .stage-header,
  .site-footer {
    flex-direction: column;
    align-items: stretch;
  }

  .scores-panel {
    position: static;
    flex-basis: auto;
    width: 100%;
  }

  .score-strip {
    width: 100%;
  }

  .score-strip div {
    flex: 1;
  }
}

@media (max-width: 520px) {
  .app-shell {
    width: min(100% - 1rem, 1180px);
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
    padding-bottom: 0.8rem;
  }

  .nav,
  .nav a {
    width: 100%;
  }

  .play-stage h2 {
    font-size: 2rem;
  }
}
