:root {
  color-scheme: light;
  --deep: #102f35;
  --ink: #173a3e;
  --muted: #506765;
  --paper: #f3efe5;
  --rust: #a44331;
  --line: #c9c9b9;
  font: 16px/1.5 system-ui, sans-serif;
  scroll-behavior: smooth;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--paper); color: var(--ink); }
a { color: inherit; }
button, .button { font: inherit; font-weight: 720; cursor: pointer; }
button:disabled, button[aria-disabled=true] { cursor: default; }
button:disabled { opacity: .53; }
button:focus-visible, a:focus-visible { outline: 3px solid #d87c39; outline-offset: 3px; }
.skip { position: fixed; top: .5rem; left: .5rem; transform: translateY(-180%); background: white; padding: .5rem; z-index: 4; }
.skip:focus { transform: none; }
.shell { width: min(1120px, calc(100% - 3rem)); margin-inline: auto; }
.top { background: var(--deep); color: #faf2df; border-bottom: 1px solid #ffffff30; }
.top-inner, .top nav, .section-head, .chart-head, .footer { display: flex; align-items: center; justify-content: space-between; gap: .7rem; }
.top-inner { min-height: 64px; }
.brand { font-family: Georgia, serif; font-weight: bold; font-size: 1.24rem; text-decoration: none; }
.brand span { color: #efad7e; margin-right: .25rem; }
.top nav a, .quiet { font-size: .86rem; }
.quiet { color: inherit; background: none; border: 1px solid #ffffff55; padding: .28rem .6rem; border-radius: 4px; }
.hero {
  background: linear-gradient(90deg, #102d35 0%, #102d35e8 26%, #102d3550 64%, #102d3524), url('./assets/ria.webp') center 53% / cover, var(--deep);
  color: #fff7e6;
  min-height: 420px;
  display: grid;
  align-items: center;
  border-bottom: 5px solid #ab6045;
}
.hero-text { padding-block: 3.2rem; }
.eyebrow { font-size: .72rem; font-weight: 800; letter-spacing: .19em; color: var(--rust); margin: 0 0 .45rem; }
.hero .eyebrow { color: #f1b18d; }
h1, h2, h3 { font-family: Georgia, serif; line-height: 1.05; margin: 0; }
h1 { font-size: clamp(3rem, 8vw, 6.7rem); font-weight: 500; letter-spacing: -.055em; }
h1 em { color: #f4c093; }
h2 { font-size: clamp(2rem, 4vw, 3.2rem); font-weight: 500; letter-spacing: -.035em; }
h3 { font-size: 1.35rem; }
.intro { color: #f5ede1; font-size: clamp(1rem, 1.8vw, 1.2rem); margin: 1rem 0 1.5rem; }
.primary, .outline { border: 1px solid transparent; border-radius: 5px; padding: .63rem .9rem; }
.primary { background: var(--rust); color: #fff; }
.primary:hover:not(:disabled) { background: #873426; }
.hero .primary { background: #f0bf91; color: #2e2820; }
.hero .primary:hover { background: #ffd5ae; }
.button { display: inline-flex; gap: .7rem; text-decoration: none; }
.outline { background: #faf6ea; color: var(--ink); border-color: #b4bbab; }
.outline:hover:not(:disabled), .outline[aria-pressed=true] { background: #d7e5df; border-color: #6b8f82; }
.play, .rules { padding-block: 2.45rem; scroll-margin-top: .5rem; }
.radio { display: flex; gap: .66rem; align-items: baseline; margin: 1.2rem 0; padding: .72rem .9rem; border: 1px solid #34595a; border-radius: 5px; background: var(--deep); color: #f8efdc; min-height: 49px; }
.radio strong { text-transform: uppercase; letter-spacing: .12em; font-size: .72rem; }
.radio-light { width: .56rem; height: .56rem; flex: 0 0 auto; border-radius: 50%; background: #ecc08a; }
.boards { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1.15rem; align-items: start; }
.chart { padding: clamp(.55rem, 2vw, 1.1rem); border: 1px solid var(--line); background: #fffcf2; border-radius: 7px; box-shadow: 0 4px 14px #2c413211; }
.chart-head { margin: .25rem 0 .9rem; }
.chart-head > span, .scan-tools small { color: var(--muted); font-size: .82rem; font-weight: 700; }
.grid { display: grid; grid-template-columns: minmax(15px, .7fr) repeat(10, minmax(0, 1fr)); gap: 2px; user-select: none; }
.axis { display: grid; place-items: center; color: var(--muted); font: 700 clamp(.62rem, 2vw, .77rem)/1 ui-monospace, monospace; }
.cell { display: grid; position: relative; place-items: center; isolation: isolate; min-width: 0; aspect-ratio: 1; border: 0; border-radius: 2px; padding: 0; background: #dbe8e3; color: var(--ink); font-weight: 850; font-size: clamp(.8rem, 2.8vw, 1.4rem); line-height: 1; touch-action: manipulation; }
.cell:nth-child(even) { background: #d2e3dd; }
.cell:focus-visible { outline-offset: -2px; z-index: 1; }
.cell:not([aria-disabled=true]):hover, .cell.preview { background: #b2d0c3; }
.cell.boat::before { content: ''; position: absolute; z-index: -1; background: var(--ship); box-shadow: inset 0 2px #ffffff38, inset 0 -3px #00000035; }
.cell.h-first::before,.cell.h-middle::before,.cell.h-last::before { inset: 20% -1px; }
.cell.h-first::before { left: 9%; border-radius: 5px 0 0 5px; }
.cell.h-last::before { right: 7%; border-radius: 0 60% 60% 0; }
.cell.v-first::before,.cell.v-middle::before,.cell.v-last::before { inset: -1px 20%; }
.cell.v-first::before { top: 9%; border-radius: 5px 5px 0 0; }
.cell.v-last::before { bottom: 7%; border-radius: 0 0 60% 60%; }
.cell.water, .sample.water { background: #c0dceb; color: #245c79; }
.cell.water::after {
  content: '';
  width: clamp(5px, 22%, 11px);
  aspect-ratio: 1;
  border-radius: 50%;
  background: currentColor;
  pointer-events: none;
}
@media (prefers-reduced-motion: no-preference) {
  .cell.water-splash { animation: water-splash .72s ease-out; }
}
@keyframes water-splash {
  0%, 15% {
    background-color: #ffba68;
    color: #702817;
    box-shadow: inset 0 0 0 2px #c64621, inset 0 0 8px #fff1a8;
  }
  42% {
    background-color: #ef793e;
    color: #602318;
    box-shadow: inset 0 0 0 2px #a53624, inset 0 0 6px #ffae57;
  }
}
.cell.hit, .sample.hit { background: #a44331; color: white; }
.cell.hit::before { opacity: .45; }
.cell.found, .sample.found { background: #563a39; color: white; }
.cell.scan-positive { box-shadow: inset 0 0 0 2px #a6540a, inset 0 0 0 4px #ffcf78; }
.cell.scan-clear { box-shadow: inset 0 0 0 2px #31728b; }
#scan-hint[data-result="scan-positive"] { color: #763a00; background: #ffe2aa; }
#scan-hint[data-result="scan-clear"] { color: #214f64; background: #d3ebf5; }
#scan-hint:not(:empty) { padding: .2em .5em; border-radius: 4px; }
.dock p { color: var(--muted); margin: -.1rem 0 .85rem; }
.ship-list { display: grid; gap: .42rem; }
.ship-choice { display: flex; align-items: center; justify-content: space-between; padding: .55rem .65rem; background: #f2efe4; color: var(--ink); border: 1px solid #d7d6c8; border-left: 5px solid var(--ship); border-radius: 4px; text-align: left; }
.ship-choice[aria-pressed=true] { background: #e2ece4; border-color: #69867a; border-left-color: var(--ship); }
.ship-choice small { display: block; color: var(--muted); font-weight: 500; }
.length { font: 700 .77rem ui-monospace, monospace; white-space: nowrap; padding-left: .4rem; }
.ship-choice[data-placed=true] .length::after { content: ' ✓'; }
.dock-actions, .scan-tools, .tabs, .legend { display: flex; align-items: center; flex-wrap: wrap; gap: .6rem; margin-top: .9rem; }
.legend { list-style: none; padding: 0; color: var(--muted); font-size: .88rem; gap: 1rem; }
.legend li { display: flex; gap: .35rem; align-items: center; }
.sample { display: inline-grid; place-items: center; width: 1.45rem; height: 1.45rem; border-radius: 3px; font-weight: 800; }
.rules, .footer { border-top: 1px solid var(--line); }
.rule-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; margin-top: 1.2rem; }
.rule-grid article { border-top: 2px solid #a85844; padding: .85rem .65rem 0 0; }
.rule-grid p, .footer { color: var(--muted); }
.footer { padding-block: .9rem; }
@media (max-width: 720px) {
  .shell { width: calc(100% - 1.5rem); }
  .hero { min-height: 350px; background-position: 64% center; }
  .hero-text { padding-block: 2.4rem; }
  .boards, .rule-grid { grid-template-columns: 1fr; }
  .play, .rules { padding-block: 1.65rem; }
  .radio { font-size: .9rem; }
  .top-inner { min-height: 55px; }
  .top nav { gap: .45rem; }
  .brand { font-size: 1rem; }
}
@media (prefers-reduced-motion: reduce) { :root { scroll-behavior: auto; } }

.game-actions, .match-controls, .match-controls > div { display: flex; align-items: center; gap: .45rem; }
.game-actions { justify-content: flex-end; flex-wrap: wrap; }
.match-controls { justify-content: space-between; flex-wrap: wrap; }
.match-controls .tabs, .match-controls .scan-tools { margin-top: 0; }
#sound[aria-pressed=false] { color: var(--muted); }
.game-screen { overflow: hidden; }
.game-screen .top, .game-screen .hero, .game-screen .rules, .game-screen .footer { display: none; }
.game-screen .play {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  gap: .5rem;
  padding-top: max(.5rem, env(safe-area-inset-top));
  padding-bottom: max(.5rem, env(safe-area-inset-bottom));
  overflow-y: auto;
  overscroll-behavior: contain;
}
.game-screen .section-head .eyebrow { display: none; }
.game-screen .section-head h2 { font-size: clamp(1.3rem, 3.2vw, 2rem); }
.game-screen .radio { margin: 0; min-height: 0; }
.game-screen .boards { flex: 1; min-height: 190px; align-items: stretch; }
.game-screen .chart:not(.dock) { display: flex; flex-direction: column; min-height: 0; }
.game-screen .board-space {
  container-type: size;
  flex: 1;
  min-height: 135px;
  display: grid;
  place-items: center;
}
.game-screen .grid { width: min(100cqw, 100cqh, 560px); }
.game-screen .legend { margin: 0; }
.game-screen .outline, .game-screen .primary { padding: .38rem .63rem; }
.game-screen .chart-head { margin: 0 0 .45rem; }

@media (max-width: 720px) {
  .game-screen .play { gap: .35rem; }
  .game-screen .boards { grid-template-rows: minmax(0, 1fr) auto; gap: .38rem; }
  .game-screen .boards:has(#dock[hidden]) { grid-template-rows: minmax(0, 1fr); }
  .game-screen .chart { padding: .4rem; }
  .game-screen .chart-head h3 { font-size: 1.05rem; }
  .game-screen .dock p { display: none; }
  .game-screen .ship-list { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .24rem; }
  .game-screen .ship-choice { font-size: .75rem; min-height: 34px; padding: .26rem .3rem; }
  .game-screen .ship-choice small { display: none; }
  .game-screen .length { font-size: .66rem; }
  .game-screen .dock-actions { margin-top: .35rem; gap: .3rem; }
  .game-screen .outline, .game-screen .primary { min-height: 36px; font-size: .76rem; padding: .26rem .38rem; }
  .game-screen .legend { gap: .5rem; font-size: .72rem; }
  .game-screen .radio { font-size: .8rem; padding: .38rem .52rem; min-height: 3rem; }
}
@media (orientation: landscape) and (max-height: 550px) {
  .game-screen .boards { min-height: 168px; }
  .game-screen .boards:has(#dock:not([hidden])) {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: minmax(0, 1fr);
  }
  .game-screen .dock p { display: none; }
  .game-screen .ship-list { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .22rem; }
  .game-screen .ship-choice { padding: .2rem .3rem; font-size: .75rem; }
  .game-screen .ship-choice small { display: none; }
  .game-screen .length { font-size: .65rem; }
  .game-screen .dock-actions { margin-top: .35rem; }
}

.boards { position: relative; }
.result-banner {
  position: absolute;
  z-index: 2;
  inset: 44% 0 auto;
  width: max-content;
  max-width: 100%;
  margin-inline: auto;
  padding: .12em .42em .18em;
  border: 1px solid currentColor;
  border-radius: .14em;
  background: #10191aeb;
  box-shadow: 0 .15em .65em #10191a70;
  color: #ffba68;
  font: 950 clamp(1.55rem, 6vw, 4rem)/1.12 system-ui, sans-serif;
  letter-spacing: .045em;
  text-align: center;
  text-shadow: 0 .055em #8e2c13, 0 0 .4em #ef541c85;
  pointer-events: none;
  animation: result-flash 1.2s ease both;
}
.result-banner[data-result="water"],
.result-banner[data-result="scan-clear"] {
  color: #a9efff;
  text-shadow: 0 .055em #176072, 0 0 .35em #40b2cb85;
}
.result-banner[data-result="sunk"],
.result-banner[data-result="win"] { color: #ffe2a0; }
.result-banner[data-result="loss"] { color: #ff976f; }
.result-banner[data-result="win"],
.result-banner[data-result="loss"] {
  font-size: clamp(2rem, 8vw, 5rem);
  animation: result-finale 3.4s ease both;
}
@keyframes result-flash {
  0% { opacity: 0; transform: translateX(-.8em) scale(.93); }
  20%, 76% { opacity: 1; transform: translateX(0) scale(1); }
  100% { opacity: 0; transform: translateX(.35em) scale(1); }
}
@keyframes result-finale {
  0% { opacity: 0; transform: translateX(-.8em) scale(.9); }
  12%, 78% { opacity: 1; transform: translateX(0) scale(1); }
  100% { opacity: 0; transform: translateX(.45em) scale(1.04); }
}
@media (prefers-reduced-motion: reduce) {
  .result-banner,
  .result-banner[data-result="win"],
  .result-banner[data-result="loss"] { animation: none; }
}

.fleet-key {
  list-style: none;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: .25rem;
  padding: .3rem;
  margin: .35rem 0 0;
  background: #e6dfc9;
  border-radius: .45rem;
}

.fleet-key li {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 24px;
}

.fleet-silhouette {
  width: min(94%, calc(1.05rem + var(--length) * .45rem));
  height: 18px;
  background: #101214;
  clip-path: polygon(0 53%, 20% 53%, 20% 32%, 32% 32%, 32% 13%, 39% 13%,
    39% 32%,  50% 32%, 50% 53%, 80% 53%, 100% 38%, 86% 89%, 10% 89%);
}

.fleet-key li:nth-child(even) .fleet-silhouette { transform: scaleX(-1); }
.fleet-key .is-sunk .fleet-silhouette { opacity: .53; }

.fleet-key .is-sunk::before,
.fleet-key .is-sunk::after {
  content: '';
  position: absolute;
  width: 25px;
  height: 3px;
  border-radius: 2px;
  background: #b51a24;
  box-shadow: 0 0 0 1px #e6dfc9;
  transform: rotate(45deg);
}

.fleet-key .is-sunk::after { transform: rotate(-45deg); }

.cell.survivor::before,
.sample.survivor {
  background: #e8ba59;
  border: 1px solid #735219;
}

.cell.survivor.hit { color: #281c0a; }

.game-version { color: var(--muted); font-size: .73rem; white-space: nowrap; }

.cell.selected-boat::before { outline: 2px solid #163b43; outline-offset: -2px; }

@media (max-width: 720px), (pointer: coarse) and (max-height: 550px) {
  html:has(body.game-screen), body.game-screen { overflow: hidden; overscroll-behavior: none; }
  .game-screen .play {
    position: fixed;
    inset: 0;
    width: 100%;
    margin: 0;
    padding-inline: max(.45rem, env(safe-area-inset-left)) max(.45rem, env(safe-area-inset-right));
  }
  .game-screen.match-screen .play { overflow: hidden; gap: .25rem; }
  .game-screen.match-screen .boards {
    min-height: 0;
    grid-template-columns: minmax(0, 1fr);
    gap: 0;
  }
  .game-screen.match-screen .board-space { min-height: 0; }
  .game-screen.match-screen .grid { width: min(100cqw, 100cqh); }
  .game-screen.match-screen .radio,
  .game-screen.match-screen .legend {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }
  .game-screen.match-screen .section-head h2 { font-size: 1rem; }
  .game-screen.match-screen .chart {
    padding: .2rem;
    background: transparent;
    border: 0;
    box-shadow: none;
  }
  .game-screen.match-screen .chart-head { margin: 0; }
  .game-screen.match-screen .match-controls { order: 1; }
  .game-screen.match-screen .game-actions, .game-screen.match-screen .match-controls { gap: .25rem; }
}

#enemy.can-flip, #enemy.can-flip .cell { cursor: pointer; }
#flip-enemy { flex-shrink: 0; }
#enemy-panel .chart-head:has(#flip-enemy:not([hidden])) { flex-wrap: wrap; }

/* Compact mobile play: diagnostic controls stay on the landing screen. */
@media (max-width:720px), (pointer:coarse) and (max-height:550px) {
 .game-screen .game-version,.game-screen #audio-test,.game-screen #audio-diagnostic,.game-screen .game-actions a {display:none!important}
 .game-screen .play {height:100vh;height:100dvh;max-width:none;gap:.3rem;overflow-x:hidden}
 .game-screen .section-head {flex-wrap:wrap;gap:.25rem}
 .game-screen .section-head h2 {font-size:1rem}
 .game-screen .game-actions {margin-left:auto}
 .game-screen.match-screen .radio {position:static;width:auto;height:auto;clip-path:none;white-space:normal;min-height:2.5rem;padding:.25rem .4rem;font-size:.75rem;line-height:1.2}
 .game-screen.match-screen .radio strong,.game-screen.match-screen .radio-light {display:none}
 .game-screen.match-screen .boards {flex:1;min-height:0}
 .game-screen.match-screen .board-space {min-height:0}
 .game-screen.match-screen .grid {width:min(100cqw,100cqh,560px);max-width:100%}
 .game-screen.match-screen .match-controls {justify-content:center;flex:none}
 .game-screen.match-screen .scan-tools small {font-size:.68rem;overflow-wrap:anywhere}
 .game-screen.match-screen .chart-head {gap:.25rem;flex-wrap:wrap}
 .game-screen.match-screen .fleet-key {margin:.15rem 0;padding:.1rem}
 .game-screen.match-screen .fleet-key li {min-height:18px}
 .game-screen.match-screen .fleet-silhouette {height:13px}
}

/* v1.4.8: use the available viewport, keeping square cells. */
@media (max-width:720px), (pointer:coarse) and (max-height:550px) {
 .game-screen .play {padding-inline:max(2px,env(safe-area-inset-left)) max(2px,env(safe-area-inset-right));gap:2px}
 .game-screen.match-screen .chart {padding:0;min-width:0}
 .game-screen.match-screen .board-space {min-width:0;width:100%}
 .game-screen.match-screen .grid {width:min(100cqw,100cqh);max-width:100%;gap:1px}
 .game-screen.match-screen .fleet-key {display:none}
 .game-screen.match-screen .chart-head {margin:0;gap:2px}
 .game-screen.match-screen .radio {min-height:0;padding:3px 5px}
 .game-screen.match-screen .section-head {margin:0}
}
