* {
  box-sizing: border-box;
}

:root {
  color-scheme: dark;
  /* Mirrors the theme's chrome roles; an e2e test fails on drift. */
  --outline: #04121d;
  --slate: #123a52;
  --line: #1c4b66;
  --border: #2a6483;
  --mute: #5f8ba3;
  --hint: #8fb3c9;
  --text-soft: #cfe6f2;
  --text: #eef7fc;
  --accent: #22d3ee;
  --accent-bright: #67e8f9;
  --accent-ink: #083344;
  --danger: #fb7185;
  --rock: #94a3b8;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  padding: 16px 12px calc(32px + env(safe-area-inset-bottom, 0px));
  background: radial-gradient(circle at 50% 0%, var(--slate), var(--outline) 70%);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, sans-serif;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.shell {
  --board-height: min(74vh, 660px, calc((100vw - 56px) * 1.5));
  --board-height: min(74dvh, 660px, calc((100vw - 56px) * 1.5));
  width: min(100%, calc(var(--board-height) * 2 / 3 + 32px));
  margin: auto;
  padding: 20px 16px 28px;
  display: grid;
  gap: 12px;
  justify-items: center;
}

.masthead {
  width: 100%;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.masthead h1 {
  margin: 0;
  font-size: 1.2rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent-bright);
}

.masthead .back {
  font-size: 0.85rem;
  color: var(--hint);
  text-decoration: none;
}

.masthead .back:hover,
.masthead .back:focus-visible {
  color: var(--accent-bright);
}

.masthead-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.mute {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 10px;
  background: transparent;
  color: var(--hint);
  font: inherit;
  font-size: 0.78rem;
  cursor: pointer;
}

.mute:hover,
.mute:focus-visible {
  color: var(--accent-bright);
  border-color: var(--accent);
}

.hud {
  width: 100%;
  display: flex;
  justify-content: space-between;
  font-size: 0.95rem;
  letter-spacing: 0.02em;
  font-variant-numeric: tabular-nums;
}

.stat strong {
  color: var(--accent);
}

.board {
  position: relative;
  width: 100%;
  max-width: calc(var(--board-height) * 2 / 3);
  aspect-ratio: 2 / 3;
}

canvas {
  width: 100%;
  height: 100%;
  display: block;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--outline);
  image-rendering: pixelated;
  touch-action: none;
}

/* Decision buttons: one centered split control, Rotate left / Place right. */
.actions {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 10px;
  display: flex;
  justify-content: center;
  gap: 0;
  z-index: 2;
}

.actions[hidden] {
  display: none;
}

/* `hidden` on a button needs its own guard: an author rule beats the UA's
   [hidden] { display: none }, so `.actions button` would otherwise override it. */
.actions button[hidden] {
  display: none;
}

.actions button {
  flex: 0 0 auto;
  min-width: 120px;
  min-height: 44px;
  padding: 0 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 0.82rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

/* the two halves share one outline: each keeps only its outer corners rounded */
.actions .secondary {
  border-right: 0;
  border-radius: 12px 0 0 12px;
}

.actions .primary {
  border-radius: 0 12px 12px 0;
}

.icon {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
}

.secondary {
  border: 1px solid var(--accent);
  border-radius: 12px;
  background: rgba(4, 18, 29, 0.72);
  color: var(--accent-bright);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

/* Fine pointers click the board to place and press R to rotate, so the buttons
   would only get in the way. */
@media (pointer: fine) {
  .actions {
    display: none;
  }
}

/* Turn clock: a bar just above the board, clear of the top row. */
.turn {
  position: absolute;
  top: -12px;
  left: 8px;
  right: 8px;
  height: 6px;
  border-radius: 999px;
  background: rgba(4, 18, 29, 0.72);
  border: 1px solid var(--line);
  overflow: hidden;
  pointer-events: none;
}

.turn-fill {
  display: block;
  height: 100%;
  width: 100%;
  background: var(--accent);
  transition: width 120ms linear;
}

.hint {
  margin: 0;
  font-size: 0.85rem;
  color: var(--hint);
  text-align: center;
}

/*
 * `hidden` must win over the layout display rules below: author declarations beat
 * the UA's [hidden] { display: none }, so without these the splash would cover the
 * board forever and the game-over overlay could never hide.
 */
.splash[hidden],
.overlay[hidden] {
  display: none;
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 10px;
  padding: 20px;
  text-align: center;
  background: rgba(4, 18, 29, 0.88);
  border-radius: 12px;
}

.overlay h2 {
  margin: 0;
  font-size: 1.3rem;
  color: var(--accent-bright);
}

.primary {
  border: 0;
  border-radius: 12px;
  padding: 10px 22px;
  font: inherit;
  font-weight: 700;
  background: var(--accent);
  color: var(--accent-ink);
  cursor: pointer;
}

.splash {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 10px;
  text-align: center;
  background: rgba(4, 18, 29, 0.9);
  border-radius: 12px;
  cursor: pointer;
}

.splash-title {
  margin: 0;
  font-size: 1.7rem;
  letter-spacing: 0.06em;
  color: var(--accent-bright);
}

.splash-tag,
.splash-hint {
  margin: 0;
  font-size: 0.85rem;
  color: var(--text-soft);
}

.about {
  width: 100%;
  font-size: 0.9rem;
  color: var(--text-soft);
}

.about h2 {
  margin: 0 0 6px;
  font-size: 1rem;
  color: var(--accent-bright);
}

.about ul {
  margin: 8px 0 0;
  padding-left: 18px;
}

.about h3 {
  margin: 14px 0 0;
  font-size: 0.95rem;
  color: var(--accent);
}

.legend {
  padding: 0;
  list-style: none;
  display: grid;
  gap: 8px;
}

.legend li {
  display: grid;
  grid-template-columns: 48px 1fr;
  gap: 10px;
  align-items: center;
}

.legend canvas {
  width: 48px;
  height: 48px;
  image-rendering: pixelated;
}

.legend strong {
  color: var(--text-soft);
}

@media (prefers-reduced-motion: reduce) {
  .turn-fill {
    transition: none;
  }
}
