:root {
  color-scheme: dark;
  --abyss: #071e29;
  --deep-sea: #082b3a;
  --harbor: #0e4c63;
  --tide: #1a7180;
  --foam: #d9e7df;
  --parchment: #f4ecd8;
  --panel: #f4ecd8;
  --paper: #fffaf0;
  --paper-deep: #eadbb9;
  --ink: #152f38;
  --muted: #587078;
  --brass: #b9812f;
  --brass-light: #e4bc67;
  --wood: #5a3727;
  --wood-dark: #352219;
  --coral: #bd563e;
  --coral-dark: #873528;
  --line: #c9a96c;
  --gold: #e9b638;
  --focus: #f7c84b;
  --display: "Palatino Linotype", "Book Antiqua", Palatino, Georgia, serif;
  --body: ui-sans-serif, "Avenir Next", "Segoe UI", system-ui, sans-serif;
  --utility: ui-monospace, "SFMono-Regular", Consolas, monospace;
}

* { box-sizing: border-box; }

html { background: var(--abyss); scroll-behavior: smooth; }

body {
  min-width: 1024px;
  margin: 0;
  overflow-x: hidden;
  color: var(--ink);
  font-family: var(--body);
  background:
    radial-gradient(ellipse at 14% -10%, #1e7080 0, transparent 38rem),
    radial-gradient(ellipse at 88% 7%, #125266 0, transparent 32rem),
    linear-gradient(145deg, var(--deep-sea), var(--abyss) 62%, #051720);
}

body::before {
  position: fixed;
  z-index: -1;
  inset: 0;
  pointer-events: none;
  content: "";
  opacity: .28;
  background-image:
    repeating-linear-gradient(0deg, transparent 0 74px, rgb(187 224 221 / .09) 75px 76px),
    repeating-linear-gradient(90deg, transparent 0 74px, rgb(187 224 221 / .07) 75px 76px);
  mask-image: linear-gradient(to bottom, #000, transparent 75%);
}

button, input, select { font: inherit; }
button, a, input, select { -webkit-tap-highlight-color: transparent; }
button { touch-action: manipulation; }

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

[hidden] { display: none !important; }

.skip-link {
  position: fixed;
  z-index: 1000;
  top: 12px;
  left: 12px;
  padding: 9px 12px;
  transform: translateY(-160%);
  border-radius: 6px;
  color: var(--ink);
  background: var(--parchment);
  box-shadow: 0 5px 20px #0008;
  text-decoration: none;
  font-weight: 800;
  transition: transform .18s ease;
}

.skip-link:focus { transform: translateY(0); }

#app { max-width: 1840px; margin: 0 auto; padding: 24px clamp(24px, 3vw, 56px) 40px; }

header {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  min-height: 62px;
  margin-bottom: 28px;
  color: #f6efe0;
}

header::after {
  position: absolute;
  right: 0;
  bottom: -14px;
  left: 0;
  height: 1px;
  content: "";
  background: linear-gradient(90deg, transparent, rgb(226 190 111 / .65) 13%, rgb(226 190 111 / .3) 87%, transparent);
  box-shadow: 0 5px 0 -4px rgb(226 190 111 / .35);
}

.brand { display: flex; align-items: center; gap: 11px; min-width: 0; }
.brand > div { min-width: 0; }
.brand strong { display: block; font-family: var(--display); font-size: 24px; letter-spacing: -.02em; line-height: 1; }
.brand small { display: block; margin-top: 4px; color: #c9ddda; font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
.compass { display: grid; flex: 0 0 auto; place-items: center; width: 37px; height: 37px; color: var(--brass-light); font-size: 32px; line-height: 1; text-shadow: 0 1px 0 #593415; transform: rotate(12deg); }

.header-actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.header-actions a { padding: 8px 7px; color: #f5eee0; text-decoration: none; font-size: 13px; font-weight: 760; letter-spacing: .01em; transition: color .16s ease, transform .16s ease; }
.header-actions a:hover { color: var(--brass-light); transform: translateY(-1px); }

.primary,
.ghost,
.sound-toggle,
.action,
.small-action {
  min-height: 38px;
  border-radius: 7px;
  cursor: pointer;
  font-weight: 800;
  line-height: 1.12;
  transition: transform .14s ease, background-color .14s ease, border-color .14s ease, color .14s ease, box-shadow .14s ease;
}

.primary {
  border: 1px solid #d87557;
  color: #fff9ed;
  background: linear-gradient(180deg, #cf6950, var(--coral));
  box-shadow: inset 0 1px rgb(255 237 203 / .4), 0 3px 0 var(--coral-dark), 0 7px 13px rgb(8 22 24 / .25);
  padding: 10px 15px;
}
.primary:hover { background: linear-gradient(180deg, #da775b, #c1513b); transform: translateY(-1px); box-shadow: inset 0 1px rgb(255 237 203 / .5), 0 4px 0 var(--coral-dark), 0 9px 16px rgb(8 22 24 / .28); }
.primary:active { transform: translateY(2px); box-shadow: inset 0 1px rgb(255 237 203 / .35), 0 1px 0 var(--coral-dark); }
.large { padding: 13px 20px; font-size: 15px; }

.ghost,
.sound-toggle,
.small-action {
  border: 1px solid #b9c8bd;
  color: #26444a;
  background: #e7eee6;
  box-shadow: inset 0 1px #fff8, 0 1px 0 #a7b8ac;
  padding: 9px 11px;
}
.ghost:hover,
.sound-toggle:hover,
.small-action:hover { border-color: #789891; color: #123c47; background: #f5f5e9; transform: translateY(-1px); }
.ghost:active,
.sound-toggle:active,
.small-action:active { transform: translateY(1px); box-shadow: inset 0 1px #cbd9cf; }

.panel {
  position: relative;
  border: 1px solid #d8bd85;
  border-radius: 12px;
  background:
    linear-gradient(90deg, transparent 0 16px, rgb(255 255 255 / .18) 16px 17px, transparent 17px),
    linear-gradient(180deg, #fffdf4, var(--parchment));
  box-shadow: 0 13px 30px rgb(0 18 27 / .28), inset 0 1px 0 #fff;
}

.panel::before,
.panel::after { position: absolute; width: 8px; height: 8px; pointer-events: none; content: ""; border-color: rgb(156 105 41 / .55); }
.panel::before { top: 7px; left: 7px; border-top: 1px solid; border-left: 1px solid; }
.panel::after { right: 7px; bottom: 7px; border-right: 1px solid; border-bottom: 1px solid; }

h1, h2, h3 { color: var(--ink); text-wrap: balance; }
h1, h2, h3, .recent-heading h2 { font-family: var(--display); }

.welcome { max-width: 1120px; margin: clamp(38px, 8vh, 100px) auto 0; padding: clamp(30px, 4.1vw, 58px); }
.welcome::after { position: absolute; right: 28px; bottom: 23px; width: 74px; height: 74px; border: 1px solid rgb(170 117 47 / .25); border-radius: 50%; content: "✦"; color: rgb(170 117 47 / .32); display: grid; place-items: center; font: 32px/1 var(--display); transform: rotate(19deg); pointer-events: none; }
.welcome h1 { max-width: 14ch; margin: 5px 0 10px; font-size: clamp(35px, 4vw, 54px); letter-spacing: -.045em; line-height: .98; }
.welcome > p:not(.eyebrow) { max-width: 73ch; margin: 0; color: #425e64; font-size: 16px; line-height: 1.6; }
.eyebrow { margin: 0; color: #956027; font: 800 10px/1.2 var(--body); letter-spacing: .16em; text-transform: uppercase; }

.setup { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 13px; margin: 29px 0 20px; }
.setup label { display: grid; min-width: 0; gap: 6px; color: #39525a; font-size: 12px; font-weight: 830; }
.setup input,
.setup select,
.team-player select,
#map-editor input,
#map-editor textarea,
#user-search {
  width: 100%;
  min-width: 0;
  min-height: 39px;
  border: 1px solid #c6aa70;
  border-radius: 6px;
  color: var(--ink);
  background: #fffdf7;
  box-shadow: inset 0 1px 2px rgb(71 46 24 / .08);
  padding: 8px 9px;
}
.setup input:hover,
.setup select:hover,
.team-player select:hover { border-color: #a97831; }
.setup input:focus-visible,
.setup select:focus-visible,
.team-player select:focus-visible { border-color: var(--brass); }
.setup .check { display: flex; align-items: center; gap: 7px; padding-top: 20px; }
.setup label:has(#seed), .setup label:has(#room-mode), .setup #timer-base, .setup #timer-increment, .setup #timer-max { grid-column: span 2; }

.start-actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.event-empty { color: var(--muted); font-size: 12px; line-height: 1.45; }

.status { display: grid; grid-template-columns: minmax(170px, .8fr) minmax(0, 1.7fr) auto auto; align-items: center; gap: 15px; min-height: 84px; margin-bottom: 14px; padding: 15px 19px; }
.status h2 { margin: 4px 0 0; font-size: clamp(22px, 2vw, 30px); letter-spacing: -.025em; }
.status small { display: block; min-height: 1.2em; margin-top: 4px; color: var(--muted); font-variant-numeric: tabular-nums; }
.scores { display: flex; min-width: 0; justify-content: center; gap: 7px; flex-wrap: wrap; }
.score { display: inline-flex; align-items: center; gap: 4px; min-height: 33px; border: 1px solid #d9c492; border-radius: 999px; color: #293f45; background: #f6eed8; padding: 6px 10px; font-size: 12px; font-weight: 800; font-variant-numeric: tabular-nums; }
.score.gold-progress { border-color: #c79227; color: #63440d; background: linear-gradient(180deg, #fff2bf, #f3da88); }

.room-panel { display: flex; align-items: center; justify-content: space-between; gap: 18px; margin: -2px 0 14px; padding: 12px 17px; }
.room-panel strong { display: block; font-family: var(--display); font-size: 18px; }
.room-panel small { display: block; max-width: 1050px; margin-top: 4px; color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }

.layout { display: grid; grid-template-columns: minmax(700px, 1fr) 300px; align-items: start; gap: 16px; }
.board-wrap { min-width: 0; padding: 14px; overflow: hidden; background: linear-gradient(135deg, #8c5d35, #4a2e22 47%, #75472b); }
.board-wrap::before { z-index: 0; top: 17px; left: 20px; width: 20px; height: 20px; border: 1px solid rgb(246 222 160 / .5); border-radius: 50%; color: rgb(246 222 160 / .75); content: "N"; display: grid; place-items: center; font: 800 9px/1 var(--utility); }
.board-wrap::after { z-index: 0; right: 20px; bottom: 17px; border: 0; content: ""; background: repeating-linear-gradient(90deg, rgb(246 222 160 / .55) 0 2px, transparent 2px 8px); }

.board { position: relative; z-index: 1; display: grid; grid-template-columns: repeat(13, minmax(0, 1fr)); gap: 2px; aspect-ratio: 1; overflow: hidden; border: 2px solid #1d3e49; border-radius: 6px; background: #103f51; box-shadow: inset 0 0 0 1px rgb(217 231 223 / .32), 0 6px 13px rgb(23 12 6 / .28); }
.board.pannable { cursor: grab; touch-action: none; }
.board.pannable.panning, .board.pannable.panning .cell { cursor: grabbing; }

.cell { position: relative; min-width: 0; overflow: hidden; border: 0; color: #fff; background: #3d765d; cursor: pointer; transform-origin: center; transition: transform .14s ease, filter .14s ease, outline-color .14s ease; }
.cell:not(.void):hover { z-index: 3; filter: brightness(1.09) saturate(1.08); transform: scale(1.028); }
.cell:active { transform: scale(.975); }
.cell.void { opacity: 0; pointer-events: none; }
.cell.land { background: #3f765e; }
.cell.water { color: #a7d7d7; background: linear-gradient(135deg, #17677b, #0d4059 58%, #0a354b); }
.cell.water::before { position: absolute; inset: 0; content: ""; opacity: .32; background: repeating-linear-gradient(160deg, transparent 0 10px, rgb(176 232 221 / .38) 11px 12px, transparent 13px 22px); }
.cell.water .wave { position: relative; z-index: 1; display: grid; height: 100%; place-items: center; opacity: .92; }
.cell.water .wave img { width: 86%; height: 86%; object-fit: contain; }
.cell.revealed { color: #284a43; background: #e8cf8f; }
.cell.revealed:has(.tile-empty) { background: #4b825d; }
.cell.revealed:has(.tile-jungle), .cell.revealed:has(.tile-swamp) { background: #a9c27b; }
.cell.revealed:has(.tile-desert), .cell.revealed:has(.tile-mountain) { background: #e7bd71; }
.cell.revealed:has(.tile-ice) { background: #c7e6e9; }
.cell.revealed:has(.tile-trap) { background: #73925a; }
.cell.revealed:has(.tile-crocodile) { background: #92be84; }
.cell.revealed:has(.tile-cannibal) { background: #d9a271; }
.cell.revealed:has(.tile-rum), .cell.revealed:has(.tile-cannon) { background: #d1b17c; }
.cell.revealed:has(.tile-balloon), .cell.revealed:has(.tile-plane) { background: #dfd1a5; }
.cell.revealed:has(.tile-treasure_1), .cell.revealed:has(.tile-treasure_2), .cell.revealed:has(.tile-treasure_3), .cell.revealed:has(.tile-treasure_4), .cell.revealed:has(.tile-treasure_5) { background: #efce75; }
.cell.unknown { background: #3b755c; }
.cell.unknown::before { position: absolute; z-index: 1; top: 50%; left: 50%; width: 16px; height: 16px; border: 1px solid rgb(232 245 203 / .72); content: ""; background: #c5dfa9; box-shadow: 0 1px 0 rgb(16 63 48 / .35); transform: translate(-50%, -50%) rotate(45deg); }
.cell.unknown::after { display: none; }
.cell.actionable { z-index: 4; outline: 3px solid #f7bb35; outline-offset: -3px; }
.cell .gold { position: absolute; z-index: 4; right: 4px; bottom: 4px; display: grid; width: 20px; height: 20px; place-items: center; border: 1px solid #8d5d0f; border-radius: 50%; color: #4d350b; background: #f5c643; box-shadow: 0 1px 0 #fff7; font: 800 11px/1 var(--utility); }

.sidebar { position: sticky; top: 16px; max-height: calc(100vh - 32px); min-height: 440px; overflow: auto; overscroll-behavior: contain; padding: 17px; }
.sidebar h3 { margin: 3px 0 8px; color: #273e3c; font-size: 19px; letter-spacing: -.01em; }
.sidebar h3 + p { min-height: 3.8em; margin: 0; color: var(--muted); font-size: 12px; line-height: 1.45; }
.actions { display: grid; gap: 7px; margin: 13px 0 22px; }
.action { width: 100%; min-height: 41px; border: 1px solid #b9c4aa; color: #234449; background: #f2f4e8; padding: 9px 10px; text-align: left; }
.action:hover { border-color: #7b9c8f; color: #153d47; background: #fffdf3; transform: translateX(2px); box-shadow: 2px 2px 0 rgb(99 127 112 / .16); }
.action:active { transform: translateX(1px) translateY(1px); box-shadow: none; }
.ship-select, .ship-move { border-color: #ba8640; color: #4f3612; background: linear-gradient(135deg, #fff0bc, #ecd28c); }
.ship-select:hover, .ship-move:hover { border-color: #8a5e20; color: #3e290b; background: #ffefbc; }
.events { display: grid; gap: 6px; }
.event { border-left: 3px solid #9a6b2b; border-radius: 3px 7px 7px 3px; color: #40595e; background: #f1e7d0; padding: 8px 9px; font-size: 12px; line-height: 1.35; }
.event-combat, .event-sea_combat, .event-pirate_eaten { border-left-color: #b64c3c; background: #f8e1d6; }
.event-gold_found, .event-gold_taken, .event-gold_banked { border-left-color: #c28a1b; background: #fff0bd; }

.editor { display: grid; grid-template-columns: minmax(650px, 1fr) 290px; gap: 16px; }
.editor .board { margin-top: 14px; }
.editor-panel { padding: 20px; }
.editor-cell { color: #38483d; background: #f2d483; }
.editor-cell.selected { z-index: 2; outline: 3px solid var(--coral); }
.editor-tools { display: grid; gap: 10px; }
.editor-tools button { border: 1px solid #d7c395; border-radius: 7px; color: var(--ink); background: #fffdf7; padding: 10px; cursor: pointer; text-align: left; }
.editor-result { color: #526e74; font-size: 13px; line-height: 1.5; white-space: pre-wrap; }

#mobile { display: none; }

@media (max-width: 1250px) {
  #app { padding-right: 22px; padding-left: 22px; }
  .layout { grid-template-columns: minmax(660px, 1fr) 292px; }
  .setup { gap: 10px; }
}

@media (max-width: 1023px) {
  #app { display: none; }
  #mobile { display: grid; min-height: 100vh; place-items: center; padding: 30px; color: #fff; background: var(--deep-sea); font: 650 18px/1.5 var(--body); text-align: center; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; scroll-behavior: auto !important; transition-duration: .01ms !important; }
}
