/* Sorcery: Godhead. Dark battlefield, ember gold, two team colours. */
:root {
  --ink: #0d0a0f;
  --panel: rgba(20, 14, 22, 0.86);
  --panel-solid: #17111a;
  --line: rgba(232, 176, 74, 0.28);
  --text: #efe6da;
  --muted: #b3a597;
  --gold: #e8b04a;
  --ember: #e2552b;
  --light: #6fc3e8;      /* team 1, good towers */
  --shadow: #c063e0;     /* team 2, evil towers */
  --ok: #7fd18b;
  --card-w: 84px;
  --trick-w: 70px;
  --radius: 10px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background: var(--ink) url('assets/cards/board.webp') center / cover fixed;
  color: var(--text);
  font: 16px/1.45 'Alegreya Sans', system-ui, sans-serif;
}
body::before { content: ''; position: fixed; inset: 0; background: radial-gradient(ellipse at center, rgba(13,10,15,.45), rgba(13,10,15,.9)); pointer-events: none; z-index: -1; }
.display { font-family: 'Cinzel Decorative', 'Cinzel', serif; font-weight: 900; letter-spacing: .02em; }
h1, h2, h3 { font-family: 'Cinzel', serif; margin: 0 0 .4em; }
a { color: var(--gold); }
button { font: inherit; color: inherit; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.t0 { --team: var(--light); }
.t1 { --team: var(--shadow); }

/* ------------------------------------------------------------ controls */
.btn {
  border: 1px solid var(--line); background: rgba(255,255,255,.06); color: var(--text);
  padding: .55em 1.1em; border-radius: 999px; cursor: pointer; font-weight: 700; letter-spacing: .02em;
}
.btn:hover:not(:disabled) { border-color: var(--gold); }
.btn.primary { background: linear-gradient(180deg, #f0c060, #c98a2a); color: #1b1006; border-color: transparent; }
.btn:disabled { opacity: .45; cursor: default; }
.btn.small { padding: .3em .8em; font-size: .9em; }
.link { background: none; border: 0; color: var(--gold); cursor: pointer; text-decoration: underline; padding: .3em; }
.chip { border: 1px solid var(--line); background: rgba(0,0,0,.35); border-radius: 999px; padding: .25em .8em; font-size: .85em; cursor: pointer; }
.chip[aria-pressed="true"] { border-color: var(--gold); color: var(--gold); }
.chip.warn { border-color: var(--ember); color: var(--ember); cursor: default; }
input, select, textarea { font: inherit; color: var(--text); background: rgba(0,0,0,.4); border: 1px solid var(--line); border-radius: 8px; padding: .5em .7em; }
.fine, .fine-dark { font-size: .8em; color: var(--muted); }

/* ------------------------------------------------------------ home */
.home { max-width: 980px; margin: 0 auto; padding: 32px 16px; display: grid; gap: 28px; grid-template-columns: 1.2fr 1fr; align-items: center; min-height: 100vh; }
.title { font-size: clamp(2.4rem, 7vw, 4.4rem); line-height: 1; margin: 0 0 .2em; color: var(--gold); text-shadow: 0 2px 24px rgba(226,85,43,.45); }
.title span { display: block; font-size: .45em; color: var(--text); letter-spacing: .2em; }
.tag { font-size: 1.15rem; color: var(--muted); max-width: 30ch; }
.fan { position: relative; height: 260px; margin-top: 18px; }
.fan img { position: absolute; width: 150px; border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,.6); left: 30%; top: 0; transform-origin: 50% 120%; }
.fan img:nth-child(1) { transform: rotate(-16deg) translateX(-70px); }
.fan img:nth-child(2) { transform: rotate(0deg); z-index: 1; }
.fan img:nth-child(3) { transform: rotate(16deg) translateX(70px); }
.entry { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 22px; display: grid; gap: 14px; }
.entry label { font-weight: 700; }
.entry fieldset { border: 0; padding: 0; margin: 0; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.entry legend { font-size: .85em; color: var(--muted); margin-bottom: 4px; }
.entry #code { width: 8em; text-transform: uppercase; }
@media (max-width: 760px) { .home { grid-template-columns: 1fr; min-height: auto; } .fan { height: 200px; } .fan img { width: 110px; } }

/* ------------------------------------------------------------ lobby */
.lobby { max-width: 560px; margin: 40px auto; padding: 24px; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; display: grid; gap: 12px; }
.invite { display: flex; gap: 8px; } .invite input { flex: 1; min-width: 0; }
.seats { margin: 0; padding-left: 1.4em; }
.waiting { color: var(--muted); text-align: center; padding: 1em; }

/* ------------------------------------------------------------ table */
.bar { display: flex; align-items: center; gap: 12px; padding: 8px 16px; background: rgba(8,6,10,.75); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.logo { background: none; border: 0; color: var(--gold); font-size: 1.1rem; cursor: pointer; padding: 0; }
.where { margin: 0; display: flex; gap: 14px; color: var(--muted); flex: 1; flex-wrap: wrap; }
.where b { color: var(--gold); }
.bar-tools { display: flex; gap: 6px; flex-wrap: wrap; }

.game { display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: 14px; padding: 12px 16px 0; max-width: 1280px; margin: 0 auto; }

/* The lane. Each team sits side by side along its own edge, tower at its base
   and minion out front. Your base is bottom left, theirs top right, so the
   lane runs corner to corner the way a MOBA map does. */
.arena { --side: 92px; display: grid; gap: 8px; }
.team-row { display: grid; grid-template-columns: var(--side) minmax(0, 1fr) var(--side); grid-template-areas: "name name name" "base heroes minion"; gap: 4px 10px; align-items: center; }
.team-row.far { grid-template-areas: "name name name" "minion heroes base"; }
.team-row.far .team-name { text-align: right; }
.team-name { grid-area: name; margin: 0 0 -2px; font-size: .75rem; letter-spacing: .12em; text-transform: uppercase; color: var(--team); }
.base { grid-area: base; display: grid; justify-items: center; gap: 3px; }
.minion { grid-area: minion; display: grid; justify-items: center; gap: 3px; }
.base .face, .minion .face { width: 58px; }
.base small, .minion small { color: var(--muted); font-size: .72rem; }
.base .stack .card { box-shadow: 0 0 0 2px var(--team), 3px 3px 0 -1px #222, 3px 3px 0 1px var(--team), 0 6px 18px rgba(0,0,0,.6); }
.minion .gone { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(0,0,0,.65); border-radius: 6px; font-size: .7rem; color: var(--ember); font-weight: 700; text-align: center; }
.heroes { grid-area: heroes; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.hp { display: flex; gap: 3px; }
.hp i { width: 16px; height: 7px; border-radius: 2px; background: var(--ok); }
.hp i.hit { background: rgba(255,255,255,.14); }

.plate { display: flex; gap: 8px; align-items: center; background: var(--panel); border: 1px solid var(--line); border-left: 4px solid var(--team); border-radius: var(--radius); padding: 6px 10px 6px 6px; min-width: 0; position: relative; }
.plate img.hero { width: 44px; height: 44px; flex: none; object-fit: cover; object-position: 50% 15%; border-radius: 8px; }
.plate .who { display: grid; line-height: 1.15; min-width: 0; }
.plate .who b { font-family: 'Cinzel', serif; font-size: .95rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.plate .who small { color: var(--muted); font-size: .76rem; }
.plate.turn { box-shadow: 0 0 0 2px var(--gold), 0 0 22px rgba(232,176,74,.45); }
.plate .tag-ready { position: absolute; top: -8px; right: -6px; background: var(--ok); color: #0b1a0e; font-size: .7rem; font-weight: 700; border-radius: 999px; padding: 1px 7px; }
.pips { display: flex; gap: 3px; margin-top: 3px; }
.pips i { width: 9px; height: 9px; border-radius: 50%; border: 1px solid var(--gold); }
.pips i.on { background: var(--gold); box-shadow: 0 0 6px var(--gold); }

/* The trick: a card lands in front of whoever played it, in the same columns as the heroes. */
.lane { position: relative; border-radius: 18px; background:
  linear-gradient(to top right, transparent 30%, rgba(226,85,43,.10) 45%, rgba(232,176,74,.14) 50%, rgba(226,85,43,.10) 55%, transparent 70%),
  rgba(10,7,12,.35); border: 1px solid rgba(232,176,74,.12); }
.trick { position: relative; display: grid; grid-template-columns: var(--side) 1fr 1fr var(--side); grid-template-rows: 1fr 1fr; gap: 6px 10px; padding: 10px 0; min-height: calc(2 * var(--trick-w) * 1.59 + 30px); }
.trick .slot { position: relative; justify-self: center; align-self: center; width: var(--trick-w); }
.trick .slot.s-tl { grid-area: 1 / 2; } .trick .slot.s-tr { grid-area: 1 / 3; }
.trick .slot.s-bl { grid-area: 2 / 2; } .trick .slot.s-br { grid-area: 2 / 3; }
.trick .slot.winning .card { box-shadow: 0 0 0 2px var(--gold), 0 0 24px rgba(232,176,74,.7); }
.trick .slot.offsuit .card { filter: saturate(.7) brightness(.85); }
.trick .slot.past { opacity: .5; }
.trick .order { position: absolute; bottom: -7px; left: 50%; transform: translateX(-50%); background: var(--panel-solid); border: 1px solid var(--line); color: var(--muted); border-radius: 999px; font-size: .7rem; padding: 0 6px; }
.trick .mod { position: absolute; top: -8px; right: -10px; background: var(--ember); color: #fff; font-weight: 700; border-radius: 999px; padding: 0 6px; font-size: .8rem; z-index: 2; }
.trick .lead { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); margin: 0; z-index: 3; background: rgba(13,10,15,.8); border: 1px solid var(--line); border-radius: 10px; padding: 4px 10px; text-align: center; color: var(--muted); font-size: .85rem; pointer-events: none; }
.trick .lead img { width: 30px; height: 30px; display: block; margin: 0 auto 2px; background: #efe6da; border-radius: 50%; padding: 3px; }
.trick button.slot { background: none; border: 0; padding: 0; cursor: pointer; }
.trick .slot.pickable .card { box-shadow: 0 0 0 3px var(--ember); }

/* ------------------------------------------------------------ cards */
.card { display: block; border-radius: 6px; box-shadow: 0 4px 14px rgba(0,0,0,.55); background: #000; aspect-ratio: 240 / 381; width: 100%; height: auto; }
.face { position: relative; display: block; }
/* Value and suit, readable at any size, on the strip that shows in a fanned hand. */
.badge { position: absolute; top: 5%; left: 6%; display: flex; flex-direction: column; align-items: center; gap: 1px; min-width: 24px; padding: 3px 3px 2px; border-radius: 6px; background: rgba(246,239,228,.95); color: #17110f; line-height: 1; box-shadow: 0 1px 4px rgba(0,0,0,.6); pointer-events: none; }
.badge b { font: 700 1rem/1 'Cinzel', serif; }
.badge.s-heart b, .badge.s-diamond b { color: #b5121b; }
.badge img { width: 15px; height: 15px; display: block; }
.badge small { font-size: .5rem; letter-spacing: 1px; color: #6b5a4a; }

#peek { position: fixed; left: 0; top: 0; width: 230px; z-index: 40; pointer-events: none; opacity: 0; transition: opacity .1s ease; background: var(--panel-solid); border: 1px solid var(--gold); border-radius: 14px; padding: 8px; box-shadow: 0 18px 50px rgba(0,0,0,.75); }
#peek.show { opacity: 1; }
#peek img { width: 100%; height: auto; display: block; border-radius: 8px; }
#peek p { margin: 8px 2px 2px; display: grid; gap: 3px; font-size: .88rem; color: var(--muted); }
#peek p b { font-family: 'Cinzel', serif; font-size: 1.1rem; color: var(--gold); }

/* ------------------------------------------------------------ side: this round + log */
.side { display: grid; gap: 12px; align-content: start; }
.field { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; }
.field h3 { font-size: .95rem; display: grid; }
.field h3 small { font-family: 'Alegreya Sans', sans-serif; color: var(--muted); font-size: .75rem; font-weight: 400; }
.tally { width: 100%; border-collapse: collapse; font-size: .9rem; }
.tally th, .tally td { text-align: center; padding: 3px 2px; }
.tally tbody th { text-align: left; color: var(--team); font-weight: 700; white-space: nowrap; }
.tally img { width: 20px; height: 20px; background: #efe6da; border-radius: 50%; padding: 2px; vertical-align: middle; }
.tally td.most { outline: 1px solid var(--team); outline-offset: -2px; border-radius: 6px; color: var(--team); font-weight: 700; }

.log { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 12px; max-height: 260px; overflow: auto; font-size: .88rem; }
.log ol { margin: 0; padding: 0; list-style: none; display: grid; gap: 3px; }
.log li { color: var(--muted); } .log li:first-child { color: var(--text); }

/* ------------------------------------------------------------ your hand + actions */
.tray { position: sticky; bottom: 0; z-index: 5; padding: 4px 16px 10px; background: linear-gradient(180deg, transparent, rgba(8,6,10,.92) 30%); margin-top: 8px; }
.prompt { text-align: center; margin: 0 0 6px; font-weight: 500; }
.prompt b { color: var(--gold); }
.actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-bottom: 8px; }
/* The hand: one grid column per visible strip, each card overhanging the next
   column. Phones split it into two rows so every badge stays readable. */
.hand { --cols: var(--n); --step: min(calc((100vw - 40px - var(--card-w)) / max(var(--cols) - 1, 1)), calc(var(--card-w) * .68));
  display: grid; grid-template-columns: repeat(var(--cols), var(--step)); justify-content: center; row-gap: 8px;
  padding: 16px calc(var(--card-w) - var(--step)) 2px 0; }
.hand .hc { width: var(--card-w); margin: 0; background: none; border: 0; padding: 0; transition: transform .12s ease; cursor: default; position: relative; }
.hand .hc.can { cursor: pointer; }
.hand .hc.can:hover, .hand .hc.can:focus-visible { transform: translateY(-14px); z-index: 2; }
.hand .hc.dim .card { filter: brightness(.45) saturate(.5); }
.hand .hc.picked { transform: translateY(-20px); }
.hand .hc.picked .card { box-shadow: 0 0 0 3px var(--gold), 0 0 18px rgba(232,176,74,.6); }
.hand .hc .pick-order { position: absolute; bottom: 4px; left: 6%; background: var(--gold); color: #1b1006; font-weight: 700; border-radius: 999px; font-size: .75rem; padding: 0 6px; }
.powers { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; }

/* ------------------------------------------------------------ panels */
.sheet-panel { position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%); width: min(560px, calc(100% - 32px)); max-height: calc(100vh - 32px); overflow: auto; background: var(--panel-solid); border: 1px solid var(--gold); border-radius: 16px; padding: 18px; z-index: 20; box-shadow: 0 20px 60px rgba(0,0,0,.7); }
.sheet-panel.wide { width: min(860px, calc(100% - 32px)); }
.panel-actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.options { display: flex; gap: 14px; flex-wrap: wrap; justify-content: center; }
.option { display: grid; gap: 6px; justify-items: center; width: 130px; }
.option .card { width: 120px; }
.pile { display: flex; flex-wrap: wrap; gap: 6px; }
.pile button { width: 58px; background: none; border: 0; padding: 0; cursor: pointer; border-radius: 6px; }
.pile button[aria-pressed="true"] .card { box-shadow: 0 0 0 3px var(--gold); }
.rating { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin: 8px 0; }
.note-label { display: block; margin: 8px 0 4px; }
textarea { width: 100%; }

.finale { text-align: center; padding: 24px; background: var(--panel); border: 1px solid var(--gold); border-radius: 16px; display: grid; gap: 10px; justify-items: center; }
.finale h2 { font-size: 2rem; color: var(--gold); }

/* ------------------------------------------------------------ rules dialog */
dialog#rules { max-width: 720px; width: calc(100% - 32px); background: var(--panel-solid); color: var(--text); border: 1px solid var(--gold); border-radius: 16px; padding: 22px; }
dialog#rules::backdrop { background: rgba(0,0,0,.7); }
.dialog-close { position: sticky; top: 0; float: right; }
.dialog-close button { background: rgba(0,0,0,.5); border: 1px solid var(--line); border-radius: 999px; padding: .3em .9em; cursor: pointer; }
.rules-table { border-collapse: collapse; width: 100%; } .rules-table td { border-top: 1px solid var(--line); padding: 6px 8px; vertical-align: top; }
.rules-table td:first-child { white-space: nowrap; color: var(--gold); font-weight: 700; }
.version { color: var(--muted); font-size: .85em; }

#toast { position: fixed; left: 50%; top: 16px; transform: translate(-50%, -150%); background: var(--panel-solid); border: 1px solid var(--gold); padding: 8px 16px; border-radius: 999px; transition: transform .25s ease; z-index: 50; max-width: calc(100% - 32px); }
#toast.show { transform: translate(-50%, 0); }

/* ------------------------------------------------------------ phones */
@media (max-width: 900px) {
  .game { grid-template-columns: 1fr; padding: 8px 8px 0; }
  .side { order: 2; }
  .log { max-height: 160px; }
}
@media (max-width: 640px) {
  :root { --card-w: 64px; --trick-w: 60px; }
  .arena { --side: 54px; gap: 6px; }
  .team-row { gap: 3px 6px; }
  .base .face, .minion .face { width: 48px; }
  .hp i { width: 11px; }
  .heroes { gap: 6px; }
  .plate { gap: 5px; padding: 4px 6px 4px 4px; }
  .plate img.hero { width: 32px; height: 32px; }
  .plate .who b { font-size: .82rem; }
  .plate .who small { font-size: .68rem; }
  .pips i { width: 7px; height: 7px; }
  .trick { gap: 6px; }
  .hand { --cols: var(--nr); }
  .badge b { font-size: .85rem; }
  .badge img { width: 13px; height: 13px; }
  .bar { padding: 6px 8px; }
  #peek { width: 200px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* Cards on the table: big number and suit over darkened art, readable across the lane. */
.face.clear .card { filter: brightness(.38) saturate(.7); }
.face.clear .big { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; pointer-events: none; }
.face.clear .big b { font: 700 calc(var(--trick-w) * .5)/1 'Cinzel', serif; color: #f6efe4; text-shadow: 0 2px 6px #000, 0 0 2px #000; }
.face.clear.s-heart .big b, .face.clear.s-diamond .big b { color: #ff6b5e; }
.face.clear .big img { width: calc(var(--trick-w) * .44); height: calc(var(--trick-w) * .44); background: #efe6da; border-radius: 50%; padding: 4px; box-shadow: 0 2px 8px rgba(0,0,0,.7); }
.face.clear .big small { color: var(--gold); font-size: .9rem; letter-spacing: 2px; text-shadow: 0 1px 3px #000; }
.face.clear { border-radius: 6px; box-shadow: inset 0 0 0 2px rgba(255,255,255,.08); }
.trick .slot.offsuit .face.clear .card { filter: brightness(.25) saturate(.4); }
.trick .slot.offsuit .face.clear .big b { opacity: .8; }
