:root {
  color-scheme: dark;
  --bg: #0b0d12;
  --surface: #151923;
  --surface-2: #1f2632;
  --line: rgba(255, 255, 255, 0.11);
  --ink: #eef4ff;
  --muted: #9ba8bb;
  --black: #050609;
  --accent: #58d2ff;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  touch-action: manipulation;
}

body {
  margin: 0;
  background:
    linear-gradient(135deg, rgba(88, 210, 255, 0.12), transparent 34%),
    linear-gradient(215deg, rgba(255, 216, 74, 0.08), transparent 32%),
    var(--bg);
  color: var(--ink);
  overflow-x: hidden;
  touch-action: manipulation;
}

button {
  font: inherit;
  touch-action: manipulation;
}

.app-shell {
  min-height: 100svh;
  display: grid;
  place-items: center;
  padding: max(18px, env(safe-area-inset-top)) 14px max(18px, env(safe-area-inset-bottom));
  touch-action: manipulation;
}

.game-shell {
  width: min(100%, 420px);
  min-height: min(880px, calc(100svh - 36px));
  display: grid;
  grid-template-rows: auto auto auto 1fr auto;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: rgba(12, 15, 21, 0.88);
  box-shadow: 0 24px 90px rgba(0, 0, 0, 0.48);
  backdrop-filter: blur(18px);
}

.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.game-header h1 {
  margin: 0;
  color: var(--ink);
  font-size: 28px;
  font-weight: 900;
  letter-spacing: 0;
  line-height: 1;
}

.score-panel {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.055);
  color: var(--ink);
  font-size: 12px;
  font-weight: 700;
}

.meter {
  min-height: 50px;
  display: grid;
  align-content: center;
  gap: 3px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
}

.meter span,
.mission-panel > span,
.high-score-panel > span {
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.meter strong {
  color: var(--ink);
  font-size: 20px;
  line-height: 1;
  text-align: left;
}

.goal-row,
.mission-panel,
.high-score-panel {
  grid-column: 1 / -1;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
}

.goal-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 10px;
  color: var(--ink);
}

.mission-panel {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px;
  align-items: center;
  min-height: 38px;
  padding: 9px 10px;
}

.mission-panel strong {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  min-width: 0;
  color: var(--ink);
  text-align: right;
}

.mission-chip {
  width: 14px;
  height: 14px;
  flex: 0 0 14px;
  border: 1px solid rgba(255, 255, 255, 0.5);
  border-radius: 4px;
}

.high-score-panel {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px;
  align-items: start;
  padding: 9px 10px;
  font-size: 11px;
}

.high-score-panel > span {
  white-space: nowrap;
}

.high-score-panel ol {
  display: grid;
  gap: 3px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.high-score-panel li {
  display: grid;
  grid-template-columns: 18px 1fr auto;
  gap: 6px;
  min-width: 0;
}

.high-score-panel b,
.high-score-panel em {
  color: var(--ink);
  font-style: normal;
  font-weight: 800;
}

.counter-strip {
  min-height: 30px;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.045);
  color: white;
  font-size: 11px;
  font-weight: 800;
}

.counter {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-width: 0;
  padding: 3px 2px;
  border-radius: 8px;
  background: var(--surface);
}

.swatch {
  width: 12px;
  height: 12px;
  flex: 0 0 12px;
  border: 1px solid rgba(255, 255, 255, 0.55);
  border-radius: 4px;
}

.board-frame {
  position: relative;
  min-height: 0;
  display: grid;
  align-items: start;
  justify-items: center;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #070910;
}

canvas {
  width: min(100%, calc(clamp(280px, calc(100svh - 420px), 420px) * 6 / 7));
  aspect-ratio: 6 / 7;
  display: block;
  border-radius: 10px;
  background: #050609;
  cursor: pointer;
  touch-action: manipulation;
}

.toast {
  position: absolute;
  left: 50%;
  top: 40%;
  transform: translate(-50%, -50%) scale(0.96);
  min-width: 124px;
  padding: 10px 14px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 14px;
  background: rgba(15, 19, 27, 0.9);
  color: white;
  text-align: center;
  font-size: 16px;
  font-weight: 900;
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

.control-bar {
  min-height: 46px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.icon-button,
.text-button {
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--ink);
  font-weight: 900;
}

.icon-button {
  width: 46px;
  font-size: 22px;
  line-height: 1;
}

.text-button {
  min-width: 84px;
  padding: 0 14px;
  font-size: 13px;
}

.icon-button:active,
.text-button:active {
  transform: translateY(1px);
}

.text-button[aria-pressed="false"] {
  color: var(--muted);
  background: #111722;
}

@media (max-width: 430px) {
  .app-shell {
    padding: 0;
  }

  .game-shell {
    width: 100%;
    min-height: 100svh;
    gap: 8px;
    padding: 8px;
    border-radius: 0;
    border-inline: 0;
  }

  .game-header h1 {
    font-size: 24px;
  }

  .score-panel {
    grid-template-columns: 1fr;
  }

  .meter {
    min-height: 42px;
  }

  .mission-panel {
    align-items: start;
  }

  .mission-panel strong {
    justify-content: flex-start;
    text-align: left;
  }

  .board-frame {
    padding: 4px;
  }

  canvas {
    width: 100%;
    max-height: none;
  }
}
