:root {
  --bg: #0d0b14;
  --panel: #1a1626;
  --panel2: #241d36;
  --ink: #ece7f5;
  --muted: #9a90b4;
  --gold: #d9b45b;
  --gold2: #f0d488;
  --danger: #e0524a;
  --good: #57c98a;
  --line: #362b4f;
  --accent: #7b5cff;
  --radius: 14px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(120% 100% at 50% 0%, #191430 0%, var(--bg) 60%);
  color: var(--ink);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  overscroll-behavior: none;
}
.screen { min-height: 100dvh; display: flex; flex-direction: column; }
.hidden { display: none !important; }

/* ---------- Lobby ---------- */
#lobby { align-items: center; justify-content: center; text-align: center; padding: 24px; }
.brand {
  font-size: clamp(38px, 12vw, 72px); letter-spacing: .18em; margin: 0;
  color: var(--gold);
  text-shadow: 0 2px 0 #000, 0 0 24px rgba(217,180,91,.35);
  font-weight: 800;
}
.tag { color: var(--muted); letter-spacing: .32em; text-transform: uppercase; font-size: 12px; margin: 6px 0 28px; }
.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px; width: min(420px, 92vw); text-align: left;
}
.panel label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; text-transform: uppercase; letter-spacing: .1em; }
input {
  width: 100%; padding: 13px 14px; background: var(--panel2); border: 1px solid var(--line);
  border-radius: 10px; color: var(--ink); font-size: 16px; outline: none;
}
input:focus { border-color: var(--accent); }
.row { display: flex; gap: 10px; margin-top: 14px; }
.row input { flex: 1; }
.or { text-align: center; color: var(--muted); margin: 16px 0 4px; font-size: 12px; letter-spacing: .1em; }
.code-input { text-transform: uppercase; letter-spacing: .3em; text-align: center; font-weight: 700; }

button {
  padding: 13px 18px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--panel2); color: var(--ink); font-size: 15px; font-weight: 600;
  cursor: pointer; transition: transform .05s ease, filter .15s ease;
}
button:active { transform: translateY(1px); }
button:disabled { opacity: .4; cursor: not-allowed; }
button.primary { background: linear-gradient(180deg, var(--gold2), var(--gold)); color: #2a1e00; border: none; }
button.ghost { background: transparent; }
.error { color: var(--danger); min-height: 18px; font-size: 13px; margin: 12px 0 0; }

/* ---------- Room ---------- */
#room { align-items: center; text-align: center; padding: 40px 20px; }
.code { color: var(--gold); letter-spacing: .3em; font-weight: 800; }
.hint { color: var(--muted); font-size: 13px; }
.seats { list-style: none; padding: 0; width: min(420px, 92vw); margin: 20px 0; }
.seats li {
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 12px 16px; margin-bottom: 8px; display: flex; justify-content: space-between; align-items: center;
}
.seats .host-badge { font-size: 11px; color: var(--gold); border: 1px solid var(--gold); border-radius: 20px; padding: 2px 8px; }

/* ---------- Game ---------- */
#game { padding: 0; }
#topbar {
  position: sticky; top: 0; z-index: 20; display: flex; justify-content: space-between; align-items: center;
  padding: 10px 14px; background: rgba(13,11,20,.9); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line);
}
.turn { font-size: 14px; font-weight: 700; }
.turn .yours { color: var(--gold); }
.me { display: flex; gap: 12px; font-weight: 700; }
.power { color: var(--gold2); }

.opponents { display: flex; gap: 8px; overflow-x: auto; padding: 8px 12px; }
.opp {
  flex: 0 0 auto; background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 6px 10px; font-size: 12px; min-width: 92px;
}
.opp.active { border-color: var(--gold); box-shadow: 0 0 0 1px var(--gold); }
.opp .n { font-weight: 700; display: block; }
.opp .s { color: var(--muted); }

.board { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(150px, 1fr); gap: 8px; padding: 10px 12px 4px; overflow-x: auto; flex: 1; }
@media (max-width: 720px) { .board { grid-auto-columns: 78vw; } }
.board.has-art { background-size: 100% 100%; background-repeat: no-repeat; }
.board.has-art .loc { background: rgba(18,14,30,.68); }
/* per-location art: the pic is its own layer; hotspots/cards/lock overlay it */
.loc.has-loc-art {
  align-self: start; min-height: 0; padding: 0; overflow: visible; border: none; background: transparent;
  display: flex; flex-direction: column;
}
.loc.has-loc-art.locked { opacity: 1; } /* greyscale (below) conveys locked, not fade */
.loc-frame { position: relative; width: 100%; aspect-ratio: 952 / 1244; overflow: hidden; border-radius: var(--radius); border: 1px solid var(--line); background: var(--panel2); }
.loc-bg { position: absolute; inset: 0; z-index: 0; background-size: 100% 100%; background-position: center; background-repeat: no-repeat; }
.loc-bg.grey { filter: grayscale(100%) contrast(0.9) brightness(0.85); }
.loc-lock { position: absolute; inset: 0; z-index: 1; display: flex; align-items: center; justify-content: center; }
.lock-img { width: 40%; max-width: 120px; opacity: 0.95; filter: drop-shadow(0 2px 8px rgba(0,0,0,.7)); }
.lock-emoji { font-size: 46px; filter: drop-shadow(0 2px 6px #000); }
.hotspot { position: absolute; z-index: 2; border-radius: 50%; }
.hotspot.active { cursor: pointer; box-shadow: 0 0 0 3px var(--gold2), 0 0 18px 5px rgba(240,212,136,.55); animation: hs-pulse 1.5s ease-in-out infinite; }
.hotspot.covered { box-shadow: inset 0 0 0 100px rgba(5,4,10,.5); }
@keyframes hs-pulse { 0%,100% { opacity: .55; } 50% { opacity: 1; } }
.loc-grants-art { position: absolute; z-index: 2; left: 4%; right: 4%; bottom: 1.5%; margin: 0; }

/* played-card artwork on locations. Zone % are first-pass — easy to nudge. */
.loc-heroes-art { position: absolute; z-index: 4; left: 0; right: 0; top: 1%; height: 42%; display: flex; gap: 2%; justify-content: center; }
.loc-heroes-art .played-art { flex: 0 1 auto; height: 100%; aspect-ratio: 952 / 1244; max-width: 96%; }
/* Allies/Items hang below the board; only the top ~8% of the card overlaps onto it.
   margin-top ≈ -(8% of card height); card height = 85% width × 1244/952 ≈ 111% of loc width. */
.loc-plays-strip { position: relative; z-index: 6; display: flex; flex-wrap: wrap; gap: 4px; justify-content: center; margin-top: -8.9%; }
.loc-plays-strip .played-art { flex: 0 0 auto; width: 85%; aspect-ratio: 952 / 1244; }
.played-art { position: relative; background-size: cover; background-position: center; background-repeat: no-repeat; border-radius: 6px; box-shadow: 0 2px 7px rgba(0,0,0,.55); cursor: pointer; }
.played-art.selectable { outline: 2px solid var(--gold); outline-offset: 1px; }
.played-art.no-art { background: var(--panel2); display: flex; align-items: center; justify-content: center; text-align: center; font-size: 9px; padding: 3px; color: var(--ink); }
.card-grant { position: absolute; z-index: 3; border-radius: 50%; }
.card-grant.active { cursor: pointer; box-shadow: 0 0 0 3px var(--gold2), 0 0 16px 5px rgba(240,212,136,.6); animation: hs-pulse 1.5s ease-in-out infinite; }
.pa-str { position: absolute; bottom: 2px; right: 3px; background: var(--gold); color: #2a1e00; font-weight: 800; font-size: 10px; min-width: 15px; height: 15px; border-radius: 8px; display: flex; align-items: center; justify-content: center; padding: 0 3px; }
.pa-att { position: absolute; top: 2px; right: 3px; background: rgba(0,0,0,.7); color: var(--gold2); font-size: 9px; padding: 1px 4px; border-radius: 6px; }

/* your playing piece, centered on the location you occupy */
.pawn-piece { position: absolute; z-index: 5; left: 50%; top: 49%; transform: translate(-50%, -50%); width: 39%; pointer-events: none; }
.pawn-piece img { width: 100%; display: block; filter: drop-shadow(0 3px 7px rgba(0,0,0,.75)); }
.pawn-piece.fallback { font-size: 34px; text-align: center; filter: drop-shadow(0 2px 4px #000); }

.loc {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  display: flex; flex-direction: column; min-height: 300px; position: relative; overflow: hidden;
}
.loc.locked { opacity: .55; }
.loc.movable { outline: 2px dashed var(--accent); outline-offset: -2px; cursor: pointer; }
.loc.here .loc-name::after { content: " ⚓"; }
.loc-name { padding: 10px; font-weight: 700; text-align: center; border-bottom: 1px solid var(--line); font-size: 14px; }
.loc-name .lock { font-size: 11px; color: var(--muted); display: block; font-weight: 400; }

.actions-row { display: flex; gap: 4px; padding: 6px; flex-wrap: wrap; justify-content: center; }
.actions-row.bottom { margin-top: auto; border-top: 1px dashed var(--line); }
.act {
  font-size: 11px; padding: 6px 8px; border-radius: 8px; background: var(--panel2);
  border: 1px solid var(--line); display: flex; align-items: center; gap: 4px; white-space: nowrap;
}
.act-ico { width: 16px; height: 16px; object-fit: contain; vertical-align: middle; display: inline-block; }
.act.granted { border-color: var(--gold); }
.act.available { background: var(--accent); color: #fff; border-color: var(--accent); cursor: pointer; font-weight: 700; }
.act.blocked { opacity: .4; }

.cards-area { padding: 6px; display: flex; flex-direction: column; gap: 6px; min-height: 60px; }
.played {
  background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px;
  font-size: 12px; display: flex; justify-content: space-between; align-items: center; cursor: pointer;
}
.played.hero { border-left: 3px solid var(--danger); }
.played.ally { border-left: 3px solid var(--good); }
.played.item { border-left: 3px solid var(--gold); }
.played.selectable { outline: 2px solid var(--gold); }
.played .str { font-weight: 800; color: var(--gold2); }
.played .attached { display: block; color: var(--muted); font-size: 10px; }
.played .pname { flex: 1; min-width: 0; }
.pthumb { width: 26px; height: 26px; object-fit: cover; border-radius: 4px; margin-right: 6px; flex: 0 0 auto; }

/* ---------- Hand ---------- */
/* hand as a toggleable bottom sheet, reachable from anywhere on the board */
.hand-tray {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  border-top: 1px solid var(--gold); background: var(--panel); padding: 8px 10px 12px;
  max-height: 44vh; box-shadow: 0 -10px 28px rgba(0,0,0,.55);
}
.hand-tray.hidden { display: none; }
.hand-label { font-size: 12px; color: var(--muted); margin-bottom: 6px; display: flex; justify-content: space-between; align-items: center; }
.hand-close { padding: 4px 10px; font-size: 14px; border-radius: 8px; }
.hand-count { cursor: pointer; user-select: none; }
.hand-count.open { color: var(--gold); }
#actionsLeft { color: var(--gold); }
.hand { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; }
/* when the hand sheet is open, lift the prompt bubble above it */
body.hand-open .prompt { bottom: calc(44vh + 8px); z-index: 46; }
.card {
  flex: 0 0 auto; width: 118px; min-height: 150px; background: linear-gradient(180deg, var(--panel2), #1b1528);
  border: 1px solid var(--line); border-radius: 10px; padding: 8px; cursor: pointer; position: relative;
}
.card.playable { border-color: var(--gold); box-shadow: 0 0 0 1px var(--gold); }
.card .cn { font-weight: 700; font-size: 12px; line-height: 1.2; }
.card .ct { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin-top: 2px; }
.card .cost { position: absolute; top: 6px; right: 6px; background: var(--gold); color: #2a1e00; border-radius: 20px; width: 22px; height: 22px; display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 12px; }
.card .cstr { position: absolute; bottom: 6px; right: 8px; font-weight: 800; color: var(--gold2); }
.card .cab { font-size: 9.5px; color: var(--muted); margin-top: 6px; line-height: 1.25; max-height: 70px; overflow: hidden; }
.card.selected { outline: 2px solid var(--danger); }
.card.has-art { background-size: cover; background-position: center; background-repeat: no-repeat; }
.card.has-art .ct, .card.has-art .cab { display: none; }
.card.has-art .cn { position: absolute; left: 8px; right: 8px; bottom: 6px; text-shadow: 0 1px 3px #000; }

/* ---------- Controls / prompt ---------- */
.controls { position: sticky; bottom: 0; display: flex; gap: 10px; padding: 10px 12px; background: rgba(13,11,20,.92); border-top: 1px solid var(--line); }
.controls button { flex: 1; }
.prompt { position: fixed; left: 50%; bottom: 76px; transform: translateX(-50%); background: var(--accent); color: #fff; padding: 10px 16px; border-radius: 20px; font-size: 13px; font-weight: 600; z-index: 30; box-shadow: 0 6px 20px rgba(0,0,0,.4); max-width: 90vw; text-align: center; }

/* ---------- Log ---------- */
.log-toggle { position: fixed; top: 8px; left: 50%; transform: translateX(-50%); z-index: 25; padding: 4px 14px; font-size: 12px; }
.log { position: fixed; inset: 0 0 0 auto; width: min(340px, 90vw); background: var(--panel); border-left: 1px solid var(--line); z-index: 40; padding: 50px 14px 14px; overflow-y: auto; font-size: 12.5px; }
.log .entry { padding: 6px 0; border-bottom: 1px solid var(--line); color: var(--muted); }
.log .entry b { color: var(--ink); }

/* ---------- Fate placement overlay ---------- */
.fate-overlay { position: fixed; inset: 0; background: rgba(5,4,10,.86); z-index: 45; display: flex; align-items: center; justify-content: center; padding: 16px; }
.fate-overlay.hidden { display: none; }
.fo-panel { background: var(--panel); border: 1px solid var(--gold); border-radius: 16px; padding: 18px; width: min(760px, 96vw); max-height: 92vh; overflow-y: auto; }
.fo-head { font-size: 15px; margin-bottom: 14px; text-align: center; line-height: 1.4; }
.fo-head b { color: var(--gold2); }
.fo-realm { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
@media (max-width: 620px) { .fo-realm { grid-template-columns: repeat(2, 1fr); } }
.fo-loc { background: var(--panel2); border: 1px solid var(--line); border-radius: 12px; min-height: 130px; display: flex; flex-direction: column; overflow: hidden; }
.fo-loc.locked { opacity: .5; }
.fo-loc.placeable { outline: 2px dashed var(--accent); outline-offset: -2px; cursor: pointer; }
.fo-loc-name { padding: 8px; font-weight: 700; text-align: center; border-bottom: 1px solid var(--line); font-size: 13px; }
.fo-cards { padding: 6px; display: flex; flex-direction: column; gap: 4px; }
.fo-card { background: #1b1528; border: 1px solid var(--line); border-radius: 8px; padding: 5px 7px; font-size: 12px; display: flex; justify-content: space-between; }
.fo-card.hero { border-left: 3px solid var(--danger); }
.fo-card.ally { border-left: 3px solid var(--good); }
.fo-card.item { border-left: 3px solid var(--gold); }
.fo-card b { color: var(--gold2); }
.fo-card.selectable { outline: 2px solid var(--gold); cursor: pointer; }
#foBack { margin-top: 14px; width: 100%; }

/* ---------- Hover tooltip ---------- */
.tooltip {
  position: fixed; z-index: 60; max-width: 250px;
  background: var(--panel2); border: 1px solid var(--gold); border-radius: 10px;
  padding: 10px 12px; pointer-events: none; box-shadow: 0 10px 28px rgba(0,0,0,.55);
  font-size: 12.5px;
}
.tooltip.hidden { display: none; }
.tooltip .tt-name { font-weight: 700; }
.tooltip .tt-meta { color: var(--muted); font-size: 10.5px; text-transform: uppercase; letter-spacing: .05em; margin: 2px 0 6px; }
.tooltip .tt-ab { line-height: 1.35; color: var(--ink); }

/* ---------- Card modal ---------- */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.7); z-index: 50; display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal-card { background: var(--panel); border: 1px solid var(--gold); border-radius: var(--radius); padding: 20px; max-width: 360px; width: 100%; max-height: 88vh; overflow-y: auto; }
.modal-card .modal-img { width: 100%; max-height: 62vh; object-fit: contain; border-radius: 10px; margin-bottom: 12px; display: block; }
.modal-card h3 { margin: 0 0 4px; }
.modal-card .mt { color: var(--muted); text-transform: uppercase; font-size: 11px; letter-spacing: .1em; }
.modal-card .mab { margin-top: 12px; line-height: 1.4; font-size: 14px; }
.modal-close { position: fixed; top: 20px; right: 20px; z-index: 51; border-radius: 50%; width: 40px; height: 40px; }
