:root {
  --sea-deep: #173f4e;
  --sea: #24596b;
  --sea-line: #3c7486;
  --chalk: #f3f6f4;
  --chalk-2: #e3eae6;
  --ink: #14262e;
  --ink-soft: #4b6069;
  --brass: #c99a2e;
  --brass-dark: #9c7618;
  --danger: #b23a2c;
  --radius-lg: 18px;
  --radius-sm: 8px;
  --font: 'Bricolage Grotesque', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif;

  --forest: #3f7a3c;
  --hills: #c4643a;
  --pasture: #9cc85a;
  --fields: #e4bf47;
  --mountains: #8c919b;
  --desert: #dcc993;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  color: var(--ink);
  background: radial-gradient(circle at 50% 35%, var(--sea) 0%, var(--sea-deep) 70%);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
button, input { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--brass); outline-offset: 2px; }

button {
  border: 0;
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  background: var(--chalk-2);
  cursor: pointer;
  font-weight: 600;
  min-height: 44px;
}
button:hover:not(:disabled) { background: #d4ded9; }
button:disabled { opacity: .45; cursor: not-allowed; }
button.primary { background: var(--brass); color: var(--ink); }
button.primary:hover:not(:disabled) { background: #d8ab40; }
button.ghost { background: transparent; box-shadow: inset 0 0 0 2px var(--chalk-2); }
button.danger { background: var(--danger); color: white; }

input {
  width: 100%;
  border: 2px solid var(--chalk-2);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  background: white;
  min-height: 44px;
}
input:focus { border-color: var(--brass); outline: none; }

.muted { color: var(--ink-soft); margin: 0; }
.hint { color: var(--ink-soft); font-size: 14px; margin: 0; }
.version { color: var(--ink-soft); font-size: 13px; margin: 4px 0 0; text-align: right; }
.hint.warn { color: var(--danger); }
.seat-wait { display: grid; gap: 8px; padding: 12px; border-radius: 10px; background: white; border: 2px solid var(--brass); }
.seat-wait p { margin: 0; }
.seat-wait #seat-wait-text { font-weight: 600; }
.seat-requests { position: fixed; top: 12px; left: 50%; transform: translateX(-50%); z-index: 15; display: grid; gap: 8px; width: min(420px, calc(100vw - 32px)); }
.seat-request { background: var(--chalk); border: 2px solid var(--brass); border-radius: 12px; padding: 12px; box-shadow: 0 12px 30px rgba(7, 26, 33, .35); display: grid; gap: 8px; }
.seat-request p { margin: 0; }
.setup-title { margin-top: 0; font-size: 24px; }
.setup-why { margin: 12px 0 16px; }
.setup-actions { margin-top: 8px; }
.error { color: var(--danger); min-height: 1.4em; margin: 8px 0 0; font-weight: 600; }
.row { display: flex; gap: 10px; justify-content: space-between; }

/* ---------- home ---------- */
#home { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; position: relative; overflow: hidden; }
#home-island { position: absolute; inset: 0; width: 100%; height: 100%; opacity: .55; pointer-events: none; }
.home-card, .lobby-card {
  position: relative;
  width: min(420px, 100%);
  background: var(--chalk);
  border-radius: var(--radius-lg);
  padding: 28px 24px 20px;
  box-shadow: 0 24px 60px rgba(7, 26, 33, .45);
}
h1 {
  font-size: clamp(44px, 12vw, 64px);
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: .95;
  margin: 0 0 10px;
  font-variation-settings: 'opsz' 96;
}
h2 { font-size: 18px; margin: 20px 0 8px; }
.lede { margin: 0 0 20px; color: var(--ink-soft); max-width: 36ch; }

.tabs { display: flex; gap: 4px; background: var(--chalk-2); padding: 4px; border-radius: 12px; margin-bottom: 16px; }
.tabs button { flex: 1; background: transparent; min-height: 38px; padding: 6px 10px; }
.tabs button[aria-selected="true"] { background: white; box-shadow: 0 1px 3px rgba(20, 38, 46, .15); }
.tabs.small { margin-bottom: 8px; }

.form { display: grid; gap: 12px; }
.form label { display: grid; gap: 4px; font-weight: 600; font-size: 14px; }
.code-input { text-transform: uppercase; letter-spacing: .3em; font-weight: 800; }

/* ---------- lobby ---------- */
#lobby, #setup { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.big-code { font-size: 48px; font-weight: 800; letter-spacing: .18em; margin: 0 0 8px; }
.member-list { list-style: none; padding: 0; margin: 0 0 12px; display: grid; gap: 6px; }
.member-list li { display: flex; align-items: center; gap: 10px; padding: 8px 10px; background: white; border-radius: var(--radius-sm); }
.online-dot { width: 9px; height: 9px; border-radius: 50%; background: #9aa7ad; flex: none; }
.online-dot.on { background: #3aa357; }
.tag { font-size: 12px; background: var(--chalk-2); border-radius: 99px; padding: 1px 8px; margin-left: auto; }
.tag + .tag { margin-left: 0; }
.tag.cpu, .pstats .cpu { background: #dfe7f0; color: #2c4a66; border-radius: 99px; padding: 0 8px; font-weight: 600; }
.remove-bot { min-height: 32px; width: 32px; padding: 0; font-size: 20px; line-height: 1; background: transparent; color: var(--ink-soft); }
.remove-bot:hover:not(:disabled) { background: var(--chalk-2); color: var(--danger); }
.add-bot { width: 100%; }
#lobby .row { margin-top: 12px; }

/* ---------- game ---------- */
#game {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  height: 100dvh;
  gap: 0;
}
.board-wrap { position: relative; min-height: 0; display: grid; place-items: center; padding: 12px; }
#board { width: 100%; height: 100%; max-height: calc(100dvh - 24px); touch-action: manipulation; }
.side {
  background: var(--chalk);
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.dice { position: absolute; top: 16px; left: 16px; display: flex; gap: 8px; }
.die {
  width: 44px; height: 44px; border-radius: 10px; background: var(--chalk);
  display: grid; place-items: center; font-weight: 800; font-size: 22px;
  box-shadow: 0 4px 0 #b9c6c0;
}
.die.red { color: var(--danger); }
.dice.rolled .die { animation: tumble .45s ease-out; }
@keyframes tumble { from { transform: rotate(-200deg) scale(.6); } to { transform: none; } }

.players { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.player {
  display: grid;
  grid-template-columns: 12px 1fr auto;
  gap: 4px 10px;
  align-items: center;
  padding: 8px 10px;
  background: white;
  border-radius: var(--radius-sm);
  border: 2px solid transparent;
}
.player.turn { border-color: var(--brass); }
.swatch { width: 12px; height: 12px; border-radius: 3px; box-shadow: inset 0 0 0 1px rgba(0,0,0,.25); }
.pname { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.vp { font-weight: 800; font-size: 20px; }
.pstats { grid-column: 2 / 4; font-size: 13px; color: var(--ink-soft); display: flex; flex-wrap: wrap; gap: 4px 12px; }
.badge { background: var(--brass); color: var(--ink); border-radius: 99px; padding: 0 8px; font-weight: 600; }
.offline { opacity: .55; }

.panel { background: white; border-radius: 12px; padding: 12px; }
.status { margin: 0 0 10px; font-weight: 600; font-size: 17px; }
.status.mine { color: var(--brass-dark); }
.round-note { margin: -4px 0 10px; font-size: 14px; color: var(--ink-soft); }
.round-note.peaceful { color: #2c4a66; }
.start-roll { font-weight: 600; color: var(--ink); }
.start-roll.waiting { font-weight: 400; color: var(--ink-soft); }
.actions { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; }
.actions .wide { grid-column: 1 / -1; }
.actions button.active { background: var(--ink); color: var(--chalk); }

.hand { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; margin-top: 12px; }
.card {
  border-radius: 8px;
  padding: 8px 2px 6px;
  text-align: center;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink);
}
.card b { display: block; font-size: 22px; line-height: 1.1; }
.card.zero { opacity: .45; }
.res-wood { background: var(--forest); color: white; }
.res-brick { background: var(--hills); color: white; }
.res-sheep { background: var(--pasture); }
.res-wheat { background: var(--fields); }
.res-ore { background: var(--mountains); color: white; }

.devcards { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.devcards:empty { display: none; }
.dev { font-size: 14px; min-height: 38px; padding: 6px 10px; background: #efe6cf; }
.dev.vpcard { background: #f1e3b2; cursor: default; }

.trade-banner { border: 2px solid var(--brass); border-radius: 10px; padding: 10px; margin-bottom: 10px; display: grid; gap: 8px; }
.trade-banner p { margin: 0; }
.trade-banner .row { justify-content: flex-start; flex-wrap: wrap; }
.trade-answers { display: grid; gap: 8px; }
.counter-row { display: grid; gap: 6px; padding: 8px; border-radius: 8px; background: var(--chalk); }
.counter-problem { min-height: 1.4em; color: var(--danger); }

.feed { display: flex; flex-direction: column; min-height: 200px; }
.log { list-style: none; padding: 0; margin: 0; font-size: 14px; max-height: 220px; overflow-y: auto; display: grid; gap: 4px; align-content: start; }
.log li { padding: 2px 0; border-bottom: 1px solid var(--chalk-2); }
.log li.private { font-weight: 600; color: var(--brass-dark); padding-left: 8px; border-left: 3px solid var(--brass); }
.log .who { font-weight: 600; }
.chat-form { display: flex; gap: 6px; margin-top: 8px; }
#chat-dot { color: var(--danger); }

.end-game { color: var(--danger); box-shadow: inset 0 0 0 2px #e6c9c4; }
.costs { background: white; border-radius: 12px; padding: 10px 12px; font-size: 14px; }
.costs summary { cursor: pointer; font-weight: 600; }
.costs ul { padding-left: 18px; margin: 8px 0 0; }

/* board svg */
.hex-tile { stroke: #f1e8cf; stroke-width: 3; }
.token { fill: #f5efdd; stroke: #3b3221; stroke-width: 1.2; }
.token-num { font-weight: 800; font-size: 19px; text-anchor: middle; fill: var(--ink); }
.token-num.red { fill: var(--danger); }
.pip { fill: var(--ink); }
.pip.red { fill: var(--danger); }
.port-label { font-size: 12px; font-weight: 800; text-anchor: middle; fill: var(--ink); }
.port-bubble { stroke: var(--ink); stroke-width: 1; }
.port-res { font-size: 8px; font-weight: 600; text-anchor: middle; fill: var(--ink); }
.port-line { stroke: var(--chalk); stroke-width: 3; stroke-dasharray: 3 3; opacity: .8; }
.road { stroke-width: 9; stroke-linecap: round; }
.road-outline { stroke: #1c1c1c; stroke-width: 12; stroke-linecap: round; }
.building { stroke: #1c1c1c; stroke-width: 2; stroke-linejoin: round; }
.spot { fill: rgba(255, 255, 255, .85); stroke: var(--brass); stroke-width: 3; cursor: pointer; }
.spot:hover { fill: var(--brass); }
.edge-spot { stroke: rgba(255, 255, 255, .95); stroke-width: 10; stroke-linecap: round; cursor: pointer; }
.edge-hit { stroke: transparent; stroke-width: 22; cursor: pointer; }
.edge-hit:hover + .edge-spot, .edge-spot:hover { stroke: var(--brass); }
.hex-target { fill: rgba(201, 154, 46, .28); stroke: var(--brass); stroke-width: 3; cursor: pointer; }
.hex-target:hover { fill: rgba(201, 154, 46, .55); }
.robber { fill: #2b2b2b; stroke: #f5efdd; stroke-width: 1.5; }
.board-sea { fill: none; stroke: var(--sea-line); stroke-width: 2; }

/* modal */
dialog {
  border: 0;
  border-radius: var(--radius-lg);
  padding: 20px;
  width: min(440px, calc(100vw - 32px));
  background: var(--chalk);
  box-shadow: 0 30px 80px rgba(0, 0, 0, .4);
}
dialog::backdrop { background: rgba(10, 30, 37, .55); }
dialog h3 { margin: 0 0 6px; font-size: 22px; }
dialog p { margin: 0 0 12px; color: var(--ink-soft); }
.picker { display: grid; gap: 6px; margin: 12px 0; }
.pick-row { display: grid; grid-template-columns: 1fr 44px 36px 44px; gap: 6px; align-items: center; }
.pick-row span.n { text-align: center; font-weight: 800; font-size: 18px; }
.pick-row button { padding: 0; min-height: 40px; }
.pick-row .label { border-radius: 8px; padding: 8px 10px; font-weight: 600; }
.choice-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; margin: 8px 0 12px; }
.choice-grid button { padding: 8px 2px; font-size: 13px; }
.choice-grid button[aria-pressed="true"] { box-shadow: inset 0 0 0 3px var(--ink); }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px; }
.section-title { font-weight: 800; margin: 16px 0 4px; }

#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: var(--chalk); padding: 10px 16px; border-radius: 10px;
  opacity: 0; transition: opacity .2s, transform .2s; pointer-events: none; z-index: 10; max-width: calc(100vw - 32px);
}
#toast.show { opacity: 1; transform: translateX(-50%); }
#conn { position: fixed; top: 0; left: 0; right: 0; background: var(--danger); color: white; text-align: center; padding: 6px; font-weight: 600; z-index: 20; }

/* ---------- phones ---------- */
@media (max-width: 860px) {
  #game { grid-template-columns: 1fr; height: auto; min-height: 100dvh; }
  .board-wrap { height: min(92vw, 62dvh); padding: 4px; }
  #board { max-height: 100%; }
  .side { overflow: visible; border-radius: 18px 18px 0 0; }
  .side > .panel:first-of-type { order: -1; }
  .dice { top: auto; bottom: 8px; left: 8px; }
  .die { width: 36px; height: 36px; font-size: 18px; }
}

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