:root {
  --bg: #eef3f7;
  --bg-2: #dfe9f1;
  --surface: #ffffff;
  --text: #0e2233;
  --muted: #5a6f80;
  --line: #c8d6e2;
  --accent: #1463a5;
  --accent-text: #ffffff;
  --water: #cfe3f2;
  --water-2: #bcd7ec;
  --ship: #4b5d6c;
  --ship-edge: #33424e;
  --hit: #d33a2c;
  --sunk: #7a1d16;
  --miss: #6e8aa0;
  --ok: #1c8f4e;
  --warn: #b7791f;
  --preview: rgba(20, 99, 165, 0.45);
  --bad: rgba(211, 58, 44, 0.45);
  --shadow: 0 1px 2px rgba(14, 34, 51, 0.06), 0 6px 20px rgba(14, 34, 51, 0.07);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #07131e;
    --bg-2: #0b1c2c;
    --surface: #102638;
    --text: #e3eef6;
    --muted: #8ba3b6;
    --line: #1f3d55;
    --accent: #3d9be0;
    --accent-text: #04121d;
    --water: #12324b;
    --water-2: #163a57;
    --ship: #8fa3b3;
    --ship-edge: #b8c8d4;
    --hit: #ff5a47;
    --sunk: #ff8a7a;
    --miss: #5d7d96;
    --ok: #3ccf80;
    --warn: #f0b35a;
    --preview: rgba(61, 155, 224, 0.5);
    --bad: rgba(255, 90, 71, 0.5);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.3);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #07131e; --bg-2: #0b1c2c; --surface: #102638; --text: #e3eef6; --muted: #8ba3b6; --line: #1f3d55;
  --accent: #3d9be0; --accent-text: #04121d; --water: #12324b; --water-2: #163a57; --ship: #8fa3b3; --ship-edge: #b8c8d4;
  --hit: #ff5a47; --sunk: #ff8a7a; --miss: #5d7d96; --ok: #3ccf80; --warn: #f0b35a;
  --preview: rgba(61, 155, 224, 0.5); --bad: rgba(255, 90, 71, 0.5); color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: radial-gradient(1200px 600px at 50% -200px, var(--bg-2), var(--bg)) fixed, var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
}
#app { max-width: 1040px; margin: 0 auto; padding: 16px 16px 48px; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
h1 { margin: 4px 0 8px; font-size: 34px; letter-spacing: -0.02em; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
  box-shadow: var(--shadow);
}
.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
.row.center { justify-content: center; }

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  padding: 9px 14px;
  border-radius: 10px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: transform 0.06s, background 0.15s, border-color 0.15s;
}
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.ghost { background: transparent; }
.btn.big { padding: 13px 18px; font-size: 16px; width: 100%; }
.btn:focus-visible, .cell:focus-visible, .code-input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Ana sayfa */
#view-home { max-width: 420px; margin: 0 auto; display: flex; flex-direction: column; gap: 16px; padding-top: 6vh; }
.hero { text-align: center; }
.logo { font-size: 54px; line-height: 1; }
.divider { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.join-row { display: flex; gap: 8px; }
.code-input {
  flex: 1;
  min-width: 0;
  font: 700 20px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  text-align: center;
  padding: 10px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
}
.rules summary { cursor: pointer; font-weight: 600; }
.rules ul { margin: 10px 0 0; padding-left: 18px; color: var(--muted); }

/* Üst çubuk */
.topbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.home-link { color: var(--text); text-decoration: none; font-weight: 700; margin-right: auto; }
.code-chip {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  background: var(--surface);
  border: 1px solid var(--line);
  padding: 4px 10px;
  border-radius: 999px;
  letter-spacing: 0.1em;
}
.presence { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); opacity: 0.5; }
.presence.on .dot { background: var(--ok); opacity: 1; box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 25%, transparent); }

.invite { text-align: center; margin-bottom: 14px; }
.invite p { margin: 0 0 6px; }
.big-code {
  font: 800 40px/1.1 ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: 0.25em;
  margin: 4px 0 12px;
  padding-left: 0.25em;
  user-select: all;
}

.banner {
  text-align: center;
  font-weight: 700;
  font-size: 17px;
  padding: 10px 14px;
  border-radius: 12px;
  margin-bottom: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
}
.banner:empty { display: none; }
.banner.turn { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.banner.wait { color: var(--muted); }

/* Tahtalar */
.board-wrap { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.board-title { font-weight: 700; }
.board {
  --n: 11;
  display: grid;
  grid-template-columns: repeat(var(--n), 1fr);
  gap: 2px;
  width: 100%;
  max-width: 440px;
  aspect-ratio: 1;
  user-select: none;
  touch-action: manipulation;
}
.label {
  display: grid;
  place-items: center;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
}
.cell {
  position: relative;
  border: 0;
  padding: 0;
  margin: 0;
  border-radius: 3px;
  background: var(--water);
  min-width: 0;
  min-height: 0;
  font: inherit;
  color: inherit;
  cursor: default;
}
.cell:nth-child(odd) { background: var(--water-2); }
.board.placing .cell, .board.enemy.active .cell:not(.shot) { cursor: crosshair; }
.board.enemy.active .cell:not(.shot):hover { background: var(--preview); }
.board.enemy:not(.active) { opacity: 0.8; }
.cell.ship { background: var(--ship); box-shadow: inset 0 0 0 1px var(--ship-edge); }
.cell.ship.picked { cursor: grab; }
.cell.preview { background: var(--preview) !important; }
.cell.bad { background: var(--bad) !important; }
.cell.miss::after {
  content: "";
  position: absolute;
  inset: 37%;
  border-radius: 50%;
  background: var(--miss);
}
.cell.hit { background: color-mix(in srgb, var(--hit) 22%, var(--water)); }
.cell.ship.hit { background: color-mix(in srgb, var(--hit) 35%, var(--ship)); }
.cell.hit::after {
  content: "";
  position: absolute;
  inset: 20%;
  background:
    linear-gradient(45deg, transparent 42%, var(--hit) 42% 58%, transparent 58%),
    linear-gradient(-45deg, transparent 42%, var(--hit) 42% 58%, transparent 58%);
}
.cell.sunk { background: color-mix(in srgb, var(--sunk) 45%, var(--water)) !important; box-shadow: inset 0 0 0 1px var(--sunk); }
.cell.sunk::after { background:
    linear-gradient(45deg, transparent 42%, var(--sunk) 42% 58%, transparent 58%),
    linear-gradient(-45deg, transparent 42%, var(--sunk) 42% 58%, transparent 58%); }
.cell.reveal { background: color-mix(in srgb, var(--ship) 55%, var(--water)); }
.cell.last { animation: pulse 0.9s ease-out 2; z-index: 1; }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 var(--hit); }
  100% { box-shadow: 0 0 0 8px transparent; }
}
.cell.last.miss { animation-name: pulse-miss; }
@keyframes pulse-miss {
  0% { box-shadow: 0 0 0 0 var(--accent); }
  100% { box-shadow: 0 0 0 8px transparent; }
}

/* Yerleştirme */
.setup { display: grid; grid-template-columns: minmax(0, 440px) minmax(0, 300px); gap: 20px; justify-content: center; align-items: start; }
.dock { display: flex; flex-direction: column; gap: 10px; }
.ship-list { display: flex; flex-direction: column; gap: 6px; }
.ship-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: transparent;
  color: var(--text);
  font: inherit;
  cursor: pointer;
  text-align: left;
}
.ship-item.selected { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.ship-item.placed { opacity: 0.55; }
.ship-item.placed .ship-name::after { content: " ✓"; color: var(--ok); }
.ship-blocks { display: flex; gap: 2px; }
.ship-blocks i { width: 12px; height: 12px; border-radius: 2px; background: var(--ship); display: block; }
.hint { margin: 0; }

/* Savaş */
.battle { display: grid; grid-template-columns: repeat(2, minmax(0, 440px)); gap: 24px; justify-content: center; }
.fleet-status { display: flex; flex-wrap: wrap; gap: 6px; font-size: 12px; }
.fleet-status span {
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
}
.fleet-status span.sunk { text-decoration: line-through; color: var(--hit); border-color: color-mix(in srgb, var(--hit) 40%, var(--line)); }

.result { text-align: center; margin: 0 auto 16px; max-width: 420px; }
.result-title { font-size: 28px; font-weight: 800; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 20px);
  background: var(--text);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: 10px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  max-width: calc(100vw - 32px);
  text-align: center;
  z-index: 10;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 760px) {
  .setup, .battle { grid-template-columns: minmax(0, 1fr); }
  .board { max-width: 100%; margin: 0 auto; }
  .battle { gap: 18px; }
  .battle .board.mine { max-width: 300px; }
  .label { font-size: 9px; }
  h1 { font-size: 28px; }
  .big-code { font-size: 32px; }
}
