:root {
  color-scheme: light;
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
  background: #dff8ff;
  color: #17364a;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  overflow-x: hidden;
}

body {
  display: flex;
  justify-content: center;
  padding: 18px;
  background:
    radial-gradient(circle at 18% 12%, rgba(255, 255, 255, 0.88), transparent 16rem),
    linear-gradient(180deg, #dff8ff 0%, #fef7d5 70%, #fff8ec 100%);
}

button {
  min-height: 58px;
  border: 0;
  border-radius: 8px;
  color: #17364a;
  font: 800 1rem/1.1 "Trebuchet MS", "Segoe UI", sans-serif;
  cursor: pointer;
  touch-action: manipulation;
}

button:focus-visible {
  outline: 4px solid #17364a;
  outline-offset: 3px;
}

.game-shell {
  position: relative;
  width: min(100%, 960px);
  min-height: 100vh;
}

.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 12px;
}

.eyebrow {
  margin: 0 0 4px;
  color: #346b84;
  font-size: 0.78rem;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  max-width: 680px;
  color: #17364a;
  font-size: 2.9rem;
  line-height: 0.98;
}

.sound-toggle {
  flex: 0 0 auto;
  min-width: 130px;
  padding: 0 18px;
  background: #17364a;
  color: #fff9df;
  box-shadow: 0 8px 0 rgba(23, 54, 74, 0.18);
}

.score-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}

.score-tile {
  min-height: 64px;
  padding: 10px;
  border: 3px solid rgba(23, 54, 74, 0.16);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.82);
  box-shadow: 0 7px 0 rgba(23, 54, 74, 0.08);
}

.score-tile span {
  display: block;
  color: #547286;
  font-size: 0.75rem;
  font-weight: 900;
  text-transform: uppercase;
}

.score-tile strong {
  display: block;
  margin-top: 2px;
  font-size: 2rem;
  line-height: 1;
}

.canvas-wrap {
  width: 100%;
  border: 4px solid #17364a;
  border-radius: 8px;
  background: #fef7d5;
  box-shadow: 0 12px 0 rgba(23, 54, 74, 0.12);
  overflow: hidden;
}

#gameCanvas {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  max-height: 68vh;
  background: #fdf2c4;
  touch-action: none;
}

.junction-panel {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 14px;
}

.lane-button,
.touch-controls button,
.result-card button {
  padding: 0 14px;
  background: #fff4a8;
  box-shadow: 0 7px 0 rgba(23, 54, 74, 0.16);
}

.lane-button[aria-pressed="true"] {
  background: #72dfc5;
  color: #103b44;
}

.touch-controls {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-top: 10px;
}

#boostButton {
  background: #ffb85f;
}

#newRoundButton {
  background: #d8c7ff;
}

.status {
  min-height: 48px;
  margin: 12px 0 0;
  padding: 12px 14px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.74);
  color: #17364a;
  font-weight: 800;
}

.result-overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(23, 54, 74, 0.46);
  z-index: 10;
}

.result-card {
  width: min(100%, 430px);
  padding: 24px;
  border: 4px solid #17364a;
  border-radius: 8px;
  background: #fff9df;
  box-shadow: 0 14px 0 rgba(23, 54, 74, 0.22);
}

.result-card p:not(.eyebrow) {
  margin: 12px 0 18px;
  font-weight: 800;
}

@media (max-width: 620px) {
  body {
    padding: 8px;
  }

  .game-header {
    align-items: stretch;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 8px;
  }

  .game-shell {
    min-height: auto;
  }

  .eyebrow {
    font-size: 0.7rem;
  }

  .sound-toggle {
    width: 100%;
    min-height: 58px;
  }

  h1 {
    font-size: 1.5rem;
    line-height: 1;
  }

  .score-strip {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
    margin-bottom: 8px;
  }

  .score-tile {
    min-height: 50px;
    padding: 7px 8px;
  }

  .score-tile span {
    font-size: 0.68rem;
  }

  .score-tile strong {
    font-size: 1.28rem;
  }

  .canvas-wrap {
    max-width: 254px;
    margin: 0 auto;
  }

  #gameCanvas {
    max-height: 190px;
  }

  .junction-panel {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
    margin-top: 8px;
  }

  .touch-controls {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
    margin-top: 8px;
  }

  .lane-button,
  .touch-controls button,
  .result-card button {
    min-height: 58px;
    padding: 0 6px;
    font-size: 0.84rem;
  }

  .status {
    min-height: 42px;
    margin-top: 8px;
    padding: 8px 10px;
    font-size: 0.85rem;
  }
}

@media (max-width: 360px) {
  body {
    padding: 6px 8px;
  }

  h1 {
    font-size: 1.38rem;
  }

  .canvas-wrap {
    max-width: 192px;
  }

  #gameCanvas {
    max-height: 144px;
  }

  .lane-button,
  .touch-controls button,
  .result-card button {
    font-size: 0.78rem;
  }

  .status {
    min-height: 38px;
    padding: 6px 8px;
    font-size: 0.78rem;
  }
}

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