:root {
  color-scheme: dark;
  font-family: "Courier Prime", "Courier New", monospace;
  background: #090909;
  color: #e9e9e9;
  --panel: #101010;
  --line: #353535;
  --muted: #aaaaaa;
  --accent: #e2e2e2;
  --hit: #f2f2f2;
}

* { box-sizing: border-box; }
body { margin: 0; }
main { width: min(1120px, 100% - 48px); margin-inline: auto; }
[hidden] { display: none !important; }

.masthead {
  min-height: 67px;
  display: flex;
  align-items: center;
  border-bottom: 1px solid var(--line);
}
.brand {
  color: inherit;
  font-size: 14px;
  font-weight: bold;
  text-transform: uppercase;
  letter-spacing: .13em;
  text-decoration: none;
}
.compass { color: var(--accent); margin-right: 9px; }
h1, h2 { font-family: Georgia, "Times New Roman", serif; font-weight: 400; }
h1 { font-size: clamp(70px, 12vw, 152px); line-height: .8; margin: 0 0 28px; }
h2 { font-size: clamp(25px, 4vw, 38px); line-height: 1.06; margin: 0; }
p { color: var(--muted); font-size: 14px; line-height: 1.5; margin: 12px 0 0; }

.hero {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  border-bottom: 1px solid var(--line);
  padding: clamp(45px, 8vw, 95px) 0;
}
.hero::before {
  content: "";
  position: absolute;
  z-index: -1;
  width: min(64vw, 620px);
  aspect-ratio: 1;
  top: 50%;
  right: 2%;
  transform: translateY(-50%);
  background:
    linear-gradient(90deg, transparent 49.8%, #494949 50%, transparent 50.2%),
    linear-gradient(transparent 49.8%, #494949 50%, transparent 50.2%),
    repeating-radial-gradient(circle closest-side, transparent 0 19.6%, #383838 19.8% 20%, transparent 20.2%);
  mask-image: linear-gradient(90deg, transparent, black 52%);
}
.hero p { max-width: 37ch; margin-bottom: 24px; }

button, select, input {
  border: 1px solid #595959;
  border-radius: 3px;
  background: #141414;
  color: inherit;
  font: inherit;
  font-size: 13px;
  min-height: 44px;
  padding: 8px 13px;
}
button { cursor: pointer; }
button:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
button:disabled { cursor: default; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.primary { background: var(--accent); border-color: var(--accent); color: #151515; font-weight: bold; }
.primary:hover:not(:disabled) { background: #f5f5f5; color: #151515; }
.primary:disabled { background: #292929; border-color: #454545; color: #a2a2a2; }
.primary span { margin-left: 18px; }

.top {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 16px;
  padding: 22px 0;
}
.eyebrow { color: var(--accent); font-size: 12px; letter-spacing: .09em; text-transform: uppercase; margin-bottom: 8px; }
.panel { border-radius: 3px; background: var(--panel); border: 1px solid var(--line); padding: clamp(12px, 2.3vw, 25px); }
.boards { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.enemy { border-top-color: #9e9e9e; }
.setup { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr); gap: 18px 28px; }
.setup .board { grid-column: 2; grid-row: 1 / span 2; margin-top: 0; }
.setup-actions, .setup-confirm { text-align: center; }
.setup-confirm { align-self: end; }
.controls { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; align-items: end; margin: 20px 0 12px; }
.controls label, .fleet-status { font-size: 12px; color: var(--muted); line-height: 1.5; }
select { display: block; margin-top: 5px; }
.error { color: var(--hit); font-size: 13px; margin-top: 10px; }
.error:empty { display: none; }

.board {
  display: grid;
  grid-template-columns: 23px repeat(10, minmax(0, 1fr)) 23px;
  grid-template-rows: 23px repeat(10, minmax(0, 1fr)) 23px;
  width: min(100%, 485px);
  aspect-ratio: 1;
  margin: 14px auto 0;
  touch-action: manipulation;
  isolation: isolate;
}
.coord, .cell { display: grid; place-items: center; }
.coord { color: var(--muted); font-size: 12px; }
.cell {
  position: relative;
  background: #0a0a0a;
  border: 0;
  border-radius: 0;
  min-width: 0;
  min-height: 0;
  padding: 0;
}
.cell::before {
  content: "";
  position: absolute;
  inset: 0;
  border-right: 1px solid #393939;
  border-bottom: 1px solid #393939;
  pointer-events: none;
}
.cell.left-edge::before { border-left: 1px solid #393939; }
.cell.top-edge::before { border-top: 1px solid #393939; }
.cell:hover:not(:disabled):is(button), .cell:focus-visible {
  background: #282828;
  outline: 1px solid var(--accent);
  outline-offset: -2px;
}
.cell.hit { background: #202020; }
.shot-mark {
  position: absolute;
  z-index: 2;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
}
.miss .shot-mark::before {
  content: "";
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: #929292;
}
.hit .shot-mark::before, .hit .shot-mark::after {
  content: "";
  grid-area: 1 / 1;
  width: 48%;
  height: 2px;
  background: #f4f4f4;
  transform: rotate(45deg);
}
.hit .shot-mark::after { transform: rotate(-45deg); }
.hull {
  z-index: 1;
  pointer-events: none;
  border: 2px solid #cecece;
  border-radius: 3px;
  background: #d6d6d623;
}
.own .board { transition: opacity 180ms ease; }
.own .board.dimmed { opacity: .57; }

.chat {
  position: fixed;
  z-index: 5;
  right: max(12px, env(safe-area-inset-right));
  bottom: max(12px, env(safe-area-inset-bottom));
  display: grid;
  justify-items: end;
  gap: 8px;
}
#chatToggle {
  width: 46px;
  height: 46px;
  padding: 0;
  display: grid;
  place-items: center;
}
.chat-bubble {
  position: relative;
  width: 17px;
  height: 13px;
  border: 1px solid currentColor;
  border-radius: 3px;
}
.chat-bubble::after {
  content: "";
  position: absolute;
  bottom: -3px;
  left: 3px;
  width: 4px;
  height: 4px;
  border-left: 1px solid currentColor;
  border-bottom: 1px solid currentColor;
  background: #141414;
  transform: rotate(-45deg);
}
.chat-pencil { display: none; font-size: 24px; line-height: 1; }
#chatToggle.unread {
  background: #dedede;
  color: #141414;
  animation: chat-pulse 1.6s ease-in-out infinite;
}
.unread .chat-bubble { display: none; }
.unread .chat-pencil { display: block; }
@keyframes chat-pulse {
  50% { box-shadow: 0 0 0 5px #e2e2e24d; }
}
@media (prefers-reduced-motion: reduce) {
  #chatToggle.unread { animation: none; }
  .own .board { transition: none; }
}
.chat-window {
  width: min(320px, calc(100vw - 24px));
  border: 1px solid #595959;
  border-radius: 3px;
  background: #141414;
  box-shadow: 0 8px 30px #000b;
  padding: 12px;
}
.chat-window header, #chatForm { display: flex; gap: 8px; align-items: center; }
.chat-window header { justify-content: space-between; }
.chat-window h2 { font-size: 23px; }
#chatMessages {
  height: min(210px, 30dvh);
  overflow-y: auto;
  margin: 8px 0;
  padding: 8px 0;
  border-block: 1px solid var(--line);
  list-style: none;
  font-size: 13px;
  overflow-wrap: anywhere;
}
#chatMessages li + li { margin-top: 10px; }
#chatMessages strong { color: var(--muted); font-size: 11px; }
#chatInput { flex: 1; min-width: 0; font-size: 16px; }
footer { color: var(--muted); padding: 22px 0 30px; font-size: 12px; }

@media (max-width: 700px) {
  main { width: calc(100% - 24px); }
  .masthead { min-height: 53px; }
  .boards, .setup { grid-template-columns: minmax(0, 1fr); }
  .setup .board { grid-column: auto; grid-row: auto; }
  .hero::before { width: 88vw; right: -19%; }
}

.hero, .hero p { text-align: center; }
.hero p, .controls select { margin-inline: auto; }
button:not(.cell):not(#chatToggle) { display: inline-grid; place-content: center; grid-auto-flow: column; }

.stake-picker {
  min-width: 0;
  width: min(100%, 340px);
  margin: 0 auto 16px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: var(--panel);
  text-align: left;
  font-size: 13px;
}
.stake-picker legend { padding-inline: 6px; color: var(--muted); font-size: 13px; }
.stake-picker .no-stake { display: flex; align-items: center; gap: 10px; min-height: 32px; }
.stake-picker input[type="checkbox"] {
  appearance: none;
  display: inline-grid;
  align-items: center;
  flex: none;
  width: 38px;
  height: 22px;
  min-height: 0;
  margin: 0;
  padding: 3px;
  border-radius: 12px;
  cursor: pointer;
}
.stake-picker input[type="checkbox"]::before {
  content: "";
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--muted);
}
.stake-picker input[type="checkbox"]:checked { background: var(--accent); }
.stake-picker input[type="checkbox"]:checked::before {
  justify-self: end;
  background: #212121;
}
.stake-options { display: grid; gap: 10px; margin-top: 10px; }
.stake-presets { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
.stake-presets label { position: relative; }
.stake-presets label:last-child { grid-column: 1 / -1; }
.stake-presets input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}
.stake-presets span {
  display: grid;
  place-items: center;
  min-height: 44px;
  padding: 6px;
  border: 1px solid #595959;
  border-radius: 3px;
  background: #141414;
  text-align: center;
}
.stake-presets label:hover span { border-color: var(--accent); }
.stake-presets input:checked + span { background: var(--accent); color: #151515; font-weight: bold; }
.stake-presets input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.custom-stake input {
  appearance: none;
  display: block;
  width: 100%;
  margin-top: 5px;
  font: inherit;
}
.custom-stake input::placeholder { color: var(--muted); }
.custom-stake input:focus { border-color: var(--accent); }
#roomStake strong, #offerText strong { color: var(--accent); overflow-wrap: anywhere; }
#offerDialog {
  width: min(520px, calc(100% - 24px));
  max-height: calc(100dvh - 24px);
  color: inherit;
  text-align: center;
}
#offerDialog::backdrop { background: #000b; }
#offerDialog form { margin-top: 16px; }
.stake-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 16px; }
