/* Shared look for the home page and every game. Colours are tokens; dark
   mode follows the OS unless the header toggle pins a theme. */
:root {
  color-scheme: light;
  --bg: #f6f3ee;
  --surface: #ffffff;
  --surface-2: #efeae2;
  --text: #1f2430;
  --muted: #646b7a;
  --border: #ddd6ca;
  --accent: #ff6b4a;
  --accent-ink: #ffffff;
  --accent-2: #2b8a8a;
  --focus: #2f6fed;
  --danger: #c93a2b;
  --ok: #23845a;
  --shadow: 0 1px 2px rgb(30 25 15 / 6%), 0 6px 20px rgb(30 25 15 / 7%);
  --radius: 14px;
  --water: #cfe6f2;
  --water-2: #b7d9ea;
  --water-line: #9cc6dc;
  --ship: #4f5d75;
  --ship-edge: #36415a;
  --miss: #4a86b0;
  --hit: #ff6b2c;
  --hit-2: #ffc23a;
  --sunk: #2c3446;
  --gift: #8b5cf6;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #12151c;
    --surface: #1b1f29;
    --surface-2: #242a36;
    --text: #e9ecf2;
    --muted: #9aa3b5;
    --border: #2f3646;
    --accent: #ff7a5c;
    --accent-ink: #1a0e0a;
    --accent-2: #4fc1c1;
    --focus: #7aa7ff;
    --danger: #ff6b5e;
    --ok: #4cc38a;
    --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 8px 24px rgb(0 0 0 / 35%);
    --water: #16324a;
    --water-2: #1b3d59;
    --water-line: #24506f;
    --ship: #8b9bb8;
    --ship-edge: #b5c2da;
    --miss: #7fb6dc;
    --hit: #ff7a3a;
    --hit-2: #ffd166;
    --sunk: #0b0e14;
    --gift: #b18cff;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #12151c;
  --surface: #1b1f29;
  --surface-2: #242a36;
  --text: #e9ecf2;
  --muted: #9aa3b5;
  --border: #2f3646;
  --accent: #ff7a5c;
  --accent-ink: #1a0e0a;
  --accent-2: #4fc1c1;
  --focus: #7aa7ff;
  --danger: #ff6b5e;
  --ok: #4cc38a;
  --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 8px 24px rgb(0 0 0 / 35%);
  --water: #16324a;
  --water-2: #1b3d59;
  --water-line: #24506f;
  --ship: #8b9bb8;
  --ship-edge: #b5c2da;
  --miss: #7fb6dc;
  --hit: #ff7a3a;
  --hit-2: #ffd166;
  --sunk: #0b0e14;
  --gift: #b18cff;
}

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

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  overflow-x: hidden;
}

a {
  color: var(--accent-2);
}

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

[hidden] {
  display: none !important;
}

h1,
h2,
h3 {
  line-height: 1.2;
  margin: 0 0 0.5em;
}

/* ---------- header ---------- */
.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  max-width: 1100px;
  margin: 0 auto;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  text-decoration: none;
  font-weight: 800;
  font-size: 1.1rem;
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.brand em {
  font-style: normal;
  color: var(--accent);
}

.logo-mark {
  width: 32px;
  height: 32px;
  flex: none;
}

.logo-bg {
  fill: var(--accent);
}

.logo-dot {
  fill: var(--accent-ink);
}

.logo-dot2 {
  fill: var(--accent-ink);
  opacity: 0.55;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.header-game {
  color: var(--muted);
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}

.icon-btn svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
}

/* ---------- layout ---------- */
.page {
  max-width: 1100px;
  margin: 0 auto;
  padding: 8px 16px 48px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

.site-footer {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px 16px 32px;
  color: var(--muted);
  font-size: 0.85rem;
  text-align: center;
}

/* ---------- buttons and fields ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 18px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  transition: transform 0.08s ease, filter 0.15s ease;
}

.btn:hover {
  filter: brightness(1.04);
}

.btn:active {
  transform: translateY(1px);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn.primary {
  background: var(--accent);
  border-color: transparent;
  color: var(--accent-ink);
}

.btn.ghost {
  background: transparent;
  border-color: transparent;
  color: var(--muted);
}

.btn.big {
  min-height: 54px;
  font-size: 1.05rem;
}

.btn.small {
  min-height: 36px;
  padding: 0 12px;
}

.field {
  display: grid;
  gap: 4px;
  margin: 12px 0;
}

.field > span {
  font-weight: 700;
  font-size: 0.9rem;
}

.field small {
  color: var(--muted);
}

input[type="text"] {
  width: 100%;
  min-height: 44px;
  padding: 0 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font: inherit;
}

/* ---------- lobby ---------- */
.lobby-card {
  max-width: 520px;
  margin: 16px auto;
  text-align: center;
}

.lobby-card .field {
  text-align: left;
}

.tagline {
  color: var(--muted);
  margin-top: 0;
}

.lobby-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 16px 0 8px;
}

.divider {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 0.85rem;
  margin: 14px 0 10px;
}

.divider::before,
.divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

.join-row,
.invite-row {
  display: flex;
  gap: 8px;
}

.join-row input {
  text-transform: uppercase;
  letter-spacing: 0.3em;
  text-align: center;
  font-weight: 800;
}

.invite-row {
  flex-wrap: wrap;
  margin: 12px 0;
}

.invite-row input {
  flex: 1 1 220px;
  font-size: 0.9rem;
}

.room-code {
  font-size: clamp(2.4rem, 12vw, 3.6rem);
  font-weight: 900;
  letter-spacing: 0.25em;
  padding-left: 0.25em;
  color: var(--accent);
  margin: 8px 0;
}

.waiting {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--muted);
}

.spinner {
  width: 18px;
  height: 18px;
  flex: none;
  border-radius: 50%;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.notice {
  background: var(--surface-2);
  border-radius: 10px;
  padding: 10px 12px;
  text-align: left;
}

.notice.error {
  border-left: 4px solid var(--danger);
}

/* ---------- overlay + toast ---------- */
.overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgb(10 12 18 / 55%);
  z-index: 50;
}

.overlay .card {
  max-width: 420px;
  width: 100%;
  text-align: center;
}

/* Top of the screen, so it never covers a game board on a phone. */
.toast {
  position: fixed;
  left: 50%;
  top: 12px;
  transform: translate(-50%, -30px);
  opacity: 0;
  pointer-events: none;
  background: var(--text);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: 999px;
  font-weight: 700;
  transition: all 0.2s ease;
  z-index: 60;
  max-width: calc(100vw - 32px);
  text-align: center;
  box-shadow: var(--shadow);
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ---------- game pages: rules panel, rematch line ---------- */
.rules {
  margin-top: 24px;
}

.rules summary {
  cursor: pointer;
  font-weight: 800;
}

.rules li {
  margin: 6px 0;
}

.rematch-status {
  margin: 10px 0 0;
  color: var(--muted);
  font-weight: 700;
}

/* ---------- home ---------- */
.hero {
  text-align: center;
  padding: 24px 0 8px;
}

.hero h1 {
  font-size: clamp(1.8rem, 6vw, 2.8rem);
  letter-spacing: -0.02em;
}

.hero p {
  color: var(--muted);
  max-width: 560px;
  margin: 0 auto;
}

.game-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 16px;
  margin-top: 24px;
  padding: 0;
  list-style: none;
}

.game-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 10px;
  color: var(--text);
  text-decoration: none;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

a.game-card:hover {
  transform: translateY(-3px);
}

.game-card h2 {
  font-size: 1.2rem;
  margin: 0;
}

.game-card p {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
  flex: 1;
}

.game-icon {
  width: 100%;
  aspect-ratio: 16 / 10;
  border-radius: 10px;
  background: var(--surface-2);
  display: grid;
  place-items: center;
  overflow: hidden;
}

.game-icon img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.monogram {
  font-size: 2.6rem;
  font-weight: 900;
  color: var(--muted);
  opacity: 0.6;
  letter-spacing: -0.04em;
}

.game-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.85rem;
  color: var(--muted);
}

.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-weight: 800;
  font-size: 0.78rem;
  background: var(--accent);
  color: var(--accent-ink);
}

.badge.soon {
  background: var(--surface-2);
  color: var(--muted);
}

.game-card.soon {
  opacity: 0.75;
}

@media (max-width: 520px) {
  .lobby-actions {
    grid-template-columns: 1fr;
  }
  .brand span {
    font-size: 1rem;
  }
  .header-game {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}

/* ---------- game settings (lobby, engine/settings.js) ---------- */
.settings-card {
  text-align: left;
}

.settings-card h2 {
  font-size: 1.1rem;
}

.settings-group {
  border: 0;
  margin: 0 0 12px;
  padding: 0;
  min-width: 0;
}

.settings-group legend {
  padding: 0;
  margin-bottom: 6px;
  font-weight: 700;
  font-size: 0.9rem;
}

.seg-options {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.seg-opt {
  position: relative;
}

.seg-opt input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}

.seg-opt span {
  display: inline-grid;
  align-content: center;
  min-height: 40px;
  padding: 4px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  font-weight: 700;
  font-size: 0.9rem;
  line-height: 1.2;
  cursor: pointer;
}

.seg-opt small {
  font-weight: 600;
  font-size: 0.75rem;
  color: var(--muted);
}

.seg-opt input:checked + span {
  background: var(--accent);
  border-color: transparent;
  color: var(--accent-ink);
}

.seg-opt input:checked + span small {
  color: inherit;
}

.seg-opt input:focus-visible + span {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.settings-card .hint {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}
