/* Crow's Nest playtest client. Palette from the Game Profile visual style guide. */
:root {
  --ink: #3E1C0C;          /* Captain's Ink */
  --rust: #5F2E07;         /* Rust Title */
  --plank-ink: #513121;
  --faded: #624A2B;
  --res-plank: #D28346;
  --act-plank: #8F592E;
  --parch: #D5B275;
  --parch-hi: #E4C68E;
  --gold: #916D3A;
  --gold-hi: #E0B350;
  --sand: #EBD2AC;
  --deep: #2D596C;
  --night: #09172B;
  --haze: #90B0B5;
  --tar: #121112;
  --wood: #463E41;
  --good: #4f8a4b;
  --bad: #a8402c;

  /* Card sizes scale with the window (card art ratio is 11:15). */
  --card-w: clamp(92px, min(8.4vw, 13vh), 132px);   /* deck, pile, played card */
  --card-h: calc(var(--card-w) * 1.364);
  --hand-w: 118px;
  --hand-h: 161px;
  --slot-w: 64px;
  --slot-h: 87px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
html { background: var(--night); }
.board, .hand, .topbar { user-select: none; -webkit-user-select: none; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--sand);
  background:
    radial-gradient(ellipse at 50% 35%, rgba(45, 89, 108, .55), transparent 65%),
    linear-gradient(180deg, #0d2036 0%, var(--night) 100%);
  background-attachment: fixed;
  min-height: 100vh;
}
button { font: inherit; cursor: pointer; }
.hidden { display: none !important; }

/* ---------- parchment + buttons ---------- */
.parchment {
  background:
    radial-gradient(ellipse at 30% 20%, rgba(255,255,255,.25), transparent 60%),
    radial-gradient(ellipse at 80% 90%, rgba(95,46,7,.25), transparent 60%),
    var(--parch);
  color: var(--ink);
  border: 3px solid var(--plank-ink);
  box-shadow: 0 0 0 6px #6b4a2c, 0 14px 40px rgba(0,0,0,.6), inset 0 0 40px rgba(95,46,7,.35);
  border-radius: 10px;
}
.btn {
  background: linear-gradient(180deg, var(--res-plank), #a9622f);
  color: #2a1206;
  border: 2px solid var(--ink);
  border-radius: 8px;
  padding: 10px 18px;
  font-family: Cinzel, serif;
  font-weight: 700;
  letter-spacing: .03em;
  box-shadow: 0 3px 0 var(--ink);
  transition: transform .08s, filter .15s;
}
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }
.btn.big { font-size: 1.25rem; padding: 12px 28px; width: 100%; margin-top: 12px; }
.btn.small { padding: 5px 10px; font-size: .8rem; }
.btn.tiny { padding: 2px 8px; font-size: .7rem; box-shadow: 0 2px 0 var(--ink); }
.btn.ghost { background: transparent; color: var(--ink); box-shadow: none; width: 100%; margin-top: 8px; }
.btn.alt { background: linear-gradient(180deg, var(--act-plank), #6b4020); color: var(--parch-hi); }
.btn.danger { background: linear-gradient(180deg, #c45a3d, #8a2f1d); color: #fff1dc; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- setup ---------- */
#setup { display: grid; place-items: center; min-height: 100vh; padding: 24px; }
.setup-card { width: min(440px, 100%); padding: 28px 30px 22px; }
.logo {
  font-family: Rye, "Cinzel Decorative", serif;
  color: var(--rust);
  font-size: 2.8rem;
  text-align: center;
  margin: 0;
  text-shadow: 0 2px 0 var(--parch-hi);
}
.tagline { text-align: center; margin: 4px 0 18px; font-family: Cinzel, serif; color: var(--faded); }
.field { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin: 12px 0; font-family: Cinzel, serif; font-weight: 700; }
.field input[type=text] {
  flex: 1; max-width: 220px; padding: 8px 10px; border: 2px solid var(--plank-ink); border-radius: 6px;
  background: var(--parch-hi); color: var(--ink); font: inherit; font-family: system-ui, sans-serif; font-weight: 600;
}
.seg { display: inline-flex; border: 2px solid var(--plank-ink); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: var(--parch-hi); color: var(--ink); padding: 7px 14px; font-weight: 700; border-right: 1px solid var(--plank-ink); }
.seg button:last-child { border-right: 0; }
.seg button.on { background: var(--act-plank); color: var(--parch-hi); }
.check { display: flex; align-items: center; gap: 8px; font-size: .9rem; }
.fine { font-size: .8rem; color: var(--faded); text-align: center; margin: 14px 0 0; }

/* ---------- hidden log = more room for the table ---------- */
body.log-hidden #table { grid-template-columns: 1fr; }
body.log-hidden .log-panel { display: none; }

/* ---------- ranks + leaderboard ---------- */
.tier { display: inline-block; padding: 1px 8px; border-radius: 10px; font: 700 .72rem Cinzel, serif; letter-spacing: .04em; border: 1px solid rgba(0,0,0,.35); vertical-align: middle; }
.tier-unranked { background: #cdbb98; color: #5b4a35; }
.tier-bronze { background: linear-gradient(180deg, #e0a36b, #a8642e); color: #2a1206; }
.tier-silver { background: linear-gradient(180deg, #f1f1f1, #a9adb3); color: #2b2f36; }
.tier-gold { background: linear-gradient(180deg, #ffe08a, #d4a019); color: #3b2a00; }
.tier-platinum { background: linear-gradient(180deg, #e6fbff, #8fc7d3); color: #123842; }
.tier-diamond { background: linear-gradient(180deg, #d9f3ff, #7bb7ff 60%, #b88bff); color: #10234a; box-shadow: 0 0 8px rgba(123,183,255,.8); }
.score-table.lb tr.is-me td { background: rgba(224,179,80,.35); font-weight: 700; }
.score-table.lb td:first-child { width: 36px; color: var(--faded); }
.tier-legend { line-height: 2; font-size: .85rem; }
.record-line { margin-top: 10px; font-weight: 600; color: var(--ink); }
#whoami { line-height: 1.6; }

/* ---------- profiles + badges ---------- */
.pirate-link { background: none; border: 0; padding: 0; font: inherit; color: var(--rust); font-weight: 700; text-decoration: underline; text-decoration-style: dotted; text-underline-offset: 3px; cursor: pointer; }
.pirate-link:hover { color: #8a2f1d; }
.pf-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin: 6px 0 4px; }
.pf-stats div { background: rgba(255,255,255,.22); border: 1px solid rgba(81,49,33,.35); border-radius: 10px; padding: 10px 6px; text-align: center; }
.pf-stats b { display: block; font: 700 1.6rem Cinzel, serif; color: var(--rust); }
.pf-stats span { font-size: .78rem; color: var(--faded); }
.pf-next { color: var(--faded) !important; font-size: .88rem; }
.modal h3 small { font: 600 .8rem system-ui, sans-serif; color: var(--faded); margin-left: 6px; }
.badge-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 10px; }
.badge-tile { display: flex; gap: 12px; align-items: center; padding: 10px; border-radius: 12px; border: 2px solid rgba(81,49,33,.4); background: rgba(255,255,255,.22); }
.badge-tile.earned { border-color: var(--gold); background: linear-gradient(135deg, rgba(255,232,163,.65), rgba(224,179,80,.35)); box-shadow: 0 0 12px rgba(224,179,80,.45); }
.badge-tile.locked .badge-icon { filter: grayscale(1) opacity(.45); }
.badge-icon { flex: none; width: 56px; height: 56px; display: inline-block; }
.badge-icon svg { width: 100%; height: 100%; }
.badge-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.badge-text b { font-family: Cinzel, serif; color: var(--rust); }
.badge-text span { font-size: .82rem; color: var(--ink); }
.badge-text em { font-size: .75rem; color: var(--faded); font-style: normal; font-weight: 600; }
.badge-progress { height: 6px; border-radius: 3px; background: rgba(62,28,12,.18); overflow: hidden; margin-top: 3px; }
.badge-progress i { display: block; height: 100%; background: linear-gradient(90deg, var(--gold-hi), var(--res-plank)); }
.badge-earned { display: flex; align-items: center; gap: 8px; margin-top: 8px; padding: 6px 10px; border-radius: 10px; background: linear-gradient(135deg, rgba(255,232,163,.8), rgba(224,179,80,.5)); animation: gain .6s; }
.badge-earned .badge-icon { width: 34px; height: 34px; }
@media (max-width: 700px) { .pf-stats { grid-template-columns: repeat(2, 1fr); } }

/* ---------- rooms ---------- */
#room-list h3 { font-family: Cinzel, serif; color: var(--rust); margin: 16px 0 6px; font-size: 1rem; }
.rooms { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.rooms li { display: flex; align-items: center; gap: 8px; background: rgba(255,255,255,.18); border: 1px solid rgba(81,49,33,.4); border-radius: 8px; padding: 6px 8px; }
.rooms li > div { flex: 1; font-size: .85rem; }
.rooms li b { font-family: Cinzel, serif; letter-spacing: .08em; color: var(--rust); }
.rooms li span { color: var(--faded); }
.room-notice { margin: 12px 0 0; padding: 6px 10px; border-radius: 6px; background: rgba(138,47,29,.15); color: #8a2f1d; font-weight: 600; font-size: .85rem; }
.room-chip {
  border: 1px solid #6b4a2c; background: #2b211c; color: var(--parch-hi); border-radius: 14px;
  padding: 3px 10px; font: 600 .78rem system-ui, sans-serif; white-space: nowrap;
}
.room-chip:empty { display: none; }
.room-chip b { font-family: Cinzel, serif; letter-spacing: .08em; color: var(--gold-hi); }
.room-chip.copied::after { content: " · link copied"; color: var(--haze); }

/* ---------- Set Sail page + crew room ---------- */
#harbor, #crew { display: grid; place-items: start center; min-height: 100vh; padding: 24px; }
.harbor { width: min(1100px, 100%); padding: 18px 24px 24px; }
.harbor-head { display: flex; align-items: center; gap: 16px; margin-bottom: 12px; }
.harbor-head .logo { flex: 1; text-align: left; }
.logo.small { font-size: 2rem; }
.net-badge { font: 600 .78rem system-ui, sans-serif; padding: 4px 10px; border-radius: 12px; background: rgba(0,0,0,.1); color: var(--faded); }
.net-badge.good { background: rgba(79,138,75,.2); color: #2c5229; }
.net-badge.warn { background: rgba(224,179,80,.3); color: #6b4a12; }
.net-badge.bad { background: rgba(168,64,44,.2); color: #8a2f1d; }
.harbor-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.panel { background: rgba(255,255,255,.18); border: 2px solid rgba(81,49,33,.35); border-radius: 12px; padding: 14px 16px; }
.panel h2 { font-family: "Cinzel Decorative", serif; color: var(--rust); font-size: 1.15rem; margin: 0 0 6px; }
.panel h2 small { font: 600 .8rem system-ui, sans-serif; color: var(--faded); }
.panel h3 { font-family: Cinzel, serif; color: var(--rust); font-size: .95rem; margin: 14px 0 6px; }
.btn.wide { width: 100%; margin-top: 10px; }
.fine.left { text-align: left; }
.join-row { display: flex; gap: 8px; }
.join-row input { flex: 1; padding: 9px 10px; border: 2px solid var(--plank-ink); border-radius: 6px; background: var(--parch-hi); color: var(--ink); font: 700 1.05rem Cinzel, serif; letter-spacing: .15em; text-transform: uppercase; }
.rooms li.empty { color: var(--faded); font-style: italic; font-size: .85rem; background: none; border-style: dashed; }
.crew-card { text-align: center; }
.crew-code { font-family: Cinzel, serif; font-size: 1rem; color: var(--ink); margin: 6px 0; }
.crew-code b { font-size: 1.8rem; letter-spacing: .18em; color: var(--rust); margin: 0 6px; vertical-align: middle; }
.crew-seats { list-style: none; padding: 0; margin: 12px 0; display: grid; gap: 6px; text-align: left; }
.crew-seats li { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; background: rgba(255,255,255,.25); border: 1px solid rgba(81,49,33,.35); font-weight: 600; }
.crew-seats li.open { border-style: dashed; color: var(--faded); background: none; }
.crew-seats li.ai { color: var(--faded); }
.crew-seats small { font-weight: 400; color: var(--faded); }
.seat-no { width: 24px; height: 24px; border-radius: 50%; background: var(--ink); color: var(--parch-hi); display: grid; place-items: center; font: 700 .75rem system-ui; }
.room-notice-soft { min-height: 1.2em; color: var(--faded); font-size: .88rem; }
@media (max-width: 800px) { .harbor-grid { grid-template-columns: 1fr; } }

/* ---------- table layout ---------- */
#table {
  display: grid;
  grid-template-columns: 1fr 260px;
  grid-template-rows: auto 1fr;
  height: 100vh;
}
.topbar {
  grid-column: 1 / -1;
  display: flex; align-items: center; gap: 16px;
  padding: 8px 16px;
  background: linear-gradient(180deg, #2b211c, #1a1411);
  border-bottom: 3px solid #5a3b24;
  box-shadow: 0 2px 10px rgba(0,0,0,.5);
}
.brand { font-family: Rye, serif; color: var(--parch); font-size: 1.4rem; white-space: nowrap; }
.turn-info { flex: 1; font-family: Cinzel, serif; font-weight: 700; color: var(--parch-hi); text-align: center; }
.turn-info .you { color: var(--gold-hi); }
.controls { display: flex; align-items: center; gap: 12px; font-size: .8rem; flex-wrap: wrap; justify-content: flex-end; }
.controls select { background: #2b211c; color: var(--sand); border: 1px solid #6b4a2c; border-radius: 4px; padding: 3px; margin-left: 4px; }

.board {
  overflow: auto;
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  gap: 10px;
  padding: 12px 14px 14px;
  /* Every board (yours and the opponents') uses the same slot size, --s,
     which the client fits to the window. Deck, pile and played card follow it. */
  --card-w: calc(var(--s, 92px) * 1.1);
  --card-h: calc(var(--card-w) * 1.364);
}
.board .slot { --slot-w: var(--s, 92px); --slot-h: calc(var(--slot-w) * 1.364); }
.opponents { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
.opponents .mat { min-width: 0; }
.mat { min-width: 0; }
.opponents .mat-head { margin-bottom: 4px; }

/* ---------- mats ---------- */
.mat {
  position: relative;
  padding: 8px 10px 10px;
  min-width: 360px;
  transition: box-shadow .3s, transform .3s;
}
.mat.active { box-shadow: 0 0 0 4px var(--gold-hi), 0 0 30px rgba(224,179,80,.55), 0 14px 40px rgba(0,0,0,.6); }
.mat-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; font-family: Cinzel, serif; font-weight: 700; }
.mat-name { font-size: 1rem; color: var(--rust); }
.mat-meta { margin-left: auto; display: flex; gap: 10px; align-items: center; font-size: .78rem; color: var(--faded); font-family: system-ui, sans-serif; font-weight: 600; }
.mat.targetable-pirate { cursor: pointer; animation: pulse 1.2s infinite; }
.type-pips { display: inline-flex; gap: 3px; }
.pip { width: 10px; height: 10px; border-radius: 50%; border: 1.5px solid var(--plank-ink); background: transparent; }
.pip.on { background: var(--good); border-color: #2c5229; }

.stacks { display: flex; gap: 6px; }
.slot {
  position: relative;
  width: var(--slot-w); height: var(--slot-h);
  border: 2px dashed rgba(81,49,33,.55);
  border-radius: 6px;
  display: grid; place-items: center;
  font-family: Cinzel, serif; font-size: .62rem; font-weight: 700; text-align: center;
  color: rgba(81,49,33,.7);
  background: rgba(255,255,255,.08);
  padding: 0;
}
.slot.filled { border: 0; background: none; }
.slot img { width: 100%; height: 100%; object-fit: cover; border-radius: 5px; box-shadow: 0 2px 5px rgba(0,0,0,.45); }
/* Layered copies: each copy below the top peeks out up and to the right. */
.slot.filled { --off: calc(var(--slot-w) * .045); }
.slot.filled img.layer {
  position: absolute;
  width: calc(100% - (var(--n) - 1) * var(--off));
  height: calc(100% - (var(--n) - 1) * var(--off));
  left: calc((var(--n) - 1 - var(--i)) * var(--off));
  top: calc(var(--i) * var(--off));
  box-shadow: 0 1px 4px rgba(0,0,0,.5);
}
.slot.filled img.layer:not(.top) { filter: brightness(.78) saturate(.9); }
.slot.filled img.layer.top { box-shadow: 0 2px 6px rgba(0,0,0,.55); }
.slot .badge { z-index: 2; }
.badge {
  position: absolute; right: -6px; top: -6px;
  min-width: 24px; height: 24px; padding: 0 5px;
  border-radius: 12px; background: var(--ink); color: var(--parch-hi);
  font: 700 .8rem/20px system-ui, sans-serif; text-align: center;
  border: 2px solid var(--parch-hi);
}
.slot.targetable { cursor: crosshair; outline: 3px solid #ff6a3d; outline-offset: 2px; animation: pulse 1s infinite; }
.slot.targetable.rig { outline-color: #6fd0ff; cursor: pointer; }
.slot.hit { animation: hit .5s; }

/* Medallion */
.medallion {
  width: 30px; height: 30px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #ffe8a3, var(--gold-hi) 40%, var(--gold) 75%, #5b3f17);
  border: 2px solid var(--ink);
  display: grid; place-items: center;
  font: 900 .7rem Rye, serif; color: var(--ink);
  box-shadow: 0 0 12px rgba(255,210,100,.8);
  animation: shine 2s infinite;
}
.medallion.lost { animation: lose 1.4s forwards; }
.medallion.gained { animation: gain .9s; }

/* Opponent hand (backs) */
.mini-hand { display: inline-flex; align-items: center; }
.mini-back {
  width: 14px; height: 19px; border-radius: 2px; margin-left: -7px;
  background: var(--card-back-img, var(--parch)) center / cover no-repeat;
  border: 1px solid var(--plank-ink);
}
.mini-back:first-child { margin-left: 0; }
.reveal-hand { display: flex; gap: 3px; flex-wrap: wrap; margin-top: 6px; }
.reveal-hand img { width: 30px; height: 41px; border-radius: 2px; }

/* ---------- center ---------- */
.center {
  /* Deck and pile sit dead center; the card being played is on the left,
     the prompt on the right. The row hugs its content (vertically centered
     between the boards) so the drop box stays compact. */
  align-self: center;
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 28px;
  padding: 8px 12px;
}
.center-main { display: contents; }
.pile-zone { display: flex; gap: 18px; align-items: flex-end; grid-column: 2; grid-row: 1; position: relative; }
/* Removed-from-game sits off to the side so the deck and pile stay centered. */
.pile-zone .small-zone { position: absolute; left: 100%; bottom: 0; margin-left: 18px; }
.center-main .inflight { grid-column: 1; grid-row: 1; justify-self: end; flex-direction: row-reverse; text-align: right; }
.center-main .prompt { grid-column: 3; grid-row: 1; justify-self: start; justify-content: flex-start; text-align: left; max-width: 380px; }
.inflight .chain { justify-content: flex-end; }
.zone { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.zone-label { font-family: Cinzel, serif; font-size: .75rem; color: var(--parch-hi); white-space: nowrap; }
.card-back {
  /* Card-back art (assets/cards/back.jpg), set as --card-back-img by js/ui.js. */
  width: var(--card-w); height: var(--card-h); border-radius: 8px;
  background: var(--card-back-img, var(--parch)) center / cover no-repeat;
  box-shadow: 0 3px 8px rgba(0,0,0,.5);
}
.card-back.stacked { box-shadow: 3px 3px 0 #2e1c0f, 6px 6px 0 #1f130a, 0 6px 12px rgba(0,0,0,.6); }
.card-back.empty { opacity: .25; }
.pile-slot {
  width: var(--card-w); height: var(--card-h); border-radius: 7px; padding: 0;
  border: 2px dashed rgba(228,198,142,.4); background: rgba(0,0,0,.2);
  color: var(--parch-hi); font-size: .7rem;
}
.pile-slot img { width: 100%; height: 100%; border-radius: 6px; object-fit: cover; filter: sepia(.35) brightness(.85); }
.removed-slot { width: calc(var(--card-w) * .5); height: calc(var(--card-h) * .5); border-radius: 4px; border: 1.5px dashed rgba(228,198,142,.35); display: grid; place-items: center; }
.removed-slot img { width: 100%; height: 100%; border-radius: 4px; opacity: .55; }

.inflight { min-height: calc(var(--card-h) + 8px); display: flex; align-items: center; gap: 14px; }
.inflight .played {
  width: var(--card-w); height: var(--card-h); border-radius: 7px; object-fit: cover;
  box-shadow: 0 0 0 3px var(--gold-hi), 0 8px 24px rgba(0,0,0,.6);
  animation: drop .35s ease-out;
}
.inflight .played.cancelled { filter: grayscale(.8) brightness(.7); box-shadow: 0 0 0 3px #888, 0 8px 24px rgba(0,0,0,.6); }
.inflight .caption { font-family: Cinzel, serif; font-weight: 700; color: var(--parch-hi); max-width: 190px; }
.inflight .caption small { display: block; font-family: system-ui, sans-serif; font-weight: 400; color: var(--haze); margin-top: 4px; }
.react-window { margin-top: 8px; }
.react-window span { display: block; font: 600 .72rem system-ui, sans-serif; color: var(--haze); letter-spacing: .04em; text-transform: uppercase; }
.react-window i { display: block; height: 5px; margin-top: 4px; border-radius: 3px; background: linear-gradient(90deg, var(--gold-hi), var(--res-plank)); transform-origin: right; animation: react-drain linear forwards; }
@keyframes react-drain { from { transform: scaleX(1); } to { transform: scaleX(0); } }
.chain { display: flex; gap: 4px; margin-top: 6px; }
.chain span { background: #2d596c; color: #fff; font-size: .7rem; padding: 2px 6px; border-radius: 10px; }
.prompt {
  min-height: 44px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: center;
  font-family: Cinzel, serif; font-weight: 700; color: var(--gold-hi); text-align: center;
}
.prompt .hint { font-family: system-ui, sans-serif; font-weight: 400; color: var(--haze); font-size: .85rem; }

/* ---------- me + hand ---------- */
.me { display: flex; justify-content: center; }
.me .mat { min-width: 0; }
.hand {
  display: flex; justify-content: center; gap: 8px; flex-wrap: wrap;
  padding: 10px; min-height: calc(var(--hand-h) + 24px);
  background: linear-gradient(180deg, rgba(70,62,65,.55), rgba(40,30,26,.75));
  border-top: 3px solid #5a3b24; border-radius: 12px;
}
.hand .empty-hand { align-self: center; color: var(--haze); font-style: italic; }
.hcard {
  position: relative;
  width: var(--hand-w); height: var(--hand-h); padding: 0; border: 0; background: none;
  border-radius: 8px; transition: transform .15s, box-shadow .15s;
}
.hcard img { width: 100%; height: 100%; border-radius: 8px; object-fit: cover; box-shadow: 0 4px 10px rgba(0,0,0,.55); }
.hand.can-play .hcard:hover { transform: translateY(-10px); }
.hand.can-play .hcard { cursor: pointer; }
.hcard.selected { transform: translateY(-16px); box-shadow: 0 0 0 4px var(--gold-hi), 0 0 24px rgba(224,179,80,.8); }
.hand:not(.can-play) .hcard { filter: saturate(.8); cursor: default; }
.hcard img { -webkit-user-drag: none; pointer-events: none; }
.hand.can-play .hcard { touch-action: none; cursor: grab; }
.hcard.dragging { opacity: .25; transform: none !important; }
.drag-ghost {
  position: fixed; left: 0; top: 0; z-index: 60; pointer-events: none;
  transition: none !important; opacity: .95;
}
.drag-ghost img { box-shadow: 0 18px 40px rgba(0,0,0,.7); }
.drag-ghost.over img { box-shadow: 0 0 0 4px var(--gold-hi), 0 0 30px rgba(224,179,80,.9), 0 18px 40px rgba(0,0,0,.7); }
body.is-dragging { cursor: grabbing; }
body.is-dragging .center { position: relative; outline: 3px dashed rgba(224,179,80,.45); outline-offset: 6px; border-radius: 14px; transition: background .15s, outline-color .15s; }
body.drop-over .center { outline-color: var(--gold-hi); background: rgba(224,179,80,.12); }
body.is-dragging .center::after {
  content: "Drop here to play"; position: absolute; top: -4px; left: 50%; transform: translate(-50%, -100%);
  font: 700 .8rem Cinzel, serif; color: var(--gold-hi); background: rgba(9,23,43,.85);
  padding: 3px 10px; border-radius: 10px; white-space: nowrap;
}
body.drop-over .center::after { content: "Release to play"; }
.hcard .new { position: absolute; left: 6px; top: 6px; background: var(--gold-hi); color: var(--ink); font: 700 .6rem system-ui; padding: 1px 5px; border-radius: 6px; }

/* ---------- log ---------- */
.log-panel {
  display: flex; flex-direction: column; min-height: 0;
  background: linear-gradient(180deg, #221a16, #15100d);
  border-left: 3px solid #5a3b24;
}
.log-head { display: flex; justify-content: space-between; align-items: center; padding: 10px 12px; font-family: Cinzel, serif; font-weight: 700; color: var(--parch); border-bottom: 1px solid #3a2a1f; }
.log { list-style: none; margin: 0; padding: 8px 12px 30px; overflow-y: auto; flex: 1; font-size: .82rem; line-height: 1.35; }
.log li { padding: 3px 0; color: #d9c7a5; border-bottom: 1px dotted rgba(144,176,181,.12); }
.log li.turn { color: var(--gold-hi); font-family: Cinzel, serif; font-weight: 700; margin-top: 6px; border: 0; }
.log li.play { color: #f1dfbd; }
.log li.react { color: #8fd0ff; }
.log li.cancel { color: #b9c7cc; font-style: italic; }
.log li.destroy { color: #ff9b7a; }
.log li.discard { color: #f0b98a; }
.log li.medal { color: #ffd76a; font-weight: 700; }
.log li.medal-lost { color: #ff8a6a; font-weight: 700; }
.log li.dig { color: #ffd98a; }

/* ---------- Treasure Map dig ---------- */
.center { position: relative; }
/* Sits beside the Buried Treasure Pile (desktop) or just above the center row (phones), never over the pile. */
.dig-toast { position: absolute; grid-column: 3; grid-row: 1; left: 4px; top: 50%; transform: translateY(-50%); z-index: 40; display: flex; align-items: center; gap: 12px;
  padding: 10px 16px 10px 10px; border-radius: 14px; border: 2px solid var(--gold); color: var(--ink); width: max-content;
  background: linear-gradient(135deg, rgba(255,240,196,.97), rgba(233,206,140,.97)); box-shadow: 0 10px 30px rgba(0,0,0,.45), 0 0 18px rgba(224,179,80,.55);
  animation: dig-in .35s ease-out; pointer-events: none; max-width: 400px; transition: opacity .35s; }
.dig-toast img { width: 54px; border-radius: 6px; box-shadow: 0 3px 8px rgba(0,0,0,.45); flex: none; }
.dig-toast div { display: flex; flex-direction: column; gap: 1px; line-height: 1.2; }
.dig-toast small { font: 700 .68rem system-ui, sans-serif; letter-spacing: .08em; text-transform: uppercase; color: var(--rust); }
.dig-toast b { font-family: Cinzel, serif; font-size: 1.05rem; }
.dig-toast span { font-size: .82rem; color: var(--faded); }
.dig-toast.out { opacity: 0; }
@keyframes dig-in { from { opacity: 0; scale: .9; } }
.card-flyer { position: fixed; z-index: 60; border-radius: 8px; pointer-events: none; object-fit: cover;
  box-shadow: 0 0 0 3px var(--gold-hi), 0 12px 28px rgba(0,0,0,.55); transform-origin: center; }
.card-flyer.fly-destroy { box-shadow: 0 0 0 3px #e0573a, 0 0 22px rgba(255,110,60,.9), 0 12px 28px rgba(0,0,0,.55); }
.card-flyer.fly-discard { box-shadow: 0 0 0 3px #f0b98a, 0 12px 28px rgba(0,0,0,.55); }
.land-flash { animation: dug-flash 1.2s ease-out; }
.hcard.arriving { visibility: hidden; }
.hcard.dug img { box-shadow: 0 0 0 3px var(--gold-hi), 0 0 22px rgba(255,215,110,.95); animation: shine 1.2s ease-in-out 2; }
.dug-line { margin-top: 4px; font-size: .85rem; color: var(--gold-hi); }
.mat-head.land-flash { border-radius: 8px; }
@keyframes dug-flash { 0% { box-shadow: 0 0 0 3px var(--gold-hi), 0 0 22px rgba(255,215,110,.95); } 100% { box-shadow: 0 0 0 0 rgba(255,215,110,0); } }
body.mobile .dig-toast { grid-column: 1 / -1; left: 50%; top: auto; bottom: calc(100% + 2px); transform: translateX(-50%); padding: 6px 12px 6px 6px; gap: 8px; max-width: 94%; }
body.mobile .dig-toast img { width: 40px; }
body.mobile .dig-toast b { font-size: .9rem; }
.log li.win { color: #fff; background: rgba(224,179,80,.25); padding: 6px; border-radius: 6px; font-weight: 700; }
.log li.system { color: var(--haze); font-style: italic; }

/* ---------- preview ---------- */
.preview {
  position: fixed; z-index: 50; pointer-events: none;
  width: 250px;
  background: #1b1310; border: 2px solid var(--gold); border-radius: 12px; padding: 8px;
  box-shadow: 0 10px 40px rgba(0,0,0,.7);
}
.preview img { width: 100%; border-radius: 8px; display: block; }
.preview h4 { margin: 8px 2px 2px; font-family: "Cinzel Decorative", serif; color: var(--parch-hi); }
.preview p { margin: 2px; font-size: .82rem; color: var(--sand); }

/* ---------- modal ---------- */
.modal-back {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(5, 10, 20, .7);
  display: grid; place-items: center; padding: 20px;
  animation: fade .2s;
}
.modal { width: min(640px, 100%); max-height: 90vh; overflow: auto; padding: 20px 22px; }
.modal h2 { font-family: "Cinzel Decorative", serif; color: var(--rust); margin: 0 0 8px; }
.modal h3 { font-family: Cinzel, serif; color: var(--rust); margin: 16px 0 6px; }
.modal p, .modal li { color: var(--ink); line-height: 1.45; }
.modal .actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: flex-end; margin-top: 16px; }
.modal .choices { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; margin-top: 10px; }
.modal .choice-card { padding: 0; border: 0; background: none; width: 110px; border-radius: 8px; transition: transform .15s; }
.modal .choice-card:hover { transform: translateY(-6px) scale(1.03); }
.modal .choice-card img { width: 100%; border-radius: 8px; box-shadow: 0 4px 10px rgba(0,0,0,.45); }
.modal .choice-card .cnt { display: block; font: 700 .8rem Cinzel, serif; color: var(--ink); margin-top: 3px; }
.pirate-choice { min-width: 150px; text-align: left; }
.pirate-choice small { display: block; font-family: system-ui; font-weight: 500; font-size: .72rem; }
.rules-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.rules-cards figure { margin: 0; text-align: center; font-size: .75rem; color: var(--ink); }
.rules-cards img { width: 100%; border-radius: 8px; }
.winner-banner { font-family: Rye, serif; font-size: 2rem; color: var(--rust); text-align: center; margin: 6px 0; }
.score-table { width: 100%; border-collapse: collapse; margin-top: 10px; color: var(--ink); }
.score-table td, .score-table th { border-bottom: 1px solid rgba(62,28,12,.3); padding: 5px; text-align: left; }

/* ---------- animations ---------- */
@keyframes pulse { 0%,100% { filter: brightness(1); } 50% { filter: brightness(1.25); } }
@keyframes shine { 0%,100% { box-shadow: 0 0 10px rgba(255,210,100,.6); } 50% { box-shadow: 0 0 20px rgba(255,220,120,1); } }
@keyframes lose { 0% { transform: scale(1); opacity: 1; } 30% { transform: scale(1.3) rotate(-15deg); } 100% { transform: translateY(30px) scale(.3) rotate(120deg); opacity: 0; } }
@keyframes gain { 0% { transform: scale(0) rotate(-180deg); } 70% { transform: scale(1.3); } 100% { transform: scale(1); } }
@keyframes drop { from { transform: translateY(-30px) scale(1.15); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes hit { 0%,100% { transform: none; } 25% { transform: translateX(-4px) rotate(-3deg); } 75% { transform: translateX(4px) rotate(3deg); } }
@keyframes fade { from { opacity: 0; } }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .center { grid-template-columns: 1fr; justify-items: center; gap: 8px; }
  .pile-zone, .center-main .inflight, .center-main .prompt { grid-column: 1; grid-row: auto; justify-self: center; justify-content: center; text-align: center; }
  #table { grid-template-columns: 1fr; grid-template-rows: auto 1fr 180px; height: auto; min-height: 100vh; }
  .log-panel { border-left: 0; border-top: 3px solid #5a3b24; max-height: 220px; }
  .board { overflow: visible; }
}
}

/* ======================================================================
   Phones (body.mobile, set by js/ui.js for windows 700px wide or less).
   The table fills the screen with no scrolling; sizes come from fitBoard().
   ====================================================================== */
.mobile-only { display: none !important; }
body.mobile .mobile-only { display: inline-flex !important; }
body.mobile #table {
  display: flex; flex-direction: column;
  height: 100vh; height: 100dvh; min-height: 0; overflow: hidden;
}
body.mobile .topbar { flex-wrap: nowrap; gap: 6px; padding: 4px 6px; padding-top: calc(4px + env(safe-area-inset-top)); position: relative; }
body.mobile .brand, body.mobile .room-chip { display: none; }
body.mobile .turn-info { flex: 1; min-width: 0; font-size: .72rem; text-align: left; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
body.mobile .topbar .btn.small { padding: 4px 8px; font-size: .72rem; }
/* Settings live in a menu on phones. */
body.mobile .controls { display: none; position: absolute; right: 6px; top: 100%; z-index: 30; flex-direction: column; align-items: stretch;
  background: #1f1713; border: 2px solid #5a3b24; border-radius: 10px; padding: 10px; gap: 8px; box-shadow: 0 10px 30px rgba(0,0,0,.6); }
body.mobile.menu-open .controls { display: flex; }
body.mobile .controls label:not(.check) { display: flex; justify-content: space-between; gap: 8px; }

body.mobile .board {
  flex: 1; min-height: 0; overflow: hidden;
  display: flex; flex-direction: column; gap: 5px; padding: 5px 6px calc(5px + env(safe-area-inset-bottom));
}
body.mobile .opponents { flex-direction: column; flex-wrap: nowrap; gap: 5px; align-items: center; }
body.mobile .mat { padding: 4px 6px 6px; border-width: 2px; box-shadow: 0 0 0 3px #6b4a2c, 0 6px 16px rgba(0,0,0,.5), inset 0 0 30px rgba(95,46,7,.3); }
body.mobile .mat.active { box-shadow: 0 0 0 3px var(--gold-hi), 0 0 18px rgba(224,179,80,.6); }
body.mobile .mat-head { margin-bottom: 3px; gap: 6px; }
body.mobile .mat-name { font-size: .78rem; }
body.mobile .mat-meta { gap: 6px; font-size: .68rem; }
body.mobile .mini-hand { display: none; }
.mobile-word { display: none; }
body.mobile .mobile-word { display: inline; }
body.mobile .pip { width: 8px; height: 8px; }
body.mobile .medallion { width: 20px; height: 20px; font-size: .5rem; }
body.mobile .stacks { gap: 4px; }
body.mobile .slot { font-size: .5rem; border-radius: 4px; }
body.mobile .slot img { border-radius: 3px; }
body.mobile .badge { min-width: 18px; height: 18px; font-size: .65rem; line-height: 14px; right: -4px; top: -4px; padding: 0 3px; }

body.mobile .opponents, body.mobile .me, body.mobile .hand { flex-shrink: 0; }
body.mobile .center { flex: 1 0 auto; align-self: stretch; gap: 8px; padding: 2px 4px; grid-template-columns: 1fr auto 1fr; justify-items: stretch; }
body.mobile .pile-zone { grid-column: 2; grid-row: 1; gap: 8px; justify-self: center; }
body.mobile .pile-zone .small-zone { display: none; }
body.mobile .zone-label { font-size: .6rem; }
body.mobile .center-main .inflight { grid-column: 1; grid-row: 1; justify-self: end; min-height: 0; gap: 6px; text-align: right; }
body.mobile .center-main .prompt { grid-column: 3; grid-row: 1; justify-self: start; justify-content: flex-start; text-align: left; font-size: .72rem; gap: 4px; min-height: 0; }
body.mobile .prompt .hint { display: none; }
body.mobile .prompt .btn { padding: 5px 9px; font-size: .75rem; }
body.mobile .inflight .caption { font-size: .6rem; max-width: 74px; }
body.mobile .inflight .caption small { font-size: .58rem; }
body.mobile .chain span { font-size: .55rem; padding: 1px 4px; }
body.mobile .react-window span { font-size: .52rem; }
body.mobile.is-dragging .center::after { font-size: .65rem; }

body.mobile .me { flex: none; }
body.mobile .hand {
  flex: none; flex-wrap: nowrap; justify-content: center; gap: 0;
  min-height: 0; padding: 6px 4px; border-radius: 10px; overflow: visible;
}
body.mobile .hcard { width: var(--hand-w); height: var(--hand-h); flex: none; }
body.mobile .hcard + .hcard { margin-left: calc(var(--hand-step, var(--hand-w)) - var(--hand-w)); }
body.mobile .hcard img { border-radius: 6px; }
body.mobile .hand.can-play .hcard:hover { transform: none; }
body.mobile .hcard.selected { transform: translateY(-12px); z-index: 2; }
body.mobile .hcard .new { font-size: .5rem; }

/* Ship's Log: a drawer on phones, opened with the Log button. */
body.mobile .log-panel {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(86vw, 340px); z-index: 35;
  max-height: none; border-top: 0; border-left: 3px solid #5a3b24;
  transform: translateX(105%); transition: transform .22s ease; box-shadow: -10px 0 30px rgba(0,0,0,.6);
  padding-top: env(safe-area-inset-top);
}
body.mobile.log-open .log-panel { transform: none; }
body.mobile .log-close { display: inline-flex !important; }
.log-close { display: none !important; }

/* Full screen: no header; small floating buttons on the right edge. */
.fs-float { display: none; }
body.mobile.fs-mode .topbar { display: none; }
body.mobile.fs-mode .fs-float {
  display: flex; flex-direction: column; gap: 6px; position: fixed; right: 4px; top: 42%; z-index: 32;
}
.fs-float button {
  width: 34px; height: 34px; border-radius: 50%; border: 2px solid var(--ink); padding: 0;
  background: rgba(210,131,70,.85); color: #2a1206; font: 700 .72rem Cinzel, serif; box-shadow: 0 2px 6px rgba(0,0,0,.5);
}
body.mobile.fs-mode .board { padding-top: calc(5px + env(safe-area-inset-top)); }

/* Phones held sideways: ask to turn upright (the table is laid out for portrait). */
.rotate-hint { display: none; }
@media (pointer: coarse) and (orientation: landscape) and (max-height: 500px) {
  body.in-game .rotate-hint {
    display: grid; place-items: center; position: fixed; inset: 0; z-index: 60; background: var(--night); color: var(--parch-hi);
    font: 700 1.1rem Cinzel, serif; text-align: center; padding: 24px;
  }
}

/* Set Sail page on narrow phones: stack each label above its control. */
@media (max-width: 480px) {
  #harbor, #crew { padding: 10px; }
  .harbor { padding: 12px; }
  .harbor .field { flex-direction: column; align-items: flex-start; gap: 6px; }
  .harbor .field input[type=text] { max-width: none; width: 100%; }
  .harbor-head { flex-wrap: wrap; gap: 8px; }
  .net-badge { flex-basis: 100%; }
}
body.mobile .dug-line { font-size: .55rem; margin-top: 2px; }

/* ---------- spectating ---------- */
.spectate-note { font-style: italic; }
body.spectating .controls label:has(#react-select), body.spectating .controls label:has(#reveal-toggle) { display: none; }

/* ---------- tutorial ---------- */
.tutorial-panel { grid-column: 1 / -1; display: flex; flex-wrap: wrap; align-items: center; gap: 6px 18px; }
.tutorial-panel h2 { flex-basis: 100%; }
.tutorial-panel p { flex: 1 1 320px; margin: 0; }
.tutorial-panel .btn { flex: 0 0 auto; width: auto; padding-inline: 26px; }
.coach { margin: 10px 10px 4px; padding: 12px 14px; border-radius: 14px; border: 2px solid var(--gold); color: var(--ink); flex: none;
  background: linear-gradient(135deg, rgba(255,243,206,.98), rgba(236,210,150,.98)); box-shadow: 0 8px 22px rgba(0,0,0,.45); animation: fade .3s; }
.coach::after { content: ''; display: block; clear: both; }
.coach-head { display: flex; flex-direction: column; margin-bottom: 6px; }
.coach-head span { font: 700 .66rem system-ui, sans-serif; letter-spacing: .08em; text-transform: uppercase; color: var(--rust); }
.coach-head b { font-family: Cinzel, serif; font-size: 1.1rem; }
.coach-text { font-size: .9rem; line-height: 1.4; }
.coach-warn { margin-top: 8px; padding: 6px 9px; border-radius: 8px; background: rgba(168,64,44,.15); color: #7a2a17; font-size: .85rem; }
.coach-warn.shake { animation: hit .35s; }
.coach .btn { margin-top: 10px; float: right; }
.hcard.tut-glow img { box-shadow: 0 0 0 4px #7fd3ff, 0 0 26px rgba(127,211,255,.95); animation: pulse 1.2s ease-in-out infinite; }
/* During the tutorial the log column stays visible, since the coach lives at its top. */
body.tutorial-on.log-hidden #table { grid-template-columns: 1fr 260px; }
body.tutorial-on.log-hidden .log-panel { display: flex; }
@media (max-width: 1100px) { body.tutorial-on .log-panel { max-height: none; } body.tutorial-on.log-hidden #table { grid-template-columns: 1fr; } }
body.mobile .coach { position: fixed; left: 6px; right: 6px; bottom: calc(var(--hand-h, 110px) + 26px); z-index: 55; margin: 0; padding: 8px 10px; }
body.mobile .coach-text { font-size: .78rem; }
body.mobile .coach-head b { font-size: .95rem; }
.coach { position: relative; z-index: 45; } /* stays bright beside an open choice window */
body.mobile .modal .coach { position: static; margin: 4px 0 12px; box-shadow: none; }
