:root {
  --bg: #12161c; --panel: #1b222b; --panel2: #232c37; --line: #33404f; --text: #e7ebf0; --muted: #9aa7b6;
  --accent: #e0a63a; --accent2: #5aa9e6; --ok: #49b16d; --bad: #e0574a; --warn: #e0a63a;
  --card-w: 100px; --card-h: 140px; --mini-w: var(--card-w); --mini-h: var(--card-h);   /* ONE card size (5:7) for every zone: hand, battlefield, stack, graveyard, choices. Only the zoom view is larger. */ --radius: 8px;
  --w: #efe6c8; --u: #3d7cc9; --b: #4a3f4f; --r: #c9452f; --g: #2f7d47; --gold: #c8a04a; --art: #8f99a3; --land: #8a7356;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-size: 15px; }
body { overscroll-behavior: none; -webkit-tap-highlight-color: transparent; }
button { font: inherit; color: var(--text); background: var(--panel2); border: 1px solid var(--line); border-radius: 6px; padding: 7px 12px; cursor: pointer; min-height: 36px; }
button:hover { border-color: var(--accent2); }
button.primary { background: var(--accent); color: #1a1205; border-color: var(--accent); font-weight: 600; }
button.danger { border-color: var(--bad); color: #ffb3ab; }
button:disabled { opacity: .45; cursor: default; }
input, select, textarea { font: inherit; color: var(--text); background: #0e1217; border: 1px solid var(--line); border-radius: 6px; padding: 7px 9px; }
textarea { width: 100%; min-height: 180px; font-family: Consolas, monospace; font-size: 13px; }
a { color: var(--accent2); }
h1, h2, h3 { margin: .2em 0 .5em; font-weight: 600; }
.muted { color: var(--muted); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }
.tag { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; border: 1px solid var(--line); }
.tag.ok { border-color: var(--ok); color: #9fe3b5; } .tag.warn { border-color: var(--warn); color: #f2d18c; } .tag.bad { border-color: var(--bad); color: #ffb3ab; }

/* ---------- app shell ---------- */
#app { display: flex; flex-direction: column; height: 100%; }
header.top { display: flex; align-items: center; gap: 10px; padding: 6px 12px; background: var(--panel); border-bottom: 1px solid var(--line); }
header.top .logo { font-weight: 700; letter-spacing: .5px; }
header.top nav { display: flex; gap: 4px; }
header.top nav button { background: transparent; border-color: transparent; }
header.top nav button.on { border-color: var(--accent); }
header.top .me { margin-left: auto; color: var(--muted); font-size: 13px; }
main.page { flex: 1; overflow: auto; padding: 14px 16px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; margin-bottom: 12px; }
.list { display: flex; flex-direction: column; gap: 6px; }
.list .item { display: flex; gap: 10px; align-items: center; padding: 8px 10px; background: var(--panel2); border-radius: 8px; flex-wrap: wrap; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 800px) { .grid2 { grid-template-columns: 1fr; } main.page { padding: 10px 16px; } }

/* ---------- toast + modal ---------- */
#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(40px); opacity: 0; transition: .2s; background: #000c; border: 1px solid var(--line); padding: 10px 16px; border-radius: 8px; z-index: 1000; max-width: min(92vw, 520px); pointer-events: none; }
#toast.show { opacity: 1; transform: translateX(-50%); }
#toast.error { border-color: var(--bad); }
.modal-back { position: fixed; inset: 0; background: #000a; display: flex; align-items: center; justify-content: center; z-index: 900; padding: 12px; }
.modal { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 16px; max-width: 560px; width: 100%; max-height: 92vh; overflow: auto; }
.modal.wide { max-width: 900px; }
.modal-buttons { display: flex; gap: 8px; justify-content: flex-end; margin-top: 12px; flex-wrap: wrap; }

/* ---------- symbols ---------- */
.ms { display: inline-block; width: 1.05em; height: 1.05em; vertical-align: -0.15em; margin: 0 1px; }
.ms svg { width: 100%; height: 100%; display: block; }
.ms-text { width: auto; font-size: .8em; border: 1px solid var(--line); border-radius: 50%; padding: 0 4px; }

/* ---------- cards ---------- */
.card { --frame: var(--art); position: relative; width: var(--card-w); height: var(--card-h); min-width: var(--card-w); max-width: var(--card-w); min-height: var(--card-h); max-height: var(--card-h); overflow: hidden; border-radius: var(--radius); padding: 4px; background: var(--frame); box-shadow: 0 2px 6px #0008; user-select: none; touch-action: pan-x pan-y; flex: 0 0 auto; transition: transform .15s; }
.card .inner { position: relative; height: 100%; border-radius: 5px; background: #f2efe7; color: #1d1a16; display: flex; flex-direction: column; overflow: hidden; }
.card .title { display: flex; justify-content: space-between; gap: 2px; padding: 3px 5px; font-size: 11px; font-weight: 700; background: #0000000f; border-bottom: 1px solid #0002; }
.card .title .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card .title .cost { white-space: nowrap; flex: 0 0 auto; }
.card .center { flex: 1; min-height: 0; overflow: hidden; display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center; padding: 4px; gap: 4px; }
.card .big-name { font-size: 15px; font-weight: 800; line-height: 1.1; display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
.card .big-type { font-size: 11px; font-weight: 600; color: #4a443b; }
.card .rules { display: none; }
.card .kws { max-height: 24px; overflow: hidden; font-size: 9.5px; text-align: center; color: #3a352d; padding: 0 3px; font-weight: 600; }
.card .foot { display: flex; align-items: flex-end; justify-content: flex-end; gap: 3px; padding: 2px 4px 4px; min-height: 22px; flex-wrap: wrap; }
.card .pt { background: #fff; border: 1px solid #0005; border-radius: 6px; padding: 0 6px; font-weight: 800; font-size: 13px; margin-left: auto; }
.card .pt.damaged { color: var(--bad); }
.card .pt.loyalty { background: #222; color: #fff; }
.card .counter { background: #222; color: #fff; border-radius: 6px; padding: 0 4px; font-size: 10px; }
.card .auto-flag { font-size: 11px; }
.card .basic-sym { flex: 1; display: flex; align-items: center; justify-content: center; }
.card .basic-sym .ms { width: 56px; height: 56px; }
.card .basic-sym.small .ms { width: 34px; height: 34px; }
.card .zzz { position: absolute; top: 20px; right: 5px; font-weight: 800; color: #6a7380; font-size: 13px; }
.card.frame-w { --frame: var(--w); } .card.frame-u { --frame: var(--u); } .card.frame-b { --frame: var(--b); }
.card.frame-r { --frame: var(--r); } .card.frame-g { --frame: var(--g); } .card.frame-multi { --frame: var(--gold); }
.card.frame-artifact { --frame: var(--art); } .card.frame-land { --frame: var(--land); } .card.frame-colorless { --frame: #b9b4aa; }
.card.frame-b .inner { background: #e9e5e8; } .card.frame-u .inner { background: #e8eef6; } .card.frame-r .inner { background: #f6ebe6; }
.card.frame-g .inner { background: #e7f0e8; } .card.frame-w .inner { background: #fbf8ee; } .card.frame-multi .inner { background: #f5efdc; }
.card.back { background: linear-gradient(135deg, #3a2a1a, #6b4a24); display: flex; align-items: center; justify-content: center; }
.card .back-mark { color: #f0d9a8; font-weight: 800; text-align: center; font-size: 14px; border: 2px solid #f0d9a8; border-radius: 50%; padding: 12px 8px; }
.card.compact { width: var(--mini-w); height: var(--mini-h); padding: 3px; }
.card.compact .title { font-size: 9px; padding: 2px 3px; }
.card.compact .title .cost { display: none; }
.card.compact .big-name { font-size: 11px; }
.card.compact .big-type { font-size: 8.5px; }
.card.compact .pt { font-size: 11px; padding: 0 4px; }
.card.tapped { rotate: 90deg; margin: 0 calc((var(--card-h) - var(--card-w)) / 2); }   /* same size; the margin only makes room for the turned card */
.card.sick .inner { filter: saturate(.55); }
.card.attacking { box-shadow: 0 0 0 3px var(--bad), 0 2px 6px #0008; }
.card.blocking { box-shadow: 0 0 0 3px var(--accent2), 0 2px 6px #0008; }
.card.selected, .card.chosen { box-shadow: 0 0 0 3px var(--accent), 0 0 14px var(--accent); }
.card.playable { box-shadow: 0 0 0 3px #7cf29a, 0 0 12px #7cf29a99; transform: translateY(-4px); }
.card.targetable { box-shadow: 0 0 0 3px #b77cff, 0 0 12px #b77cff; cursor: crosshair; }
.card.token .inner::after { content: "token"; position: absolute; left: 4px; bottom: 3px; font-size: 8px; color: #7a7266; }
.card.dragging { opacity: .35; }
.drag-ghost { position: fixed; pointer-events: none; z-index: 1500; transform: rotate(4deg) scale(1.05); }
.card.lift { transform: scale(1.07); }

/* zoomed card */
.zoom { display: flex; gap: 16px; align-items: flex-start; flex-wrap: wrap; }
.zoom .card { --card-w: 200px; --card-h: 280px; }
.zoom .card .big-name { font-size: 22px; } .zoom .card .big-type { font-size: 14px; } .zoom .card .title { font-size: 14px; }
.zoom-text { flex: 1; min-width: 220px; }
.zoom-text p { line-height: 1.45; }
.zt { color: var(--muted); margin-bottom: 6px; }
.reminder { color: var(--muted); }
.failed { margin-top: 10px; padding: 8px; border: 1px dashed var(--warn); border-radius: 8px; }
.zoom-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }

/* ---------- game board ---------- */
.board { display: grid; grid-template-columns: minmax(0, 1fr) 300px; grid-template-rows: auto 1fr auto; height: 100%; gap: 0; }
.board .opps { grid-column: 1; grid-row: 1; display: flex; gap: 8px; padding: 8px; overflow-x: auto; border-bottom: 1px solid var(--line); background: #0f1318; }
.board .field { grid-column: 1; grid-row: 2; overflow: auto; padding: 8px; display: flex; flex-direction: column; gap: 8px; }
.board .handbar { grid-column: 1; grid-row: 3; background: var(--panel); border-top: 1px solid var(--line); }
.board .side { grid-column: 2; grid-row: 1 / span 3; border-left: 1px solid var(--line); background: var(--panel); display: flex; flex-direction: column; min-height: 0; }
.opp { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 6px 8px; min-width: 260px; flex: 1; }
.opp.active { border-color: var(--accent); }
.opp.target-player, .me-strip.target-player { box-shadow: 0 0 0 3px #b77cff; cursor: crosshair; }
.opp.drop-hover, .zone.drop-hover { outline: 2px dashed var(--accent); }
.pinfo { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; font-size: 13px; }
.pinfo .pname { font-weight: 700; font-size: 14px; }
.pinfo .life { font-size: 20px; font-weight: 800; color: #ffd27a; }
.pinfo .lost { color: var(--bad); }
.cmd-dmg { font-size: 11px; color: var(--muted); }
.zone { display: flex; gap: 6px; flex-wrap: wrap; align-items: flex-start; min-height: calc(var(--mini-h) + 8px); padding: 4px; border-radius: 8px; }
.zone.mine { background: #ffffff06; border: 1px dashed #ffffff14; }
.zone-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; }
.opp .zone { min-height: 60px; }
.me-strip { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; padding: 4px 8px; background: var(--panel); border-radius: 10px; border: 1px solid var(--line); }
.me-strip.active { border-color: var(--accent); }
.pool { display: flex; gap: 2px; align-items: center; }
.pool .rmana { border: 1px dashed var(--accent); border-radius: 6px; padding: 0 4px; font-size: 11px; }
.piles { display: flex; gap: 6px; flex-wrap: wrap; }
.pile { font-size: 12px; padding: 4px 8px; border-radius: 6px; background: var(--panel2); border: 1px solid var(--line); cursor: pointer; }
.phasebar { display: flex; gap: 2px; padding: 6px 8px; overflow-x: auto; align-items: center; }
.phasebar .ph { font-size: 11px; padding: 3px 6px; border-radius: 5px; color: var(--muted); white-space: nowrap; border: 1px solid transparent; }
.phasebar .ph.on { color: #1a1205; background: var(--accent); font-weight: 700; }
.phasebar .ph.stop { border-color: #ffffff30; }
.actionbar { display: flex; gap: 8px; align-items: center; padding: 6px 8px; flex-wrap: wrap; border-top: 1px solid var(--line); }
.actionbar .prompt { flex: 1; min-width: 200px; font-weight: 600; }
.actionbar .prompt.waiting { color: var(--muted); font-weight: 400; }
.hand { display: flex; gap: 6px; padding: 8px; overflow-x: auto; min-height: calc(var(--card-h) + 16px); }
.stackzone { border: 1px solid var(--line); border-radius: 8px; padding: 6px; margin: 8px; }
.stack-item { display: flex; gap: 8px; align-items: center; padding: 4px; border-bottom: 1px solid #ffffff10; font-size: 13px; }
.stack-item:last-child { border-bottom: 0; }
.stack-item.top { background: #e0a63a22; border-radius: 6px; }
.side .tabs { display: flex; border-bottom: 1px solid var(--line); }
.side .tabs button { flex: 1; border: 0; border-radius: 0; background: transparent; }
.side .tabs button.on { border-bottom: 2px solid var(--accent); }
.side .pane { flex: 1; overflow: auto; padding: 8px; font-size: 13px; min-height: 0; }
.log-line { padding: 2px 0; border-bottom: 1px solid #ffffff08; }
.log-line.turn { color: var(--accent); font-weight: 700; margin-top: 6px; }
.log-line.manual { color: #f2d18c; }
.chat-form { display: flex; gap: 6px; padding: 8px; border-top: 1px solid var(--line); }
.chat-form input { flex: 1; min-width: 0; }
.decision { padding: 8px; display: flex; flex-direction: column; gap: 8px; }
.choice-cards { display: flex; flex-wrap: wrap; gap: 6px; }
.banner { padding: 8px 12px; background: #e0574a22; border: 1px solid var(--bad); border-radius: 8px; margin: 8px; }
.banner.info { background: #5aa9e622; border-color: var(--accent2); }
.loading { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100%; gap: 12px; }
.bar { width: min(420px, 80vw); height: 10px; background: var(--panel2); border-radius: 5px; overflow: hidden; }
.bar > div { height: 100%; background: var(--accent); width: 0; transition: width .2s; }
.side-toggle { display: none; }
table.stats { border-collapse: collapse; width: 100%; font-size: 13px; }
table.stats th, table.stats td { padding: 4px 8px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
table.stats th:first-child, table.stats td:first-child { text-align: left; }
.replaybar { background: #5aa9e614; }
.replaybar select { min-height: 36px; }

@media (max-width: 900px) {
  :root { --card-w: 88px; --card-h: 123.2px; }   /* phones: one smaller size for all cards */
  .board { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto 1fr auto; }
  .board .side { position: fixed; right: 0; top: 0; bottom: 0; width: min(88vw, 340px); z-index: 800; transform: translateX(100%); transition: transform .2s; }
  .board .side.open { transform: none; box-shadow: -8px 0 20px #000a; }
  .side-toggle { display: inline-block; }
  .opp { min-width: 180px; }
  .opp .zone { min-height: 0; }
  header.top { padding: 4px 8px; gap: 6px; }
  header.top .me { display: none; }
  .actionbar .prompt { min-width: 140px; font-size: 14px; }
  header.top nav button { padding: 6px 8px; }
}
.board > * { min-width: 0; }
.board-host { overflow: hidden; }
.card.compact .kws { font-size: 8px; line-height: 1.1; max-height: 18px; overflow: hidden; }
.card.compact .foot { min-height: 18px; padding: 1px 3px 3px; }
.card.compact .big-type { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.float-num { position: fixed; z-index: 1200; pointer-events: none; font-weight: 800; font-size: 22px; text-shadow: 0 2px 4px #000; translate: -50% 0; }
.float-num.dmg { color: #ff7a6b; } .float-num.gain { color: #7cf29a; }

/* ---------- rules text on cards ---------- */
.card .ctype { font-size: 8.5px; font-weight: 700; color: #4a443b; padding: 2px 4px 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .rtext { flex: 1; min-height: 0; overflow: hidden; padding: 1px 4px 0; font-size: 9px; line-height: 1.18; color: #2a2620; -webkit-mask-image: linear-gradient(to bottom, #000 calc(100% - 9px), transparent); mask-image: linear-gradient(to bottom, #000 calc(100% - 9px), transparent); }
.card .rtext .ms { width: .95em; height: .95em; margin: 0; }
.card .kws.granted { color: #1d5fa8; }
.card.has-text .title { font-size: 10px; }
.card.full.has-text .rtext { font-size: 10px; }
.card.full.has-text .ctype { font-size: 9px; }
/* the board's text size changes the type size on the cards, never the card size (text clips inside the card; the hover card and the zoom show it all) */
.txt-large .card .rtext { font-size: 10.5px; }
.txt-large .card .ctype { font-size: 9.5px; }
.txt-large .card.compact .title { font-size: 10.5px; }
.txt-small .zone, .txt-large .zone { min-height: 0; }
.txt-off .card .rtext, .txt-off .card .ctype { display: none; }
/* hover card */
#hovercard { position: fixed; z-index: 1100; width: 270px; max-height: 80vh; overflow: hidden; pointer-events: none; background: var(--panel); border: 1px solid var(--accent2); border-radius: 10px; padding: 10px 12px; box-shadow: 0 8px 24px #000a; font-size: 13px; line-height: 1.4; }
#hovercard h3 { margin: 0 0 2px; font-size: 15px; display: flex; justify-content: space-between; gap: 8px; }
#hovercard .zt { color: var(--muted); margin-bottom: 4px; font-size: 12px; }
#hovercard p { margin: 4px 0; }
#hovercard .hv-face + .hv-face { border-top: 1px solid var(--line); margin-top: 8px; padding-top: 6px; }
#hovercard .hv-state { margin-top: 6px; padding-top: 6px; border-top: 1px dashed var(--line); font-size: 12px; color: #cfd8e3; }
#hovercard .hv-state b { color: var(--text); }
#hovercard .tc-word { color: #4cd07d; font-weight: 700; }   /* @@v4 words changed by a text-changing effect */
#hovercard .ms { width: 1.05em; height: 1.05em; }
.stack-item .st-text { display: block; font-size: 11px; color: var(--muted); font-weight: 400; max-width: 100%; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.stack-item { flex-wrap: wrap; }
.stack-item .st-main { display: flex; gap: 8px; align-items: center; width: 100%; }

/* deck picker: colour pips, PRECON tag, commander picker */
.pips { display: inline-flex; gap: 3px; vertical-align: middle; }
.cpip { display: inline-block; width: 18px; height: 18px; border-radius: 50%; font: 700 10px/18px system-ui, sans-serif; text-align: center; color: #111; border: 1px solid rgba(0,0,0,.45); }
.cp-W { background: #f8f3d4; } .cp-U { background: #8fc6ee; } .cp-B { background: #9d928d; } .cp-R { background: #f0836a; } .cp-G { background: #7dc48f; } .cp-C { background: #cfd2d6; }
.tag.precon { border-color: #c9a227; color: #f2d77a; font-weight: 700; letter-spacing: .04em; }
.deckpicker { display: flex; flex-direction: column; gap: 6px; min-width: 260px; }
.dsum { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; padding: 6px 8px; background: var(--panel2); border-radius: 8px; }
.cmdbox { display: flex; flex-direction: column; gap: 6px; }
.list .item .pips { flex: none; }

/* Hearthstone-style arrows and hand */
.arrow-layer { position: fixed; inset: 0; width: 100vw; height: 100vh; pointer-events: none; z-index: 90; overflow: visible; }
.arrow-body { animation: arrow-march 1.6s linear infinite; }   /* dots move from the source toward the target (the arrow is drawn source to target) */
@keyframes arrow-march { to { stroke-dashoffset: -12; } }
.arrow.live { animation: arrow-pulse 1s ease-in-out infinite; }
@keyframes arrow-pulse { 50% { opacity: .7; } }
.hand { padding-top: 26px; align-items: flex-end; }
.hand .card { transition: transform .18s cubic-bezier(.2,.8,.2,1), box-shadow .18s; transform-origin: 50% 100%; }
.hand .card + .card { margin-left: -10px; }
.hand .card:hover { transform: translateY(-20px) scale(1.14); z-index: 30; box-shadow: 0 10px 22px #000a; }
.hand .card:hover + .card { transform: translateX(12px); }
.hand .card.playable:hover { transform: translateY(-24px) scale(1.14); }
.card.dragging { opacity: .35; }
.drag-ghost { transform: rotate(-3deg) scale(1.06); box-shadow: 0 14px 28px #000b; transition: none; }
@media (prefers-reduced-motion: reduce) { .arrow-body, .arrow.live { animation: none; } .hand .card { transition: none; } }
/* card images (Scryfall) and the drawn card back */
/* the whole card image is shown: never cropped, stretched or covered at the bottom, where the artist credit and copyright line are */
.card .art { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; border-radius: var(--radius); z-index: 0; pointer-events: none; }
.card.has-art { padding: 0; background: #111; }
.card.has-art .inner, .card.facedown .inner { position: absolute; inset: 0; z-index: 1; background: transparent !important; justify-content: flex-end; pointer-events: none; }
.card.has-art .inner { bottom: 9%; }   /* counters, P/T and keyword badges stay above the artist credit */
.card.has-art .title, .card.has-art .center, .card.has-art .ctype, .card.has-art .rtext, .card.has-art .basic-sym, .card.has-art .kws:not(.granted),
.card.facedown .title, .card.facedown .center, .card.facedown .ctype, .card.facedown .rtext, .card.facedown .kws:not(.granted) { display: none; }
.card.has-art .kws.granted, .card.facedown .kws.granted { background: #000c; color: #9cd0ff; border-radius: 4px; margin: 0 3px 1px; padding: 1px 3px; }
.card.has-art .pt, .card.facedown .pt { box-shadow: 0 1px 3px #000a; }
.card.has-art .zzz { background: #000a; color: #fff; border-radius: 4px; padding: 0 3px; top: 4px; right: 4px; }
.card.has-art.sick .art { opacity: .8; }   /* no recolouring of card art: summoning sickness is shown by the z badge and a dimmer image */
.card.has-art.token .inner::after { content: none; }
.card.has-art.tapped { opacity: .9; }
.card.back, .card.facedown { padding: 0; background: #22130a; }
.card .back-art { position: absolute; inset: 0; width: 100%; height: 100%; border-radius: var(--radius); display: block; }
.libcount { display: inline-flex; align-items: center; gap: 3px; }
.mini-back { display: inline-block; width: 13px; height: 18px; position: relative; border-radius: 2px; overflow: hidden; box-shadow: 0 1px 2px #0008; }
.mini-back .back-art { position: absolute; inset: 0; width: 100%; height: 100%; }
.card.basic-card.has-art .art { object-position: 50% 24%; }
.card .back-img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; border-radius: var(--radius); display: block; }
.mini-back .back-img { border-radius: 2px; }
.mini-back.big { width: 44px; height: 61px; border-radius: 4px; }
.mini-back .back-img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
label.btn { display: inline-flex; align-items: center; font: inherit; color: var(--text); background: var(--panel2); border: 1px solid var(--line); border-radius: 6px; padding: 7px 12px; cursor: pointer; min-height: 36px; } label.btn:hover { border-color: var(--accent2); }

/* @@w2p stack entries and priority buttons */
.stack-item .st-top { color: var(--accent); align-self: flex-start; }
.stack-item .st-body { flex: 1 1 0; min-width: 0; }
.stack-item .st-head { display: inline-flex; gap: 6px; align-items: baseline; flex-wrap: wrap; }
.stack-item .st-kind { font-size: 10px; text-transform: uppercase; letter-spacing: .04em; padding: 1px 5px; border-radius: 4px; border: 1px solid #ffffff30; color: var(--muted); }
.stack-item .st-kind.k-spell { color: #9fc8f2; border-color: #5aa9e680; }
.stack-item .st-kind.k-act, .stack-item .st-kind.k-equip { color: #d9cdfc; border-color: #b8a2f580; }
.stack-item .st-kind.k-trig { color: #f2c6ea; border-color: #e08fd080; }
.stack-item .st-kind.k-loy { color: #c9f0e4; border-color: #5fd6b080; }
.stack-item .st-thumb { width: 30px; height: 42px; flex: 0 0 auto; border-radius: 3px; overflow: hidden; background: #0003 center/cover no-repeat; }
.stack-item .st-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.stack-item .st-ability { display: block; margin: 3px 0 0 0; font-size: 13px; font-weight: 700; color: #c9b6ff; line-height: 1.3; max-width: 100%; overflow-wrap: anywhere; }
.stack-item .st-ability.approx { font-weight: 600; opacity: .85; }
.stack-item .st-meta { font-size: 11px; margin-top: 2px; }
.log-line .log-ab { color: #c9b6ff; font-weight: 700; cursor: pointer; }
.log-ab-full { color: #c9b6ff; line-height: 1.4; }
#hovercard mark.ab-hi { background: #c9b6ff2a; color: #e6dcff; font-weight: 700; border-left: 3px solid #c9b6ff; padding: 0 3px; border-radius: 2px; display: inline-block; }
.actionbar button.endturn { background: #7a2e2e; border-color: #e0574a; color: #fff; font-weight: 700; }
.actionbar button.endturn:hover { background: #963a3a; }
.actionbar button.yieldopp { border-color: var(--accent2); }

/* @@ui1 a window whose card has left the game: stays open, greyed out, until the player closes it */
.modal.gone > *:not(.gone-note):not(.modal-buttons) { opacity: .45; filter: grayscale(1); pointer-events: none; }
.gone-note { background: var(--panel-2, #333); border: 1px solid var(--line, #666); border-radius: 6px; padding: 6px 10px; margin-bottom: 8px; font-weight: 600; }

/* @@ui3 floating +N / -N numbers (src/ui/statfloat.mjs): above everything, never take a click */
#fx-floaters { position: fixed; inset: 0; pointer-events: none; z-index: 1100; overflow: hidden; }
.fx-float { position: absolute; left: 0; top: 0; pointer-events: none; font-family: system-ui, "Segoe UI", Roboto, sans-serif; font-weight: 800; white-space: nowrap; line-height: 1; will-change: transform, opacity; user-select: none; }
.fx-float span { pointer-events: none; }
.stat-flash-up { animation: statflash-up .5s ease-out; } .stat-flash-down { animation: statflash-down .5s ease-out; }
@keyframes statflash-up { 0% { box-shadow: 0 0 0 4px #37d65a, 0 0 14px 6px #37d65a99; } 100% { box-shadow: 0 0 0 0 #37d65a00; } }
@keyframes statflash-down { 0% { box-shadow: 0 0 0 4px #ff4438, 0 0 14px 6px #ff443899; } 100% { box-shadow: 0 0 0 0 #ff443800; } }

/* @@e1 card history panel (src/ui/history.mjs) */
.hist { font-size: 12px; line-height: 1.35; margin-top: 6px; border-top: 1px solid var(--line, #444); padding-top: 6px; }
.hist-h { font-size: 13px; } .hist-pt { font-weight: 700; color: #4ade80; }
.hist-sub { margin-top: 6px; font-weight: 700; font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted, #999); }
.hist-list { margin: 2px 0 0; padding-left: 16px; } .hist-m.grey { opacity: .5; text-decoration: line-through; text-decoration-color: #fff3; }
.hist-q { font-style: italic; opacity: .85; } .hist-note { opacity: .75; } .hist-tok { margin-top: 4px; }
#hist-pins { position: fixed; right: 312px; top: 44px; width: 300px; max-height: calc(100vh - 60px); overflow-y: auto; z-index: 940; display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
.hist-pin { pointer-events: auto; position: relative; background: var(--panel, #1c2128); border: 1px solid var(--accent, #4ade80); border-radius: 8px; padding: 8px 28px 8px 10px; box-shadow: 0 6px 18px #000a; }
.hist-pin .hist { border-top: 0; margin-top: 0; padding-top: 0; } .hist-pin.gone .hist-body > *:not(.gone-note) { opacity: .45; filter: grayscale(1); }
.hist-x { position: absolute; right: 4px; top: 4px; padding: 0 6px; line-height: 20px; }
@media (max-width: 760px) { #hist-pins { right: 8px; top: auto; bottom: 8px; width: min(92vw, 320px); } }

/* MTG Web additions to the MTG Live styles: shell pages, forms, phones. */
.small { font-size: 12.5px; }
.ok { color: #9fe3b5; } .bad { color: #ffb3ab; }
button.big { padding: 10px 18px; font-size: 16px; }
button.link { background: none; border: none; padding: 0 4px; min-height: 0; color: var(--accent2); text-decoration: underline; cursor: pointer; font-size: 12px; }
.panel h2 { font-size: 18px; }
.panel label { display: flex; flex-direction: column; gap: 4px; margin: 8px 0; font-size: 13px; color: var(--muted); }
.panel label > input, .panel label > select, .panel label > span > select, .panel form input { color: var(--text); }
.panel form input[name], .panel > input, form.panel input:not([type=radio]) { width: 100%; }
.panel textarea { min-height: 120px; }
.seg { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }
.seg label { flex-direction: row; align-items: center; gap: 6px; margin: 0; padding: 6px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel2); color: var(--text); cursor: pointer; }
.seg label:has(input:checked) { border-color: var(--accent); }
.seg label:has(input:disabled) { opacity: .55; cursor: default; }
.deckpick select { width: 100%; }
.bots { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin: 8px 0; font-size: 13px; color: var(--muted); }
.hero h1 { font-size: 24px; }
.hero p { max-width: 60ch; }
.banner { padding: 10px 12px; border-radius: 8px; background: #3a1d1a; border: 1px solid var(--bad); margin-bottom: 10px; }
.banner.info { background: #1a2a3a; border-color: var(--accent2); }
.prose { max-width: 820px; line-height: 1.55; }
.prose li { margin: 4px 0; }
.notice { border-left: 3px solid var(--accent); padding-left: 10px; }
.code { font-family: Consolas, monospace; font-size: 20px; letter-spacing: 3px; color: var(--accent); }
.decklist { white-space: pre-wrap; font-size: 12.5px; max-height: 50vh; overflow: auto; background: #0e1217; padding: 8px; border-radius: 6px; }
.log-line.sys { color: var(--muted); font-style: italic; }
.chat-tools { opacity: .6; } .log-line:hover .chat-tools { opacity: 1; }
table.stats { border-collapse: collapse; width: 100%; font-size: 13px; }
table.stats td, table.stats th { border-bottom: 1px solid var(--line); padding: 4px 6px; text-align: left; }
.loading .small { margin-top: 10px; }
/* @@live1 waiting / connecting states */
.spinner { display: inline-block; width: 16px; height: 16px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin9 .9s linear infinite; vertical-align: -3px; margin-right: 8px; }
@keyframes spin9 { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } }
.code.big { font-size: 34px; letter-spacing: 6px; }
.invite { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin: 6px 0; }
.invite input { flex: 1; min-width: 220px; }
.waitline { font-size: 16px; margin: 10px 0; }

/* phones: header wraps, nav scrolls sideways, big touch targets */
@media (max-width: 640px) {
  header.top { flex-wrap: wrap; padding: 6px 10px; gap: 6px; }
  header.top nav { order: 3; width: 100%; overflow-x: auto; scrollbar-width: none; }
  header.top nav button { flex: 0 0 auto; padding: 6px 10px; }
  header.top .me { font-size: 12px; }
  main.page { padding: 10px 16px; }
  .panel { padding: 10px 12px; }
  button { min-height: 40px; }
  .seg label { flex: 1 1 auto; justify-content: center; }
  table.stats { font-size: 12px; }
}
@supports (padding: env(safe-area-inset-bottom)) { main.page { padding-bottom: calc(10px + env(safe-area-inset-bottom)); } }
/* in a game on a phone the board gets the whole screen (Leave is in the Log / Chat panel) */
@media (max-width: 640px) { body.in-game header.top { display: none; } }

/* effects canvas (src/ui/fx.mjs): above the board, never takes the pointer */
.fx-canvas { position: fixed; inset: 0; width: 100vw; height: 100vh; pointer-events: none; z-index: 800; }

/* ---------- card sizes: guards ---------- */
/* Every card is one 5:7 box (see --card-w / --card-h in styles.css). Nothing may stretch or squash it. */
.hand .card, .zone .card, .stack-item .card, .choice-cards .card, .item .card, .modal .card:not(.zoom .card) { flex: 0 0 auto; }
.card .art, .card .back-img, .card .back-art { object-position: center; }
.card .title .name, .card .ctype { min-width: 0; }

/* ---------- mana pool ---------- */
.pool { display: inline-flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 2px 8px; border: 1px solid var(--line); border-radius: 8px; background: #0e1217; min-height: 28px; }
.pool-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.mchip { display: inline-flex; align-items: center; gap: 2px; padding: 0 6px 0 2px; border-radius: 12px; background: var(--panel2); border: 1px solid var(--line); font-size: 13px; }
.mchip b { font-weight: 700; }
.pool-hint { font-size: 11px; color: var(--accent2); }

/* ---------- sound control in the top bar ---------- */
header.top .snd { display: inline-flex; gap: 0; align-items: center; margin-left: auto; }
header.top .snd button { padding: 4px 6px; font-size: 16px; }

/* ---------- table layout: opponents small along the top, my side large, stack as an overlay ---------- */
.board { grid-template-columns: minmax(0, 1fr) var(--side-w, 300px); grid-template-rows: clamp(120px, 33vh, 340px) minmax(0, 1fr) auto; }
.board.side-min { --side-w: 40px; }
.board .opps { overflow: hidden; gap: 6px; padding: 6px; }
.board .opps .opp { flex: 1 1 0; min-width: 0; overflow: hidden; display: flex; flex-direction: column; gap: 2px; --card-w: 58px; --card-h: 81.2px; --mini-w: 58px; --mini-h: 81.2px; }
.board .opps.n1 .opp { --card-w: 76px; --card-h: 106.4px; --mini-w: 76px; --mini-h: 106.4px; }
.board .opps .opp .zone { flex: 1 1 auto; min-height: 0; overflow: auto; padding: 2px; gap: 4px; align-content: flex-start; }
.board .opps .opp .card .rtext, .board .opps .opp .card .ctype, .board .opps .opp .card .kws { display: none; }
.board .opps .opp .card .title { font-size: 8px; }
.board .opps .opp .card.compact { padding: 2px; }
.board .opps .opp .pinfo { gap: 6px; font-size: 12px; }
.board .field { padding: 6px 8px; gap: 4px; }
.board .field .zone.mine { flex: 0 0 auto; }
.board .stackzone { grid-column: 1; grid-row: 2; align-self: start; justify-self: end; z-index: 30; width: min(280px, 38vw); max-height: 60%; overflow: auto; margin: 8px 12px; background: #151b22f2; box-shadow: 0 6px 20px #000a; }
.board .side.min { align-items: center; padding-top: 6px; gap: 8px; overflow: hidden; }
.board .side.min .sidemin-label { writing-mode: vertical-rl; color: var(--muted); font-size: 12px; letter-spacing: 1px; }
.sidemin-btn { flex: 0 0 auto; border: 0; background: transparent; }
.cmdchip { display: inline-flex; align-items: center; gap: 4px; padding: 1px 6px; border-radius: 10px; background: var(--panel2); border: 1px solid var(--line); cursor: pointer; font-size: 12px; max-width: 220px; }
.cmdchip .cn { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cmdchip .ci { display: inline-flex; gap: 1px; }
.cmdchip .ci .ms { width: 1em; height: 1em; }
.cmdchip.ready { border-color: var(--accent); box-shadow: 0 0 6px var(--accent); }
.resp { color: var(--muted); font-weight: 400; }
.resp.low { color: var(--bad); font-weight: 700; }
/* hover: a large upright card (art and text), with the readable text and live state underneath */
#hovercard { width: auto; max-width: 340px; padding: 8px; }
#hovercard .hv-card .card { --card-w: min(300px, 38vh * 0.714); --card-h: min(420px, 38vh); margin: 0 auto; rotate: none; box-shadow: 0 2px 10px #000a; }
#hovercard .hv-card .card .rules { font-size: 11px; }
#hovercard .hv-text { margin-top: 6px; max-height: 32vh; overflow: hidden; font-size: 12px; }
.castfly { position: fixed; left: 50%; top: 50%; z-index: 1300; pointer-events: none; margin: -168px 0 0 -120px; }
.castfly .card { --card-w: 240px; --card-h: 336px; box-shadow: 0 10px 40px #000c; }
@media (max-width: 900px) {
  .board { grid-template-rows: clamp(100px, 28vh, 240px) minmax(0, 1fr) auto; }
  .board .stackzone { width: min(240px, 60vw); }
}
/* my battlefield: one open area, no boxes. Drop a card anywhere on it (or anywhere on the table) to cast it. */
.board .field .mybf { flex: 1 1 auto; min-height: 120px; display: flex; flex-direction: column; gap: 4px; border-radius: 8px; }
.board .field .mybf .zone.mine { background: none; border: 0; padding: 2px; min-height: 0; }
.board .field .mybf .zone.mine:empty { display: none; }

/* Table layouts (src/ui/layouts.mjs). Card SIZES are not set here: the script fits them to each area and writes them as
   --card-w / --card-h (always 5:7). The sizes below are only the first guess before it runs. */
.board.lay { grid-template-rows: minmax(0, var(--top-fr, .6fr)) auto minmax(0, var(--bot-fr, 1fr)) auto; }
.board.lay .opps { grid-row: 1; }
.board.lay .opps.empty { display: none; }
.board.lay .field { grid-row: 3; overflow: hidden; display: flex; flex-direction: column; gap: 4px; }
.board.lay .handbar { grid-row: 4; }
.board.lay .side { grid-row: 1 / span 4; }

/* the stack sits in its own band between the top row and my row: it never covers a battlefield, a hand or a button, and takes no room when empty */
.board.lay .stackzone { grid-column: 1; grid-row: 2; align-self: stretch; justify-self: stretch; width: auto; max-height: 27vh; margin: 4px 8px; display: flex; flex-wrap: nowrap; gap: 6px; align-items: stretch; overflow: auto; border-color: var(--accent); background: #1b2330; box-shadow: 0 0 10px #e0a63a44; }
.board.lay .stackzone > .zone-label { flex: 0 0 auto; writing-mode: vertical-rl; transform: rotate(180deg); align-self: center; white-space: nowrap; }
.board.lay .stackzone > .stack-item { flex: 0 0 clamp(220px, 24vw, 340px); border: 1px solid var(--line); border-radius: 6px; align-content: flex-start; overflow: auto; }

/* every player's cards spread across the whole width of their area, not packed to the left */
.board.lay .zone { justify-content: center; align-content: flex-start; min-height: 0; }
.board.lay .opps { gap: 6px; padding: 6px; }
.board.lay .opp { flex: 1 1 0; min-width: 0; overflow: hidden; display: flex; flex-direction: column; gap: 2px; --card-w: 58px; --card-h: 81.2px; --mini-w: var(--card-w); --mini-h: var(--card-h); }
.board.lay .opp > .zones { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; gap: 4px; overflow: auto; }
.board.lay .opp .zone { flex: 0 1 auto; padding: 2px; gap: 4px; }
.board.lay .opp > .zones.sbs, .board.lay .field .mybf.sbs { flex-direction: row; }
.board.lay .zones.merge { flex-direction: row; flex-wrap: wrap; justify-content: center; align-content: flex-start; padding: 2px; }
.board.lay .zones.merge > .zone { display: contents; }
.board.lay .sbs > .zone { min-width: 0; align-self: stretch; }
.board.lay .opp .card .rtext, .board.lay .opp .card .ctype, .board.lay .opp .card .kws { display: none; }
.board.lay .opp .card .title { font-size: 8px; }
.board.lay .opp .card.compact { padding: 2px; }
.board.lay .opp .pinfo { gap: 4px 6px; font-size: 12px; }
.board.lay .opp .pinfo .cmdchip { max-width: 130px; }
.board.lay .opp .pinfo .pname { font-size: 13px; }

/* my row: me in the middle, an opponent on my left and/or right when the layout seats one there */
.board.lay .lay-row { flex: 1 1 0; min-height: 0; display: flex; gap: 8px; }
.board.lay .mecol { flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.board.lay .lay-row > .opp.seated { border-color: #3d4b5d; }
.board.lay .mecol .me-strip { flex: 0 0 auto; }
.board.lay .field .mybf { flex: 1 1 0; min-height: 0; overflow: auto; justify-content: flex-start; }
.board.lay .field .mybf .zone.mine { justify-content: center; }

/* the layout drop-down in the phase bar */
.layout-pick { flex: 0 0 auto; margin-right: 8px; display: inline-flex; gap: 6px; align-items: center; font-size: 12px; color: var(--muted); white-space: nowrap; }
.layout-pick select { min-height: 28px; padding: 2px 6px; font-size: 12px; max-width: 230px; }

@media (max-width: 700px) {
  .board.lay .lay-row { flex-direction: column; }
}

/* @@ui2 editable layout (src/ui/layoutedit.mjs) */
@media (min-width: 700px) { .board.ed { grid-template-columns: minmax(0, 1fr) var(--side-w, 300px); position: relative; } }
.board.ed-hide-side > .side { display: none; }
.board.ed-hide-phase .phasebar .ph, .board.ed-hide-phase .phasebar > .muted:first-child { display: none; }
.board.ed-hide-pool .me-strip .pool { display: none; }
.board.ed-hide-lands .mybf > .zone:nth-child(2), .board.ed-hide-other .mybf > .zone:nth-child(1) { display: none; }
.board.ed .mybf { display: flex; flex-direction: column; }
.board.ed .mybf > .zone:nth-child(1) { order: 1; } .board.ed .mybf > .zone:nth-child(2) { order: 2; }
.board.ed.ed-landsfront .mybf > .zone:nth-child(1) { order: 2; } .board.ed.ed-landsfront .mybf > .zone:nth-child(2) { order: 1; }
.board.ed .mybf .zone { gap: var(--bf-gap, 6px); }
.board.ed .mybf .card:not(.grouped) + .card:not(.grouped) { margin-left: calc(var(--card-w) * var(--bf-overlap, 0) * -1); }
.board.ed .mybf .card.grouped { display: none; }
.card .gcount { position: absolute; right: 4px; bottom: 4px; background: #000c; color: #fff; border: 1px solid #fff8; border-radius: 10px; padding: 0 6px; font-weight: 700; font-size: 13px; z-index: 5; pointer-events: none; }
.ed-handle { position: absolute; z-index: 700; touch-action: none; background: #4ade8055; border: 1px dashed #4ade80; }
.ed-handle.ed-v { top: 0; bottom: 0; width: 10px; cursor: col-resize; }
.ed-handle.ed-h { left: 0; height: 10px; cursor: row-resize; }
.ed-on .board .opp, .ed-on .board .mybf, .ed-on .board .handbar { outline: 1px dashed #ffffff40; outline-offset: -2px; }
.ed-bar { position: fixed; left: 8px; bottom: 8px; z-index: 950; display: flex; flex-wrap: wrap; gap: 6px; align-items: flex-end; max-width: min(340px, 94vw); }
.ed-bar button { font-size: 12px; padding: 4px 8px; opacity: .85; }
.ed-bar.on .ed-toggle { background: var(--accent, #4ade80); color: #000; opacity: 1; }
.ed-panel { flex-basis: 100%; background: var(--panel, #1c2128); border: 1px solid var(--line, #444); border-radius: 8px; padding: 8px; max-height: 70vh; overflow: auto; box-shadow: 0 6px 20px #000a; order: -1; }
.ed-panel[hidden] { display: none; }
.ed-row { display: flex; align-items: center; gap: 6px; margin: 4px 0; font-size: 12px; } .ed-row span { flex: 0 0 120px; } .ed-row input[type=range] { flex: 1; min-width: 0; } .ed-row b { width: 44px; text-align: right; }
.ed-sub { margin-top: 8px; font-weight: 700; font-size: 12px; } .ed-note { font-size: 11px; opacity: .7; margin: 4px 0; }
@media (prefers-reduced-motion: no-preference) { .ed-panel { transition: none; } }
.ed-bar { top: 5px; bottom: auto; left: auto; right: 230px; justify-content: flex-end; align-items: flex-start; }
.ed-panel { order: 0; width: 330px; }
.ed-bar button { padding: 2px 7px; }
.ed-bar.off { display: none; }
@media (max-width: 760px) { .ed-bar { left: auto; right: 8px; top: 44px; } }
