:root {
  color-scheme: dark;
  --bg: #06111d;
  --bg-soft: #0b1e30;
  --panel: rgba(12, 29, 45, 0.9);
  --panel-strong: #10263a;
  --panel-raised: rgba(18, 42, 63, 0.92);
  --stroke: rgba(148, 187, 218, 0.2);
  --stroke-strong: rgba(148, 205, 238, 0.42);
  --water: #0c2d48;
  --water-hi: #155078;
  --text: #f0f6fb;
  --muted: #98aec2;
  --accent: #54d4ff;
  --accent-soft: rgba(84, 212, 255, 0.13);
  --accent-ink: #02283b;
  --hit: #ff7048;
  --miss: #91c9ef;
  --good: #5ce695;
  --bad: #ff7c7c;
  --gold: #f8c86b;
  --focus: #ffdf8a;
  --radius: 16px;
  --radius-sm: 10px;
  --cell-gap: 2px;
  --shadow: 0 22px 54px rgba(0, 7, 14, 0.32);
}

body.theme-arctic,
.theme-arctic {
  --bg: #07131c;
  --bg-soft: #0d2735;
  --panel: rgba(12, 34, 46, 0.91);
  --panel-strong: #123242;
  --panel-raised: rgba(17, 53, 68, 0.93);
  --stroke: rgba(184, 226, 238, 0.23);
  --stroke-strong: rgba(202, 244, 255, 0.48);
  --water: #164252;
  --water-hi: #257388;
  --accent: #9aebf4;
  --accent-soft: rgba(154, 235, 244, 0.14);
  --accent-ink: #062a31;
  --miss: #c4eaf4;
}

body.theme-sunset,
.theme-sunset {
  --bg: #180d1c;
  --bg-soft: #29182b;
  --panel: rgba(40, 23, 40, 0.91);
  --panel-strong: #3a223c;
  --panel-raised: rgba(58, 34, 60, 0.94);
  --stroke: rgba(242, 177, 164, 0.22);
  --stroke-strong: rgba(255, 185, 151, 0.45);
  --water: #233852;
  --water-hi: #3c5971;
  --accent: #ffb37d;
  --accent-soft: rgba(255, 179, 125, 0.14);
  --accent-ink: #361204;
  --hit: #ff6b5c;
  --miss: #a9c7df;
  --gold: #ffd27e;
}

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

html {
  min-width: 0;
  min-height: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-width: 0;
  min-height: 100vh;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  color: var(--text);
  background:
    radial-gradient(900px 560px at 10% -12%, color-mix(in srgb, var(--water-hi) 82%, transparent), transparent 66%),
    radial-gradient(760px 520px at 105% 4%, color-mix(in srgb, var(--accent) 15%, transparent), transparent 64%),
    var(--bg);
  background-attachment: fixed;
  transition: background-color 180ms ease, color 180ms ease;
}

img,
svg {
  max-width: 100%;
}

button,
select {
  font: inherit;
}

button,
select,
[tabindex] {
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
select:focus-visible,
[tabindex]:focus-visible,
.cell:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

button:disabled,
select:disabled {
  cursor: not-allowed;
  opacity: 0.46;
}

.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

.hidden {
  display: none !important;
}

.skip-link {
  position: fixed;
  top: 10px;
  left: 10px;
  z-index: 100;
  transform: translateY(-180%);
  padding: 10px 14px;
  border-radius: 8px;
  color: var(--accent-ink);
  background: var(--focus);
  font-weight: 750;
  text-decoration: none;
  transition: transform 120ms ease;
}

.skip-link:focus {
  transform: translateY(0);
}

/* ---------- global controls ---------- */

.ghost-btn,
.primary-btn,
.daily-btn,
.icon-btn,
.segment,
.action-list button {
  min-height: 44px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition:
    transform 120ms ease,
    color 160ms ease,
    background-color 160ms ease,
    border-color 160ms ease,
    box-shadow 160ms ease;
}

.ghost-btn,
.primary-btn {
  padding: 10px 16px;
  font-size: 0.875rem;
  font-weight: 700;
}

.ghost-btn {
  color: var(--text);
  background: rgba(255, 255, 255, 0.045);
  border: 1px solid var(--stroke);
}

.ghost-btn:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.09);
  border-color: var(--stroke-strong);
}

.primary-btn {
  color: var(--accent-ink);
  background: linear-gradient(180deg, color-mix(in srgb, var(--accent) 94%, white), var(--accent));
  border: 1px solid transparent;
  box-shadow: 0 9px 24px color-mix(in srgb, var(--accent) 20%, transparent);
}

.primary-btn:hover:not(:disabled) {
  box-shadow: 0 11px 30px color-mix(in srgb, var(--accent) 31%, transparent);
  filter: saturate(1.07) brightness(1.03);
}

.ghost-btn:active:not(:disabled),
.primary-btn:active:not(:disabled),
.daily-btn:active:not(:disabled),
.segment:active:not(:disabled),
.icon-btn:active:not(:disabled),
.action-list button:active:not(:disabled) {
  transform: translateY(1px);
}

select {
  width: 100%;
  min-width: 0;
  min-height: 44px;
  padding: 9px 38px 9px 12px;
  color: var(--text);
  background-color: var(--panel-strong);
  border: 1px solid var(--stroke);
  border-radius: var(--radius-sm);
  cursor: pointer;
}

select:hover:not(:disabled) {
  border-color: var(--stroke-strong);
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--accent);
  font-size: 0.66rem;
  line-height: 1.2;
  font-weight: 800;
  letter-spacing: 0.19em;
  text-transform: uppercase;
}

/* ---------- top bar ---------- */

.topbar {
  position: relative;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  width: 100%;
  min-width: 0;
  padding: 15px max(22px, calc((100vw - 1220px) / 2));
  border-bottom: 1px solid var(--stroke);
  background: color-mix(in srgb, var(--bg) 84%, transparent);
  box-shadow: 0 10px 35px rgba(0, 6, 12, 0.16);
  backdrop-filter: blur(18px);
}

.brand-lockup {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 12px;
}

.logo-mark {
  position: relative;
  display: grid;
  flex: 0 0 42px;
  width: 42px;
  height: 42px;
  place-items: center;
  color: var(--accent);
  border: 1px solid var(--stroke-strong);
  border-radius: 50%;
  background:
    radial-gradient(circle at 50% 50%, var(--accent-soft), transparent 66%),
    var(--panel);
  box-shadow: 0 0 24px var(--accent-soft);
}

.flag-anchor .logo-mark::after,
.flag-skull .logo-mark::after,
.flag-ensign .logo-mark::after {
  position: absolute;
  right: -5px;
  bottom: -5px;
  display: grid;
  width: 20px;
  height: 20px;
  place-items: center;
  color: var(--accent-ink);
  background: var(--accent);
  border: 2px solid var(--bg);
  border-radius: 50%;
  font-size: 0.66rem;
  font-weight: 900;
}

.flag-anchor .logo-mark::after {
  content: "⚓";
}

.flag-skull .logo-mark::after {
  content: "☠";
}

.flag-ensign .logo-mark::after {
  content: "★";
}

.logo {
  max-width: 100%;
  margin: 0;
  font-size: clamp(1rem, 2vw, 1.25rem);
  line-height: 1;
  font-weight: 720;
  letter-spacing: 0.19em;
  text-transform: uppercase;
  overflow-wrap: anywhere;
}

.topbar-actions {
  display: flex;
  flex: 0 1 auto;
  min-width: 0;
  gap: 9px;
}

/* ---------- primary layout ---------- */

.layout {
  display: grid;
  width: min(100%, 1220px);
  min-width: 0;
  margin: 0 auto;
  padding: 26px 22px 64px;
  gap: 22px;
}

.layout > *,
.command-grid > *,
.boards > *,
.dashboard-grid > *,
.power-grid > *,
.replay-boards > *,
.stats-grid > * {
  min-width: 0;
}

.panel {
  min-width: 0;
  padding: 20px 22px;
  border: 1px solid var(--stroke);
  border-radius: var(--radius);
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.035), transparent 45%),
    var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

.panel h2 {
  margin: 0;
  font-size: clamp(1rem, 1.8vw, 1.15rem);
  line-height: 1.25;
  letter-spacing: 0.055em;
  text-transform: uppercase;
}

.section-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  min-width: 0;
  gap: 20px;
  margin-bottom: 18px;
}

.compact-heading {
  align-items: center;
}

.section-note,
.hint {
  max-width: 48ch;
  margin: 0;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.5;
}

kbd {
  display: inline-block;
  min-width: 22px;
  padding: 1px 6px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid var(--stroke);
  border-radius: 5px;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.1);
  font-family: inherit;
  font-size: 0.72rem;
  line-height: 1.5;
  text-align: center;
}

/* ---------- command panel ---------- */

.command-panel {
  position: relative;
  overflow: hidden;
}

.command-panel::after {
  position: absolute;
  top: -84px;
  right: -65px;
  width: 220px;
  height: 220px;
  content: "";
  pointer-events: none;
  border: 1px solid var(--stroke);
  border-radius: 50%;
  box-shadow:
    0 0 0 28px rgba(255, 255, 255, 0.012),
    0 0 0 58px rgba(255, 255, 255, 0.008);
}

.command-grid {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: minmax(280px, 1.55fr) repeat(3, minmax(150px, 1fr));
  align-items: start;
  gap: 14px;
}

.control-group {
  display: grid;
  min-width: 0;
  margin: 0;
  padding: 0;
  gap: 7px;
  border: 0;
}

.control-group > label,
.control-group > legend,
.control-label {
  padding: 0;
  color: var(--muted);
  font-size: 0.67rem;
  line-height: 1.3;
  font-weight: 780;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.segmented-control {
  display: grid;
  min-width: 0;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 5px;
  padding: 4px;
  border: 1px solid var(--stroke);
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.16);
}

.segment {
  display: grid;
  min-width: 0;
  padding: 6px 10px;
  text-align: left;
  color: var(--muted);
  background: transparent;
  border: 1px solid transparent;
}

.segment span {
  color: inherit;
  font-size: 0.84rem;
  font-weight: 780;
}

.segment small {
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.66rem;
  line-height: 1.25;
}

.segment:hover:not(:disabled) {
  color: var(--text);
  background: rgba(255, 255, 255, 0.04);
}

.segment.is-active,
.segment[aria-pressed="true"] {
  color: var(--text);
  background: var(--accent-soft);
  border-color: color-mix(in srgb, var(--accent) 55%, transparent);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.025);
}

.segment.is-active small,
.segment[aria-pressed="true"] small {
  color: color-mix(in srgb, var(--accent) 60%, var(--muted));
}

.daily-btn {
  display: flex;
  align-items: center;
  width: 100%;
  gap: 8px;
  padding: 9px 12px;
  color: var(--gold);
  background: color-mix(in srgb, var(--gold) 8%, var(--panel-strong));
  border: 1px solid color-mix(in srgb, var(--gold) 37%, var(--stroke));
  font-size: 0.78rem;
  font-weight: 760;
  text-align: left;
}

.daily-btn:hover:not(:disabled) {
  color: #ffe7ad;
  background: color-mix(in srgb, var(--gold) 14%, var(--panel-strong));
  border-color: color-mix(in srgb, var(--gold) 57%, var(--stroke));
}

.daily-btn > span {
  display: grid;
  flex: 0 0 24px;
  width: 24px;
  height: 24px;
  place-items: center;
  border: 1px solid currentColor;
  border-radius: 50%;
}

.control-status {
  min-height: 1rem;
  margin: 0;
  color: var(--muted);
  font-size: 0.67rem;
  line-height: 1.4;
}

/* ---------- fleet setup ---------- */

.tray {
  display: flex;
  flex-wrap: wrap;
  min-width: 0;
  margin: 0 0 16px;
  padding: 0;
  gap: 9px;
  list-style: none;
}

.tray > li {
  min-width: 0;
}

.tray-item {
  display: flex;
  align-items: center;
  min-width: 0;
  min-height: 44px;
  gap: 9px;
  padding: 8px 12px;
  border: 1px solid var(--stroke);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.025);
  cursor: grab;
  user-select: none;
  touch-action: none;
  transition:
    opacity 160ms ease,
    color 160ms ease,
    background-color 160ms ease,
    border-color 160ms ease;
}

button.tray-item {
  width: 100%;
  color: var(--text);
  text-align: left;
}

.tray-item:hover {
  border-color: var(--stroke-strong);
  background: rgba(255, 255, 255, 0.05);
}

.tray-item.selected {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.tray-item.placed {
  opacity: 0.45;
}

.tray-item img {
  width: auto;
  max-width: 84px;
  height: 21px;
  pointer-events: none;
}

.tray-item .tray-name {
  min-width: 0;
  font-size: 0.78rem;
  font-weight: 700;
}

.tray-item .tray-size {
  color: var(--muted);
  font-size: 0.7rem;
}

.setup-actions {
  display: flex;
  flex-wrap: wrap;
  min-width: 0;
  gap: 9px;
}

.setup-actions .primary-btn {
  margin-left: auto;
}

/* ---------- boards ---------- */

.boards {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: start;
  min-width: 0;
  gap: 22px;
}

.board-column {
  display: flex;
  flex-direction: column;
  width: 100%;
  min-width: 0;
  gap: 10px;
}

.board-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-width: 0;
  gap: 10px;
}

.board-title {
  min-width: 0;
  margin: 0;
  color: var(--muted);
  font-size: 0.75rem;
  line-height: 1.4;
  font-weight: 780;
  letter-spacing: 0.15em;
  text-transform: uppercase;
}

.board-tag {
  flex: 0 0 auto;
  padding: 4px 8px;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid color-mix(in srgb, var(--accent) 28%, transparent);
  border-radius: 999px;
  font-size: 0.6rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.danger-tag {
  color: var(--hit);
  background: color-mix(in srgb, var(--hit) 10%, transparent);
  border-color: color-mix(in srgb, var(--hit) 30%, transparent);
}

.board-wrap {
  position: relative;
  isolation: isolate;
  display: grid;
  width: 100%;
  min-width: 0;
  grid-template-columns: 20px minmax(0, 1fr);
  grid-template-rows: 20px minmax(0, 1fr);
  gap: 4px;
  padding: 12px;
  overflow: hidden;
  background:
    linear-gradient(rgba(255, 255, 255, 0.015), rgba(255, 255, 255, 0)),
    var(--bg-soft);
  border: 1px solid var(--stroke);
  border-radius: var(--radius);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.035),
    0 20px 45px rgba(0, 5, 10, 0.27);
}

.labels-row {
  display: grid;
  grid-area: 1 / 2;
  grid-template-columns: repeat(10, minmax(0, 1fr));
  gap: var(--cell-gap);
}

.labels-col {
  display: grid;
  grid-area: 2 / 1;
  grid-template-rows: repeat(10, minmax(0, 1fr));
  gap: var(--cell-gap);
}

.labels-row span,
.labels-col span {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  color: var(--muted);
  font-size: clamp(0.52rem, 1.3vw, 0.68rem);
  font-variant-numeric: tabular-nums;
}

.grid {
  position: relative;
  z-index: 1;
  display: grid;
  grid-area: 2 / 2;
  grid-template-columns: repeat(10, minmax(0, 1fr));
  grid-template-rows: repeat(10, minmax(0, 1fr));
  min-width: 0;
  aspect-ratio: 1;
  gap: var(--cell-gap);
}

.ship-layer,
.marker-layer {
  position: relative;
  min-width: 0;
  grid-area: 2 / 2;
  pointer-events: none;
}

.ship-layer {
  z-index: 2;
}

.marker-layer {
  z-index: 3;
}

.cell-slot {
  position: absolute;
  width: 10%;
  height: 10%;
}

.marker {
  position: absolute;
  inset: 0;
}

.marker::after {
  position: absolute;
  inset: 0;
  margin: auto;
  content: "";
  border-radius: 50%;
}

.marker-miss::after {
  width: 30%;
  height: 30%;
  background: var(--miss);
  box-shadow: 0 0 8px color-mix(in srgb, var(--miss) 50%, transparent);
  opacity: 0.86;
}

.marker-hit::after {
  width: 46%;
  height: 46%;
  background: radial-gradient(circle at 35% 30%, #ffe4a6, var(--hit) 55%, #8b2908);
  box-shadow: 0 0 12px color-mix(in srgb, var(--hit) 70%, transparent);
}

.cell {
  position: relative;
  min-width: 0;
  min-height: 0;
  padding: 0;
  overflow: hidden;
  background: linear-gradient(155deg, var(--water-hi), var(--water));
  border: 0;
  border-radius: clamp(2px, 0.7vw, 5px);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.045);
  cursor: default;
}

.cell:focus-visible {
  z-index: 5;
  outline-width: 2px;
  outline-offset: -1px;
}

.enemy .cell:not(.shot) {
  cursor: crosshair;
}

.enemy:not(.active) .cell {
  cursor: not-allowed;
  opacity: 0.82;
}

.enemy.active .cell:not(.shot):hover {
  background: linear-gradient(
    155deg,
    color-mix(in srgb, var(--water-hi) 74%, var(--accent)),
    color-mix(in srgb, var(--water) 78%, var(--accent))
  );
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 68%, transparent);
}

.cell.preview-valid {
  background: linear-gradient(155deg, #2682a4, #17617c);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--good) 78%, transparent);
}

.cell.preview-invalid {
  background: linear-gradient(155deg, #7a2b3a, #501c29);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--bad) 82%, transparent);
}

.cell.sunk {
  background: linear-gradient(155deg, #542020, #2c1113);
}

.cell.scan-area {
  background: linear-gradient(
    155deg,
    color-mix(in srgb, var(--water-hi) 58%, var(--gold)),
    color-mix(in srgb, var(--water) 82%, var(--gold))
  );
  box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--gold) 68%, transparent);
}

.ship-sprite {
  position: absolute;
  display: block;
  filter: drop-shadow(0 6px 10px rgba(0, 0, 0, 0.55));
  transition: opacity 200ms ease;
}

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

.ship-sprite.vertical {
  transform: rotate(90deg);
}

.ship-sprite.draggable {
  pointer-events: auto;
  cursor: grab;
  touch-action: none;
}

.ship-sprite.lifted {
  opacity: 0.25;
}

.drag-ghost {
  position: fixed;
  z-index: 60;
  pointer-events: none;
  opacity: 0.92;
  filter: drop-shadow(0 12px 18px rgba(0, 0, 0, 0.6));
}

.drag-ghost img {
  display: block;
  width: 100%;
  height: 100%;
}

.drag-ghost.vertical {
  transform: rotate(90deg);
}

.drag-ghost.invalid img {
  filter: grayscale(0.5) sepia(1) saturate(5) hue-rotate(-28deg);
}

body.dragging-ship {
  cursor: grabbing;
  user-select: none;
}

body.dragging-ship .ship-sprite.draggable {
  cursor: grabbing;
}

.grid.deploying {
  touch-action: none;
}

.ship-sprite.sunk img {
  filter: grayscale(0.65) brightness(0.6);
}

.fleet-status {
  min-height: 18px;
  margin: 0;
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1.55;
  overflow-wrap: anywhere;
}

.fleet-status .down {
  color: var(--bad);
  text-decoration: line-through;
}

/* ---------- combat effects ---------- */

@keyframes splash-ring {
  0% {
    opacity: 0.9;
    transform: scale(0.2);
  }
  100% {
    opacity: 0;
    transform: scale(2.4);
  }
}

@keyframes blast {
  0% {
    opacity: 1;
    transform: scale(0.2);
  }
  55% {
    opacity: 0.95;
    transform: scale(1.35);
  }
  100% {
    opacity: 0;
    transform: scale(1.9);
  }
}

@keyframes heavy-blast {
  0% {
    opacity: 1;
    transform: scale(0.1) rotate(-10deg);
  }
  45% {
    opacity: 1;
    transform: scale(1.65) rotate(6deg);
  }
  100% {
    opacity: 0;
    transform: scale(2.25) rotate(0);
  }
}

@keyframes smoke-rise {
  0% {
    opacity: 0.65;
    transform: translateY(0) scale(0.6);
  }
  100% {
    opacity: 0;
    transform: translateY(-90%) scale(1.7);
  }
}

@keyframes shake {
  0%,
  100% {
    transform: translate(0, 0);
  }
  25% {
    transform: translate(-3px, 2px);
  }
  50% {
    transform: translate(3px, -2px);
  }
  75% {
    transform: translate(-2px, -2px);
  }
}

@keyframes sink {
  0% {
    opacity: 1;
  }
  100% {
    opacity: 0.35;
    filter: brightness(0.5) blur(1px);
  }
}

.fx {
  position: absolute;
  inset: 0;
  margin: auto;
  border-radius: 50%;
  pointer-events: none;
}

.fx-splash {
  width: 80%;
  height: 80%;
  border: 2px solid rgba(204, 236, 255, 0.9);
  animation: splash-ring 620ms ease-out forwards;
}

.fx-blast {
  width: 90%;
  height: 90%;
  background: radial-gradient(
    circle,
    #fff5c8 0%,
    #ffb540 35%,
    var(--hit) 60%,
    rgba(140, 32, 4, 0) 72%
  );
  animation: blast 520ms ease-out forwards;
}

.fx-smoke {
  width: 60%;
  height: 60%;
  background: radial-gradient(circle, rgba(165, 165, 165, 0.85), rgba(90, 90, 90, 0));
  animation: smoke-rise 1100ms ease-out forwards;
}

.effect-impact .fx-blast,
.fx.effect-impact {
  width: 110%;
  height: 110%;
  animation-name: heavy-blast;
  animation-duration: 680ms;
}

.effect-impact .board-wrap.shake {
  animation-duration: 440ms;
}

.effect-minimal .fx-smoke {
  display: none;
}

.effect-minimal .fx-blast,
.effect-minimal .fx-splash {
  width: 54%;
  height: 54%;
  animation-duration: 380ms;
}

.board-wrap.shake {
  animation: shake 320ms ease-in-out;
}

.ship-sprite.sinking {
  animation: sink 900ms ease-in forwards;
}

/* ---------- power mode ---------- */

.power-panel {
  border-color: color-mix(in srgb, var(--gold) 24%, var(--stroke));
  background:
    linear-gradient(145deg, color-mix(in srgb, var(--gold) 5%, transparent), transparent 44%),
    var(--panel);
}

.power-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.power-bank,
.record-card {
  min-width: 0;
  padding: 16px;
  border: 1px solid var(--stroke);
  border-radius: 13px;
  background: rgba(0, 0, 0, 0.12);
}

.power-bank h3,
.record-card h3,
.replay-board-panel h3 {
  margin: 0 0 11px;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 820;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.action-list,
.record-list,
.achievement-list {
  display: grid;
  min-width: 0;
  margin: 0;
  padding: 0;
  gap: 8px;
  list-style: none;
}

.action-list > li:not(.empty-state) {
  min-width: 0;
  padding: 9px;
  border: 1px solid var(--stroke);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.025);
}

.action-list button {
  width: 100%;
  min-width: 0;
  padding: 9px 11px;
  color: var(--text);
  background: var(--accent-soft);
  border: 1px solid color-mix(in srgb, var(--accent) 36%, var(--stroke));
  font-weight: 720;
  text-align: left;
}

.action-list button:hover:not(:disabled) {
  background: color-mix(in srgb, var(--accent) 20%, transparent);
  border-color: color-mix(in srgb, var(--accent) 60%, var(--stroke));
}

.action-list button.is-selected,
.action-list button[aria-pressed="true"] {
  color: var(--accent-ink);
  background: var(--accent);
  border-color: var(--accent);
}

.action-list small {
  display: block;
  margin-top: 7px;
  color: var(--muted);
  font-size: 0.68rem;
  line-height: 1.4;
}

.empty-state {
  color: var(--muted);
  font-size: 0.76rem;
  line-height: 1.5;
}

/* ---------- live stats ---------- */

.status-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.turn-banner {
  margin: 0;
  font-size: clamp(0.94rem, 2vw, 1.08rem);
  line-height: 1.4;
  font-weight: 720;
}

.signal-dot {
  position: relative;
  flex: 0 0 10px;
  width: 10px;
  height: 10px;
  background: var(--good);
  border-radius: 50%;
  box-shadow: 0 0 0 5px color-mix(in srgb, var(--good) 10%, transparent);
}

.signal-dot::after {
  position: absolute;
  inset: -5px;
  content: "";
  border: 1px solid color-mix(in srgb, var(--good) 45%, transparent);
  border-radius: inherit;
  animation: signal-pulse 2s ease-out infinite;
}

@keyframes signal-pulse {
  0% {
    opacity: 0.9;
    transform: scale(0.65);
  }
  70%,
  100% {
    opacity: 0;
    transform: scale(1.45);
  }
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.stat-block h3 {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.stat-block dl {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  min-width: 0;
  margin: 0;
  gap: 7px;
}

.stat-block dl div {
  min-width: 0;
  padding: 9px 6px;
  overflow-wrap: anywhere;
  text-align: center;
  background: rgba(255, 255, 255, 0.035);
  border: 1px solid var(--stroke);
  border-radius: 10px;
}

.stat-block dt {
  color: var(--muted);
  font-size: clamp(0.5rem, 1vw, 0.62rem);
  line-height: 1.25;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.stat-block dd {
  margin: 4px 0 0;
  font-size: clamp(0.95rem, 2.5vw, 1.15rem);
  font-weight: 760;
  font-variant-numeric: tabular-nums;
}

.log-wrap {
  margin-top: 16px;
  padding-top: 13px;
  border-top: 1px solid var(--stroke);
}

.log-label {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 0.62rem;
  font-weight: 800;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

.log {
  display: flex;
  max-height: 132px;
  min-width: 0;
  flex-direction: column;
  margin: 0;
  padding: 0;
  gap: 5px;
  overflow-y: auto;
  color: var(--muted);
  font-size: 0.77rem;
  line-height: 1.45;
  list-style: none;
  scrollbar-color: var(--stroke-strong) transparent;
}

.log li {
  overflow-wrap: anywhere;
}

.log li.you {
  color: color-mix(in srgb, var(--accent) 56%, white);
}

.log li.sunk-line {
  color: var(--hit);
}

/* ---------- profile and records ---------- */

.dashboard-heading {
  align-items: center;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.career-card {
  grid-column: span 1;
}

.custom-card {
  grid-column: 1 / -1;
}

.career-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin: 0;
  gap: 8px;
}

.career-stats div {
  min-width: 0;
  padding: 9px;
  background: rgba(255, 255, 255, 0.025);
  border-radius: 9px;
}

.career-stats dt {
  color: var(--muted);
  font-size: 0.61rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.career-stats dd {
  margin: 4px 0 0;
  font-size: 1.1rem;
  font-weight: 760;
}

.record-list {
  max-height: 154px;
  overflow-y: auto;
}

.record-list > li:not(.empty-state) {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-width: 0;
  gap: 10px;
  padding: 8px 0;
  color: var(--text);
  border-bottom: 1px solid var(--stroke);
  font-size: 0.74rem;
}

.record-list > li:last-child {
  border-bottom: 0;
}

.history-replay {
  min-height: 44px;
  padding: 6px 8px;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid color-mix(in srgb, var(--accent) 32%, var(--stroke));
  border-radius: 8px;
  font-size: 0.67rem;
  font-weight: 720;
  white-space: nowrap;
  cursor: pointer;
}

.history-replay:hover {
  border-color: var(--accent);
}

.achievement {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 10px;
  padding: 8px;
  border: 1px solid var(--stroke);
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.025);
}

.achievement-icon {
  display: grid;
  flex: 0 0 30px;
  width: 30px;
  height: 30px;
  place-items: center;
  color: var(--gold);
  background: color-mix(in srgb, var(--gold) 9%, transparent);
  border: 1px solid color-mix(in srgb, var(--gold) 28%, transparent);
  border-radius: 50%;
}

.achievement > span:last-child {
  display: grid;
  min-width: 0;
  gap: 2px;
}

.achievement strong {
  font-size: 0.75rem;
}

.achievement small {
  color: var(--muted);
  font-size: 0.67rem;
  line-height: 1.35;
}

.achievement.locked {
  opacity: 0.58;
}

.achievement.unlocked,
.achievement.is-unlocked {
  border-color: color-mix(in srgb, var(--gold) 42%, var(--stroke));
}

.record-copy {
  margin: -4px 0 12px;
  color: var(--muted);
  font-size: 0.72rem;
}

.customization-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.customization-grid label {
  display: grid;
  min-width: 0;
  gap: 6px;
}

.customization-grid label > span {
  color: var(--muted);
  font-size: 0.65rem;
  font-weight: 760;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

/* ---------- overlays ---------- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  min-width: 0;
  padding: 18px;
  overflow: auto;
  background: rgba(2, 8, 14, 0.82);
  backdrop-filter: blur(9px);
}

.overlay-card {
  width: min(100%, 430px);
  min-width: 0;
  max-height: calc(100dvh - 36px);
  padding: 30px;
  overflow: auto;
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.05), transparent 45%),
    var(--panel-strong);
  border: 1px solid var(--stroke-strong);
  border-radius: 20px;
  box-shadow: 0 34px 90px rgba(0, 0, 0, 0.58);
}

.result-card {
  position: relative;
  overflow: hidden;
  text-align: center;
}

.result-card > * {
  position: relative;
  z-index: 1;
}

.result-card::before {
  position: absolute;
  top: -140px;
  left: 50%;
  width: 290px;
  height: 290px;
  content: "";
  pointer-events: none;
  background: radial-gradient(circle, var(--accent-soft), transparent 68%);
  transform: translateX(-50%);
}

.overlay-card h2 {
  margin: 0 0 6px;
  font-size: clamp(1.7rem, 7vw, 2.15rem);
  line-height: 1.15;
  letter-spacing: 0.075em;
  text-transform: uppercase;
}

.overlay-card > p:not(.eyebrow):not(.replay-frame-label) {
  margin: 0 0 18px;
  color: var(--muted);
}

.overlay-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin: 0 0 22px;
  gap: 9px;
  text-align: left;
}

.overlay-stats div {
  min-width: 0;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--stroke);
  border-radius: 10px;
}

.overlay-stats dt {
  color: var(--muted);
  font-size: 0.6rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.overlay-stats dd {
  margin: 4px 0 0;
  font-size: 1rem;
  font-weight: 760;
}

.result-card .primary-btn {
  min-width: 150px;
}

@keyframes victory-glow {
  0%,
  100% {
    box-shadow: 0 34px 90px rgba(0, 0, 0, 0.58);
  }
  50% {
    box-shadow:
      0 34px 90px rgba(0, 0, 0, 0.58),
      0 0 46px color-mix(in srgb, var(--accent) 28%, transparent);
  }
}

@keyframes victory-burst {
  0% {
    opacity: 0;
    transform: translateX(-50%) scale(0.35);
  }
  55% {
    opacity: 1;
  }
  100% {
    opacity: 0.2;
    transform: translateX(-50%) scale(1.2);
  }
}

.victory-signal .result-card,
.overlay.victory-signal .result-card {
  animation: victory-glow 2.2s ease-in-out infinite;
}

.victory-fireworks .result-card::before,
.overlay.victory-fireworks .result-card::before {
  background:
    repeating-conic-gradient(
      from 0deg,
      transparent 0deg 14deg,
      color-mix(in srgb, var(--gold) 75%, transparent) 15deg 17deg,
      transparent 18deg 30deg
    );
  animation: victory-burst 1.3s ease-out both;
}

.victory-fleet .result-card,
.overlay.victory-fleet .result-card {
  border-color: color-mix(in srgb, var(--gold) 52%, var(--stroke));
  box-shadow:
    0 34px 90px rgba(0, 0, 0, 0.58),
    inset 0 0 42px color-mix(in srgb, var(--gold) 8%, transparent);
}

/* ---------- replay ---------- */

.replay-overlay {
  z-index: 40;
}

.replay-card {
  width: min(100%, 860px);
  text-align: left;
}

.replay-header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  min-width: 0;
  gap: 16px;
  margin-bottom: 14px;
}

.replay-header h2 {
  margin-bottom: 0;
  font-size: clamp(1.25rem, 4vw, 1.7rem);
}

.icon-btn {
  display: grid;
  flex: 0 0 44px;
  width: 44px;
  padding: 0;
  place-items: center;
  color: var(--text);
  background: rgba(255, 255, 255, 0.045);
  border: 1px solid var(--stroke);
  font-size: 1.6rem;
  line-height: 1;
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.09);
  border-color: var(--stroke-strong);
}

.replay-frame-label {
  margin: 0 0 12px;
  padding: 9px 11px;
  color: var(--accent);
  background: var(--accent-soft);
  border-left: 3px solid var(--accent);
  border-radius: 0 8px 8px 0;
  font-size: 0.76rem;
  font-weight: 700;
}

.replay-boards {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  min-width: 0;
  gap: 16px;
}

.replay-board-panel {
  min-width: 0;
}

.replay-grid {
  display: grid;
  width: 100%;
  min-width: 0;
  grid-template-columns: repeat(10, minmax(0, 1fr));
  grid-template-rows: repeat(10, minmax(0, 1fr));
  aspect-ratio: 1;
  gap: 2px;
  padding: 8px;
  background: var(--bg-soft);
  border: 1px solid var(--stroke);
  border-radius: 12px;
}

.replay-grid > *,
.replay-cell {
  min-width: 0;
  min-height: 0;
  padding: 0;
  background: linear-gradient(155deg, var(--water-hi), var(--water));
  border: 0;
  border-radius: 3px;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.04);
}

.replay-grid .hit,
.replay-cell.hit {
  background:
    radial-gradient(circle at center, var(--hit) 0 20%, transparent 22%),
    linear-gradient(155deg, var(--water-hi), var(--water));
}

.replay-grid .miss,
.replay-cell.miss {
  background:
    radial-gradient(circle at center, var(--miss) 0 13%, transparent 15%),
    linear-gradient(155deg, var(--water-hi), var(--water));
}

.replay-grid .ship,
.replay-cell.ship {
  box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--accent) 60%, transparent);
}

.replay-controls {
  display: flex;
  justify-content: end;
  min-width: 0;
  margin-top: 16px;
  gap: 9px;
}

/* ---------- responsive ---------- */

@media (max-width: 980px) {
  .command-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .mode-group {
    grid-column: 1 / -1;
  }

  .dashboard-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .customization-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  .topbar {
    padding-inline: 16px;
  }

  .layout {
    padding-inline: 16px;
  }

  .boards {
    grid-template-columns: minmax(0, 1fr);
    gap: 28px;
  }

  .board-column {
    width: min(100%, 590px);
    margin-inline: auto;
  }

  .power-grid,
  .stats-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .dashboard-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .custom-card {
    grid-column: auto;
  }
}

@media (max-width: 560px) {
  .topbar {
    flex-wrap: wrap;
    padding: 13px 12px;
  }

  .brand-lockup {
    flex: 1 1 100%;
  }

  .topbar-actions {
    width: 100%;
  }

  .topbar-actions > * {
    flex: 1 1 0;
  }

  .layout {
    padding: 16px 11px 40px;
    gap: 16px;
  }

  .panel {
    padding: 16px 14px;
    border-radius: 14px;
  }

  .section-heading,
  .compact-heading,
  .dashboard-heading {
    align-items: stretch;
    flex-direction: column;
    gap: 8px;
  }

  .section-note,
  .hint {
    max-width: none;
  }

  .command-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .mode-group {
    grid-column: auto;
  }

  .setup-actions > * {
    flex: 1 1 calc(50% - 5px);
  }

  .setup-actions .primary-btn {
    margin-left: 0;
  }

  .board-wrap {
    grid-template-columns: 17px minmax(0, 1fr);
    grid-template-rows: 17px minmax(0, 1fr);
    gap: 3px;
    padding: 8px;
  }

  .stat-block dl {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .customization-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .replay-open-btn {
    width: 100%;
  }

  .overlay {
    padding: 10px;
  }

  .overlay-card {
    max-height: calc(100dvh - 20px);
    padding: 22px 16px;
    border-radius: 16px;
  }

  .replay-boards {
    grid-template-columns: minmax(0, 1fr);
  }

  .replay-board-panel {
    width: min(100%, 320px);
    margin-inline: auto;
  }

  .replay-controls > * {
    flex: 1 1 0;
    min-width: 0;
    padding-inline: 8px;
  }
}

@media (max-width: 360px) {
  .logo {
    letter-spacing: 0.15em;
  }

  .segmented-control {
    grid-template-columns: minmax(0, 1fr);
  }

  .tray > li,
  .tray-item {
    flex: 1 1 100%;
    width: 100%;
  }

  .board-tag {
    font-size: 0.52rem;
  }

  .replay-controls {
    flex-direction: column-reverse;
  }

  .replay-controls > * {
    width: 100%;
  }
}

.hud-feed {
  position: fixed;
  top: 86px;
  left: 50%;
  z-index: 25;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: min(420px, calc(100vw - 32px));
  transform: translateX(-50%);
  pointer-events: none;
}

.hud-card {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 12px 16px;
  color: var(--text);
  background: color-mix(in srgb, var(--panel-strong) 58%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 45%, var(--stroke));
  border-radius: var(--radius-sm);
  box-shadow: 0 18px 40px rgba(3, 12, 20, 0.45);
  backdrop-filter: blur(14px);
  opacity: 0;
  transform: translateY(-10px) scale(0.97);
  transition: opacity 220ms ease, transform 220ms ease;
}

.hud-card.visible {
  opacity: 1;
  transform: translateY(0) scale(1);
}

.hud-card.leaving {
  opacity: 0;
  transform: translateY(-8px) scale(0.98);
}

.hud-card .hud-icon {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid color-mix(in srgb, var(--accent) 40%, transparent);
  border-radius: 50%;
  font-size: 0.95rem;
}

.hud-card .hud-title {
  margin: 0 0 2px;
  color: var(--accent);
  font-size: 0.66rem;
  font-weight: 750;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.hud-card .hud-detail {
  margin: 0;
  font-size: 0.92rem;
  line-height: 1.35;
}

.hud-card.reward {
  border-color: color-mix(in srgb, var(--gold) 52%, var(--stroke));
}

.hud-card.reward .hud-icon,
.hud-card.reward .hud-title {
  color: var(--gold);
}

.hud-card.reward .hud-icon {
  background: color-mix(in srgb, var(--gold) 13%, transparent);
  border-color: color-mix(in srgb, var(--gold) 42%, transparent);
}

@media (max-width: 720px) {
  .hud-feed {
    top: auto;
    bottom: 16px;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}

@media (prefers-contrast: more) {
  :root {
    --stroke: rgba(218, 235, 248, 0.44);
    --stroke-strong: rgba(236, 248, 255, 0.75);
    --muted: #c4d2de;
  }
}
