:root {
  color-scheme: light;
  --ink: #17202a;
  --muted: #627080;
  --line: #d5dde5;
  --paper: #f7fafc;
  --panel: #ffffff;
  --blue: #1f6fbf;
  --blue-dark: #164d82;
  --cyan: #cae9f7;
  --ship: #34495e;
  --hit: #d64545;
  --miss: #7da5bd;
  --accent: #f0a33a;
  --green: #247b59;
  --red: #b73535;
  font-family: Inter, "Segoe UI", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(31, 111, 191, 0.14), transparent 34rem),
    linear-gradient(135deg, rgba(31, 111, 191, 0.08), rgba(36, 123, 89, 0.08)),
    var(--paper);
}

button,
input {
  font: inherit;
}

button {
  border: 0;
  border-radius: 6px;
  color: #fff;
  background: var(--blue);
  cursor: pointer;
  min-height: 42px;
  padding: 0 16px;
  font-weight: 700;
}

button:hover {
  background: var(--blue-dark);
}

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

input {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 12px;
  color: var(--ink);
  background: #fff;
}

.shell {
  width: min(1180px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 28px 0;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 20px;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: clamp(2rem, 4vw, 3.9rem);
  line-height: 1;
}

h2 {
  font-size: 1.05rem;
}

h3 {
  font-size: 1rem;
}

.connection {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.8);
  white-space: nowrap;
}

.connection.online {
  color: var(--green);
  border-color: rgba(36, 123, 89, 0.35);
}

.connection.offline {
  color: var(--hit);
  border-color: rgba(214, 69, 69, 0.35);
}

.lobby {
  display: grid;
  grid-template-columns: 1fr minmax(300px, 420px);
  gap: 24px;
  align-items: start;
}

.lobby-panel {
  display: grid;
  gap: 12px;
  align-content: start;
  min-height: 382px;
  padding: 22px;
}

.lobby-panel label {
  font-weight: 800;
}

.rules-panel {
  display: grid;
  align-content: start;
}

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

.rule-card {
  display: grid;
  gap: 14px;
  grid-template-rows: 1fr auto;
  min-height: 382px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 12px 34px rgba(24, 45, 67, 0.08);
}

.rule-card p {
  margin-top: 6px;
  color: var(--muted);
  line-height: 1.4;
}

.fleet-picture,
.mini-board {
  min-height: 170px;
  border-radius: 8px;
  background:
    repeating-linear-gradient(0deg, transparent 0 23px, rgba(22, 77, 130, 0.14) 23px 25px),
    repeating-linear-gradient(90deg, transparent 0 23px, rgba(22, 77, 130, 0.14) 23px 25px),
    #e8f6fb;
}

.fleet-picture {
  display: grid;
  align-content: center;
  gap: 6px;
  padding: 14px;
}

.fleet-picture span {
  display: block;
  width: calc(var(--decks) * 28px);
  height: 16px;
  border-radius: 4px;
  background: var(--ship);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.18);
}

.mini-board {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 3px;
  padding: 10px;
}

.mini-board i {
  display: block;
  min-width: 0;
  border-radius: 5px;
  background: rgba(202, 233, 247, 0.78);
}

.mini-board .ship {
  background: var(--ship);
}

.mini-board .gap,
.mini-board .checked {
  background: rgba(125, 165, 189, 0.55);
}

.mini-board .hit {
  background: #f5c7c7;
  box-shadow: inset 0 0 0 7px var(--hit);
}

.mini-board .miss {
  background: #d9edf6;
  box-shadow: inset 0 0 0 7px var(--miss);
}

.room-actions {
  display: grid;
  gap: 10px;
}

.join-row {
  display: grid;
  grid-template-columns: 1fr 110px;
  gap: 10px;
}

.social-links {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding-top: 2px;
}

.social-links a {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  background: #eef4f8;
  font-weight: 800;
  text-decoration: none;
}

.social-links a:hover {
  border-color: rgba(31, 111, 191, 0.35);
  background: #e2edf4;
}

.social-links svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

.index-phrase {
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.35;
}

.game {
  display: grid;
  grid-template-columns: 270px 1fr;
  gap: 22px;
}

.status-panel,
.board-wrap,
.lobby-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 12px 34px rgba(24, 45, 67, 0.08);
}

.status-panel {
  display: grid;
  align-content: start;
  gap: 14px;
  padding: 18px;
}

.back-button {
  width: 42px;
  min-height: 42px;
  padding: 0;
  color: var(--ink);
  background: #e7edf3;
  font-size: 1.35rem;
}

.back-button:hover {
  background: #d9e4ee;
}

.room-code,
.status-card,
.ship-row {
  display: grid;
  gap: 5px;
}

.room-code span,
.status-card span,
.ship-row span,
.board-title span {
  color: var(--muted);
  font-size: 0.86rem;
}

.room-code strong {
  font-size: 2rem;
}

.status-card strong,
.ship-row strong {
  font-size: 1.05rem;
}

.placement-tools {
  display: grid;
  gap: 10px;
  padding-top: 4px;
}

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

.ship-token {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  padding: 7px 9px;
  color: var(--ink);
  background: #eef4f8;
  border: 1px solid transparent;
}

.ship-token:hover {
  background: #e2edf4;
}

.ship-token.selected {
  border-color: var(--accent);
  background: #fff3dc;
}

.ship-token.placed {
  color: var(--muted);
  background: #edf1f5;
  opacity: 0.75;
}

.ship-token-body {
  display: grid;
  grid-template-columns: repeat(var(--decks), 16px);
  gap: 2px;
}

.ship-token.vertical .ship-token-body {
  grid-template-columns: 16px;
  grid-auto-rows: 16px;
}

.ship-token-body i {
  display: block;
  width: 16px;
  height: 16px;
  border-radius: 3px;
  background: var(--ship);
}

.ship-token-label {
  min-width: 18px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
  text-align: right;
}

.tool-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.secondary,
.tool-row button {
  color: var(--ink);
  background: #e7edf3;
}

.secondary:hover,
.tool-row button:hover {
  background: #d9e4ee;
}

.log {
  display: grid;
  gap: 8px;
  min-height: 120px;
  margin: 0;
  padding: 0 0 0 20px;
  color: var(--muted);
}

.boards {
  display: grid;
  grid-template-columns: repeat(2, minmax(280px, 1fr));
  gap: 22px;
}

.board-wrap {
  padding: 18px;
}

.board-title {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.board {
  display: grid;
  grid-template-columns: repeat(10, minmax(22px, 1fr));
  width: 100%;
  aspect-ratio: 1;
  border: 2px solid var(--blue-dark);
  background: var(--blue-dark);
  gap: 2px;
}

.cell {
  position: relative;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 0;
  min-height: 0;
  padding: 0;
  color: var(--ink);
  background: var(--cyan);
}

.cell:hover {
  background: #b4dfee;
}

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

.cell.preview {
  background: var(--accent);
}

.cell.invalid {
  background: var(--hit);
}

.cell.hit::after,
.cell.miss::after {
  content: "";
  width: 42%;
  height: 42%;
  border-radius: 999px;
}

.cell.hit {
  background: #f5c7c7;
}

.cell.hit::after {
  background: var(--hit);
}

.cell.miss::after {
  background: var(--miss);
}

.enemy .cell {
  cursor: crosshair;
}

.enemy .cell:disabled {
  cursor: default;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  max-width: min(360px, calc(100vw - 44px));
  border-radius: 8px;
  padding: 14px 16px;
  color: #fff;
  background: #243547;
  box-shadow: 0 16px 40px rgba(23, 32, 42, 0.25);
}

.hidden {
  display: none !important;
}

@media (max-width: 920px) {
  .game,
  .boards,
  .lobby {
    grid-template-columns: 1fr;
  }

  .rules-grid {
    grid-template-columns: 1fr;
  }

  .rule-card {
    min-height: auto;
    grid-template-columns: minmax(160px, 220px) 1fr;
    grid-template-rows: none;
    align-items: center;
  }

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

  .placement-tools,
  .log {
    grid-column: 1 / -1;
  }
}

@media (max-width: 620px) {
  .shell {
    width: min(100vw - 20px, 1180px);
    padding: 16px 0;
  }

  .topbar {
    display: grid;
  }

  .connection {
    white-space: normal;
  }

  .board-wrap,
  .status-panel {
    padding: 14px;
  }

  .status-panel,
  .join-row {
    grid-template-columns: 1fr;
  }

  .rule-card,
  .social-links {
    grid-template-columns: 1fr;
  }

  .rule-card {
    grid-template-rows: none;
  }

  .board-title {
    display: grid;
  }
}
