/* Corps of Discovery Map Randomizer: tablet-first, dark wood table, parchment and felt. */

:root {
  --ink: #3b2412;
  --ink-soft: #6e4c2c;
  --parchment: #f2e4c5;
  --parchment-2: #e5d0a5;
  --parchment-edge: #c9ab76;
  --wood: #20140b;
  --wood-2: #33210f;
  --wood-3: #4a3018;
  --felt: #5c6d3d;
  --gold: #e8b552;
  --gold-2: #ffd98a;
  --ember: #ff8a2b;
  --danger: #b5352b;
  --ok: #3f7d3a;
  --cream: #f7ecd2;
  --font-ui: 'Barlow Condensed', 'Arial Narrow', 'Roboto Condensed', system-ui, sans-serif;
  --font-script: 'Kaushan Script', 'Segoe Script', 'Brush Script MT', cursive;
  --radius: 14px;
  --shadow: 0 10px 30px rgb(0 0 0 / 45%);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  font-family: var(--font-ui);
  font-size: 18px;
  color: var(--cream);
  background-color: var(--wood);
  background-image:
    radial-gradient(ellipse at 30% 20%, rgb(255 190 120 / 8%), transparent 60%),
    repeating-linear-gradient(97deg, rgb(255 255 255 / 2.5%) 0 2px, transparent 2px 9px),
    repeating-linear-gradient(93deg, rgb(0 0 0 / 18%) 0 1px, transparent 1px 23px),
    linear-gradient(180deg, var(--wood-2), var(--wood));
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}

img { -webkit-user-drag: none; user-select: none; }

button {
  font: inherit;
  color: inherit;
  touch-action: manipulation;
}

#app { position: fixed; inset: 0; }

.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding: var(--safe-top) var(--safe-right) var(--safe-bottom) var(--safe-left);
}

.scroll { overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }

.script { font-family: var(--font-script); font-weight: 400; letter-spacing: 0.01em; }

.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}

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

.btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45em;
  min-height: 48px;
  padding: 0 1.1em;
  border: 0;
  border-radius: 999px;
  font-weight: 600;
  font-size: 1.05rem;
  letter-spacing: 0.02em;
  cursor: pointer;
  white-space: nowrap;
  user-select: none;
  -webkit-user-select: none;
  transition: transform 0.12s ease, filter 0.15s ease, background-color 0.15s;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.45; cursor: default; transform: none; }
.btn .ico { width: 1.35em; height: 1.35em; object-fit: contain; }

.btn-primary {
  color: #2a1606;
  background: linear-gradient(180deg, var(--gold-2), var(--gold) 55%, #c98f2e);
  box-shadow: 0 3px 0 #8a5a17, 0 6px 16px rgb(0 0 0 / 35%);
}
.btn-primary:active { box-shadow: 0 1px 0 #8a5a17, 0 3px 8px rgb(0 0 0 / 35%); transform: translateY(2px); }

.btn-ghost {
  color: var(--cream);
  background: rgb(255 255 255 / 8%);
  box-shadow: inset 0 0 0 1.5px rgb(255 235 200 / 22%);
}
.btn-ghost:hover { background: rgb(255 255 255 / 13%); }

.btn-ink {
  color: var(--parchment);
  background: var(--ink);
  box-shadow: 0 2px 0 #1b0e04;
}
.btn-quiet {
  color: var(--ink);
  background: rgb(59 36 18 / 9%);
  box-shadow: inset 0 0 0 1.5px rgb(59 36 18 / 22%);
}
.btn-danger { color: #fff; background: var(--danger); box-shadow: 0 2px 0 #6e1a13; }
.btn-small { min-height: 38px; padding: 0 0.85em; font-size: 0.95rem; }
.btn-block { width: 100%; }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border: 0;
  border-radius: 50%;
  background: rgb(255 255 255 / 7%);
  color: var(--cream);
  cursor: pointer;
}
.icon-btn:active { transform: scale(0.94); }
.icon-btn svg { width: 24px; height: 24px; }
.icon-btn:disabled { opacity: 0.35; }

/* hold-to-confirm: a fill sweeps across while held */
.hold { overflow: hidden; isolation: isolate; }
.hold::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: -1;
  background: linear-gradient(90deg, rgb(255 140 50 / 55%), rgb(255 210 120 / 60%));
  transform-origin: left center;
  transform: scaleX(var(--hold, 0));
}
.hold.btn-primary::before { background: linear-gradient(90deg, #c46a12, #ff9b3d); }
.hold .hold-hint { font-weight: 500; opacity: 0.75; font-size: 0.85em; }
.hold.done { animation: pulse-done 0.45s ease; }
@keyframes pulse-done { 50% { transform: scale(1.04); filter: brightness(1.25); } }

/* ---------- parchment --------------------------------------------------------------------- */

.parchment {
  color: var(--ink);
  background:
    radial-gradient(ellipse at 20% 10%, rgb(255 255 255 / 40%), transparent 55%),
    radial-gradient(ellipse at 80% 90%, rgb(160 110 50 / 18%), transparent 60%),
    url('../img/art/parchment.webp') center / cover,
    linear-gradient(180deg, var(--parchment), var(--parchment-2));
  border-radius: 6px;
  box-shadow: inset 0 0 0 1px rgb(120 80 30 / 25%), inset 0 0 40px rgb(140 90 30 / 22%), var(--shadow);
}

.ribbon-title {
  font-family: var(--font-script);
  color: var(--ink);
  text-align: center;
  line-height: 1;
}

/* ---------- top bar ----------------------------------------------------------------------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 58px;
  padding: 6px 12px;
  background: linear-gradient(180deg, rgb(0 0 0 / 45%), rgb(0 0 0 / 15%));
  border-bottom: 1px solid rgb(255 220 170 / 8%);
}
.topbar .title {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 1;
}
.topbar .title img { width: 38px; height: 38px; border-radius: 50%; }
.topbar .title b { font-family: var(--font-script); font-weight: 400; font-size: 1.55rem; }
.topbar .title span { opacity: 0.7; white-space: nowrap; }
.topbar .title .stack { display: flex; flex-direction: column; line-height: 1.05; min-width: 0; }
.topbar .title .stack span { font-size: 0.9rem; overflow: hidden; text-overflow: ellipsis; }

/* ---------- home --------------------------------------------------------------------------- */

.home {
  background:
    linear-gradient(180deg, rgb(20 12 6 / 55%), rgb(20 12 6 / 92%) 55%),
    url('../img/art/cover.webp') center 20% / cover no-repeat;
}
.home-inner {
  width: min(1100px, 100%);
  margin: 0 auto;
  padding: 26px 20px 40px;
}
.home-hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 4px;
  margin: 8px 0 22px;
}
.home-hero .logo { width: min(440px, 80vw); filter: drop-shadow(0 4px 12px rgb(0 0 0 / 60%)) brightness(1.6) sepia(0.25); }
.home-hero h1 {
  margin: 0;
  font-family: var(--font-script);
  font-weight: 400;
  font-size: clamp(1.9rem, 5vw, 2.7rem);
  color: var(--gold-2);
  text-shadow: 0 3px 10px rgb(0 0 0 / 70%);
}
.home-hero p { margin: 4px 0 0; max-width: 640px; opacity: 0.85; font-size: 1.05rem; }

.section-label {
  margin: 24px 4px 10px;
  font-size: 0.95rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--gold);
  opacity: 0.9;
}

.continue-card {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 16px;
  border-radius: var(--radius);
  background: linear-gradient(135deg, rgb(255 220 150 / 14%), rgb(255 220 150 / 5%));
  box-shadow: inset 0 0 0 1.5px rgb(232 181 82 / 45%), var(--shadow);
}
.continue-card img { width: 64px; height: 64px; border-radius: 50%; flex: none; }
.continue-card .info { flex: 1; min-width: 0; }
.continue-card .info b { display: block; font-size: 1.25rem; }
.continue-card .info span { opacity: 0.75; }
.continue-card .progress {
  height: 6px;
  margin-top: 6px;
  border-radius: 3px;
  background: rgb(255 255 255 / 12%);
  overflow: hidden;
}
.continue-card .progress i { display: block; height: 100%; background: var(--gold); }

.chapter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 16px;
}
.chapter-card {
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 250px;
  padding: 0;
  overflow: hidden;
  border: 0;
  border-radius: var(--radius);
  text-align: left;
  color: var(--cream);
  background: #000 var(--art) center / cover no-repeat;
  box-shadow: var(--shadow), inset 0 0 0 1px rgb(255 230 190 / 12%);
  cursor: pointer;
  transition: transform 0.18s ease, box-shadow 0.18s;
}
.chapter-card::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgb(0 0 0 / 0%) 30%, rgb(15 8 3 / 92%) 78%);
}
.chapter-card:hover { transform: translateY(-3px); box-shadow: 0 16px 34px rgb(0 0 0 / 55%), inset 0 0 0 1.5px rgb(232 181 82 / 60%); }
.chapter-card:active { transform: scale(0.98); }
.chapter-card .body { position: relative; z-index: 1; margin-top: auto; padding: 14px 16px 16px; }
.chapter-card .badge {
  position: absolute;
  z-index: 1;
  top: 12px;
  left: 12px;
  width: 54px;
  height: 54px;
  border-radius: 50%;
  box-shadow: 0 4px 12px rgb(0 0 0 / 55%);
}
.chapter-card .num {
  position: absolute;
  z-index: 1;
  top: 14px;
  right: 14px;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 0.8rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  background: rgb(0 0 0 / 55%);
}
.chapter-card h3 { margin: 0; font-family: var(--font-script); font-weight: 400; font-size: 1.85rem; line-height: 1.1; color: var(--gold-2); }
.chapter-card p { margin: 4px 0 0; font-size: 1rem; line-height: 1.25; opacity: 0.9; }

.home-actions { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 22px; }
.home-foot { margin-top: 30px; font-size: 0.85rem; opacity: 0.55; line-height: 1.4; }

/* ---------- dialogs and sheets ----------------------------------------------------------- */

.backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgb(10 5 2 / 62%);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  animation: fade-in 0.18s ease;
}
@keyframes fade-in { from { opacity: 0; } }

.dialog {
  position: relative;
  width: min(560px, 100%);
  max-height: calc(100% - 24px);
  overflow-y: auto;
  padding: 22px 22px 20px;
  animation: pop-in 0.22s cubic-bezier(0.2, 1.4, 0.4, 1);
}
.dialog.wide { width: min(760px, 100%); }
@keyframes pop-in { from { transform: scale(0.94) translateY(8px); opacity: 0; } }
.dialog h2 { margin: 0 0 6px; font-family: var(--font-script); font-weight: 400; font-size: 2rem; }
.dialog p { margin: 0.5em 0; line-height: 1.35; }
.dialog .row { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 16px; }
.dialog .row.end { justify-content: flex-end; }
.dialog .close {
  position: absolute;
  z-index: 3;
  top: 10px;
  right: 10px;
  color: var(--ink);
  background: rgb(59 36 18 / 10%);
}

.setup-art {
  height: 170px;
  margin: -22px -22px 14px;
  border-radius: 6px 6px 0 0;
  background: #000 var(--art) center 30% / cover;
  position: relative;
}
.setup-art img {
  position: absolute;
  left: 18px;
  bottom: -26px;
  width: 72px;
  height: 72px;
  border-radius: 50%;
  box-shadow: 0 4px 14px rgb(0 0 0 / 50%);
}
.setup-head { padding-left: 86px; min-height: 36px; }

.field { display: flex; flex-direction: column; gap: 4px; margin-top: 12px; }
.field label, .field .label { font-size: 0.85rem; letter-spacing: 0.08em; text-transform: uppercase; opacity: 0.75; }
.field input[type='text'], .field input[type='number'], .field select {
  min-height: 46px;
  padding: 0 12px;
  border: 1.5px solid rgb(59 36 18 / 30%);
  border-radius: 10px;
  font: inherit;
  font-size: 1.1rem;
  color: var(--ink);
  background: rgb(255 255 255 / 55%);
}
.field input.code { text-transform: uppercase; letter-spacing: 0.25em; font-weight: 600; width: 9em; }
.segmented {
  display: inline-flex;
  align-self: flex-start;
  padding: 3px;
  border-radius: 999px;
  background: rgb(59 36 18 / 12%);
  gap: 2px;
  flex-wrap: wrap;
}
.segmented button {
  min-height: 40px;
  padding: 0 14px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--ink);
  font-weight: 600;
  cursor: pointer;
}
.segmented button[aria-pressed='true'] { background: var(--ink); color: var(--parchment); }

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 52px;
  border-bottom: 1px solid rgb(59 36 18 / 14%);
}
.toggle-row:last-child { border-bottom: 0; }
.toggle-row small { display: block; opacity: 0.7; font-size: 0.85rem; }
.switch {
  position: relative;
  flex: none;
  width: 54px;
  height: 32px;
  border: 0;
  border-radius: 999px;
  background: rgb(59 36 18 / 25%);
  cursor: pointer;
  transition: background 0.2s;
}
.switch::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgb(0 0 0 / 30%);
  transition: transform 0.2s;
}
.switch[aria-checked='true'] { background: var(--ok); }
.switch[aria-checked='true']::after { transform: translateX(22px); }

.toggle-row input[type='range'] { width: min(200px, 45vw); accent-color: var(--ink); }
.now-row { min-height: 44px; }
.now-row:has(.now-playing:empty) { display: none; }
.now-playing { font-size: 0.92rem; font-style: italic; opacity: 0.85; }
details.credits { margin: 6px 0 4px; }
details.credits summary { cursor: pointer; font-weight: 600; padding: 8px 0; }
details.credits p { font-size: 0.92rem; }
details.credits ol { margin: 6px 0 0; padding-left: 1.3em; font-size: 0.9rem; line-height: 1.3; }
details.credits li { margin: 5px 0; }
details.credits a { color: var(--ink-soft); }

/* menu list */
.menu-list { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.menu-list .btn { justify-content: flex-start; border-radius: 12px; min-height: 52px; }

/* ---------- game layout -------------------------------------------------------------------- */

.game .table {
  flex: 1;
  min-height: 0;
  display: flex;
  gap: 14px;
  padding: 10px 14px 12px;
}
.board-wrap {
  position: relative;
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: grid;
  place-items: center;
}
.side {
  flex: none;
  width: clamp(290px, 31vw, 400px);
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
}

@media (orientation: portrait), (max-width: 760px) {
  .game .table { flex-direction: column; padding: 8px 10px 10px; gap: 10px; }
  .board-wrap { flex: none; width: 100%; height: min(calc(100vw - 20px), 60vh); }
  .side {
    width: auto;
    flex: 1;
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: minmax(0, 1fr) auto;
    gap: 10px;
  }
  .side .briefing { grid-area: 1 / 1; }
  .side .turn { grid-area: 1 / 2; min-height: 0; }
  .side .tools { grid-area: 2 / 1 / 3 / 3; }
}
@media (max-width: 620px) {
  .side { grid-template-columns: 1fr; grid-template-rows: auto auto auto; overflow-y: auto; }
  .side .briefing, .side .turn, .side .tools { grid-area: auto; }
  .side .briefing { max-height: none; }
  .topbar .title span { display: none; }
}
.board.resizing .tok { transition: none; }

/* ---------- the board --------------------------------------------------------------------- */

.board {
  --cell: 90px;
  --pitch: calc(var(--cell) * 1.1);
  --label: calc(var(--cell) * 0.32);
  position: relative;
  width: calc(var(--pitch) * var(--cols) + var(--label) + var(--cell) * 0.7);
  height: calc(var(--pitch) * var(--rows) + var(--label) + var(--cell) * 0.12);
  border-radius: 10px;
  background:
    radial-gradient(ellipse at 50% 40%, rgb(255 255 220 / 10%), transparent 70%),
    url('../img/art/felt.webp') center / cover,
    var(--felt);
  box-shadow:
    0 0 0 3px #2e1d0e,
    0 0 0 7px #6f4a25,
    0 0 0 9px #2a190b,
    0 18px 40px rgb(0 0 0 / 60%),
    inset 0 0 60px rgb(0 0 0 / 35%);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  transition: transform 0.6s cubic-bezier(0.3, 0.7, 0.2, 1);
}
.board.maldonado { background: url('../img/art/felt-maldonado.webp') center / cover, var(--felt); }
.board.flipped { transform: rotate(180deg); }
.board.flipped .cell-inner, .board.flipped .tok, .board.flipped .axis span { transform: rotate(180deg); }

.board .river {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: calc(var(--cell) * 0.62);
  border-radius: 0 10px 10px 0;
  background:
    repeating-linear-gradient(170deg, rgb(255 255 255 / 6%) 0 2px, transparent 2px 14px),
    linear-gradient(90deg, rgb(60 110 105 / 0%), rgb(76 138 136 / 85%) 30%, rgb(66 128 132));
  pointer-events: none;
}
.board .boat {
  position: absolute;
  right: 0;
  bottom: 0;
  width: calc(var(--cell) * 0.62);
  height: calc(var(--cell) * 1.25);
  overflow: hidden;
  border-radius: 0 0 10px 0;
  pointer-events: none;
  -webkit-mask-image: linear-gradient(to top, #000 70%, transparent);
  mask-image: linear-gradient(to top, #000 70%, transparent);
}
.board .boat img {
  position: absolute;
  left: 50%;
  top: 50%;
  width: calc(var(--cell) * 1.25);
  height: calc(var(--cell) * 0.66);
  object-fit: cover;
  transform: translate(-50%, -50%) rotate(-90deg);
}

.axis {
  position: absolute;
  display: flex;
  pointer-events: none;
  font-weight: 600;
  font-size: calc(var(--cell) * 0.2);
  color: rgb(255 248 220 / 58%);
}
.axis.rows { left: 0; top: calc(var(--cell) * 0.05); flex-direction: column; width: var(--label); }
.axis.rows span { height: var(--pitch); display: grid; place-items: center; }
.axis.cols { left: var(--label); bottom: 0; height: var(--label); }
.axis.cols span { width: var(--pitch); display: grid; place-items: center; }

.cell {
  position: absolute;
  left: calc(var(--label) + var(--c) * var(--pitch) + (var(--pitch) - var(--cell)) / 2);
  top: calc(var(--cell) * 0.05 + var(--r) * var(--pitch) + (var(--pitch) - var(--cell)) / 2);
  width: var(--cell);
  height: var(--cell);
}
.cell-inner { position: absolute; inset: 0; transition: transform 0.6s; }
.cell .hole {
  position: absolute;
  inset: -3%;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 42%, rgb(0 0 0 / 50%), rgb(0 0 0 / 28%) 62%, rgb(255 255 255 / 6%) 70%, transparent 72%);
}
.cell .terrain {
  position: absolute;
  inset: 4%;
  width: 92%;
  height: 92%;
  border-radius: 50%;
  object-fit: contain;
  filter: drop-shadow(0 2px 2px rgb(0 0 0 / 45%));
}
.cell.revealed .terrain { animation: terrain-in 0.55s cubic-bezier(0.2, 1.5, 0.45, 1) both; }
@keyframes terrain-in {
  0% { transform: scale(0.7); filter: brightness(2.2) drop-shadow(0 0 12px #fff3c0); }
  60% { transform: scale(1.06); }
  100% { transform: scale(1); }
}
.cell .hill-num {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding-bottom: 22%;
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: calc(var(--cell) * 0.42);
  color: #fff;
  -webkit-text-stroke: calc(var(--cell) * 0.018) #1f2a14;
  paint-order: stroke fill;
  text-shadow: 0 2px 4px rgb(0 0 0 / 50%);
  pointer-events: none;
}
.cell.flora-dead .terrain { filter: grayscale(0.85) brightness(0.75) drop-shadow(0 2px 2px rgb(0 0 0 / 45%)); }
.cell .ash {
  position: absolute;
  inset: 8%;
  border-radius: 50%;
  background: radial-gradient(circle, rgb(40 25 15 / 0%) 35%, rgb(40 25 15 / 55%) 75%);
  pointer-events: none;
}

/* path token sitting in the hole */
.ptoken {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  perspective: 600px;
  transition: transform 0.25s cubic-bezier(0.3, 1.5, 0.5, 1), filter 0.2s;
}
.ptoken img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  filter: drop-shadow(0 3px 3px rgb(0 0 0 / 50%)) brightness(1.06) saturate(1.08);
}
.ptoken::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 28%, rgb(255 255 230 / 22%), transparent 45%);
  box-shadow: inset 0 0 0 1px rgb(30 40 15 / 35%);
  pointer-events: none;
}
.cell.reach .hole {
  box-shadow: 0 0 0 calc(var(--cell) * 0.035) rgb(255 222 140 / 38%), 0 0 calc(var(--cell) * 0.25) rgb(255 215 120 / 30%);
  animation: reach-glow 2.6s ease-in-out infinite;
}
@keyframes reach-glow { 50% { box-shadow: 0 0 0 calc(var(--cell) * 0.035) rgb(255 222 140 / 18%), 0 0 calc(var(--cell) * 0.12) rgb(255 215 120 / 10%); } }

/* holding: the token peels up at one edge and lamplight leaks out from under it */
.cell.holding .ptoken {
  transform: translateY(calc(var(--p, 0) * var(--cell) * -0.08)) scale(calc(1 + var(--p, 0) * 0.1));
  filter: drop-shadow(0 calc(4px + var(--p, 0) * 12px) calc(4px + var(--p, 0) * 12px) rgb(0 0 0 / 55%));
  transition: none;
}
.cell.holding .ptoken img,
.cell.holding .ptoken::after {
  transform: perspective(calc(var(--cell) * 5)) rotateX(calc(var(--p, 0) * 26deg)) rotateY(calc(var(--p, 0) * -12deg));
  transform-origin: 50% 85%;
}
.cell .glow {
  position: absolute;
  inset: -24%;
  border-radius: 50%;
  background: radial-gradient(circle closest-side, rgb(255 238 175 / 95%) 58%, rgb(255 192 85 / 55%) 74%, transparent 100%);
  opacity: 0;
  pointer-events: none;
}
.cell.holding .glow { opacity: calc(var(--p, 0) * 1); }
.cell.off-trail.holding .glow { background: radial-gradient(circle closest-side, rgb(255 170 100 / 90%) 58%, rgb(210 85 40 / 50%) 74%, transparent 100%); }

.cell .ring {
  position: absolute;
  inset: -12%;
  width: 124%;
  height: 124%;
  transform: rotate(-90deg);
  pointer-events: none;
  opacity: 0;
}
.cell.holding .ring { opacity: 1; }
.cell .ring circle { fill: none; stroke-width: 5; stroke-linecap: round; }
.cell .ring .track { stroke: rgb(0 0 0 / 35%); }
.cell .ring .fill { stroke: var(--gold-2); filter: drop-shadow(0 0 4px rgb(255 210 120 / 90%)); }
.cell.off-trail .ring .fill { stroke: var(--ember); }

.cell.denied .ptoken { animation: shake 0.42s ease; }
@keyframes shake {
  20%, 60% { transform: translateX(-6%) rotate(-4deg); }
  40%, 80% { transform: translateX(6%) rotate(4deg); }
}

/* the Rock resource token marking the Peak, the Greek Fire, a guess marker */
.cell .peak, .cell .mark {
  position: absolute;
  right: -6%;
  bottom: -6%;
  width: 52%;
  height: 52%;
  border-radius: 50%;
  pointer-events: none;
}
.cell .peak {
  left: 22%;
  top: 22%;
  width: 56%;
  height: 56%;
  background: radial-gradient(circle at 40% 35%, #fff9e8, var(--parchment-2));
  box-shadow: 0 3px 5px rgb(0 0 0 / 50%), inset 0 0 0 2px rgb(110 75 35 / 45%);
}
.cell .peak img { width: 100%; height: 100%; padding: 12%; object-fit: contain; }
.cell .mark img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  box-shadow: 0 2px 5px rgb(0 0 0 / 55%), 0 0 0 2px rgb(255 245 220 / 85%);
}
.cell .mark.unsure img { filter: grayscale(1) brightness(0.8) contrast(1.1); }
.cell .mark .q {
  position: absolute;
  right: -10%;
  top: -10%;
  width: 46%;
  height: 46%;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: calc(var(--cell) * 0.17);
  line-height: 1;
  color: #fff;
  background: #555048;
  box-shadow: 0 1px 3px rgb(0 0 0 / 50%), 0 0 0 1.5px rgb(255 245 220 / 85%);
}

.cell.peeking .ptoken { transform: translate(28%, -32%) rotate(24deg) scale(0.92); opacity: 0.85; transition: transform 0.3s cubic-bezier(0.3, 1.4, 0.5, 1), opacity 0.3s; }
.cell.peeking .mark { opacity: 0; }
.cell .peek-terrain { position: absolute; inset: 4%; width: 92%; height: 92%; border-radius: 50%; }

.cell.highlight .hole { box-shadow: 0 0 0 calc(var(--cell) * 0.05) rgb(255 120 60 / 85%), 0 0 calc(var(--cell) * 0.3) rgb(255 120 60 / 60%); animation: none; }
.cell.highlight { cursor: pointer; }
.cell.last .hole { box-shadow: 0 0 0 calc(var(--cell) * 0.03) rgb(255 230 160 / 70%); }

/* loose tokens on the map */
.tok {
  position: absolute;
  z-index: 5;
  left: calc(var(--label) + var(--c) * var(--pitch) + var(--pitch) / 2 + var(--ox, 0px));
  top: calc(var(--cell) * 0.05 + var(--r) * var(--pitch) + var(--pitch) / 2 + var(--oy, 0px));
  width: calc(var(--cell) * var(--s, 0.82));
  height: calc(var(--cell) * var(--s, 0.82));
  margin: calc(var(--cell) * var(--s, 0.82) / -2) 0 0 calc(var(--cell) * var(--s, 0.82) / -2);
  transition: left 0.45s cubic-bezier(0.3, 1.2, 0.5, 1), top 0.45s cubic-bezier(0.3, 1.2, 0.5, 1);
  touch-action: none;
  cursor: grab;
}
.tok img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 4px 4px rgb(0 0 0 / 55%));
  transform: rotate(var(--turn, 0deg));
  transition: transform 0.4s;
}
.tok .n {
  position: absolute;
  right: -4%;
  top: -4%;
  min-width: 34%;
  height: 34%;
  padding: 0 0.2em;
  border-radius: 999px;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: calc(var(--cell) * 0.18);
  color: #fff;
  background: #7d1d16;
  box-shadow: 0 1px 3px rgb(0 0 0 / 50%);
}
.tok.dragging { z-index: 30; transition: none; filter: drop-shadow(0 12px 10px rgb(0 0 0 / 50%)); transform: scale(1.12); cursor: grabbing; }
.tok.small { --s: 0.46; }
.tok.crew { --s: 0.62; }
.tok.crew img { object-fit: contain; }
.tok.arrive { animation: tok-in 0.5s cubic-bezier(0.2, 1.5, 0.4, 1); }
@keyframes tok-in { from { transform: translateY(-40%) scale(1.5); opacity: 0; } }

/* reveal effects */
.flyer {
  position: absolute;
  z-index: 20;
  pointer-events: none;
  perspective: 700px;
}
.flyer .card {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  animation: flip-away 0.85s cubic-bezier(0.4, 0, 0.3, 1) forwards;
}
.flyer img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}
.flyer img.sun { transform: rotateY(180deg); }
@keyframes flip-away {
  0% { transform: translate(0, -7%) scale(1.08) rotateY(0); }
  35% { transform: translate(8%, -40%) scale(1.25) rotateY(180deg); opacity: 1; }
  100% { transform: translate(var(--fx, 160%), var(--fy, -220%)) scale(0.5) rotateY(180deg) rotate(25deg); opacity: 0; }
}
.flyer.drop .card { animation: drop-in 0.55s cubic-bezier(0.3, 1.3, 0.5, 1) forwards; }
@keyframes drop-in {
  0% { transform: translateY(-80%) scale(1.5); opacity: 0; }
  70% { opacity: 1; }
  100% { transform: none; opacity: 1; }
}
.spark {
  position: absolute;
  z-index: 21;
  width: calc(var(--cell) * 0.07);
  height: calc(var(--cell) * 0.07);
  border-radius: 50%;
  background: var(--spark, #fff2c0);
  box-shadow: 0 0 6px var(--spark, #ffe39a);
  pointer-events: none;
  animation: spark 0.75s ease-out forwards;
}
@keyframes spark {
  from { transform: translate(-50%, -50%) scale(1); opacity: 1; }
  to { transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) scale(0.2); opacity: 0; }
}

/* placement mode */
.board.placing .cell { cursor: crosshair; }
.place-hint {
  position: absolute;
  z-index: 40;
  left: 50%;
  top: 8px;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px 6px 14px;
  border-radius: 999px;
  background: rgb(20 12 6 / 88%);
  box-shadow: var(--shadow);
  white-space: nowrap;
}

/* ---------- side panel --------------------------------------------------------------------- */

.briefing {
  padding: 14px 16px 12px;
  overflow-y: auto;
  min-height: 0;
}
.briefing .head { display: flex; align-items: center; gap: 12px; }
.briefing .head img { width: 50px; height: 50px; border-radius: 50%; flex: none; }
.briefing .head h2 { margin: 0; font-family: var(--font-script); font-weight: 400; font-size: 1.9rem; line-height: 1; }
.briefing .head .mapno { font-weight: 700; letter-spacing: 0.06em; font-size: 0.9rem; opacity: 0.8; }
.briefing dl { margin: 10px 0 0; display: grid; grid-template-columns: auto 1fr; gap: 3px 10px; font-size: 1.02rem; }
.briefing dt { font-weight: 700; }
.briefing dd { margin: 0; }
.briefing ul { margin: 8px 0 0; padding-left: 1.1em; font-size: 0.98rem; line-height: 1.3; }
.briefing li { margin: 2px 0; }
.briefing .minimap-wrap { display: flex; align-items: center; gap: 12px; margin-top: 10px; }
.minimap {
  display: grid;
  grid-template-columns: repeat(2, 44px);
  grid-auto-rows: 44px;
  gap: 3px;
  padding: 6px;
  border-radius: 4px;
  background: #fbf7ef;
  box-shadow: inset 0 0 0 1px rgb(59 36 18 / 20%), 0 2px 5px rgb(0 0 0 / 15%);
}
.minimap img { width: 100%; height: 100%; object-fit: contain; }
.fog-window {
  margin-top: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  background: rgb(59 36 18 / 8%);
  box-shadow: inset 0 0 0 1.5px rgb(59 36 18 / 25%);
}
.fog-window .rule { display: flex; align-items: center; gap: 8px; margin: 4px 0; line-height: 1.2; }
.fog-window .rule img { width: 34px; height: 34px; flex: none; }
.fog-window .rule.hidden { opacity: 0.6; font-style: italic; }

.turn {
  flex: 1;
  min-height: 140px;
  padding: 14px 16px;
  border-radius: var(--radius);
  background: linear-gradient(180deg, rgb(255 236 200 / 9%), rgb(255 236 200 / 4%));
  box-shadow: inset 0 0 0 1.5px rgb(255 230 190 / 14%);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.turn .found { display: flex; gap: 12px; align-items: center; animation: slide-up 0.35s ease both; }
@keyframes slide-up { from { transform: translateY(10px); opacity: 0; } }
.turn .found img { width: 62px; height: 62px; flex: none; filter: drop-shadow(0 3px 4px rgb(0 0 0 / 50%)); }
.turn .found h3 { margin: 0; font-family: var(--font-script); font-weight: 400; font-size: 1.6rem; color: var(--gold-2); line-height: 1.05; }
.turn .found .where { font-size: 0.9rem; opacity: 0.7; letter-spacing: 0.05em; }
.turn .lines { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 6px; }
.turn .lines li {
  padding: 7px 10px;
  border-radius: 9px;
  background: rgb(0 0 0 / 22%);
  line-height: 1.25;
  animation: slide-up 0.35s ease both;
}
.turn .lines li.reward { background: linear-gradient(90deg, rgb(232 181 82 / 30%), rgb(232 181 82 / 10%)); box-shadow: inset 0 0 0 1px rgb(232 181 82 / 50%); }
.turn .lines li.warn { background: rgb(181 53 43 / 28%); box-shadow: inset 0 0 0 1px rgb(255 120 100 / 35%); }
.turn .lines li.note { background: transparent; padding: 0 2px; opacity: 0.75; font-size: 0.95rem; }
.turn .actions { display: flex; flex-wrap: wrap; gap: 8px; }
.turn .idle { opacity: 0.8; line-height: 1.35; }
.turn .idle b { color: var(--gold-2); }
.turn .stats { display: flex; gap: 14px; flex-wrap: wrap; font-size: 0.95rem; opacity: 0.8; margin-top: auto; }
.turn .stats b { color: var(--gold-2); }

.fire-pair { display: inline-flex; }
.fire-pair img { width: 1.25em; height: 1.4em; object-fit: contain; margin-right: -0.25em; }

.tools { display: flex; flex-wrap: wrap; gap: 8px; }
.tools .btn { flex: 1 1 auto; }

/* ---------- popovers on the board ------------------------------------------------------- */

.pop {
  position: fixed;
  z-index: 45;
  width: min(360px, calc(100vw - 20px));
  max-height: min(78vh, 640px);
  overflow-y: auto;
  padding: 14px 14px 12px;
  animation: pop-in 0.18s cubic-bezier(0.2, 1.4, 0.4, 1);
}
.pop-scrim { position: fixed; inset: 0; z-index: 44; }
.pop h3 { margin: 0; font-size: 1.25rem; display: flex; align-items: center; gap: 8px; }
.pop h3 img { width: 40px; height: 40px; }
.pop .sub { font-size: 0.92rem; opacity: 0.75; margin-top: 2px; }
.pop .rules { margin: 8px 0 0; padding-left: 1.1em; font-size: 0.95rem; line-height: 1.28; }
.pop .group { margin-top: 12px; }
.pop .group > .label { font-size: 0.8rem; letter-spacing: 0.1em; text-transform: uppercase; opacity: 0.7; margin-bottom: 6px; display: flex; justify-content: space-between; align-items: center; }
.pop .actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.pick-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(56px, 1fr)); gap: 6px; }
.pick-grid button {
  position: relative;
  aspect-ratio: 1;
  padding: 4px;
  border: 0;
  border-radius: 12px;
  background: rgb(59 36 18 / 8%);
  cursor: pointer;
}
.pick-grid button img { width: 100%; height: 100%; object-fit: contain; }
.pick-grid button[aria-pressed='true'] { background: rgb(232 181 82 / 45%); box-shadow: inset 0 0 0 2px var(--ink); }
.pick-grid button .cap { position: absolute; left: 0; right: 0; bottom: -2px; font-size: 0.7rem; color: var(--ink); text-align: center; }
.pick-grid.unsure button img { filter: grayscale(1) brightness(0.85); }
.pick-grid.tokens button { aspect-ratio: auto; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 2px; }
.pick-grid.tokens button img { height: 48px; }
.pick-grid.tokens button span { font-size: 0.8rem; color: var(--ink); line-height: 1.05; text-align: center; }

/* ---------- toasts ------------------------------------------------------------------------ */

.toasts {
  position: fixed;
  z-index: 60;
  left: 50%;
  bottom: calc(18px + var(--safe-bottom));
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}
.toast {
  padding: 10px 18px;
  border-radius: 999px;
  background: rgb(18 10 4 / 92%);
  box-shadow: var(--shadow), inset 0 0 0 1px rgb(232 181 82 / 35%);
  animation: toast 3.2s ease forwards;
  max-width: 90vw;
  text-align: center;
}
@keyframes toast {
  0% { transform: translateY(12px); opacity: 0; }
  8%, 85% { transform: none; opacity: 1; }
  100% { opacity: 0; }
}

/* reward banner flourish over the board */
.banner {
  position: absolute;
  z-index: 35;
  left: 50%;
  top: 40%;
  transform: translate(-50%, -50%);
  padding: 12px 34px;
  color: var(--ink);
  font-family: var(--font-script);
  font-size: clamp(1.4rem, 3.5vw, 2.3rem);
  white-space: nowrap;
  background: url('../img/art/ribbon.webp') center / 100% 100% no-repeat;
  filter: drop-shadow(0 8px 10px rgb(0 0 0 / 50%));
  pointer-events: none;
  animation: banner 2.2s cubic-bezier(0.2, 1.3, 0.4, 1) forwards;
}
@keyframes banner {
  0% { transform: translate(-50%, -50%) scale(0.4) rotate(-6deg); opacity: 0; }
  15% { transform: translate(-50%, -50%) scale(1.05); opacity: 1; }
  80% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
  100% { transform: translate(-50%, -60%) scale(0.96); opacity: 0; }
}

/* generation overlay */
.surveying { display: grid; place-items: center; gap: 14px; text-align: center; }
.compass-spin { width: 92px; height: 92px; animation: spin 2.4s cubic-bezier(0.5, 0, 0.5, 1) infinite; filter: drop-shadow(0 4px 8px rgb(0 0 0 / 40%)); }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- print screen (on screen) ---------------------------------------------------- */

.print-screen .content { width: min(900px, 100%); margin: 0 auto; padding: 18px 18px 40px; }
.print-screen .panel { padding: 18px 20px; margin-top: 14px; }
.print-screen .grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 8px 18px; }
.print-screen .codes { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.print-screen .codes span { padding: 4px 10px; border-radius: 999px; background: rgb(59 36 18 / 10%); font-weight: 600; letter-spacing: 0.12em; }
.secret-note { display: flex; gap: 12px; align-items: flex-start; margin-top: 12px; padding: 10px 12px; border-radius: 10px; background: rgb(181 53 43 / 10%); box-shadow: inset 0 0 0 1px rgb(181 53 43 / 30%); }

#print-root { display: none; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}
