:root {
  color-scheme: light;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #eef3f1;
  color: #142026;
  --ink: #142026;
  --muted: #66747a;
  --line: #c9d4d2;
  --paper: #ffffff;
  --navy: #0b3d4f;
  --navy-strong: #062d3c;
  --water: #d8edf0;
  --water-line: #98c6cd;
  --hit: #c83832;
  --miss: #ffffff;
  --signal: #e3c94d;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: #0b3d4f;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  padding-bottom: env(safe-area-inset-bottom);
  background: #eef3f1;
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
}

button,
input {
  font: inherit;
}

button {
  touch-action: manipulation;
}

button:focus-visible,
input:focus-visible,
a:focus-visible {
  outline: 3px solid #e3c94d;
  outline-offset: 3px;
}

[hidden] {
  display: none !important;
}

.topbar {
  display: flex;
  min-height: calc(62px + env(safe-area-inset-top));
  align-items: center;
  justify-content: space-between;
  padding: env(safe-area-inset-top) max(18px, env(safe-area-inset-right)) 0 max(18px, env(safe-area-inset-left));
  border-bottom: 1px solid #174f60;
  background: var(--navy);
  color: #ffffff;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: #ffffff;
  font-size: 16px;
  font-weight: 900;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  width: 30px;
  height: 30px;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.55);
  border-radius: 6px;
  font-size: 14px;
}

.connection {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: #dce9e8;
  font-size: 12px;
  font-weight: 800;
}

.connection::before {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #65c890;
  content: "";
}

.connection.offline::before {
  background: #f08b71;
}

main {
  width: min(1160px, 100%);
  margin: 0 auto;
  padding: 38px 24px 70px;
}

.screen {
  min-width: 0;
}

.home-screen {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(300px, 420px);
  gap: 72px;
  align-items: center;
  min-height: calc(100dvh - 170px);
}

.eyebrow {
  margin: 0 0 10px;
  color: #287568;
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: 44px;
  line-height: 1.05;
  letter-spacing: 0;
}

.home-copy > p:not(.eyebrow) {
  max-width: 610px;
  margin: 18px 0 0;
  color: var(--muted);
  font-size: 19px;
  line-height: 1.5;
}

.fleet-preview {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1px;
  margin: 34px 0 0;
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--line);
  list-style: none;
}

.fleet-preview li {
  min-width: 0;
  padding: 13px 10px;
  background: var(--paper);
  color: var(--muted);
  font-size: 11px;
  line-height: 1.3;
  overflow-wrap: anywhere;
}

.fleet-preview strong {
  display: block;
  margin-bottom: 3px;
  color: var(--navy);
  font-size: 20px;
}

.rules-list {
  display: grid;
  gap: 7px;
  margin: 18px 0 0;
  padding: 0;
  color: var(--muted);
  font-size: 13px;
  list-style: none;
}

.rules-list li::before {
  content: "✓";
  margin-right: 8px;
  color: var(--navy);
  font-weight: 800;
}

.join-panel {
  padding: 26px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  box-shadow: 0 12px 32px rgba(10, 44, 53, 0.08);
}

label {
  display: block;
  margin: 0 0 7px;
  color: #435158;
  font-size: 12px;
  font-weight: 850;
}

input {
  width: 100%;
  height: 48px;
  padding: 0 13px;
  border: 1px solid #aebdbb;
  border-radius: 6px;
  background: #ffffff;
  color: var(--ink);
  font-size: 16px;
}

input::placeholder {
  color: #95a19f;
}

button {
  min-height: 45px;
  padding: 0 18px;
  border: 0;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 850;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.primary {
  background: var(--navy);
  color: #ffffff;
}

.primary:not(:disabled):hover {
  background: var(--navy-strong);
}

.secondary {
  border: 1px solid #aebdbb;
  background: #ffffff;
  color: #23343b;
}

.secondary:not(:disabled):hover {
  border-color: var(--navy);
}

.text-button {
  background: transparent;
  color: #57666c;
}

.wide {
  width: 100%;
}

.join-panel > .primary {
  margin-top: 15px;
}

.divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 23px 0;
  color: #889593;
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.divider::before,
.divider::after {
  height: 1px;
  flex: 1;
  background: #d9e0de;
  content: "";
}

.join-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 9px;
}

#roomCodeInput {
  font-weight: 900;
  letter-spacing: 3px;
  text-transform: uppercase;
}

.error {
  min-height: 19px;
  margin: 11px 0 0;
  color: #b32f2b;
  font-size: 13px;
  font-weight: 750;
  line-height: 1.4;
}

.centered {
  text-align: center;
}

.screen-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--line);
}

.screen-heading h1 {
  font-size: 34px;
}

.room-code {
  display: grid;
  grid-template-columns: auto auto auto;
  align-items: center;
  gap: 10px;
}

.room-code > span,
.round-room {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.room-code strong {
  font-size: 27px;
  letter-spacing: 4px;
}

.icon-button {
  display: grid;
  width: 42px;
  min-height: 42px;
  padding: 0;
  place-items: center;
  background: transparent;
  color: var(--navy);
  font-size: 23px;
}

.icon-button.bordered {
  border: 1px solid #aebdbb;
  background: #ffffff;
}

.lobby-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 64px;
  padding-top: 30px;
}

.section-label,
.board-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
}

.section-label span,
.board-title span,
.board-title div > span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
  text-transform: uppercase;
}

.player-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.player-list li {
  display: flex;
  min-height: 64px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--paper);
}

.player-name {
  font-weight: 850;
}

.player-meta {
  margin-top: 2px;
  color: var(--muted);
  font-size: 11px;
}

.kick-button {
  width: 38px;
  min-height: 38px;
  padding: 0;
  background: transparent;
  color: #9e302d;
  font-size: 22px;
}

.status-note {
  margin: 15px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.lobby-actions {
  padding-top: 28px;
}

.lobby-actions .text-button {
  margin-top: 7px;
}

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

.setup-layout {
  display: grid;
  grid-template-columns: minmax(0, 640px) minmax(260px, 340px);
  gap: 56px;
  align-items: start;
  padding-top: 28px;
}

.board-section {
  min-width: 0;
}

.ocean-board {
  display: grid;
  width: 100%;
  max-width: 620px;
  grid-template-columns: 24px repeat(10, minmax(0, 1fr));
  grid-template-rows: 24px repeat(10, minmax(0, 1fr));
  aspect-ratio: 1 / 1;
  user-select: none;
}

.axis {
  display: grid;
  place-items: center;
  color: #67787d;
  font-size: 10px;
  font-weight: 850;
}

.sea-cell {
  position: relative;
  min-width: 0;
  min-height: 0;
  padding: 0;
  border: 0;
  border-right: 1px solid var(--water-line);
  border-bottom: 1px solid var(--water-line);
  border-radius: 0;
  background: var(--water);
  color: transparent;
}

.sea-cell.edge-top {
  border-top: 1px solid var(--water-line);
}

.sea-cell.edge-left {
  border-left: 1px solid var(--water-line);
}

.sea-cell.ship {
  background: #3b5964;
  box-shadow: inset 0 0 0 2px #243e47;
}

.setup-board .sea-cell:not(:disabled):hover,
.setup-board .sea-cell.preview {
  background: #82b9b8;
}

.setup-board .sea-cell.invalid {
  background: #e9a09b;
}

.sea-cell.miss::after,
.sea-cell.hit::after {
  position: absolute;
  inset: 28%;
  border-radius: 50%;
  content: "";
}

.sea-cell.miss::after {
  border: 2px solid #5c8c97;
  background: #ffffff;
}

.sea-cell.hit {
  background: #e7a09c;
}

.sea-cell.hit::after {
  background: var(--hit);
  box-shadow: 0 0 0 2px #ffffff;
}

.sea-cell.sunk {
  background: #893833;
}

.target-board.can-fire .sea-cell:not(.miss):not(.hit) {
  cursor: crosshair;
}

.target-board.can-fire .sea-cell:not(.miss):not(.hit):hover {
  background: #acd6d8;
  box-shadow: inset 0 0 0 3px var(--navy);
}

.fleet-controls {
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
}

.ship-tray {
  display: grid;
  max-height: 485px;
  gap: 6px;
  margin-bottom: 18px;
  padding-right: 3px;
  overflow-y: auto;
}

.ship-option {
  display: grid;
  min-height: 50px;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  padding: 8px 11px;
  border: 1px solid #cad3d1;
  background: #ffffff;
  color: var(--ink);
  text-align: left;
  touch-action: none;
  cursor: grab;
}

.ship-option:active,
.ship-option.dragging {
  cursor: grabbing;
}

.ship-option.dragging {
  opacity: 0.58;
}

.ship-option.selected {
  border-color: var(--navy);
  background: #e4eeee;
  box-shadow: inset 4px 0 0 var(--navy);
}

.ship-option.placed {
  color: #536268;
}

.ship-option strong {
  overflow-wrap: anywhere;
}

.ship-option-copy {
  display: grid;
  gap: 2px;
}

.ship-option-copy small {
  color: var(--muted);
  font-size: 11px;
}

.ship-blocks {
  display: flex;
  gap: 2px;
}

.ship-option.vertical .ship-blocks {
  flex-direction: column;
}

.ship-blocks i {
  display: block;
  width: 11px;
  height: 11px;
  background: #4a6570;
}

.ship-option.placed .ship-blocks i {
  background: #71a486;
}

.control-row {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 7px;
  margin-bottom: 10px;
}

.control-row button {
  padding: 0 10px;
}

.battle-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 22px;
}

.battle-header h1 {
  font-size: 32px;
}

.last-shot {
  min-width: 180px;
  padding: 10px 12px;
  border-left: 3px solid var(--signal);
  background: #ffffff;
  color: #536268;
  font-size: 12px;
  font-weight: 750;
}

.battle-notice {
  min-height: 22px;
  margin: 18px 0 8px;
  color: #385159;
  font-size: 14px;
  font-weight: 750;
}

.battle-layout {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 46px;
  align-items: start;
}

.board-title {
  min-height: 42px;
}

.board-title div {
  display: grid;
  gap: 3px;
}

.board-title strong {
  font-size: 17px;
}

.mini-fleet {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 12px;
}

.mini-ship {
  display: inline-flex;
  min-height: 29px;
  align-items: center;
  gap: 3px;
  padding: 4px 7px;
  border: 1px solid #bcc8c6;
  border-radius: 4px;
  background: #ffffff;
}

.mini-ship i {
  display: block;
  width: 7px;
  height: 7px;
  background: #415e68;
}

.mini-ship.sunk {
  border-color: #bd716d;
  background: #f4d9d7;
  opacity: 0.7;
}

.results-screen {
  text-align: center;
}

.result-copy {
  max-width: 680px;
  margin: 0 auto;
}

.result-copy h1 {
  font-size: 48px;
}

.result-copy > p:last-child {
  color: var(--muted);
  font-size: 17px;
}

.results-actions {
  display: flex;
  justify-content: center;
  gap: 9px;
  margin: 24px 0 40px;
}

.result-boards {
  text-align: left;
}

.toast {
  position: fixed;
  right: max(18px, env(safe-area-inset-right));
  bottom: max(18px, env(safe-area-inset-bottom));
  z-index: 10;
  max-width: min(360px, calc(100% - 36px));
  padding: 12px 15px;
  border-radius: 6px;
  background: #142026;
  color: #ffffff;
  font-size: 13px;
  font-weight: 750;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.22);
}

@media (max-width: 850px) {
  .home-screen {
    grid-template-columns: 1fr;
    gap: 34px;
    min-height: auto;
  }

  .home-copy {
    max-width: 680px;
  }

  .join-panel {
    width: 100%;
    max-width: 520px;
  }

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

  .fleet-controls {
    max-width: 620px;
  }

  .lobby-actions {
    width: min(320px, 100%);
    padding-top: 0;
  }

  .battle-layout {
    gap: 24px;
  }
}

@media (max-width: 640px) {
  main {
    padding: 26px 14px 50px;
  }

  h1 {
    font-size: 35px;
  }

  .home-copy > p:not(.eyebrow) {
    font-size: 17px;
  }

  .fleet-preview {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .join-panel {
    padding: 19px;
  }

  .screen-heading,
  .battle-header {
    align-items: start;
    flex-direction: column;
  }

  .screen-heading h1,
  .battle-header h1 {
    font-size: 29px;
  }

  .room-code {
    width: 100%;
    justify-content: start;
  }

  .round-room {
    align-self: start;
  }

  .setup-layout {
    padding-top: 20px;
  }

  .ocean-board {
    max-width: none;
    grid-template-columns: 19px repeat(10, minmax(0, 1fr));
    grid-template-rows: 19px repeat(10, minmax(0, 1fr));
  }

  .axis {
    font-size: 8px;
  }

  .fleet-controls {
    padding: 15px;
  }

  .battle-layout {
    grid-template-columns: 1fr;
    gap: 40px;
  }

  .target-section {
    order: -1;
  }

  .last-shot {
    width: 100%;
  }

  .result-copy h1 {
    font-size: 39px;
  }

  .result-boards {
    gap: 32px;
  }
}

@media (max-width: 370px) {
  main {
    padding-right: 9px;
    padding-left: 9px;
  }

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

  .control-row {
    grid-template-columns: 1fr 1fr 42px;
  }

  .control-row button {
    font-size: 12px;
  }
}

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