/* Hexhaven - a tabletop at night. Shared by every page. */

:root {
  --felt: #17352a;
  --felt-deep: #0e231b;
  --felt-line: #2a5342;
  --paper: #f4ecd8;
  --paper-edge: #d6c5a0;
  --paper-sunk: #ebe1c8;
  --ink: #1f1a14;
  --ink-soft: #5b5042;
  --amber: #d9922b;
  --amber-dark: #b97817;
  --danger: #9b2b20;
  --cream-on-felt: #efe6cf;
  --red: #c8362b;
  --blue: #2b5fb8;
  --orange: #e0862b;
  --white: #f3efe4;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --gutter: 16px;
}

*, *::before, *::after { box-sizing: border-box; }

html { background: var(--felt-deep); }

body {
  margin: 0;
  min-height: 100vh;
  font: 16px/1.45 var(--sans);
  color: var(--ink);
  background:
    radial-gradient(ellipse 120% 90% at 50% 25%, var(--felt) 0%, #123026 55%, var(--felt-deep) 100%);
  -webkit-text-size-adjust: 100%;
}

h1, h2, h3 { font-family: var(--serif); font-weight: 600; margin: 0; letter-spacing: 0.005em; }

button, input, select { font: inherit; color: inherit; }

:focus-visible { outline: 3px solid var(--amber); outline-offset: 2px; }

.app { max-width: 1120px; margin: 0 auto; padding: 0 var(--gutter) 48px; }

/* ---------- header ---------- */

.top {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 0 12px;
  color: var(--cream-on-felt);
}
.brand { display: flex; align-items: center; gap: 10px; margin-right: auto; }
.brand svg { width: 30px; height: 30px; flex: none; }
.brand h1 { font-size: 26px; color: var(--cream-on-felt); }
.who { font-size: 15px; opacity: 0.9; }

/* ---------- buttons ---------- */

.btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 18px;
  border-radius: 8px;
  border: 1px solid var(--ink);
  background: var(--paper);
  color: var(--ink);
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  line-height: 1;
}
.btn:hover { background: #fffaea; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.55; cursor: default; transform: none; }
.btn-primary { background: var(--amber); border-color: #7a4d0b; box-shadow: 0 2px 0 #7a4d0b; }
.btn-primary:hover { background: #e4a037; }
.btn-primary:active { box-shadow: 0 1px 0 #7a4d0b; transform: translateY(1px); }
.btn-quiet { background: transparent; border-color: var(--paper-edge); }
.btn-ghost {
  background: transparent;
  color: var(--cream-on-felt);
  border-color: rgba(239, 230, 207, 0.45);
  min-height: 40px;
  padding: 0 14px;
}
.btn-ghost:hover { background: rgba(239, 230, 207, 0.12); }
.btn-small { min-height: 38px; padding: 0 12px; font-size: 14px; }
.btn-danger { color: var(--danger); border-color: #b9a98a; background: transparent; }
.btn-danger:hover { background: #f8e4de; border-color: var(--danger); }

/* ---------- paper cards ---------- */

.card {
  background: var(--paper);
  border: 1px solid var(--paper-edge);
  border-radius: 10px;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.5) inset, 0 6px 16px rgba(0, 0, 0, 0.35);
  padding: 16px;
}

/* ---------- login ---------- */

.login-wrap { min-height: 100vh; display: flex; flex-direction: column; justify-content: center; padding: 24px 0; }
.login-brand { text-align: center; color: var(--cream-on-felt); margin-bottom: 22px; }
.login-brand svg { width: 76px; height: 76px; display: block; margin: 0 auto 10px; }
.login-brand h1 { font-size: 44px; line-height: 1.05; }
.login-brand p { margin: 8px 0 0; opacity: 0.8; }
.login-card { width: 100%; max-width: 380px; margin: 0 auto; padding: 22px 20px 20px; }
.login-card .btn { width: 100%; margin-top: 6px; }

/* ---------- forms ---------- */

.field { display: block; margin: 0 0 14px; }
.field > span, .legend { display: block; font-size: 14px; font-weight: 600; margin-bottom: 5px; color: var(--ink-soft); }
input[type="text"], input[type="password"], select {
  width: 100%;
  min-height: 44px;
  padding: 8px 10px;
  background: #fffdf5;
  border: 1px solid #b9a98a;
  border-radius: 7px;
  box-shadow: inset 0 1px 2px rgba(60, 40, 10, 0.12);
}
select {
  appearance: none;
  padding-right: 32px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%231f1a14' stroke-width='2'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 11px center;
}
.error { margin: 0 0 12px; padding: 9px 11px; border-radius: 7px; background: #f6dcd5; border: 1px solid #c98b80; color: #6e1d14; font-size: 15px; }
.error:empty { display: none; }

/* ---------- dashboard layout ---------- */

.board { display: grid; gap: 20px; grid-template-columns: 1fr; align-items: start; }
.newgame { display: none; }
.newgame.open { display: block; }
.toolbar { margin: 4px 0 18px; }
.toolbar .btn { width: 100%; }

.group { margin-bottom: 26px; }
.group h2 { font-size: 22px; color: var(--cream-on-felt); margin: 0 0 10px; display: flex; align-items: baseline; gap: 8px; }
.group h2 .count { font: 600 14px var(--sans); opacity: 0.7; }
.group-list { display: grid; gap: 12px; }

.empty {
  color: var(--cream-on-felt);
  border: 1px dashed rgba(239, 230, 207, 0.4);
  border-radius: 10px;
  padding: 26px 16px;
  text-align: center;
  font-family: var(--serif);
  font-size: 18px;
}

/* ---------- game cards ---------- */

.game { position: relative; display: grid; gap: 10px; }
.game.mine { border-left: 6px solid var(--amber); padding-left: 12px; }
.game-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.game-name { font-size: 20px; line-height: 1.2; overflow-wrap: anywhere; }
.badge {
  flex: none;
  font-size: 12px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--paper-sunk);
  border: 1px solid var(--paper-edge);
  color: var(--ink-soft);
}
.badge-stalled { background: #f6dcd5; border-color: #c98b80; color: #6e1d14; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 0; padding: 0; list-style: none; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 4px 10px 4px 5px;
  background: #fffdf5;
  border: 1px solid var(--paper-edge);
  border-radius: 999px;
  font-size: 14px;
  max-width: 100%;
}
.chip .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip .pts { font-weight: 700; font-variant-numeric: tabular-nums; }
.chip.turn { border-color: var(--amber-dark); box-shadow: 0 0 0 1px var(--amber); }
.swatch {
  display: inline-block;
  width: 18px;
  height: 18px;
  flex: none;
  border-radius: 50%;
  border: 2px solid var(--ink);
  /* a little light on top and shade below, so the color reads as a painted disc */
  box-shadow: inset 0 -3px 2px -1px rgba(0, 0, 0, 0.22), inset 0 2px 1px -1px rgba(255, 255, 255, 0.55);
}

.game-meta { margin: 0; font-size: 15px; color: var(--ink-soft); }
.game-meta strong { color: var(--ink); }
.game-actions { display: flex; gap: 8px; }
.game-actions .btn-primary { flex: 1; }

/* ---------- new game form ---------- */

.newgame h2 { font-size: 22px; margin-bottom: 12px; }
.seat {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 4px 8px;
  padding: 10px;
  margin: 0 0 10px;
  background: var(--paper-sunk);
  border: 1px solid var(--paper-edge);
  border-radius: 8px;
}
.seat .seat-type { grid-column: 1 / 2; }
.seat .seat-color { grid-column: 2 / 3; }
.seat .seat-name { grid-column: 1 / 3; }
.seat .seat-remove { margin-left: auto; min-height: 36px; padding: 0 10px; font-size: 13px; }
.seat-label { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 14px; color: var(--ink-soft); grid-column: 1 / 3; margin-bottom: 2px; }
.seat-title { display: inline-flex; align-items: center; gap: 8px; }
.seat-label .swatch { width: 16px; height: 16px; }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
legend.legend { padding: 0; float: none; width: 100%; }
.radios { display: flex; gap: 8px; margin-bottom: 14px; }
.radios label {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  border: 1px solid #b9a98a;
  border-radius: 7px;
  background: #fffdf5;
  cursor: pointer;
  font-weight: 600;
}
.radios input { position: absolute; opacity: 0; pointer-events: none; }
.radios label:has(input:checked) { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.radios label:has(input:focus-visible) { outline: 3px solid var(--amber); outline-offset: 2px; }
.check { display: flex; align-items: center; gap: 10px; min-height: 44px; margin-bottom: 8px; }
.check input { width: 22px; height: 22px; accent-color: var(--ink); }
.advanced { margin-bottom: 12px; }
.advanced summary { min-height: 44px; display: flex; align-items: center; cursor: pointer; font-weight: 600; color: var(--ink-soft); }
.advanced .field { margin-top: 4px; }
.advanced .hint { margin: 0; font-size: 13px; color: var(--ink-soft); }
.form-actions { display: flex; gap: 8px; margin-top: 8px; }
.form-actions .btn-primary { flex: 1; }
.add-seat { width: 100%; margin-bottom: 14px; }
fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }

/* ---------- laptop ---------- */

@media (min-width: 900px) {
  .app { padding-bottom: 72px; }
  .board { grid-template-columns: 380px 1fr; gap: 32px; }
  .newgame { display: block; position: sticky; top: 16px; }
  .toolbar { display: none; }
  .newgame .cancel { display: none; }
  .game-actions .btn-primary { flex: none; min-width: 140px; }
  .group-list { grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); }
  .login-brand h1 { font-size: 52px; }
}

@media (prefers-reduced-motion: reduce) {
  .btn:active { transform: none; }
}

/* ---------- game page: the board fills the screen, the HUD floats over it ---------- */

.game-page {
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
}

#board {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  cursor: grab;
}
#board.dragging { cursor: grabbing; }
#board:focus { outline: none; }
#board:focus-visible { outline: 3px solid var(--amber); outline-offset: -3px; }
#board * { pointer-events: none; }
#board .hit { pointer-events: all; fill: transparent; stroke: transparent; cursor: pointer; }
#board .hit-edge { stroke-linecap: round; }

/* legal spots: a dark halo under a warm glow so they show on every terrain */
#board .hl-halo { fill: none; stroke: #1a1006; stroke-opacity: 0.45; stroke-width: 7; stroke-linecap: round; stroke-linejoin: round; }
#board .hl-vertex-fill { fill: #fff1c2; fill-opacity: 0.3; }
#board .hl-vertex-ring { fill: none; stroke: #ffc53d; stroke-width: 3.5; }
#board .hl-vertex {
  animation: hl-pulse 1.4s ease-in-out infinite;
  transform-box: fill-box;
  transform-origin: center;
}
#board .hl-edge .hl-halo { stroke-width: 12; }
#board .hl-edge-bar { stroke: #ffc53d; stroke-width: 5; stroke-linecap: round; }
#board .hl-edge-dots { stroke: #fff4c4; stroke-width: 8; stroke-linecap: round; stroke-dasharray: 0 10.5; }
#board .hl-hex-rim { fill: #fff1c2; fill-opacity: 0.2; stroke: #ffc53d; stroke-width: 5.5; stroke-linejoin: round; }
#board .hl-hex .hl-halo { stroke-width: 9; }
#board .hl-edge, #board .hl-hex { animation: hl-fade 1.4s ease-in-out infinite; }

@keyframes hl-pulse {
  0%, 100% { opacity: 0.8; scale: 0.94; }
  50% { opacity: 1; scale: 1.08; }
}
@keyframes hl-fade {
  0%, 100% { opacity: 0.65; }
  50% { opacity: 1; }
}

/* ---------- HUD (hud.js, dialogs.js) ---------- */

:root {
  --r-brick: #b4533a;
  --r-lumber: #4f7d3b;
  --r-wool: #9fbc5b;
  --r-grain: #dcb23a;
  --r-ore: #7a8794;
  --hud-bg: rgba(11, 29, 22, 0.95);
  --hud-line: #2a5342;
  --sheet-h: 190px;
  --top-h: 96px;
}

#hud { display: contents; color: var(--cream-on-felt); }
#hud :focus-visible { outline-color: #ffc53d; }

/* ----- top bar ----- */
#top {
  position: fixed;
  z-index: 3;
  top: 0;
  left: 0;
  right: 0;
  padding: calc(2px + env(safe-area-inset-top)) var(--gutter) 5px;
  background: var(--hud-bg);
  border-bottom: 1px solid var(--hud-line);
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.3);
}
.top-row { display: flex; align-items: center; gap: 8px; min-height: 44px; }
.title { flex: 1; min-width: 0; display: grid; }
.gname { font: 600 17px/1.15 var(--serif); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.turnno { font-size: 12px; opacity: 0.75; }
.dice { display: flex; gap: 5px; }
.die { display: block; width: 30px; height: 30px; }
.die svg { display: block; filter: drop-shadow(0 2px 1px rgba(0, 0, 0, 0.45)); }
.die.blank svg { filter: none; }
.dice.rolling .die:nth-child(1) { animation: tumble 0.16s linear infinite; }
.dice.rolling .die:nth-child(2) { animation: tumble 0.16s linear infinite reverse; }
@keyframes tumble {
  0% { transform: translateY(0) rotate(0deg); }
  25% { transform: translateY(-4px) rotate(14deg); }
  50% { transform: translateY(0) rotate(-10deg); }
  75% { transform: translateY(-3px) rotate(8deg); }
  100% { transform: translateY(0) rotate(0deg); }
}
.hbtn {
  appearance: none;
  min-height: 44px;
  min-width: 52px;
  padding: 0 10px;
  border-radius: 8px;
  border: 1px solid rgba(239, 230, 207, 0.4);
  background: rgba(239, 230, 207, 0.06);
  color: var(--cream-on-felt);
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
}
.hbtn:hover, .hbtn[aria-expanded="true"] { background: rgba(239, 230, 207, 0.16); }

.opps { display: flex; gap: 6px; list-style: none; margin: 0; padding: 7px 0 0; overflow-x: auto; scrollbar-width: none; }
.opps:empty { display: none; }
.opp {
  flex: 1 1 0;
  min-width: 96px;
  position: relative;
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-areas: "dot name" "stats stats";
  align-items: center;
  column-gap: 5px;
  row-gap: 1px;
  padding: 4px 6px 3px;
  border-radius: 8px;
  background: rgba(239, 230, 207, 0.07);
  border: 1px solid rgba(239, 230, 207, 0.18);
  font-size: 12px;
  line-height: 15px;
}
.opp.turn { border-color: var(--amber); background: rgba(217, 146, 43, 0.2); box-shadow: 0 0 0 1px var(--amber); }
.opp.wait { border-style: dashed; border-color: rgba(217, 146, 43, 0.8); }
.opp-dot { grid-area: dot; position: relative; display: inline-flex; }
.opp .swatch { width: 14px; height: 14px; border-width: 2px; border-color: #0b1d16; }
.opp-name { grid-area: name; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.opp-badges { position: absolute; top: -7px; right: 6px; display: inline-flex; gap: 3px; }
.opp-stats { grid-area: stats; display: flex; gap: 6px; font-variant-numeric: tabular-nums; opacity: 0.95; }
.opp-stats span { display: inline-flex; align-items: center; gap: 2px; }
.opp-stats svg { width: 12px; height: 12px; }
.online { position: absolute; right: -3px; bottom: -3px; width: 7px; height: 7px; border-radius: 50%; background: #6b6b60; border: 1.5px solid #0b1d16; }
.online.on { background: #5fd07a; }
.badge-lr, .badge-la { font: 800 9px/1 var(--sans); padding: 1.5px 4px; border-radius: 4px; letter-spacing: 0.02em; }
.badge-lr { background: var(--amber); color: var(--ink); }
.badge-la { background: var(--cream-on-felt); color: var(--ink); }

/* ----- bottom sheet: hand and actions ----- */
#sheet {
  position: fixed;
  z-index: 3;
  left: 0;
  right: 0;
  bottom: 0;
  min-height: 180px;
  padding: 5px var(--gutter) calc(5px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 4px;
  background: var(--hud-bg);
  border-top: 1px solid var(--hud-line);
  box-shadow: 0 -6px 14px rgba(0, 0, 0, 0.3);
}
#hand:empty { display: none; }
#reason {
  position: absolute;
  left: var(--gutter);
  right: var(--gutter);
  bottom: 100%;
  margin-bottom: 8px;
  padding: 9px 12px;
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
  font-size: 14px;
  font-weight: 600;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  opacity: 0;
  transform: translateY(4px);
  pointer-events: none;
  transition: opacity 0.15s, transform 0.15s;
}
#reason.show { opacity: 1; transform: none; }

/* what a highlighted spot yields: a small cream label above it (mouse and pen) */
.spot-tip {
  position: fixed;
  z-index: 5;
  padding: 5px 9px;
  border-radius: 7px;
  background: var(--paper);
  color: var(--ink);
  border: 1px solid var(--paper-edge);
  font: 600 13px/1.2 var(--sans);
  white-space: nowrap;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.45);
  pointer-events: none;
}
.spot-tip[hidden] { display: none; }
/* the setup confirm sheet keeps the board readable behind it */
#dialog:has(.modal.settle) { background: rgba(8, 20, 15, 0.25); }
.modal.settle .settle-yield { font-size: 17px; font-weight: 600; color: var(--ink); }

.meline { display: flex; align-items: center; gap: 6px; min-height: 18px; font-size: 13px; }
.meline .swatch { width: 14px; height: 14px; border-color: #0b1d16; }
.me-name { font-family: var(--serif); font-size: 15px; }
.grow { flex: 1; }
.me-stat { display: inline-flex; align-items: center; gap: 3px; font-variant-numeric: tabular-nums; }
.me-stat svg { width: 14px; height: 14px; }
.me-stat small { opacity: 0.75; font-size: 11px; }
.pill { font: 800 11px/1 var(--sans); padding: 3px 8px; border-radius: 999px; background: var(--amber); color: var(--ink); }

.cards { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
.rcard, .dcard {
  position: relative;
  height: 50px;
  border-radius: 7px;
  border: 1px solid #0b1d16;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  padding: 0 0 2px;
  overflow: hidden;
  color: var(--ink);
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.45);
}
.rcard { background: linear-gradient(#fbf4e0, #eadfc2); }
.rcard::before { content: ""; position: absolute; left: 0; right: 0; top: 0; height: 5px; background: var(--rc, #888); }
.rcard.res-brick { --rc: var(--r-brick); }
.rcard.res-lumber { --rc: var(--r-lumber); }
.rcard.res-wool { --rc: var(--r-wool); }
.rcard.res-grain { --rc: var(--r-grain); }
.rcard.res-ore { --rc: var(--r-ore); }
.rcard svg { width: 26px; height: 26px; margin-top: 4px; }
.rcard b, .dcard b { font: 700 17px/1 var(--serif); font-variant-numeric: tabular-nums; }
.rcard.zero { opacity: 0.42; filter: saturate(0.4); box-shadow: none; }
.dcard {
  appearance: none;
  cursor: pointer;
  justify-content: center;
  gap: 1px;
  color: var(--cream-on-felt);
  background:
    repeating-linear-gradient(135deg, rgba(217, 146, 43, 0.16) 0 6px, transparent 6px 12px),
    linear-gradient(#2d2217, #1a120a);
  border-color: #6b5a3c;
}
.dcard small { font-size: 10px; letter-spacing: 0.04em; opacity: 0.8; }
.dcard.zero { opacity: 0.5; }
.dcard.ready { border-color: #ffc53d; box-shadow: 0 0 0 2px rgba(255, 197, 61, 0.55), 0 2px 0 rgba(0, 0, 0, 0.45); }
.dcard.ready small { color: #ffc53d; opacity: 1; font-weight: 700; }

.abar { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.abtn {
  appearance: none;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 4px 6px;
  border-radius: 8px;
  border: 1px solid var(--ink);
  background: var(--paper);
  color: var(--ink);
  font: 600 14px/1.1 var(--sans);
  text-align: center;
  text-decoration: none;
  cursor: pointer;
}
.abtn:hover { background: #fffaea; }
.abtn:active { transform: translateY(1px); }
.abtn.primary { background: var(--amber); border-color: #7a4d0b; box-shadow: 0 2px 0 #7a4d0b; font-size: 16px; }
.abtn.primary:hover { background: #e4a037; }
.abtn[aria-disabled="true"] { opacity: 0.5; cursor: default; box-shadow: none; }
.abtn[aria-disabled="true"]:active { transform: none; }
.abar.status, .abar.placing { display: flex; flex-direction: column; justify-content: center; min-height: 94px; gap: 3px; }
.abar.placing { flex-direction: row; align-items: center; gap: 10px; }
.place-text { flex: 1; min-width: 0; }
.abar.placing .abtn { flex: none; min-width: 96px; }
.status-main { margin: 0; font: 600 19px/1.2 var(--serif); }
.status-sub { margin: 0; font-size: 13px; opacity: 0.72; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status-btns { display: flex; gap: 8px; margin-top: 6px; }
.status-btns .abtn { flex: 1; }

/* ----- log ----- */
#log {
  display: none;
  position: fixed;
  z-index: 4;
  left: var(--gutter);
  right: var(--gutter);
  bottom: calc(var(--sheet-h) + 8px);
  max-height: 38vh;
  overflow-y: auto;
  padding: 8px 12px 10px;
  background: var(--paper);
  color: var(--ink);
  border: 1px solid var(--paper-edge);
  border-radius: 10px;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.5);
}
body.log-open #log { display: block; }
.log-title { font-size: 15px; margin: 0 0 4px; color: var(--ink-soft); }
.log-list { list-style: none; margin: 0; padding: 0; }
.log-line { display: flex; gap: 8px; align-items: flex-start; padding: 3px 0; font-size: 14px; line-height: 1.35; }
.log-line .swatch { width: 12px; height: 12px; margin-top: 4px; border-width: 1.5px; }
.log-line .swatch.none { visibility: hidden; }
.log-turn { margin: 6px 0 2px; font: 700 11px/1 var(--sans); letter-spacing: 0.04em; color: var(--ink-soft); border-top: 1px solid var(--paper-edge); padding-top: 6px; }
.log-empty { font-size: 14px; color: var(--ink-soft); }

/* ----- toasts, dialogs, curtain ----- */
#toast {
  position: fixed;
  z-index: 9;
  left: 50%;
  top: calc(var(--top-h) + 10px);
  transform: translateX(-50%);
  width: min(92vw, 420px);
  display: grid;
  gap: 6px;
  pointer-events: none;
}
.toast {
  padding: 10px 14px;
  border-radius: 8px;
  background: var(--ink);
  color: var(--cream-on-felt);
  border: 1px solid var(--amber);
  font-size: 15px;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.5);
}

#dialog {
  position: fixed;
  inset: 0;
  z-index: 6;
  display: none;
  align-items: flex-end;
  justify-content: center;
  background: rgba(8, 20, 15, 0.55);
}
#dialog.modal-open { display: flex; }
.modal {
  width: 100%;
  max-width: 480px;
  max-height: 88vh;
  max-height: 88dvh;
  display: flex;
  flex-direction: column;
  background: var(--paper);
  color: var(--ink);
  border: 1px solid var(--paper-edge);
  border-bottom: 0;
  border-radius: 14px 14px 0 0;
  box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.55);
  outline: none;
}
.modal-head { display: flex; align-items: center; gap: 8px; padding: 12px 8px 4px 16px; }
.modal-head h2 { flex: 1; font-size: 22px; }
.modal-x { appearance: none; width: 44px; height: 44px; border: 0; background: transparent; font-size: 28px; line-height: 1; color: var(--ink-soft); cursor: pointer; border-radius: 8px; }
.modal-x:hover { background: var(--paper-sunk); }
.modal-body { overflow-y: auto; padding: 4px 16px 12px; }
.modal-foot { display: flex; gap: 8px; padding: 10px 16px calc(14px + env(safe-area-inset-bottom)); border-top: 1px solid var(--paper-edge); background: var(--paper-sunk); border-radius: 0; }
.modal-foot:empty { display: none; }
.modal-foot .btn, .modal-foot .foot-row { flex: 1; }
.foot-row { display: flex; gap: 8px; }
.foot-row .btn { flex: 1; padding: 0 8px; }
.btn[aria-disabled="true"] { opacity: 0.5; cursor: default; }
.btn[hidden] { display: none; }
.modal-foot .btn { white-space: nowrap; }
@media (min-width: 600px) {
  #dialog { align-items: center; }
  .modal { border-radius: 14px; border-bottom: 1px solid var(--paper-edge); }
  .modal-foot { border-radius: 0 0 14px 14px; }
}

.dlg-lead { margin: 2px 0 8px; color: var(--ink-soft); font-size: 15px; }
.dlg-status { margin: 10px 0 0; min-height: 22px; font-size: 14px; color: var(--ink-soft); }
.dlg-status.ok { color: #2d5a1e; font-weight: 600; }
.rows { display: grid; }
.row { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 8px; min-height: 52px; border-bottom: 1px solid rgba(214, 197, 160, 0.7); }
.row.dim { opacity: 0.55; }
.row:last-child { border-bottom: 0; }
.res-name { display: inline-flex; align-items: center; gap: 8px; min-width: 0; }
.res-text { display: grid; line-height: 1.15; }
.res-text small { font-size: 11px; color: var(--ink-soft); }
.trade-head, .trade-row { grid-template-columns: 1fr 110px 110px; gap: 4px; }
.trade-head { display: grid; font: 700 12px var(--sans); color: var(--ink-soft); text-align: center; padding: 2px 0; }
.trade-row.harbor-rate .res-text small { color: #8a5a07; font-weight: 700; }
.stepper { display: inline-flex; align-items: center; justify-content: center; }
.step-btn {
  appearance: none;
  width: 44px;
  height: 44px;
  border: 1px solid #b9a98a;
  background: #fffdf5;
  border-radius: 8px;
  font: 600 20px/1 var(--sans);
  color: var(--ink);
  cursor: pointer;
}
.step-btn:disabled { opacity: 0.35; cursor: default; }
.step-btn:not(:disabled):active { background: var(--paper-sunk); }
.step-n { width: 22px; text-align: center; font: 700 19px var(--serif); font-variant-numeric: tabular-nums; }
.step-n.zero { opacity: 0.4; }

.tabs { display: flex; gap: 6px; margin: 0 0 8px; }
.tab { appearance: none; flex: 1; min-height: 44px; border: 1px solid #b9a98a; border-radius: 8px; background: #fffdf5; font-weight: 700; cursor: pointer; }
.tab[aria-selected="true"] { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.tab:disabled { opacity: 0.45; cursor: default; }
.pane[hidden] { display: none; }

.bundle { display: inline-flex; flex-wrap: wrap; gap: 4px 8px; align-items: center; vertical-align: middle; }
.bundle-item { display: inline-flex; align-items: center; gap: 2px; }
.bundle-item b { font: 700 15px var(--serif); }
.bundle-empty { color: var(--ink-soft); font-style: italic; }
.offer-line { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; padding: 8px 0 12px; font-size: 15px; }
.offer-lines { display: grid; gap: 2px; padding: 4px 0 8px; }
.offer-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 48px; border-bottom: 1px solid rgba(214, 197, 160, 0.7); font-size: 16px; }
.offer-row:last-child { border-bottom: 0; }
.resp-list { list-style: none; margin: 0; padding: 0; display: grid; }
.resp-row { display: grid; grid-template-columns: auto auto 1fr auto; align-items: center; gap: 8px; min-height: 52px; border-top: 1px solid rgba(214, 197, 160, 0.7); }
.resp-name { font-weight: 700; }
.resp-status { font-size: 14px; color: var(--ink-soft); }
.resp-status.yes { color: #2d5a1e; font-weight: 700; }
.resp-status.no { color: var(--danger); }
.resp-status.counter { color: var(--ink); }
.resp-row .btn { min-height: 44px; }

.res-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; margin-top: 8px; }
.res-pick { appearance: none; display: grid; justify-items: center; gap: 2px; padding: 8px 2px; min-height: 76px; border: 1px solid #b9a98a; border-radius: 10px; background: #fffdf5; font-size: 12px; cursor: pointer; }
.res-pick b { font-size: 12px; }
.res-pick small { color: var(--ink-soft); font-size: 10px; }
.res-pick:disabled { opacity: 0.35; cursor: default; }
.res-pick[aria-pressed="true"] { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.res-pick[aria-pressed="true"] small { color: var(--paper-edge); }
.picks { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 4px 0 6px; }
.pick-slot { display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 52px; border: 1px dashed #b9a98a; border-radius: 10px; color: var(--ink-soft); font-size: 14px; background: transparent; }
.pick-slot.filled { border: 1px solid var(--ink); background: #fffdf5; color: var(--ink); cursor: pointer; }

.victims { display: grid; gap: 8px; }
.victim { justify-content: flex-start; gap: 10px; min-height: 56px; font-size: 16px; }
.victim small { margin-left: auto; font-size: 13px; color: var(--ink-soft); font-weight: 600; }

.dev-list { list-style: none; margin: 0; padding: 0; display: grid; }
.dev-row { display: flex; align-items: center; gap: 10px; min-height: 60px; padding: 6px 0; border-bottom: 1px solid rgba(214, 197, 160, 0.7); }
.dev-row:last-child { border-bottom: 0; }
.dev-info { flex: 1; display: grid; gap: 1px; }
.dev-info small { color: var(--ink-soft); font-size: 13px; }
.tag { justify-self: start; font: 800 10px/1 var(--sans); padding: 2px 6px; border-radius: 4px; background: var(--paper-sunk); border: 1px solid var(--paper-edge); }

.menu-list { display: grid; gap: 8px; padding-bottom: 6px; }
.menu-item { justify-content: flex-start; min-height: 52px; font-size: 16px; }

fieldset legend { padding: 0; font-weight: 700; font-size: 14px; color: var(--ink-soft); margin: 6px 0 4px; }
.choices { display: grid; gap: 6px; }
.choice { display: flex; align-items: center; gap: 10px; min-height: 48px; padding: 0 12px; border: 1px solid #b9a98a; border-radius: 10px; background: #fffdf5; cursor: pointer; }
.choice small { margin-left: auto; color: var(--ink-soft); }
.choice input { width: 20px; height: 20px; accent-color: var(--ink); }
.choice:has(input:checked) { border-color: var(--ink); box-shadow: 0 0 0 2px var(--ink) inset; }

.winner { display: flex; align-items: center; gap: 10px; margin: 0 0 8px; font: 600 24px var(--serif); }
.winner .swatch { width: 24px; height: 24px; }
.final { list-style: none; margin: 0; padding: 0; display: grid; }
.final-row { display: flex; align-items: center; gap: 10px; min-height: 56px; border-top: 1px solid rgba(214, 197, 160, 0.7); }
.final-info { flex: 1; display: grid; }
.final-info small { color: var(--ink-soft); font-size: 12px; }
.final-pts { font: 700 28px var(--serif); font-variant-numeric: tabular-nums; }
.final-row.won .final-pts { color: var(--amber-dark); }

#curtain {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 24px;
  background: radial-gradient(ellipse 100% 80% at 50% 35%, var(--felt) 0%, var(--felt-deep) 100%);
  color: var(--cream-on-felt);
  text-align: center;
}
#curtain[hidden] { display: none; }
.curtain-card { display: grid; justify-items: center; gap: 12px; max-width: 360px; }
.curtain-card h2 { font-size: 32px; line-height: 1.1; text-wrap: balance; }
.curtain-card p { margin: 0 0 8px; opacity: 0.8; text-wrap: balance; }
.curtain-swatch { display: block; filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.5)); }
.curtain-go { min-height: 56px; width: 100%; font-size: 18px; }
body.curtained #hud, body.curtained #board { visibility: hidden; }

.btn-small { min-height: 44px; }

/* ----- tablet portrait: the phone layout keeps the board full width; the HUD gets larger type ----- */
@media (min-width: 600px) and (max-width: 899px) and (min-height: 700px) {
  .gname { font-size: 20px; }
  .turnno { font-size: 13px; }
  .opps { gap: 8px; }
  .opp { font-size: 14px; line-height: 18px; padding: 5px 10px; column-gap: 7px; }
  .opp .swatch { width: 16px; height: 16px; }
  .opp-stats { gap: 10px; }
  .opp-stats svg { width: 14px; height: 14px; }
  .badge-lr, .badge-la { font-size: 10px; }
  .meline { font-size: 14px; min-height: 22px; }
  .me-name { font-size: 18px; }
  .me-stat svg { width: 16px; height: 16px; }
  .cards { gap: 8px; }
  .rcard, .dcard { height: 64px; }
  .rcard svg { width: 30px; height: 30px; margin-top: 7px; }
  .rcard b, .dcard b { font-size: 20px; }
  .abar { gap: 8px; }
  .abtn { min-height: 50px; font-size: 16px; }
  .abtn.primary { font-size: 18px; }
  .status-main { font-size: 22px; }
  .status-sub { font-size: 14px; }
}
@media (min-width: 600px) and (max-width: 899px) {
  .app { max-width: 680px; }
}

/* ----- laptop (and a phone turned sideways): the HUD is a right-hand column ----- */
/* keep this query in step with `wide` in hud.js */
@media (min-width: 900px), (min-width: 640px) and (max-height: 500px) {
  #hud {
    position: fixed;
    z-index: 3;
    top: 0;
    right: 0;
    bottom: 0;
    width: 372px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 14px;
    background: var(--hud-bg);
    border-left: 1px solid var(--hud-line);
    box-shadow: -8px 0 22px rgba(0, 0, 0, 0.35);
  }
  #top, #sheet { position: static; padding: 0; background: none; border: 0; box-shadow: none; min-height: 0; }
  #sheet { gap: 8px; }
  .top-row { gap: 10px; }
  .log-toggle, .phone-only { display: none; }
  .opps { flex-direction: column; margin-top: 8px; padding-top: 0; overflow: visible; }
  .opp {
    min-width: 0;
    grid-template-columns: auto 1fr auto auto;
    grid-template-areas: "dot name badges stats";
    column-gap: 8px;
    padding: 7px 10px;
    font-size: 13px;
  }
  .opp .swatch { width: 18px; height: 18px; }
  .opp-badges { position: static; grid-area: badges; }
  .badge-lr, .badge-la { font-size: 10px; padding: 2px 4px; }
  .opp-stats { gap: 9px; }
  .opp-stats svg { width: 14px; height: 14px; }
  .rcard, .dcard { height: 64px; }
  .rcard svg { width: 30px; height: 30px; margin-top: 7px; }
  .rcard b, .dcard b { font-size: 20px; }
  #log {
    display: flex;
    flex-direction: column;
    position: static;
    flex: 1;
    min-height: 0;
    max-height: none;
    padding: 8px 12px;
    overflow: hidden;
    background: rgba(239, 230, 207, 0.07);
    color: var(--cream-on-felt);
    border: 1px solid rgba(239, 230, 207, 0.16);
    box-shadow: none;
  }
  .log-title { color: var(--cream-on-felt); opacity: 0.8; }
  .log-list { overflow-y: auto; flex: 1; scrollbar-width: thin; }
  .log-turn { color: var(--cream-on-felt); opacity: 0.6; border-color: rgba(239, 230, 207, 0.2); }
  .log-empty { color: var(--cream-on-felt); }
  #reason { position: static; margin: 0; order: -1; display: none; }
  #reason.show { display: block; }
  #toast { left: calc(50% - 186px); top: 16px; }
  .abar.status, .abar.placing { min-height: 94px; }
}

/* a phone on its side: a slimmer column, the log opens over the board from the Log button */
@media (min-width: 640px) and (max-height: 500px) {
  #hud { width: 330px; gap: 6px; padding: 8px 10px calc(8px + env(safe-area-inset-bottom)); }
  .log-toggle { display: inline-block; }
  .opps { margin-top: 4px; gap: 4px; }
  .opp { padding: 4px 8px; }
  .opp .swatch { width: 14px; height: 14px; }
  .rcard, .dcard { height: 48px; }
  .rcard svg { width: 24px; height: 24px; margin-top: 4px; }
  .rcard b, .dcard b { font-size: 17px; }
  #log { display: none; }
  body.log-open #log {
    display: flex;
    position: fixed;
    z-index: 4;
    left: 8px;
    right: 338px;
    top: 8px;
    bottom: 8px;
    max-height: none;
    background: var(--paper);
    color: var(--ink);
    box-shadow: 0 8px 22px rgba(0, 0, 0, 0.5);
  }
  body.log-open .log-title, body.log-open .log-empty { color: var(--ink-soft); opacity: 1; }
  body.log-open .log-turn { color: var(--ink-soft); opacity: 1; border-color: var(--paper-edge); }
  .abar.status, .abar.placing { min-height: 0; }
  #toast { left: calc(50% - 165px); }
}

@media (prefers-reduced-motion: reduce) {
  #board .hl-vertex, #board .hl-edge, #board .hl-hex { animation: none; }
  .dice.rolling .die { animation: none; }
  #reason { transition: none; }
}
