/*
 * NavalGame: a harbour-poster look built on the International Code of Signals.
 * Flat blocks, black rules, no gradients, no shadows, no rounded corners.
 * Every text colour pair below meets WCAG AA; yellow is only ever a fill behind ink.
 */

@font-face {
  font-family: "Barlow";
  font-weight: 400;
  font-display: swap;
  src: url("/fonts/barlow-400.woff2") format("woff2");
}

@font-face {
  font-family: "Barlow";
  font-weight: 600;
  font-display: swap;
  src: url("/fonts/barlow-600.woff2") format("woff2");
}

@font-face {
  font-family: "Barlow Condensed";
  font-weight: 600;
  font-display: swap;
  src: url("/fonts/barlow-condensed-600.woff2") format("woff2");
}

@font-face {
  font-family: "Barlow Condensed";
  font-weight: 800;
  font-display: swap;
  src: url("/fonts/barlow-condensed-800.woff2") format("woff2");
}

:root {
  color-scheme: light;
  --paper: #f7f5f0;
  --surface: #ffffff;
  --ink: #111111;
  --ink-soft: #454545;
  --red: #d6231d;
  --yellow: #f4c20d;
  --blue: #1d4e9e;
  --link: #1d4e9e;
  /* Text on signal fills never changes with the theme. */
  --on-signal: #111111;
  --flag-white: #ffffff;
  --flag-blue: #1d4e9e;
  --on-red: var(--flag-white);
  --danger-bg: #fdecea;
  --line-soft: #d9d5cc;
  --rule: 2px solid var(--ink);
  --hairline: 1px solid var(--ink);
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --space-12: 3rem;
  /*
   * 10 cells + labels must fit a 320px phone: that caps the minimum at 24px. On a phone held
   * sideways the height is the limit, so a whole board fits the screen.
   */
  --cell: clamp(24px, min(8vw, var(--cell-by-height)), 40px);
  /* The largest cell that still lets a whole board (11 rows with labels) fit the screen height. */
  --screen-height: 100vh;
  --cell-by-height: calc((var(--screen-height) - 5rem) / 11);
  --font-body: "Barlow", "Arial Narrow", Arial, sans-serif;
  --font-display: "Barlow Condensed", "Arial Narrow", Arial, sans-serif;
  --z-topbar: 10;
  --z-notice: 20;
  --cross: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 10'%3E%3Cpath d='M1.5 1.5l7 7M8.5 1.5l-7 7' stroke='%23000' stroke-width='1.6'/%3E%3C/svg%3E");
}

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

/* Night signals: same flags and fills, light ink on a dark hull. Set by js/theme-init.js. */
:root[data-theme="dark"] {
  color-scheme: dark;
  --paper: #141414;
  --surface: #1f1f1f;
  --ink: #f2efe7;
  --ink-soft: #b8b3a7;
  --blue: #3d74d6;
  --link: #8fb3ff;
  --danger-bg: #3a1614;
  --line-soft: #3a3a3a;
}

/* Screens set their own display; `hidden` must still win. */
[hidden] {
  display: none !important;
}

html {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 100%;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  /* Mobile browsers' toolbars come and go: size to the viewport left with them shown. */
  min-height: 100svh;
  display: flex;
  flex-direction: column;
}

main {
  flex: 1;
  width: 100%;
  max-width: 76rem;
  margin: 0 auto;
  padding: var(--space-6) var(--space-4) var(--space-12);
  outline: none;
}

h1,
h2 {
  font-family: var(--font-display);
  font-weight: 800;
  line-height: 0.95;
  letter-spacing: -0.01em;
  margin: 0 0 var(--space-4);
}

h1 {
  font-size: clamp(2.5rem, 7vw, 4.5rem);
}

h2 {
  font-size: 1.5rem;
}

p {
  margin: 0 0 var(--space-3);
}

a {
  color: var(--link);
  text-decoration-thickness: 2px;
  text-underline-offset: 3px;
}

kbd {
  font-family: var(--font-display);
  font-weight: 600;
  border: var(--hairline);
  padding: 0 0.35em;
  background: var(--surface);
}

.muted {
  color: var(--ink-soft);
}

.kicker {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: var(--space-2);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.skip-link {
  position: absolute;
  left: var(--space-4);
  top: -4rem;
  z-index: var(--z-notice);
  padding: var(--space-2) var(--space-4);
  background: var(--yellow);
  color: var(--on-signal);
  border: var(--rule);
  font-weight: 600;
}

.skip-link:focus {
  top: var(--space-2);
}

:focus-visible {
  outline: 3px solid var(--blue);
  outline-offset: 3px;
}

/* Top bar and footer */
.topbar {
  position: sticky;
  top: 0;
  z-index: var(--z-topbar);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-3) var(--space-4);
  background: var(--paper);
  border-bottom: var(--rule);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: var(--space-3);
  min-height: 44px;
  color: var(--ink);
  text-decoration: none;
}

.flag-hoist {
  display: inline-flex;
  gap: 3px;
}

.flag {
  width: 27px;
  height: 18px;
  outline: 1px solid var(--ink);
}

.wordmark {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.6rem;
  line-height: 1;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.wordmark-light {
  font-weight: 600;
  margin-left: 0.15em;
}

.topbar-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-3);
  margin-left: auto;
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 44px;
  padding: var(--space-1) var(--space-3);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1rem;
  color: var(--ink);
  background: var(--surface);
  border: var(--rule);
  border-radius: 0;
  cursor: pointer;
}

/*
 * Touch screens keep a hover state after a tap: hover effects only where some pointer can hover
 * (a mouse, or a trackpad on a tablet, which `hover: hover` would miss).
 */
@media (any-hover: hover) {
  .theme-toggle:hover {
    background: var(--yellow);
    color: var(--on-signal);
  }
}

.theme-toggle-icon {
  width: 18px;
  height: 18px;
}

/* In dark mode the icon flips, so the control shows the state it is in. */
.theme-toggle[aria-pressed="true"] .theme-toggle-icon {
  transform: rotate(180deg);
}

.connection-status {
  margin: 0;
  padding: var(--space-1) var(--space-3);
  background: var(--yellow);
  color: var(--on-signal);
  border: var(--hairline);
  font-weight: 600;
}

.footer {
  border-top: var(--rule);
  padding: var(--space-4);
  font-size: 0.9rem;
}

.footer p {
  max-width: 76rem;
  margin: 0 auto;
}

/* Panels, fields, buttons */
.panel {
  background: var(--surface);
  border: var(--rule);
  padding: var(--space-6);
}

.panel-title {
  font-size: 1.1rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
  border-bottom: var(--rule);
  padding-bottom: var(--space-2);
  margin-bottom: var(--space-4);
}

.field {
  display: grid;
  gap: var(--space-1);
  margin-bottom: var(--space-4);
}

.field-label {
  font-weight: 600;
}

.field-hint {
  color: var(--ink-soft);
  font-size: 0.9rem;
  margin: 0;
}

input {
  width: 100%;
  min-height: 48px;
  padding: var(--space-2) var(--space-3);
  font: inherit;
  font-size: 1.1rem;
  color: var(--ink);
  background: var(--surface);
  border: var(--rule);
  border-radius: 0;
}

input[aria-invalid="true"] {
  border-color: var(--red);
  background: var(--danger-bg);
}

.code-input {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.5rem;
  text-transform: uppercase;
  letter-spacing: 0.3em;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: 48px;
  padding: var(--space-2) var(--space-6);
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.15rem;
  letter-spacing: 0.03em;
  color: var(--ink);
  background: var(--surface);
  border: var(--rule);
  border-radius: 0;
  cursor: pointer;
  transition: background-color 120ms linear, color 120ms linear;
}

@media (any-hover: hover) {
  .button:hover:not(:disabled) {
    background: var(--yellow);
    color: var(--on-signal);
  }
}

.button:active:not(:disabled) {
  transform: translate(1px, 1px);
}

.button-primary {
  background: var(--ink);
  color: var(--paper);
}

.button-ghost {
  justify-self: start;
  padding-inline: 0;
  background: transparent;
  border-color: transparent;
  text-decoration: underline;
  text-underline-offset: 4px;
}

@media (any-hover: hover) {
  .button-ghost:hover:not(:disabled) {
    background: transparent;
    color: var(--ink);
    text-decoration-thickness: 3px;
  }
}

/* Busy but still focusable (aria-disabled): looks unavailable like a disabled button. */
.button[aria-disabled="true"] {
  cursor: progress;
  background: var(--paper);
  color: var(--ink-soft);
  border-style: dashed;
}

.button:disabled {
  cursor: not-allowed;
  background: var(--paper);
  color: var(--ink-soft);
  border-style: dashed;
}

.button-wide {
  width: 100%;
}

.status-line {
  min-height: 1.5em;
  margin: var(--space-3) 0 0;
  font-weight: 600;
}

.result-panel .status-line:empty {
  display: none;
}

.notice {
  position: sticky;
  top: 5rem;
  z-index: var(--z-notice);
  margin-bottom: var(--space-4);
  padding: var(--space-3) var(--space-4);
  background: var(--red);
  color: var(--on-red);
  border: var(--rule);
  font-weight: 600;
}

/* Home */
.home {
  display: grid;
  gap: var(--space-8);
  align-items: start;
}

.home-hero h1 {
  font-size: clamp(3.2rem, 12vw, 7.5rem);
  text-transform: uppercase;
  max-width: 9ch;
}

.lede {
  font-size: 1.2rem;
  max-width: 34rem;
}

.home-panel {
  display: grid;
  gap: var(--space-4);
  max-width: 30rem;
  width: 100%;
}

.join-form {
  display: grid;
  border-top: var(--rule);
  padding-top: var(--space-4);
}

/* From an invite link, joining is the only action: no divider above it. */
.join-form.is-invite {
  border-top: 0;
  padding-top: 0;
}

.rules {
  border-top: var(--rule);
  padding-top: var(--space-2);
  max-width: 44rem;
}

.rules summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  list-style: none;
  min-height: 44px;
  cursor: pointer;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.3rem;
  text-transform: uppercase;
}

/* A flex summary loses the native disclosure triangle, so draw an explicit marker. */
.rules summary::-webkit-details-marker {
  display: none;
}

.rules summary::after {
  content: "+";
  font-size: 1.8rem;
  line-height: 1;
}

.rules[open] summary::after {
  content: "−";
}

.rules ol {
  padding-left: 1.4rem;
}

.rules li {
  margin-bottom: var(--space-2);
}

/* Flag picker: a disclosure over a radio group of the 26 signal flags. */
.flag-picker {
  border: var(--rule);
  background: var(--surface);
}

.flag-picker-summary {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-3);
  min-height: 48px;
  padding: var(--space-2) var(--space-3);
  list-style: none;
  cursor: pointer;
}

.flag-picker-summary::-webkit-details-marker {
  display: none;
}

.flag-picker-summary::after {
  content: "Change";
  margin-left: auto;
  font-family: var(--font-display);
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.flag-picker[open] .flag-picker-summary::after {
  content: "Done";
}

.flag-picker-current {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-weight: 600;
}

.flag-picker-options {
  margin: 0;
  padding: var(--space-3);
  border: 0;
  border-top: var(--rule);
}

.flag-options {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(6.5rem, 1fr));
  gap: var(--space-2);
}

.flag-option {
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 44px;
  padding: var(--space-1) var(--space-2);
  border: var(--hairline);
  font-size: 0.95rem;
  cursor: pointer;
}

/* The radio covers its label: the whole option is the target, the flag is the visible state. */
.flag-option input {
  position: absolute;
  inset: 0;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.flag-option:has(input:checked) {
  background: var(--yellow);
  color: var(--on-signal);
  border-color: var(--on-signal);
  box-shadow: inset 0 0 0 2px var(--on-signal);
}

.flag-option:has(input:focus-visible) {
  outline: 3px solid var(--blue);
  outline-offset: 2px;
}

.flag-option:has(input:disabled) {
  cursor: not-allowed;
  color: var(--ink-soft);
  text-decoration: line-through;
}

.flag-option:has(input:disabled) .flag {
  opacity: 0.4;
}

.flag-inline {
  margin-inline: 0.2em 0.35em;
  vertical-align: -0.15em;
}

/* The flag sits beside the board title, outside the heading, so the heading reads only its title. */
.board-heading {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.board-flag:not(:empty) {
  display: inline-flex;
}

/* Legal pages: a readable single column. */
.legal {
  max-width: 46rem;
}

.legal h2 {
  font-size: 1.6rem;
  margin-top: var(--space-8);
  padding-top: var(--space-4);
  border-top: var(--rule);
}

.legal ul {
  padding-left: 1.3rem;
}

.legal li {
  margin-bottom: var(--space-2);
}

a.button {
  text-decoration: none;
}

/* Lobby */
.lobby {
  max-width: 44rem;
}

.room-code {
  margin: var(--space-6) 0;
}

#lobby-code {
  display: inline-flex;
  gap: var(--space-2);
}

.code-char {
  display: inline-grid;
  place-items: center;
  width: clamp(2rem, 11vw, 4.5rem);
  height: clamp(2.8rem, 14vw, 5.6rem);
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(1.8rem, 8vw, 3.6rem);
  background: var(--surface);
  border: var(--rule);
}

.lobby-actions,
.result-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
}

.signal-lamp {
  display: flex;
  gap: var(--space-2);
  margin: var(--space-8) 0 var(--space-4);
}

.signal-lamp span {
  width: 28px;
  height: 28px;
  border: var(--rule);
  background: var(--surface);
  animation: blink 1.8s steps(1) infinite;
}

.signal-lamp span:nth-child(1) {
  --lamp: var(--red);
}

.signal-lamp span:nth-child(2) {
  --lamp: var(--yellow);
  animation-delay: 0.6s;
}

.signal-lamp span:nth-child(3) {
  --lamp: var(--blue);
  animation-delay: 1.2s;
}

@keyframes blink {
  0% {
    background: var(--lamp);
  }
  33% {
    background: var(--surface);
  }
}

.leave-button {
  margin-top: var(--space-4);
}

.result-actions .leave-button {
  margin-top: 0;
}

/* Placement */
.screen-header {
  margin-bottom: var(--space-6);
  border-bottom: var(--rule);
  padding-bottom: var(--space-2);
}

.placement-layout,
.battle-layout {
  display: grid;
  gap: var(--space-8);
  align-items: start;
}

.placement-panel {
  display: grid;
  gap: var(--space-3);
}

.ship-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: var(--space-2);
}

.ship-button {
  width: 100%;
  justify-content: space-between;
  padding-inline: var(--space-4);
}

.ship-button[aria-pressed="true"] {
  background: var(--yellow);
  color: var(--on-signal);
  box-shadow: inset 0 0 0 2px var(--on-signal);
}

.ship-button.is-placed .ship-name::after {
  content: " · placed";
  font-weight: 600;
}

.ship-dock-art {
  display: inline-block;
  width: calc(var(--len) * 1.15rem);
  height: 1.15rem;
  /* Grabbing the drawing drags the ship; the rest of the button still scrolls the page. */
  touch-action: none;
}

/* On yellow, the hull uses the flag's own dark blue so it keeps 3:1 in both themes. */
.ship-button[aria-pressed="true"] .ship-hull {
  fill: var(--flag-blue);
}

@media (any-hover: hover) {
  .ship-button:hover:not(:disabled) .ship-hull {
    fill: var(--flag-blue);
  }
}

/* Placed ships can be dragged by touch as well. */
.board-placement .cell.state-ship {
  touch-action: none;
}

.placement-actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(6.5rem, 1fr));
  gap: var(--space-2);
}

/* "Rotate: horizontal" is the longest label: in narrow columns it wraps instead of overflowing. */
.placement-actions .button {
  padding-inline: var(--space-2);
  flex-wrap: wrap;
  column-gap: 0.25em;
  text-align: center;
}

/* Boards: each cell draws a 1px ink outline, so the grid reads as ruled paper. */
.board-wrap,
.board-column {
  display: grid;
  justify-items: start;
  gap: var(--space-3);
}

.board-title {
  margin: 0;
  font-size: 1.3rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.board {
  position: relative;
  isolation: isolate;
  display: grid;
  grid-template-columns: calc(var(--cell) * 0.6) repeat(10, var(--cell));
  gap: 1px;
  user-select: none;
  touch-action: manipulation;
}

/* Ships are drawn under the cells: an absolutely positioned grid item over the 10x10 area. */
.ship-layer {
  position: absolute;
  inset: 0;
  grid-row: 2 / span 10;
  grid-column: 2 / span 10;
  pointer-events: none;
}

.ship {
  position: absolute;
  left: calc(var(--col) * 10%);
  top: calc(var(--row) * 10%);
  width: calc(var(--len) * 10%);
  height: 10%;
  background: var(--surface);
}

.ship.is-vertical {
  width: 10%;
  height: calc(var(--len) * 10%);
}

.ship-art {
  display: block;
  width: 100%;
  height: 100%;
}

.ship-hull {
  fill: var(--blue);
}

.ship-deck {
  fill: var(--flag-white);
}

.ship-stripe {
  fill: none;
  stroke: var(--flag-white);
  stroke-width: 0.8;
  stroke-dasharray: 2.5 1.5;
}

/* The selected ship takes the yellow of every other selected state, with signal-ink details. */
.ship.is-selected .ship-hull {
  fill: var(--yellow);
}

.ship.is-selected .ship-deck {
  fill: var(--on-signal);
}

.ship.is-selected .ship-stripe {
  stroke: var(--on-signal);
}

.board-small {
  --cell: clamp(22px, min(5.6vw, var(--cell-by-height)), 32px);
}

.board [role="row"],
.board [role="gridcell"],
.board-header {
  display: contents;
}

.board-label {
  display: grid;
  place-items: center;
  height: calc(var(--cell) * 0.7);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.85rem;
}

.board-label.row-label {
  height: var(--cell);
}

.cell {
  position: relative;
  width: var(--cell);
  height: var(--cell);
  padding: 0;
  background: var(--surface);
  border: 0;
  border-radius: 0;
  outline: 1px solid var(--ink);
  cursor: default;
}

.board.is-interactive .cell:not([aria-disabled="true"]) {
  cursor: crosshair;
}

@media (any-hover: hover) {
  .board.is-interactive .cell:not([aria-disabled="true"]):hover {
    background: var(--yellow);
  }
}

.cell:focus-visible {
  outline: 1px solid var(--ink);
  /* Fixed ink, not the theme's: the focused cell may sit on a yellow preview. */
  box-shadow: inset 0 0 0 3px var(--on-signal), inset 0 0 0 6px var(--yellow);
  z-index: 1;
}

/* An intact ship cell is see-through, so the hull under it shows; hit and sunk paint over it. */
.cell.state-ship {
  background: transparent;
}

.cell-sample.state-ship {
  background: var(--blue);
}

.cell.state-preview-ok {
  background: var(--yellow);
}

.cell.state-preview-bad {
  background: repeating-linear-gradient(45deg, var(--red) 0 4px, var(--surface) 4px 8px);
}

/* Shot markers: a distinct symbol and pattern for each outcome, never colour alone. */
.cell.state-miss::after,
.cell.state-hit::after,
.cell.state-sunk::after,
.cell-sample.state-miss::after,
.cell-sample.state-hit::after,
.cell-sample.state-sunk::after {
  content: "";
  position: absolute;
}

.cell.state-miss::after,
.cell-sample.state-miss::after {
  inset: 36%;
  border-radius: 50%;
  background: var(--ink);
}

.cell.state-hit,
.cell-sample.state-hit {
  background: var(--red);
}

/* The cross is drawn, not typed: the self-hosted fonts have no U+2715, so a glyph would vary. */
.cell.state-hit::after,
.cell.state-sunk::after,
.cell-sample.state-hit::after,
.cell-sample.state-sunk::after {
  inset: 20%;
  -webkit-mask: var(--cross) center / contain no-repeat;
  mask: var(--cross) center / contain no-repeat;
}

.cell.state-hit::after,
.cell-sample.state-hit::after {
  background: var(--on-red);
}

/* Sunk borrows flag "O" (Oscar): red and yellow split on the diagonal. */
.cell.state-sunk,
.cell-sample.state-sunk {
  background: linear-gradient(135deg, var(--red) 50%, var(--yellow) 50%);
}

.cell.state-sunk::after,
.cell-sample.state-sunk::after {
  background: var(--on-signal);
}

/* High-contrast modes repaint backgrounds: draw the crosses in the system text colour. */
@media (forced-colors: active) {
  .cell.state-hit::after,
  .cell.state-sunk::after,
  .cell-sample.state-hit::after,
  .cell-sample.state-sunk::after {
    forced-color-adjust: none;
    background: CanvasText;
  }
}

.cell.state-revealed {
  background: repeating-linear-gradient(45deg, var(--blue) 0 3px, var(--surface) 3px 7px);
}

/* The newest shot lands with a short animation: transform and opacity only. */
.cell.is-new.state-miss::before {
  content: "";
  position: absolute;
  inset: 22%;
  border: 2px solid var(--ink);
  border-radius: 50%;
  animation: splash 600ms ease-out both;
  pointer-events: none;
}

@keyframes splash {
  from {
    transform: scale(0.4);
    opacity: 0.9;
  }

  to {
    transform: scale(1.8);
    opacity: 0;
  }
}

/* A hit turns the cell over in 3D, like a signal flag flipped to its marked side. */
.cell.is-new.state-hit,
.cell.is-new.state-sunk {
  animation: turn-over 340ms ease-out both;
  animation-delay: calc(var(--i, 0) * 70ms);
}

@keyframes turn-over {
  from {
    transform: perspective(300px) rotateX(-90deg);
  }

  to {
    transform: perspective(300px) rotateX(0deg);
  }
}

.cell.is-new.state-hit::before {
  content: "";
  position: absolute;
  inset: -10%;
  background: var(--yellow);
  clip-path: polygon(50% 0, 60% 38%, 100% 50%, 60% 62%, 50% 100%, 40% 62%, 0 50%, 40% 38%);
  animation: burst 420ms 220ms ease-out both;
  pointer-events: none;
}

@keyframes burst {
  from {
    transform: scale(0.3);
    opacity: 1;
  }

  to {
    transform: scale(1.5);
    opacity: 0;
  }
}

/* Battle */
.turn-banner {
  margin-bottom: var(--space-6);
  padding: var(--space-3) var(--space-4);
  border: var(--rule);
  background: var(--surface);
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(1.4rem, 4vw, 2rem);
  line-height: 1.1;
}

.turn-banner.is-your-turn {
  background: var(--yellow);
  color: var(--on-signal);
}

.result-panel {
  margin-bottom: var(--space-6);
  padding: var(--space-6);
  border: var(--rule);
}

.result-panel h2 {
  font-size: clamp(3rem, 12vw, 6rem);
  text-transform: uppercase;
  margin-bottom: var(--space-2);
  /* Swings in around its left edge, like a flag run up the halyard. */
  transform-origin: left center;
  animation: hoist 520ms ease-out both;
}

@keyframes hoist {
  from {
    transform: perspective(700px) rotateY(75deg);
    opacity: 0;
  }

  to {
    transform: perspective(700px) rotateY(0deg);
    opacity: 1;
  }
}

.result-panel p {
  font-size: 1.15rem;
  font-weight: 600;
}

.result-panel.is-victory {
  background: var(--yellow);
  color: var(--on-signal);
}

.result-panel.is-defeat {
  background: var(--red);
  color: var(--on-red);
}

.result-panel.is-defeat .button:not(.button-primary):not(:hover) {
  background: var(--surface);
}

.fleet-status {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
  font-weight: 600;
  font-size: 0.9rem;
}

.fleet-status li {
  padding: 1px var(--space-2);
  border: var(--hairline);
  background: var(--surface);
}

.fleet-status li.is-sunk {
  background: var(--ink);
  color: var(--paper);
  text-decoration: line-through;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-6);
  margin: var(--space-6) 0;
  padding: var(--space-3) 0;
  border-top: var(--rule);
  border-bottom: var(--rule);
  font-weight: 600;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
}

.cell-sample {
  position: relative;
  display: inline-block;
  width: 24px;
  height: 24px;
  background: var(--surface);
  border: 1px solid var(--ink);
}

.shot-log {
  margin: 0;
  padding-left: var(--space-6);
  max-height: 13rem;
  overflow-y: auto;
  font-variant-numeric: tabular-nums;
}

.shot-log li {
  padding: 2px 0;
  border-bottom: 1px solid var(--line-soft);
}

/* On yellow, borders and dark fills use the fixed signal ink so they keep 3:1 in both themes. */
.skip-link,
.connection-status,
.ship-button[aria-pressed="true"],
.turn-banner.is-your-turn,
.result-panel.is-victory,
.result-panel.is-victory .button {
  border-color: var(--on-signal);
}

.result-panel.is-victory .button-primary:not(:disabled) {
  background: var(--on-signal);
  color: var(--yellow);
}

@media (any-hover: hover) {
  .button:not(.button-ghost):hover:not(:disabled),
  .theme-toggle:hover {
    border-color: var(--on-signal);
  }
}

/* The blue focus ring is too faint on signal fills: use their fixed contrasting ink. */
.result-panel.is-victory :focus-visible {
  outline-color: var(--on-signal);
}

.result-panel.is-defeat :focus-visible {
  outline-color: var(--on-red);
}

@media (any-hover: hover) {
  .result-panel.is-victory .button-primary:hover:not(:disabled) {
    background: var(--flag-white);
    color: var(--on-signal);
  }
}

/* Layout */
@media (max-width: 420px) {
  .flag {
    width: 18px;
    height: 12px;
  }

  .wordmark {
    font-size: 1.3rem;
  }

  /* The pressed state and the icon carry the meaning; keep the name for assistive tech. */
  .theme-toggle-label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }

  #lobby-code {
    gap: var(--space-1);
  }
}

@media (min-width: 900px) {
  .home {
    grid-template-columns: 1.3fr 1fr;
  }

  .rules {
    grid-column: 1 / -1;
  }

  .placement-layout {
    grid-template-columns: auto minmax(18rem, 24rem);
    justify-content: start;
    column-gap: var(--space-12);
  }
}

/*
 * From tablets up the two battle boards sit side by side, sized from the width (the enemy
 * board takes the larger share) and the height, so neither needs a scroll to be seen whole.
 */
@media (min-width: 720px) {
  .battle-layout {
    grid-template-columns: auto auto;
    justify-content: start;
  }

  /* 54% and 44% of the width, not 55/45: a visible scrollbar is inside 100vw. */
  .battle-layout .board {
    --cell: clamp(24px, min(calc((54vw - 2.2rem - 10px) / 10.6), var(--cell-by-height)), 40px);
  }

  .battle-layout .board-small {
    --cell: clamp(22px, min(calc((44vw - 1.8rem - 10px) / 10.6), var(--cell-by-height)), 40px);
  }
}

/* On short screens (a phone on its side) a sticky top bar would cover the boards. */
@media (max-height: 500px) {
  .topbar {
    position: static;
  }

  .notice {
    top: var(--space-2);
  }
}

/*
 * A phone on its side: the ship dock sits beside the board instead of below it, so a ship can
 * be dragged from one to the other without scrolling (the page cannot scroll during a drag).
 */
@media (max-height: 500px) and (min-width: 600px) {
  .placement-layout {
    grid-template-columns: auto minmax(0, 1fr);
    column-gap: var(--space-6);
  }

  .placement-panel {
    padding: var(--space-4);
  }
}

@supports (height: 100svh) {
  :root {
    --screen-height: 100svh;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-delay: 0s !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
