:root {
  --bg: #15171c;
  --panel: #1f232b;
  --panel2: #282d37;
  --text: #e7e9ee;
  --muted: #9aa1ad;
  --accent: #5aa0ff;
  --select: #ffd34d;
  --attack: #ff5a5a;
  --block: #4dd28a;
  --danger: #c0392b;
  --card-w: 110px;
  --card-h: 153px;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.4 system-ui, sans-serif; }
header#top { display: flex; justify-content: space-between; padding: 6px 14px; background: var(--panel); }
#title { font-weight: 600; }
#status { color: var(--muted); }
main { padding: 10px 14px; }
.screen { display: none; }
.screen.on { display: block; }
#match.on { display: grid; grid-template-columns: 1fr 300px; gap: 10px; }
h1, h2, h3 { margin: 10px 0 6px; }
.hint { color: var(--muted); font-size: 12px; }
.err { color: #ff8a80; min-height: 1.2em; }
button { background: var(--accent); color: #081020; border: 0; border-radius: 6px; padding: 6px 12px; font-weight: 600; cursor: pointer; }
button:disabled { background: #444b57; color: #888; cursor: default; }
button.danger { background: var(--danger); color: white; }
button.ghost { background: var(--panel2); color: var(--text); }
input { background: var(--panel2); color: var(--text); border: 1px solid #3a404c; border-radius: 4px; padding: 5px 7px; }
#sets button { margin: 4px; min-width: 70px; }

.cards { display: flex; flex-wrap: wrap; gap: 6px; }
.card { position: relative; width: var(--card-w); height: var(--card-h); border-radius: 6px; background: var(--panel2);
  overflow: hidden; cursor: pointer; flex: none; border: 2px solid transparent; transition: transform .1s; }
.cards.small .card, .zone .card { --card-w: 84px; --card-h: 117px; width: var(--card-w); height: var(--card-h); }
.card img { width: 100%; height: 100%; object-fit: cover; display: block; }
.card .txt { padding: 4px; font-size: 10px; line-height: 1.2; height: 100%; overflow: hidden; }
.card .txt b { display: block; font-size: 11px; }
.card.hidden { background: repeating-linear-gradient(45deg, #2c3240, #2c3240 6px, #252a35 6px, #252a35 12px); }
/* A tapped card turns clockwise about a point half a card HEIGHT in from its top-left corner, so the turned card
   fills [0, height] x [0, width] of its stack: the space a stack reserves (STACK_GAP in app.js), never a neighbour's. */
.card.tapped { transform: rotate(90deg); transform-origin: calc(var(--card-h) / 2) calc(var(--card-h) / 2); }
.stack { position: relative; flex: none; }
.stack > .card { position: absolute; }
.badge.count { position: absolute; z-index: 50; background: #111; border: 1px solid #888; }
.card.selectable { border-color: var(--select); box-shadow: 0 0 8px var(--select); }
.card.highlighted { border-color: var(--accent); }
.card.attacking { border-color: var(--attack); }
.card.blocking { border-color: var(--block); }
.card.chosen { outline: 3px solid var(--select); }
.badge { position: absolute; background: rgba(0,0,0,.78); color: white; font-size: 11px; font-weight: 700; padding: 1px 4px; border-radius: 4px; }
.badge.pt { right: 2px; bottom: 2px; }
.badge.dmg { left: 2px; bottom: 2px; background: #a32626; }
.badge.ctr { left: 2px; top: 2px; background: #2c5aa0; }
.badge.sick { right: 2px; top: 2px; background: #555; }

.player { background: var(--panel); border-radius: 8px; padding: 6px 8px; }
.pinfo { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.pinfo .name { font-weight: 700; }
.pinfo .life { font-size: 20px; font-weight: 800; cursor: pointer; padding: 0 6px; border-radius: 5px; }
.pinfo .life.selectable { background: var(--select); color: #111; }
.pinfo .life.highlighted { outline: 2px solid var(--accent); }
.mana span { display: inline-block; min-width: 22px; text-align: center; border-radius: 10px; padding: 0 4px; margin-right: 3px; cursor: pointer; font-weight: 700; }
.m-W { background: #f3edcf; color: #222; } .m-U { background: #3f84d0; } .m-B { background: #444; } .m-R { background: #d4553b; }
.m-G { background: #3d9a5a; } .m-C { background: #aaa; color: #222; }
.row { display: flex; flex-wrap: wrap; gap: 6px; min-height: 60px; padding: 4px 0; }
.zones { display: flex; gap: 10px; font-size: 12px; color: var(--muted); }
.zones a { color: var(--accent); cursor: pointer; }
#middle { background: var(--panel2); border-radius: 8px; padding: 6px 8px; margin: 8px 0; }
#phase { color: var(--muted); font-size: 12px; }
#stack .item { display: flex; gap: 8px; align-items: center; padding: 3px 0; border-bottom: 1px solid #333a46; }
#promptBar { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 40px; }
#promptMsg { font-weight: 600; white-space: pre-wrap; }
#buttons button { margin-left: 6px; }
#side { background: var(--panel); border-radius: 8px; padding: 8px; max-height: calc(100vh - 70px); overflow: auto; position: sticky; top: 8px; }
#log { padding-left: 18px; font-size: 12px; margin: 4px 0 10px; }
#log li { cursor: pointer; padding: 1px 0; }
#log li:hover { color: var(--select); }
#stops table { font-size: 12px; border-collapse: collapse; }
#stops td { padding: 1px 4px; }

#overlay { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex; align-items: center; justify-content: center; z-index: 10; }
#overlay.hidden, #zoom.hidden, #toast.hidden { display: none; }
#dialog { background: var(--panel); border-radius: 10px; padding: 14px; max-width: min(1000px, 95vw); max-height: 90vh; overflow: auto; }
#dialog .opts { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
#dialog .opt { background: var(--panel2); border-radius: 6px; padding: 6px 8px; cursor: pointer; border: 2px solid transparent; }
#dialog .opt.on { border-color: var(--select); }
#dialog .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px; }
#dialog ol li { margin: 3px 0; }
#zoom { position: fixed; right: 320px; top: 60px; z-index: 20; background: var(--panel); border-radius: 10px; padding: 8px; width: 270px; pointer-events: none; }
#zoom img { width: 100%; border-radius: 8px; }
#zoom .ztxt { font-size: 12px; white-space: pre-wrap; margin-top: 6px; }
#toast { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); background: #333a46; padding: 8px 14px; border-radius: 8px; z-index: 30; }

@media (max-width: 900px) {
  #match.on { grid-template-columns: 1fr; }
  #zoom { right: 10px; }
}

/* ---- the board, laid out after Forge's match screen ---- */
#board { position: relative; }
#arrows { position: absolute; left: 0; top: 0; pointer-events: none; z-index: 60; overflow: visible; }
#arrows line { stroke-width: 4; stroke-linecap: round; opacity: .85; }
#arrows line.attack { stroke: #ff5a5a; }
#arrows line.block { stroke: #4dd28a; }
#arrows line.target { stroke: #ffa53d; stroke-dasharray: 8 5; }

.player { display: grid; grid-template-columns: 92px 30px 1fr; gap: 8px; align-items: start; }
.pcol { display: flex; flex-direction: column; gap: 3px; align-items: stretch; }
.pname { font-weight: 700; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pcol .life { font-size: 30px; font-weight: 800; text-align: center; border-radius: 8px; background: var(--panel2);
  cursor: pointer; line-height: 1.3; }
.pcol .life.highlighted { outline: 3px solid var(--select); }
.stat { display: flex; justify-content: space-between; font-size: 13px; padding: 1px 6px; border-radius: 4px; }
.stat.link { cursor: pointer; color: var(--accent); }
.stat.link:hover { background: var(--panel2); }
.stat .ico { opacity: .8; }
.mana { display: grid; grid-template-columns: repeat(3, 1fr); gap: 3px; margin-top: 4px; }
.mana .m { text-align: center; border-radius: 10px; font-size: 11px; font-weight: 700; padding: 1px 0; cursor: default; }
.mana .m:not(.zero) { cursor: pointer; box-shadow: 0 0 6px rgba(255,255,255,.4); }
.mana .m.zero { opacity: .28; }

.phases { display: flex; flex-direction: column; gap: 2px; }
.ph { font-size: 10px; font-weight: 700; text-align: center; padding: 2px 0; border-radius: 4px; cursor: pointer;
  background: #2a2f39; color: #6b7280; }
.ph.on { background: #2f6fb8; color: #e8f0ff; }
.ph.now { background: var(--select); color: #111; }

.field { min-width: 0; }
.zone .card, .stack > .card { --card-w: 100px; --card-h: 140px; width: var(--card-w); height: var(--card-h); }
.row.backs .card { --card-w: 48px; --card-h: 67px; width: 48px; height: 67px; }
.row.backs { min-height: 0; }
#hand { background: var(--panel); border-radius: 8px; padding: 6px 8px; margin-top: 8px; }
#hand .card { --card-w: 120px; --card-h: 168px; width: 120px; height: 168px; }
#hand .card:hover { transform: translateY(-8px); }

.card .nm { position: absolute; left: 0; right: 0; top: 0; padding: 1px 4px; font-size: 10px; font-weight: 700;
  color: #fff; background: linear-gradient(rgba(0,0,0,.8), rgba(0,0,0,.45)); white-space: nowrap; overflow: hidden;
  text-overflow: ellipsis; }
.card .sickmark { position: absolute; left: 50%; bottom: 4px; transform: translateX(-50%); width: 22px; height: 22px;
  border-radius: 11px; background: #3060c0; color: #fff; font-size: 15px; line-height: 22px; text-align: center;
  box-shadow: 0 0 4px #000; }
.badge.sick { display: none; }

#side { display: flex; flex-direction: column; gap: 6px; }
#detail { min-height: 120px; }
#detail img { width: 100%; border-radius: 10px; display: block; }
#detail .ztxt { font-size: 12px; white-space: pre-wrap; margin-top: 6px; color: var(--muted); }
#log li { display: flex; gap: 6px; align-items: center; }
#log li.turn { font-weight: 700; color: var(--accent); cursor: default; margin-top: 6px; }
#log .thumb { width: 30px; height: 42px; object-fit: cover; border-radius: 3px; flex: none; }
#match.on { grid-template-columns: 1fr 320px; }

/* The side panel is a fixed-height column: the card detail keeps its full size (never shrunk under the log), and only
   the log scrolls, in whatever height is left. */
#side { overflow: hidden; height: calc(100vh - 70px); max-height: none; }
#side > * { flex: none; }
#detail img { width: auto; max-width: 100%; max-height: 40vh; margin: 0 auto; }
#detail .ztxt { max-height: 18vh; overflow: auto; }
#side > #log { flex: 1 1 auto; min-height: 0; overflow-y: auto; margin: 0; }

/* dialogs: a card with its controls under it (ordering, damage and amounts) */
.ordercell { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.orderctl { display: flex; align-items: center; gap: 6px; }
