:root {
  --sea-deep: #0b1f2e;
  --sea-mid: #1e4560;
  --ink: #16303f;
  --ink-soft: #23303a;
  --gold: #c9a227;
  --gold-dark: #a67f1e;
  --gold-mut: #8a6a2c;
  --parch-1: #ece0c4;
  --parch-2: #ddcda1;
  --parch-border: #b8863b;
  --text-italic: #5a4a30;
  --ship-grad: linear-gradient(160deg, #5a6b74, #3d4a52);
  --water-grad: linear-gradient(160deg, #dfd2ab, #cbb98d);
  --hit-grad: linear-gradient(160deg, #b1503b, #7c3220);
  --cell: 34px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 48px 24px;
  font-family: 'EB Garamond', Georgia, serif;
  color: var(--ink);
  background: radial-gradient(ellipse 80% 60% at 50% -10%, var(--sea-mid), var(--sea-deep) 65%);
  position: relative;
  overflow-x: hidden;
}

.hidden { display: none !important; }

/* decorative compass rose behind everything */
.compass-bg {
  position: fixed;
  top: 50%; left: 50%;
  width: 900px; height: 900px;
  margin: -450px 0 0 -450px;
  border-radius: 50%;
  border: 1px solid rgba(201, 162, 39, 0.08);
  background: repeating-conic-gradient(rgba(201,162,39,0.05) 0deg 1deg, transparent 1deg 15deg);
  pointer-events: none;
  z-index: 0;
}

.screen {
  position: relative;
  z-index: 1;
  width: 100%;
  display: flex;
  justify-content: center;
}

/* ---------- Parchment card ---------- */
.parchment {
  width: 100%;
  background: linear-gradient(160deg, var(--parch-1), var(--parch-2));
  border: 3px solid var(--parch-border);
  border-radius: 3px;
  box-shadow: 0 30px 60px rgba(0, 0, 0, 0.45);
  padding: 12px;
}
.parchment-inner {
  border: 1px solid rgba(27, 42, 51, 0.35);
  border-radius: 2px;
  padding: 40px 40px;
}
.lobby-card { max-width: 520px; }
.place-card { max-width: 760px; }
.battle-card { max-width: 920px; }
.over-card { max-width: 520px; }
.over-card .parchment-inner { padding: 56px 40px; }

/* ---------- Typography ---------- */
.kicker {
  font-family: 'Cinzel', serif;
  font-size: 14px; letter-spacing: 6px;
  color: var(--gold-mut);
  margin-bottom: 10px;
}
.title {
  font-family: 'Cinzel', serif;
  font-weight: 700;
  font-size: 42px; letter-spacing: 5px;
  color: var(--ink);
  margin-bottom: 8px;
}
.title-sm {
  font-family: 'Cinzel', serif;
  font-weight: 700;
  font-size: 24px; letter-spacing: 3px;
  color: var(--ink);
}
.subtitle {
  font-style: italic;
  color: var(--text-italic);
  font-size: 19px;
  margin-bottom: 32px;
}
.label {
  font-family: 'Cinzel', serif;
  font-size: 12px; letter-spacing: 2px;
  color: var(--gold-mut);
  margin-bottom: 8px;
}
.hint {
  font-size: 12px; font-style: italic;
  color: var(--gold-mut);
  margin-top: 8px;
  max-width: 362px;
}
.err { color: #9c3b2c; font-size: 15px; min-height: 1.2em; margin-top: 8px; }
.pulse { animation: sb-pulse 1.6s ease-in-out infinite; }
@keyframes sb-pulse { 0%,100%{opacity:.4} 50%{opacity:1} }

/* ---------- Buttons ---------- */
.btn {
  font-family: 'Cinzel', serif;
  letter-spacing: 2px;
  font-size: 15px;
  padding: 14px 20px;
  border-radius: 2px;
  cursor: pointer;
  transition: filter .15s ease, background .15s ease, transform .06s ease;
}
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn-block { display: block; width: 100%; }

.btn-gold {
  border: none;
  background: linear-gradient(160deg, var(--gold), var(--gold-dark));
  color: #231a05;
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.25);
}
.btn-gold:hover:not(:disabled) { filter: brightness(1.07); }

.btn-outline {
  border: 2px solid var(--ink);
  background: transparent;
  color: var(--ink);
  font-size: 13px; letter-spacing: 1px;
  padding: 11px 16px;
}
.btn-outline:hover:not(:disabled) { background: rgba(22, 48, 63, 0.08); }

/* ---------- Lobby ---------- */
.divider {
  display: flex; align-items: center; gap: 12px;
  margin: 20px 0;
}
.divider::before, .divider::after {
  content: ""; flex: 1; height: 1px; background: rgba(27, 42, 51, 0.25);
}
.divider span { font-size: 13px; letter-spacing: 2px; color: var(--gold-mut); }

.join-row { display: flex; gap: 10px; }
input {
  flex: 1; min-width: 0;
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 4px;
  font-family: 'Cinzel', serif;
  font-size: 18px;
  padding: 14px 8px;
  border: 2px solid var(--ink);
  border-radius: 2px;
  background: #fbf6e6;
  color: var(--ink);
}
input:focus { outline: none; border-color: var(--gold-dark); }
input::placeholder { color: rgba(22, 48, 63, 0.4); letter-spacing: 3px; }

.room-code {
  font-family: 'Cinzel', serif;
  font-weight: 700;
  font-size: 44px; letter-spacing: 10px;
  color: var(--ink);
  margin: 6px 0 18px;
}
.room-code.sm { font-size: 22px; letter-spacing: 5px; margin: 0; cursor: pointer; }

/* ---------- Boards ---------- */
.board {
  display: grid;
  grid-template-columns: repeat(10, var(--cell));
  grid-template-rows: repeat(10, var(--cell));
  border-top: 1px solid rgba(11, 31, 46, 0.35);
  border-left: 1px solid rgba(11, 31, 46, 0.35);
  width: max-content;
}
.cell {
  width: var(--cell);
  height: var(--cell);
  border-right: 1px solid rgba(11, 31, 46, 0.35);
  border-bottom: 1px solid rgba(11, 31, 46, 0.35);
  background: var(--water-grad);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: bold;
  color: #ece0c4;
  cursor: default;
}

.cell.ship {
  background: var(--ship-grad);
  border-right: 1px solid var(--ink-soft);
  border-bottom: 1px solid var(--ink-soft);
}
.cell.hit { background: var(--hit-grad); }
.cell.hit::after { content: "✕"; color: #fff; }
.cell.miss::after { content: "•"; color: rgba(22, 48, 63, 0.55); }

/* cheat reveal — only visible to the cheater's own enemy board */
.cell.cheat {
  box-shadow: inset 0 0 0 2px var(--gold);
  background: repeating-linear-gradient(45deg,
    rgba(201,162,39,.30), rgba(201,162,39,.30) 5px,
    rgba(201,162,39,.12) 5px, rgba(201,162,39,.12) 10px);
}

.cell.preview { background: rgba(74, 122, 74, 0.75); }
.cell.preview-bad { background: rgba(156, 59, 44, 0.7); }

.enemy.active .cell:not(.hit):not(.miss):hover {
  background: rgba(22, 48, 63, 0.2);
  cursor: crosshair;
}

/* ---------- Placement ---------- */
.place-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 22px;
}
.code-box { text-align: right; }
.place-wrap { display: flex; gap: 28px; flex-wrap: wrap; }
.board-side { display: flex; flex-direction: column; align-items: center; }
.place-panel {
  width: 200px; flex: none;
  display: flex; flex-direction: column; gap: 12px;
}
.place-panel .label { margin-bottom: 0; }

.fleet-list { display: flex; flex-direction: column; gap: 7px; margin-bottom: 4px; }
.fleet-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 7px 8px; border-radius: 2px;
  border: 1px solid transparent;
}
.fleet-row.active { border-color: var(--parch-border); background: rgba(184, 134, 59, 0.18); }
.fleet-row.done { opacity: 0.4; }
.mini-ship { display: flex; gap: 2px; }
.mini-ship span {
  width: 16px; height: 16px;
  background: var(--ship-grad);
  border: 1px solid var(--ink-soft);
}
.fleet-count { font-size: 13px; color: var(--gold-mut); }
.waiting-note { text-align: center; font-style: italic; color: var(--text-italic); font-size: 14px; }

/* ---------- Battle ---------- */
.turn-wrap { text-align: center; margin-bottom: 22px; }
.turn-badge {
  font-family: 'Cinzel', serif;
  font-size: 15px; letter-spacing: 4px;
  padding: 8px 20px;
  display: inline-block;
  border: 1px solid var(--ink);
  border-radius: 2px;
  color: rgba(22, 48, 63, 0.5);
  transition: color .2s, background .2s;
}
.turn-badge.my-turn {
  color: var(--ink);
  background: rgba(201, 162, 39, 0.15);
  border-color: var(--gold-dark);
}
.battle-wrap { display: flex; gap: 36px; justify-content: center; flex-wrap: wrap; }
.board-label {
  font-family: 'Cinzel', serif;
  font-size: 13px; letter-spacing: 2px;
  color: var(--gold-mut);
  margin-bottom: 8px;
  text-align: center;
}
.stat { text-align: center; margin-top: 8px; font-size: 14px; color: var(--text-italic); }

/* ---------- Overlay ---------- */
.overlay {
  position: fixed; inset: 0;
  background: rgba(5, 12, 22, 0.78);
  display: grid; place-items: center;
  backdrop-filter: blur(4px);
  z-index: 50;
  padding: 24px;
}

/* ---------- Secret version button ---------- */
.version-btn {
  position: fixed;
  bottom: 6px; right: 8px;
  background: none; border: none;
  color: rgba(236, 224, 196, 0.15);
  font-family: 'EB Garamond', serif;
  font-size: 11px;
  cursor: pointer;
  user-select: none;
  z-index: 40;
}
.version-btn:hover { color: rgba(236, 224, 196, 0.3); }

.cheat-box {
  position: fixed;
  bottom: 28px; right: 8px;
  display: flex; gap: 6px;
  background: var(--sea-deep);
  padding: 8px;
  border-radius: 4px;
  border: 1px solid rgba(201, 162, 39, 0.3);
  z-index: 60;
}
.cheat-box input {
  letter-spacing: normal; text-transform: none;
  width: 130px; padding: 8px; font-family: 'EB Garamond', serif;
  font-size: 15px;
}
.cheat-box .btn { padding: 8px 12px; }
.shake { animation: shake .4s; border-color: #9c3b2c !important; }
@keyframes shake {
  0%,100%{transform:translateX(0)}
  25%{transform:translateX(-5px)}
  75%{transform:translateX(5px)}
}

@media (max-width: 560px) {
  :root { --cell: 30px; }
  .parchment-inner { padding: 28px 20px; }
  .title { font-size: 32px; }
  .place-wrap { justify-content: center; }
}
