:root {
  color-scheme: dark;
  font-family: system-ui, sans-serif;
  --ink: #edf9fa;
  --muted: #a7c3ca;
  --mint: #79f3d0;
  --line: #285164;
  --panel: #0c2434;
  --coral: #ff977e;
  background: #071827;
  color: var(--ink);
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(ellipse at 18% 0%, #153b4d, transparent 62%);
}
main { max-width: 1230px; margin: auto; padding: 24px clamp(14px, 4vw, 48px) 48px; }
h1, h2, p { margin: 0; }
h1, h2 { letter-spacing: -.035em; line-height: 1.04; }
h2 { font-size: clamp(1.35rem, 3vw, 1.9rem); }
.masthead, .room-bar, .status { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.masthead { padding-bottom: 20px; border-bottom: 1px solid var(--line); }
.masthead-controls { display: flex; align-items: center; gap: clamp(8px, 2vw, 18px); }
#audio { white-space: nowrap; }
#audio[aria-pressed="true"] { border-color: var(--mint); color: var(--mint); }
#audio-status { color: #ffd5c8; margin-top: 10px; }
.brand { color: var(--ink); text-decoration: none; font-size: 1.45rem; font-weight: 850; letter-spacing: -.055em; }
.brand span, em { color: var(--mint); }
.overline { color: var(--muted); font: 650 .72rem/1.5 ui-monospace, monospace; letter-spacing: .12em; text-transform: uppercase; }
.signal { display: inline-block; width: .55rem; height: .55rem; margin-right: .25rem; border-radius: 50%; background: var(--mint); box-shadow: 0 0 14px var(--mint); }
.lobby { display: grid; grid-template-columns: 1.25fr 1fr; gap: clamp(24px, 6vw, 86px); align-items: center; padding-top: clamp(38px, 8vh, 105px); }
.hero { position: relative; isolation: isolate; overflow: hidden; min-height: 360px; padding: 20px 0 90px; }
.hero h1 { margin: 14px 0 20px; font-size: clamp(3rem, 8vw, 6.5rem); letter-spacing: -.08em; }
.hero em { font-style: normal; }
.intro { max-width: 32ch; color: var(--muted); font-size: 1.13rem; line-height: 1.6; }
.radar {
  z-index: -1;
  position: absolute;
  width: min(390px, 85%);
  aspect-ratio: 1;
  bottom: -52%;
  right: 0;
  border: 1px solid #488579;
  border-radius: 50%;
  background: conic-gradient(from 330deg, #79f3d035, transparent 85deg), linear-gradient(90deg, transparent 49.8%, #488579 50%, transparent 50.2%), linear-gradient(transparent 49.8%, #488579 50%, transparent 50.2%);
  opacity: .46;
}
.radar i { position: absolute; inset: 14%; border: 1px solid #488579; border-radius: 50%; }
.radar i:nth-child(2) { inset: 29%; }
.radar i:nth-child(3) { inset: 43%; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 20px; box-shadow: 0 14px 30px #030e1760; }
.entry { display: grid; gap: 10px; padding: clamp(20px, 4vw, 36px); }
.entry h2 { margin: 0 0 12px; }
.room-settings { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 0; min-width: 0; border: 1px solid var(--line); border-radius: 9px; }
.room-settings legend { color: var(--muted); font-size: .82rem; padding: 0 4px; }
.room-settings select { display: block; width: 100%; min-height: 44px; margin-top: 4px; border: 1px solid var(--line); border-radius: 8px; background: #143649; color: var(--ink); font: inherit; }
#room-settings-message { grid-column: 1 / -1; color: var(--muted); font-size: .8rem; }
#room-settings-message.placement-error { color: #ffd5c8; }
label { font-size: .88rem; font-weight: 680; }
input, button { font: inherit; }
input { width: 100%; color: var(--ink); background: #081b29; border: 1px solid #3c6171; border-radius: 9px; padding: 11px 12px; min-height: 46px; }
input::placeholder { color: #8ba9b2; }
#code { text-transform: uppercase; letter-spacing: .16em; }
button { cursor: pointer; touch-action: manipulation; }
button:disabled { cursor: default; }
:focus-visible { outline: 2px solid #fff; outline-offset: 3px; z-index: 1; }
.primary, .secondary, .ship-option { border-radius: 10px; padding: 10px 14px; min-height: 44px; font-weight: 720; }
.primary { background: var(--mint); color: #07232a; border: 1px solid var(--mint); }
.primary:not(:disabled):hover { background: #afffe9; }
.secondary, .ship-option { background: #143649; color: var(--ink); border: 1px solid #386072; }
.secondary:not(:disabled):hover, .ship-option:not(:disabled):hover { background: #204b5c; }
.primary:disabled, .secondary:disabled, .ship-option:disabled { opacity: .56; }
.divider { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: .8rem; margin: 8px 0; }
.divider::before, .divider::after { content: ''; height: 1px; background: var(--line); flex: 1; }
#notice { margin-top: 16px; border: 1px solid #9a5d50; border-radius: 10px; background: #372530; color: #ffd5c8; padding: 12px 16px; }
.room-bar { margin: 18px 0; }
.game-header { display: flex; flex-direction: column; }
.game-header:not(.compact-header) #room-details { order: -1; }
.compact-header { padding-top: 12px; }
.compact-header .status:not(.victory) { padding-block: 8px; }
.status-tools { display: flex; align-items: center; justify-content: flex-end; gap: 8px; max-width: 48%; min-width: 0; }
#room-toggle { padding-inline: 10px; white-space: nowrap; font-size: .82rem; }
.compact-header #room-details { border-bottom: 1px solid var(--line); margin-bottom: 12px; }
.compact-header .room-bar { margin-top: 0; }
.seat-help { color: var(--muted); font-size: .85rem; margin: -8px 0 14px; }
#room-code { color: var(--mint); font: 800 1.2rem ui-monospace, monospace; letter-spacing: .15em; margin: 3px 4px 3px 0; }
#copy-hint, #copy-status { color: var(--muted); font-size: .8rem; }
#manual-code { max-width: 12ch; margin-top: 5px; }
.status { padding: clamp(12px, 2vw, 20px); margin-bottom: 14px; }
.status h1 { margin-top: 4px; font-size: clamp(1.2rem, 3vw, 2rem); overflow-wrap: anywhere; }
.status.victory {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  padding-block: 26px;
  border-color: #9c8052;
  background: linear-gradient(110deg, #274441, var(--panel) 68%);
}
.victory h1 { color: #ffe4a0; }
.celebration { position: absolute; inset: 0; z-index: -1; pointer-events: none; }
.celebration span {
  position: absolute;
  left: var(--x);
  top: var(--y);
  color: var(--mint);
  font-size: var(--size, .72rem);
  animation: confetti .9s cubic-bezier(.15, .6, .3, 1) both;
}
.celebration span:nth-child(1) { --x: 66%; --y: 10%; --size: 1.15rem; }
.celebration span:nth-child(2) { --x: 77%; --y: 19%; color: #ffe4a0; }
.celebration span:nth-child(3) { --x: 88%; --y: 7%; --size: 1.15rem; color: #ff977e; }
.celebration span:nth-child(4) { --x: 95%; --y: 16%; }
.celebration span:nth-child(5) { --x: 54%; --y: 76%; color: #ff977e; }
.celebration span:nth-child(6) { --x: 70%; --y: 71%; }
.celebration span:nth-child(7) { --x: 83%; --y: 74%; --size: 1.15rem; }
.celebration span:nth-child(8) { --x: 94%; --y: 74%; color: #ffe4a0; }
@keyframes confetti {
  from { left: 80%; top: 50%; opacity: 0; transform: scale(.2) rotate(-150deg); }
  55% { opacity: 1; }
  to { opacity: .8; transform: scale(1) rotate(12deg); }
}
.presence { text-align: right; color: var(--muted); font-size: .88rem; overflow-wrap: anywhere; }
#connection { display: block; color: #ffd5c8; }
.boards { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: clamp(10px, 2vw, 20px); align-items: start; }
.board-panel { padding: clamp(12px, 2vw, 24px); }
.board-panel h2 { margin: 4px 0 14px; }
.board { display: grid; grid-template-columns: 1.05rem repeat(var(--board-size), minmax(0, 1fr)); gap: clamp(2px, .4vw, 5px); }
.dense-grid .board-panel { padding: 12px; }
.dense-grid .board { gap: 2px; }
.axis { display: grid; place-items: center; color: var(--muted); font: 650 .68rem ui-monospace, monospace; }
.cell {
  display: grid;
  place-items: center;
  padding: 0;
  aspect-ratio: 1;
  line-height: 1;
  border: 1px solid #326477;
  border-radius: 20%;
  background: #10394d;
  color: var(--ink);
  font-weight: 850;
  font-size: clamp(.85rem, 2vw, 1.55rem);
}
.cell:not(:disabled):hover, .cell:not(:disabled):active { background: #23657a; border-color: var(--mint); }
.cell.ship {
  position: relative;
  --hull-paint: linear-gradient(180deg, #c0ded8 0 17%, #79a8a4 18% 67%, #3b7379 68%);
}
.cell.ship::before, .cell.hull-bridge::after {
  content: '';
  position: absolute;
  pointer-events: none;
}
.cell.ship::before { inset: 20% 0; background: var(--hull-paint); }
.cell.hull-bow { --hull-shape: polygon(0 50%, 32% 0, 100% 0, 100% 100%, 32% 100%); }
.cell.hull-stern { --hull-shape: polygon(0 0, 70% 0, 96% 24%, 96% 76%, 70% 100%, 0 100%); }
.cell.hull-horizontal::before { clip-path: var(--hull-shape, inset(0)); }
.cell.hull-vertical::before {
  inset: 0 20%;
  background: linear-gradient(90deg, #c0ded8 0 17%, #79a8a4 18% 67%, #3b7379 68%);
}
.cell.hull-vertical.hull-bow::before { clip-path: polygon(50% 0, 100% 32%, 100% 100%, 0 100%, 0 32%); }
.cell.hull-vertical.hull-stern::before { clip-path: polygon(0 0, 100% 0, 100% 70%, 76% 96%, 24% 96%, 0 70%); }
.cell.hull-bridge::after { inset: 32% 18%; border: 1px solid #d5efeb; border-radius: 2px; background: #335c67; }
.cell.hull-vertical.hull-bridge::after { inset: 18% 32%; }
.cell.selected { border-color: var(--mint); }
.cell.miss { background: #15485e; color: #b7eeff; border-color: #54899b; }
.cell.hit { background: #864531; color: #fff3e8; border-color: var(--coral); }
.cell.sunk { background: #552533; color: #ffc2b3; border-color: #c76c7f; }
.cell.pulse { animation: ping .65s ease-out; }
.cell.sunk.pulse { animation-name: sinking; }
@keyframes ping {
  0% { transform: scale(.85); box-shadow: 0 0 0 0 currentColor; }
  45% { transform: scale(1.12); }
  100% { transform: scale(1); box-shadow: 0 0 0 8px transparent; }
}
@keyframes sinking {
  0% { transform: scale(1.12); box-shadow: 0 0 0 0 currentColor; }
  45% { transform: scale(.85); }
  100% { transform: scale(1); box-shadow: 0 0 0 8px transparent; }
}
#setup-help { color: var(--muted); line-height: 1.5; }
#placement-feedback { color: var(--mint); min-height: 2.8em; margin-top: 10px; font-size: .88rem; line-height: 1.4; }
#placement-feedback.placement-error { color: #ffd5c8; }
.ships { display: grid; gap: 6px; margin: 12px 0; }
.ship-option { display: flex; justify-content: space-between; text-align: left; }
.ship-option[aria-pressed="true"] { border-color: var(--mint); color: var(--mint); }
.controls, .legend { display: flex; flex-wrap: wrap; gap: 8px; }
.legend { color: var(--muted); gap: 16px; margin-top: 12px; font-size: .85rem; }
.key-hit { color: #ffb799; }
.key-miss { color: #b7eeff; }
.key-sunk { color: #ffacbe; }
.battle-message { min-height: 1.4em; color: var(--mint); margin: 0 0 12px; }
@media (max-width: 890px) {
  .large-grid .boards { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 730px) {
  .lobby, .boards { grid-template-columns: 1fr; }
  .hero { min-height: 0; padding: 0 0 18px; }
  .radar { bottom: -80%; }
}
@media (max-width: 410px) {
  .masthead-label { display: none; }
  .status { align-items: start; }
  .presence { font-size: .74rem; }
}
@media (max-width: 550px) {
  .compact-header .status-tools { flex-direction: column-reverse; align-items: flex-end; gap: 3px; }
}
@media (prefers-reduced-motion: reduce) {
  .cell.pulse, .cell.sunk.pulse, .celebration span { animation: none; }
}
