:root {
  color-scheme: light;
  font-family:
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
  background: #fff7ea;
  color: #2d3340;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100svh;
  overflow: auto;
  background:
    radial-gradient(circle at 12% 8%, rgba(142, 205, 230, 0.28) 0 7rem, transparent 7.1rem),
    radial-gradient(circle at 92% 24%, rgba(255, 210, 116, 0.26) 0 6rem, transparent 6.1rem),
    linear-gradient(180deg, #fff8ed 0%, #fffdf8 54%, #f6f0e6 100%);
}

button {
  min-height: 2.75rem;
  border: 1px solid rgba(93, 73, 53, 0.18);
  border-radius: 8px;
  background: #fffaf1;
  color: #334155;
  font: inherit;
  font-weight: 850;
  cursor: pointer;
  box-shadow: 0 0.45rem 0.9rem rgba(95, 69, 38, 0.08);
  transition: transform 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}

button:hover {
  transform: translateY(-1px);
  border-color: rgba(68, 124, 94, 0.35);
  background: #ffffff;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
  transform: none;
}

button:focus-visible,
a:focus-visible,
input:focus-visible {
  outline: 3px solid #57c7b2;
  outline-offset: 3px;
}

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

.draw-game {
  position: relative;
  min-height: 100svh;
  overflow: hidden;
}

.play-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(16.5rem, 22rem);
  grid-template-rows: auto minmax(0, 1fr);
  gap: clamp(0.6rem, 1.6vw, 1rem);
  width: min(100%, 76rem);
  height: 100svh;
  min-height: 0;
  margin: 0 auto;
  padding: clamp(0.65rem, 1.6vw, 1rem);
}

.stage-header {
  grid-column: 1 / -1;
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 1rem;
  border: 1px solid rgba(166, 126, 72, 0.2);
  border-radius: 8px;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.86), rgba(255, 250, 240, 0.82)),
    repeating-linear-gradient(0deg, transparent 0 27px, rgba(87, 145, 170, 0.07) 28px 29px);
  padding: clamp(0.72rem, 1.7vw, 1rem);
  box-shadow: 0 0.85rem 1.8rem rgba(95, 69, 38, 0.08);
}

.eyebrow {
  margin: 0 0 0.25rem;
  color: #d25d4c;
  font-size: 0.76rem;
  font-weight: 950;
  letter-spacing: 0;
  text-transform: uppercase;
}

.stage-header h2,
.title-card h1,
.result-card h2 {
  margin: 0;
  color: #233044;
  letter-spacing: 0;
}

.stage-header h2 {
  font-size: clamp(1.2rem, 3vw, 1.65rem);
  line-height: 1.15;
}

#mission-text {
  margin: 0.3rem 0 0;
  color: #586174;
  font-size: 0.95rem;
  font-weight: 740;
  line-height: 1.55;
}

.stage-stats {
  display: grid;
  flex: 0 0 auto;
  gap: 0.35rem;
  min-width: min(17rem, 44vw);
  color: #334155;
  font-size: 0.84rem;
  font-weight: 820;
  text-align: right;
}

.board-shell {
  position: relative;
  display: grid;
  min-height: 0;
  place-items: start center;
}

#game-canvas {
  display: block;
  width: min(100%, calc((100svh - 10.2rem) * 1));
  max-height: calc(100svh - 10.2rem);
  aspect-ratio: 1 / 1;
  border: 1px solid rgba(121, 93, 60, 0.2);
  border-radius: 8px;
  background: #fffdf6;
  box-shadow: 0 1rem 2.2rem rgba(65, 51, 35, 0.14);
  touch-action: none;
}

.hud-panel {
  align-self: stretch;
  display: grid;
  align-content: start;
  gap: 0.8rem;
  min-height: 0;
  overflow: auto;
  border: 1px solid rgba(166, 126, 72, 0.2);
  border-radius: 8px;
  background: rgba(255, 252, 246, 0.92);
  padding: 0.85rem;
  box-shadow: 0 0.85rem 1.8rem rgba(95, 69, 38, 0.08);
}

.meters {
  display: grid;
  gap: 0.55rem;
}

.meter-card {
  display: grid;
  gap: 0.35rem;
  border: 1px solid rgba(89, 132, 113, 0.18);
  border-radius: 8px;
  background: #f5fbf7;
  padding: 0.7rem;
}

.meter-card span {
  color: #5f6d75;
  font-size: 0.75rem;
  font-weight: 850;
}

.meter-card strong {
  color: #233044;
  font-size: 1.05rem;
  line-height: 1.1;
}

.button-row,
.result-actions,
.title-actions {
  display: grid;
  gap: 0.52rem;
}

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

.primary-button {
  border-color: rgba(37, 139, 100, 0.3);
  background: linear-gradient(180deg, #4dbd9e, #258b64);
  color: #ffffff;
}

.hint-card {
  border: 1px solid rgba(226, 167, 40, 0.25);
  border-radius: 8px;
  background: #fff8d9;
  padding: 0.75rem;
}

.hint-card strong {
  display: block;
  color: #8a5f0a;
  font-size: 0.82rem;
  line-height: 1.35;
}

.hint-card p,
.keyboard-help,
.title-copy,
.result-card p {
  margin: 0.35rem 0 0;
  color: #647083;
  font-size: 0.88rem;
  line-height: 1.6;
}

.settings-row {
  display: flex;
  align-items: center;
  min-height: 2.75rem;
}

.sound-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  color: #475569;
  font-size: 0.88rem;
  font-weight: 800;
}

.sound-toggle input {
  width: 1.15rem;
  height: 1.15rem;
  accent-color: #258b64;
}

.stage-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 0.45rem;
}

.stage-grid button {
  min-height: 2.45rem;
  padding: 0.2rem;
  font-size: 0.82rem;
}

.stage-grid button.is-current {
  border-color: rgba(37, 139, 100, 0.38);
  background: #e8f7ef;
  color: #116149;
}

.stage-grid button.is-cleared::after {
  content: " ★";
  color: #d89b13;
}

.title-screen {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: clamp(0.85rem, 3vw, 1.5rem);
  background:
    radial-gradient(circle at 14% 18%, rgba(87, 199, 178, 0.22) 0 8rem, transparent 8.1rem),
    radial-gradient(circle at 84% 16%, rgba(255, 209, 102, 0.26) 0 7rem, transparent 7.1rem),
    linear-gradient(180deg, rgba(255, 248, 237, 0.97), rgba(255, 253, 248, 0.98));
}

.title-screen[hidden] {
  display: none;
}

.title-card,
.result-card {
  width: min(100%, 36rem);
  border: 1px solid rgba(166, 126, 72, 0.22);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.94), rgba(255, 250, 240, 0.94)),
    repeating-linear-gradient(0deg, transparent 0 27px, rgba(68, 124, 94, 0.06) 28px 29px);
  padding: clamp(1rem, 3vw, 1.4rem);
  box-shadow: 0 1.2rem 3rem rgba(82, 61, 35, 0.14);
}

.title-card h1 {
  font-size: clamp(2rem, 7vw, 3.15rem);
  line-height: 1.05;
}

.title-actions {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin: 1rem 0 0.9rem;
}

.result-modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgba(40, 50, 66, 0.52);
  backdrop-filter: blur(7px);
}

.result-modal[hidden] {
  display: none;
}

.result-card {
  text-align: center;
}

.result-card h2 {
  font-size: clamp(1.8rem, 5vw, 2.8rem);
}

.result-score {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.7rem;
  margin: 1rem 0;
}

.result-score div {
  border-radius: 8px;
  background: #f3fbf6;
  padding: 0.8rem;
}

.result-score dt {
  color: #697484;
  font-size: 0.75rem;
  font-weight: 850;
}

.result-score dd {
  margin: 0.2rem 0 0;
  color: #233044;
  font-size: 1.55rem;
  font-weight: 950;
  line-height: 1;
}

.result-actions {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

@media (max-width: 880px) {
  .play-shell {
    grid-template-columns: 1fr;
    height: auto;
    min-height: auto;
  }

  #game-canvas {
    width: min(100%, calc(100svh - 18rem));
    max-height: none;
  }

  .hud-panel {
    overflow: visible;
  }
}

@media (max-width: 640px) {
  .play-shell {
    padding: 0.55rem;
  }

  .stage-header {
    align-items: stretch;
    flex-direction: column;
  }

  .stage-stats {
    min-width: 0;
    text-align: left;
  }

  #game-canvas {
    width: 100%;
  }

  .button-row,
  .title-actions,
  .result-actions {
    grid-template-columns: 1fr;
  }

  .stage-grid {
    grid-template-columns: repeat(5, minmax(2.4rem, 1fr));
  }
}
