/*
 * The board uses the original game's three result colours: white for a miss,
 * dark blue for a body square and red for a cockpit. Type is B612, the face
 * Airbus commissioned for cockpit displays.
 *
 * Light mode is the daytime "find the cockpits" game. Dark mode is the
 * "avoid the cockpits" game and repaints the same page as a night scene.
 */
:root {
  --page: #e9eff3;
  --surface: #ffffff;
  --ink: #13283b;
  --muted: #4d6274;
  --rule: #c9d6df;
  --unshot: #7d8b97;
  --unshot-hover: #8f9ca7;
  --unshot-edge: rgba(19, 40, 59, 0.22);
  --miss: #ffffff;
  --miss-edge: #c9d6df;
  --body: #17467f;
  --head: #d62839;
  --button-bg: #13283b;
  --button-fg: #ffffff;
  --ready-bg: #f0b429;
  --ready-fg: #13283b;
  --flypast: #f0b429;
  --error: #b3202f;
  --gap: clamp(3px, 0.9vw, 6px);
  --pad: clamp(6px, 1.6vw, 12px);
  --label: 1.6rem;
}

:root[data-mode="dark"] {
  --page: #090b12;
  --surface: #131625;
  --ink: #dcdde6;
  --muted: #8f94ac;
  --rule: #262b3f;
  --unshot: #1f2335;
  --unshot-hover: #2c3048;
  --unshot-edge: rgba(0, 0, 0, 0.55);
  --miss: #e9e4d6;
  --miss-edge: transparent;
  --body: #3f74d6;
  --head: #e0263c;
  --button-bg: #dcdde6;
  --button-fg: #090b12;
  --ready-bg: #e0263c;
  --ready-fg: #ffffff;
  --flypast: #e9e4d6;
  --error: #ff7a88;
  color-scheme: dark;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--page);
  color: var(--ink);
  font-family: "B612", "Segoe UI", system-ui, sans-serif;
  font-size: 1rem;
  line-height: 1.5;
}

.page {
  position: relative;
  z-index: 1;
  max-width: 62rem;
  margin: 0 auto;
  padding: 2.5rem 1.25rem 2rem;
}

button {
  font: inherit;
  color: inherit;
}

button:focus-visible,
input:focus-visible,
a:focus-visible {
  outline: 3px solid var(--ink);
  outline-offset: 2px;
}

/* Masthead */

.masthead {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1.25rem 1.5rem;
  flex-wrap: wrap;
  padding-bottom: 1.5rem;
  border-bottom: 2px solid var(--ink);
}

h1 {
  margin: 0;
  font-size: clamp(2rem, 6vw, 3rem);
  line-height: 1.05;
  letter-spacing: -0.02em;
}

.brief {
  margin: 0.6rem 0 0;
  max-width: 30rem;
  color: var(--muted);
}

.toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.icon-button,
.pill-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  height: 2.9rem;
  border: 2px solid var(--ink);
  border-radius: 999px;
  background: transparent;
  cursor: pointer;
  transition: background-color 0.2s, color 0.2s;
}

.icon-button {
  width: 2.9rem;
  padding: 0;
}

.pill-button {
  padding: 0 1rem 0 0.8rem;
  max-width: 12rem;
}

.pill-button span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.icon-button:hover,
.pill-button:hover {
  background: var(--ink);
  color: var(--page);
}

.toolbar svg,
.sheet-close svg {
  flex: none;
  width: 1.3rem;
  height: 1.3rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* The toggle shows where it will take you: a moon by day, a sun by night. */
.icon-sun,
:root[data-mode="dark"] .icon-moon {
  display: none;
}

:root[data-mode="dark"] .icon-sun {
  display: block;
}

.new-game {
  height: 2.9rem;
  padding: 0 1.3rem;
  font-weight: 700;
  border: 2px solid var(--button-bg);
  border-radius: 999px;
  background: var(--button-bg);
  color: var(--button-fg);
  cursor: pointer;
  transition: background-color 0.2s, color 0.2s;
}

.new-game:hover {
  background: var(--body);
  border-color: var(--body);
  color: #ffffff;
}

.new-game.is-ready {
  background: var(--ready-bg);
  color: var(--ready-fg);
  border-color: var(--ink);
}

/* Layout */

.layout {
  display: grid;
  grid-template-columns: minmax(0, 34rem) minmax(0, 1fr);
  gap: 2.5rem;
  padding-top: 2rem;
  align-items: start;
}

/* Board */

.field {
  display: grid;
  grid-template-columns: var(--label) minmax(0, 1fr);
  grid-template-rows: var(--label) auto;
}

.cols,
.rows {
  display: grid;
  gap: var(--gap);
  color: var(--muted);
  font-size: 0.8rem;
  text-align: center;
}

.cols {
  grid-column: 2;
  grid-template-columns: repeat(10, minmax(0, 1fr));
  padding: 0 var(--pad);
}

.rows {
  grid-row: 2;
  grid-template-rows: repeat(10, minmax(0, 1fr));
  padding: var(--pad) 0;
  align-items: center;
}

.board {
  position: relative;
  grid-row: 2;
  grid-column: 2;
  display: grid;
  grid-template-columns: repeat(10, minmax(0, 1fr));
  grid-template-rows: repeat(10, minmax(0, 1fr));
  gap: var(--gap);
  padding: var(--pad);
  aspect-ratio: 1;
  overflow: hidden;
  container-type: inline-size;
}

.cell {
  position: relative;
  padding: 0;
  border: 0;
  border-radius: 24%;
  background: var(--unshot);
  box-shadow: inset 0 -3px 0 var(--unshot-edge);
  cursor: pointer;
  transition: transform 0.12s ease-out, background-color 0.15s;
}

.cell[data-state="hidden"]:hover {
  transform: translateY(-2px);
  background: var(--unshot-hover);
}

.cell[data-state="hidden"]:active {
  transform: scale(0.92);
}

.cell:not([data-state="hidden"]) {
  cursor: default;
  box-shadow: none;
}

/* White on a pale page needs an edge to read as a square. */
.cell[data-state="miss"] {
  background: var(--miss);
  box-shadow: inset 0 0 0 1.5px var(--miss-edge);
}

.cell[data-state="body"] {
  background: var(--body);
}

.cell[data-state="head"] {
  background: var(--head);
}

.cell.is-revealed {
  animation: reveal 0.28s ease-out both;
  animation-delay: var(--delay, 0ms);
}

.cell.is-celebrating {
  animation: salute 0.6s ease-in-out both;
  animation-delay: var(--delay, 0ms);
}

@keyframes reveal {
  from { transform: scale(0.55); opacity: 0.3; }
  to { transform: none; opacity: 1; }
}

@keyframes salute {
  0%, 100% { transform: none; }
  45% { transform: scale(1.18); }
}

/* Winning fly-past: one aircraft crosses the board, trailing vapour. */

.flypast {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.flypast-plane {
  position: absolute;
  left: -15%;
  top: 78%;
  width: 13%;
  transform: translate(-50%, -50%) rotate(-25deg);
  animation: flypast 1.9s cubic-bezier(0.35, 0.1, 0.4, 1) 0.35s both;
}

.flypast-plane svg {
  display: block;
  width: 100%;
  height: auto;
  fill: var(--flypast);
  filter: drop-shadow(0 3px 0 rgba(19, 40, 59, 0.3));
}

.flypast-plane::before {
  content: "";
  position: absolute;
  right: 88%;
  top: 50%;
  width: 420%;
  height: 8%;
  transform: translateY(-50%);
  border-radius: 999px;
  background: linear-gradient(to left, var(--flypast), transparent);
}

@keyframes flypast {
  from { left: -15%; top: 78%; }
  to { left: 118%; top: 16%; }
}

.status {
  min-height: 3em;
  margin: 1rem 0 0 var(--label);
  font-weight: 700;
}

/* Side panel */

.counts {
  display: grid;
  grid-template-columns: repeat(3, auto);
  justify-content: start;
  gap: 1rem 2rem;
  margin: 0;
}

.counts dt {
  color: var(--muted);
  font-size: 0.875rem;
}

.counts dd {
  margin: 0;
  font-size: 2rem;
  font-weight: 700;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.counts dd.is-empty {
  font-size: 1rem;
  font-weight: 400;
  line-height: 2.4;
  color: var(--muted);
}

.chart {
  margin-top: 1.75rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--rule);
}

.chart h2 {
  margin: 0;
  font-size: 1.125rem;
}

.chart p {
  margin: 0.4rem 0 0;
  color: var(--muted);
  font-size: 0.9375rem;
  max-width: 30rem;
}

.shapes {
  display: flex;
  flex-wrap: wrap;
  gap: 1.25rem 0.75rem;
  margin: 1.25rem 0 0;
  padding: 0;
  list-style: none;
}

.shapes li {
  min-width: 6.75rem;
}

.shape-grid {
  display: grid;
  grid-template-columns: repeat(5, 13px);
  grid-auto-rows: 13px;
  gap: 2px;
  height: 73px; /* five rows, so the names line up under shorter shapes */
}

.shape-grid i {
  border-radius: 3px;
  background: var(--body);
}

.shape-grid i.is-head {
  background: var(--head);
}

.shape-name {
  display: block;
  margin-top: 0.6rem;
  font-weight: 700;
}

.shape-meta {
  display: block;
  color: var(--muted);
  font-size: 0.875rem;
}

.key {
  display: grid;
  gap: 0.45rem;
  margin: 1.75rem 0 0;
  padding: 1.5rem 0 0;
  border-top: 1px solid var(--rule);
  list-style: none;
  font-size: 0.9375rem;
}

.key li {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.swatch {
  flex: none;
  width: 1.15rem;
  height: 1.15rem;
  border-radius: 24%;
}

.swatch-hidden {
  background: var(--unshot);
  box-shadow: inset 0 -2px 0 var(--unshot-edge);
}

.swatch-miss {
  background: var(--miss);
  box-shadow: inset 0 0 0 1.5px var(--miss-edge);
}

.swatch-body {
  background: var(--body);
}

.swatch-head {
  background: var(--head);
}

.credits {
  margin-top: 3rem;
  padding-top: 1rem;
  border-top: 1px solid var(--rule);
  color: var(--muted);
  font-size: 0.875rem;
}

.credits p {
  margin: 0;
}

a {
  color: var(--body);
}

/* Dialogs: account and leaderboard */

.sheet {
  width: min(26rem, calc(100vw - 2rem));
  max-height: calc(100vh - 2rem);
  padding: 1.75rem 1.5rem 1.5rem;
  border: 2px solid var(--ink);
  border-radius: 18px;
  background: var(--surface);
  color: var(--ink);
}

.sheet::backdrop {
  background: rgba(9, 14, 22, 0.6);
}

.sheet h2 {
  margin: 0;
  padding-right: 2.5rem;
  font-size: 1.5rem;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.sheet-lede {
  margin: 0.4rem 0 0;
  color: var(--muted);
}

.sheet-close {
  position: absolute;
  top: 0.9rem;
  right: 0.9rem;
  display: grid;
  place-items: center;
  width: 2.4rem;
  height: 2.4rem;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
}

.sheet-close:hover {
  background: var(--rule);
}

.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  margin-top: 1.25rem;
  padding: 4px;
  border-radius: 999px;
  background: var(--rule);
}

.tabs button {
  padding: 0.5rem;
  border: 0;
  border-radius: 999px;
  background: transparent;
  font-weight: 700;
  cursor: pointer;
}

.tabs button[aria-selected="true"] {
  background: var(--surface);
}

#account-form {
  display: grid;
  margin-top: 1.25rem;
}

#account-form label {
  font-weight: 700;
  font-size: 0.9375rem;
}

#account-form input {
  margin: 0.3rem 0 1rem;
  padding: 0.7rem 0.8rem;
  border: 2px solid var(--muted);
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
}

.field-hint {
  margin: -0.5rem 0 1rem;
  color: var(--muted);
  font-size: 0.875rem;
}

.form-error {
  margin: 0 0 1rem;
  color: var(--error);
  font-weight: 700;
}

.form-error[hidden],
.field-hint[hidden] {
  display: none;
}

.primary,
.secondary {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 2px solid var(--button-bg);
  border-radius: 999px;
  font-weight: 700;
  cursor: pointer;
}

.primary {
  background: var(--button-bg);
  color: var(--button-fg);
}

.primary[disabled] {
  opacity: 0.6;
  cursor: progress;
}

.secondary {
  margin-top: 0.75rem;
  background: transparent;
}

.secondary:hover {
  background: var(--rule);
}

#account-signed-in .secondary {
  margin-top: 1.5rem;
}

.board-message {
  margin: 1.25rem 0 0;
  color: var(--muted);
}

.board-message:empty {
  display: none;
}

.ranks {
  margin: 1rem 0 0;
  padding: 0;
  list-style: none;
  max-height: 22rem;
  overflow-y: auto;
}

.ranks li {
  display: grid;
  grid-template-columns: 2.25rem minmax(0, 1fr) auto;
  align-items: baseline;
  gap: 0.5rem;
  padding: 0.55rem 0.5rem;
  border-top: 1px solid var(--rule);
  font-variant-numeric: tabular-nums;
}

.ranks li:first-child {
  border-top: 0;
}

.ranks .rank {
  color: var(--muted);
}

.ranks .who {
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ranks li.is-you {
  border-radius: 10px;
  background: var(--rule);
}

#leaderboard-note {
  margin: 1rem 0 0;
}

/* ---------- Play a friend: lobby ---------- */

.friend-button {
  border-color: var(--head);
  background: var(--head);
  color: #ffffff;
}

.friend-button:hover {
  border-color: var(--ink);
}

.room-sheet {
  width: min(28rem, calc(100vw - 2rem));
}

.room-name {
  display: grid;
  gap: 0.3rem;
  margin-top: 1.25rem;
}

.room-name label,
.room-label {
  margin: 0;
  font-weight: 700;
  font-size: 0.9375rem;
}

.room-name input {
  padding: 0.6rem 0.8rem;
  border: 2px solid var(--muted);
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
}

.room-signed-in {
  margin: 1rem 0 0;
  color: var(--muted);
  font-size: 0.9375rem;
}

.room-host {
  margin-top: 1.25rem;
  padding: 1.1rem 1rem 1rem;
  border-radius: 14px;
  background: var(--page);
}

.room-host.is-collapsed {
  display: none;
}

.code-tiles {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.6rem;
}

.code-tile {
  display: grid;
  place-items: center;
  width: 3.4rem;
  height: 4rem;
  border: 2px solid var(--ink);
  border-radius: 12px;
  background: var(--surface);
  font-size: 2rem;
  font-weight: 700;
  line-height: 1;
  animation: tile-in 0.3s ease-out both;
}

.code-tile:nth-child(2) { animation-delay: 50ms; }
.code-tile:nth-child(3) { animation-delay: 100ms; }
.code-tile:nth-child(4) { animation-delay: 150ms; }

.code-tile.is-empty {
  border-style: dashed;
  border-color: var(--muted);
  animation: tile-wait 1.2s ease-in-out infinite;
}

@keyframes tile-in {
  from { transform: translateY(6px); opacity: 0; }
  to { transform: none; opacity: 1; }
}

@keyframes tile-wait {
  50% { opacity: 0.4; }
}

.code-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  margin-top: 0.85rem;
}

.code-actions .secondary,
.place-actions .secondary {
  margin-top: 0;
  padding: 0.55rem 0.75rem;
}

.secondary[disabled] {
  opacity: 0.5;
  cursor: default;
}

.room-wait {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  min-height: 1.5em;
  margin: 0.85rem 0 0;
  color: var(--muted);
  font-size: 0.9375rem;
}

.wait-dot {
  flex: none;
  width: 0.6rem;
  height: 0.6rem;
  border-radius: 50%;
  background: var(--body);
  animation: wait-dot 1.4s ease-in-out infinite;
}

@keyframes wait-dot {
  0%, 100% { transform: scale(0.7); opacity: 0.5; }
  50% { transform: scale(1.15); opacity: 1; }
}

.make-own {
  margin-top: 1.25rem;
}

.or-rule {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin: 1.25rem 0 1rem;
  color: var(--muted);
  font-size: 0.875rem;
}

.or-rule::before,
.or-rule::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--rule);
}

.code-inputs {
  display: flex;
  gap: 0.5rem;
  margin: 0.6rem 0 1rem;
}

.code-inputs input {
  width: 3.4rem;
  height: 4rem;
  padding: 0;
  border: 2px solid var(--muted);
  border-radius: 12px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 2rem;
  font-weight: 700;
  text-align: center;
  text-transform: uppercase;
}

.code-inputs input:focus {
  border-color: var(--ink);
}

/* ---------- Play a friend: match screen ---------- */

.match {
  padding-top: 1.5rem;
}

.match[hidden],
body.in-match .layout,
body.in-match #new-game,
body.in-match #open-room {
  display: none;
}

.match-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.match-who {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  min-width: 0;
}

.room-chip {
  padding: 0.3rem 0.75rem;
  border-radius: 999px;
  background: var(--rule);
  font-size: 0.875rem;
}

.room-chip b {
  letter-spacing: 0.12em;
}

.match-vs {
  font-weight: 700;
  overflow-wrap: anywhere;
}

.match-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 1.25rem;
}

.match-title {
  margin: 0;
  font-size: clamp(1.4rem, 4vw, 2rem);
  line-height: 1.15;
}

.match-clock {
  margin: 0;
  font-size: clamp(1.6rem, 5vw, 2.4rem);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.match-clock.is-low {
  color: var(--head);
  animation: clock-low 1s steps(2, jump-none) infinite;
}

@keyframes clock-low {
  50% { opacity: 0.55; }
}

.match-layout {
  display: grid;
  grid-template-columns: minmax(0, 34rem) minmax(0, 1fr);
  gap: 2.5rem;
  padding-top: 1rem;
  align-items: start;
}

.board-title {
  margin: 0 0 0.5rem var(--label);
  color: var(--muted);
  font-size: 0.9375rem;
}

#match-board {
  touch-action: manipulation;
}

#match-board.is-locked .cell {
  cursor: default;
}

#match-board.is-locked .cell[data-state="hidden"]:hover {
  transform: none;
  background: var(--unshot);
}

[data-phase="placing"] #match-board {
  touch-action: none;
}

[data-phase="placing"] #match-board .cell.is-mine {
  cursor: grab;
}

[data-phase="placing"] #match-board.is-locked .cell.is-mine {
  cursor: default;
}

.cell.is-drop-ok {
  box-shadow: inset 0 0 0 3px #2f9e5b;
  background: color-mix(in srgb, var(--unshot) 55%, #2f9e5b);
}

.cell.is-drop-bad {
  box-shadow: inset 0 0 0 3px var(--head);
}

.cell.is-mine.is-drop-bad {
  background: color-mix(in srgb, var(--head) 55%, var(--unshot));
}

.cell.is-pending {
  animation: wait-dot 0.8s ease-in-out infinite;
}

/* Aircraft squares you never found, shown after the round as outlines. */
.cell.is-unfound[data-state] {
  background: var(--unshot);
  box-shadow: inset 0 0 0 3px var(--body);
}

.cell.is-unfound[data-state="head"] {
  box-shadow: inset 0 0 0 3px var(--head);
}

.drag-ghost {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 20;
  pointer-events: none;
  opacity: 0.8;
  filter: drop-shadow(0 8px 14px rgba(0, 0, 0, 0.3));
}

.drag-ghost i {
  position: absolute;
  border-radius: 24%;
  background: var(--body);
}

.drag-ghost i.is-head {
  background: var(--head);
}

.side-lede {
  margin: 0;
  color: var(--muted);
  max-width: 30rem;
}

.hangar {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.6rem;
  margin: 1.25rem 0 0;
  padding: 0;
  list-style: none;
}

.hangar-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  height: 100%;
  padding: 0.85rem 0.4rem 0.7rem;
  border: 2px solid var(--rule);
  border-radius: 14px;
  background: var(--surface);
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  transition: border-color 0.15s, opacity 0.15s;
}

.hangar-item:hover:not([disabled]):not(.is-used) {
  border-color: var(--ink);
}

.hangar-item.is-used,
.hangar-item.is-unavailable,
.hangar-item[disabled] {
  cursor: default;
  opacity: 0.45;
}

.hangar-shape {
  display: grid;
  grid-template-columns: repeat(5, 14px);
  grid-auto-rows: 14px;
  gap: 2px;
  height: 78px;
}

.hangar-shape i {
  border-radius: 3px;
  background: var(--body);
}

.hangar-shape i.is-head {
  background: var(--head);
}

.hangar-name {
  margin-top: 0.5rem;
  font-weight: 700;
}

.hangar-tag {
  min-height: 1.4em;
  color: var(--muted);
  font-size: 0.75rem;
  text-align: center;
}

.place-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  margin: 1rem 0 0.75rem;
}

.opp-line {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  margin: 1rem 0 0;
  color: var(--muted);
}

.opp-line::before {
  content: "";
  width: 0.6rem;
  height: 0.6rem;
  border-radius: 50%;
  background: var(--muted);
  animation: wait-dot 1.4s ease-in-out infinite;
}

.opp-line.is-ready {
  color: var(--ink);
  font-weight: 700;
}

.opp-line.is-ready::before {
  background: #2f9e5b;
  animation: none;
}

.duel {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin: 0;
}

.duel > div {
  padding: 0.85rem 1rem;
  border: 2px solid var(--rule);
  border-radius: 14px;
}

.duel > div.is-done {
  border-color: #2f9e5b;
}

.duel dt {
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.duel dd {
  margin: 0;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.duel dd b {
  color: var(--ink);
  font-size: 1.75rem;
}

.match-shapes {
  margin-top: 0.5rem;
}

.match-shapes li {
  min-width: 0;
}

.match-shapes .shape-name {
  margin-top: 0.3rem;
  font-size: 0.875rem;
}

.mini-title {
  margin: 1.5rem 0 0.5rem;
  color: var(--muted);
  font-size: 0.9375rem;
}

.mini-board {
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  gap: 3px;
  width: min(100%, 15rem);
  aspect-ratio: 1;
}

.mini-cell {
  position: relative;
  border-radius: 22%;
  background: var(--unshot);
}

.mini-cell[data-state="miss"] { background: var(--miss); box-shadow: inset 0 0 0 1px var(--miss-edge); }
.mini-cell[data-state="body"] { background: var(--body); }
.mini-cell[data-state="head"] { background: var(--head); }

.mini-cell.is-hit::after {
  content: "";
  position: absolute;
  inset: 22%;
  border-radius: 50%;
  background: #ffffff;
}

.result-title {
  margin: 0;
  font-size: clamp(2.2rem, 7vw, 3.2rem);
  font-weight: 700;
  line-height: 1.05;
  animation: tile-in 0.4s ease-out both;
}

.result[data-outcome="won"] .result-title { color: #2f9e5b; }
.result[data-outcome="lost"] .result-title { color: var(--head); }

#result-detail p {
  margin: 0.6rem 0 0;
  color: var(--muted);
}

.result-scores {
  display: grid;
  gap: 0.35rem;
  margin: 1rem 0 0;
}

.result-scores div {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.5rem 0.75rem;
  border-radius: 10px;
  background: var(--page);
}

.result-scores dt { font-weight: 700; }
.result-scores dd { margin: 0; }

.result-saved {
  min-height: 1.5em;
  margin: 1rem 0;
  font-weight: 700;
}

.result-saved:empty {
  margin: 0.5rem 0;
}

/* ---------- Dark mode: the night game ---------- */

/* Fog drifting behind the page, and darkness closing in at the edges. */
:root[data-mode="dark"] body::before,
:root[data-mode="dark"] body::after {
  content: "";
  position: fixed;
  inset: -10%;
  pointer-events: none;
}

:root[data-mode="dark"] body::before {
  background:
    radial-gradient(60rem 28rem at 18% 12%, rgba(104, 116, 190, 0.17), transparent 62%),
    radial-gradient(48rem 26rem at 86% 74%, rgba(160, 36, 60, 0.13), transparent 62%),
    radial-gradient(40rem 20rem at 60% 40%, rgba(200, 205, 230, 0.05), transparent 60%);
  animation: fog 36s ease-in-out infinite alternate;
}

:root[data-mode="dark"] body::after {
  background: radial-gradient(ellipse at 50% 42%, transparent 48%, rgba(0, 0, 0, 0.72));
  transition: background 0.6s;
}

/* Losing leaves the edges of the page red. */
:root[data-mode="dark"][data-outcome="lost"] body::after {
  background: radial-gradient(ellipse at 50% 42%, transparent 34%, rgba(128, 0, 18, 0.6));
}

@keyframes fog {
  from { transform: translate3d(-3%, -1%, 0) scale(1); }
  to { transform: translate3d(4%, 2%, 0) scale(1.08); }
}

:root[data-mode="dark"] h1 {
  font-family: "Creepster", "B612", system-ui, sans-serif;
  font-weight: 400;
  font-size: clamp(2.6rem, 8vw, 4rem);
  letter-spacing: 0.03em;
  color: var(--miss);
  text-shadow: 0 0 18px rgba(224, 38, 60, 0.55), 0 0 2px rgba(224, 38, 60, 0.9);
  animation: flicker 7s linear infinite;
}

/* A failing bulb: steady most of the time, then two quick dips. */
@keyframes flicker {
  0%, 86%, 89%, 92%, 100% { opacity: 1; }
  87.5% { opacity: 0.35; }
  90.5% { opacity: 0.6; }
}

:root[data-mode="dark"] .cell[data-state="hidden"]:hover {
  box-shadow: inset 0 0 0 1.5px rgba(224, 38, 60, 0.55), 0 0 12px rgba(224, 38, 60, 0.25);
}

:root[data-mode="dark"] .cell[data-state="head"] {
  animation: reveal 0.28s ease-out both, pulse 1.6s ease-in-out 0.3s infinite;
  animation-delay: var(--delay, 0ms), calc(var(--delay, 0ms) + 0.3s);
}

:root[data-mode="dark"] .cell[data-state="head"]::after {
  content: "\2620";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #12060a;
  font-size: 5.6cqw;
  line-height: 1;
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 6px 0 rgba(224, 38, 60, 0.5); }
  50% { box-shadow: 0 0 18px 4px rgba(224, 38, 60, 0.85); }
}

:root[data-mode="dark"][data-outcome="lost"] .status {
  color: var(--error);
}

:root[data-mode="dark"] .flypast-plane {
  opacity: 0.75;
}

:root[data-mode="dark"] .flypast-plane svg {
  filter: drop-shadow(0 0 10px rgba(233, 228, 214, 0.8));
}

/* A cockpit hit in dark mode jolts the page and flashes it red. */
.page.is-jolted {
  animation: jolt 0.45s cubic-bezier(0.36, 0.07, 0.19, 0.97);
}

@keyframes jolt {
  10%, 90% { transform: translate3d(-2px, 0, 0); }
  20%, 80% { transform: translate3d(5px, -1px, 0); }
  30%, 50%, 70% { transform: translate3d(-8px, 2px, 0); }
  40%, 60% { transform: translate3d(8px, -2px, 0); }
}

.blood-flash {
  position: fixed;
  inset: 0;
  z-index: 5;
  pointer-events: none;
  background: radial-gradient(ellipse at center, rgba(224, 38, 60, 0.15), rgba(160, 0, 20, 0.7));
  animation: blood-flash 0.7s ease-out forwards;
}

@keyframes blood-flash {
  from { opacity: 1; }
  to { opacity: 0; }
}

/* ---------- Small screens and reduced motion ---------- */

@media (max-width: 52rem) {
  .layout {
    grid-template-columns: minmax(0, 1fr);
    gap: 2rem;
  }

  .play,
  .match-main {
    max-width: 34rem;
  }

  .match-layout {
    grid-template-columns: minmax(0, 1fr);
    gap: 1.5rem;
  }
}

@media (max-width: 26rem) {
  :root {
    --label: 1.1rem;
  }

  .page {
    padding: 1.5rem 0.75rem 1.5rem;
  }

  .counts {
    gap: 1rem 1.25rem;
  }

  .toolbar {
    gap: 0.45rem;
  }

  .pill-button {
    padding: 0 0.8rem 0 0.65rem;
    max-width: 9.5rem;
  }

  .code-tile,
  .code-inputs input {
    width: 3rem;
    height: 3.6rem;
    font-size: 1.75rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .cell,
  .new-game,
  .icon-button,
  .pill-button {
    transition: none;
  }

  .cell.is-revealed,
  .cell.is-celebrating,
  .page.is-jolted,
  :root[data-mode="dark"] h1,
  :root[data-mode="dark"] body::before,
  :root[data-mode="dark"] .cell[data-state="head"] {
    animation: none;
  }

  :root[data-mode="dark"] .cell[data-state="head"] {
    box-shadow: 0 0 12px 2px rgba(224, 38, 60, 0.7);
  }

  .blood-flash {
    display: none;
  }

  .code-tile,
  .wait-dot,
  .opp-line::before,
  .match-clock.is-low,
  .result-title,
  .cell.is-pending {
    animation: none;
  }
}
