:root {
  --felt: #12352b;
  --felt-2: #0d2a22;
  --wood: #2a1a12;
  --ink: #f3ecdf;
  --muted: #b9c4bb;
  --brass: #e0a93b;
  --brass-ink: #2a1a06;
  --panel: #18261f;
  --line: rgba(255, 255, 255, .12);
  --red: #e2475b;
  --teal: #4fd1c5;
  --lime: #b5e655;
  --blue: #6aa8ff;
  --cw: clamp(46px, min(5.8vw, 9.6vh), 118px);
  --ch: calc(var(--cw) * 1.396);
  --hw: calc(var(--cw) * 1.08);
  color-scheme: dark;
}
* { box-sizing: border-box; min-width: 0; }
html, body { height: 100%; }
body { margin: 0; background: var(--felt-2); color: var(--ink); font: 15px/1.45 Barlow, system-ui, sans-serif; overflow-x: hidden; }
[hidden] { display: none !important; }
h1, h2, h3 { font-family: "Barlow Condensed", Barlow, sans-serif; letter-spacing: .01em; margin: 0 0 .5em; }
h1 { font-size: clamp(36px, 5vw, 56px); line-height: 1.02; }
h2 { font-size: 24px; }
h3 { font-size: 18px; margin-top: 1em; }
input, select, button { font: inherit; color: inherit; }
input, select { background: #0b1c16; border: 1px solid #3c5a4d; border-radius: 8px; padding: 9px 11px; min-height: 40px; font-size: 16px; }
input:focus, select:focus { outline: 2px solid var(--brass); outline-offset: 1px; }
kbd { background: #0b1c16; border: 1px solid #3c5a4d; border-radius: 4px; padding: 0 5px; font-size: 13px; }
.btn { background: #24423a; border: 1px solid #3f6557; border-radius: 8px; padding: 8px 14px; min-height: 40px; cursor: pointer; font-weight: 600; white-space: nowrap; }
.btn:hover { background: #2d5247; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--brass); color: var(--brass-ink); border-color: #f1c46a; }
.btn.primary:hover { background: #ecb951; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.small { min-height: 30px; padding: 4px 10px; font-size: 13px; }
.btn.big { width: 100%; min-height: 50px; font-size: 18px; }
.btn.on { background: var(--brass); color: var(--brass-ink); }
.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.row input { flex: 1; }
.spacer { flex: 1; }
.msg { color: #ffb4a8; min-height: 1.4em; margin: 8px 0 0; }
.hint { color: var(--muted); font-size: 13px; margin: 6px 0; }

/* HOME */
#home { min-height: 100%; background: radial-gradient(1200px 600px at 20% -10%, #1f5443 0%, transparent 60%), var(--felt-2); }
.home-wrap { max-width: 1100px; margin: 0 auto; padding: 32px max(5vw, 16px) 48px; }
.home-hero { display: flex; gap: 28px; align-items: center; margin-bottom: 28px; }
.hero-card { width: 120px; border-radius: 8px; box-shadow: 0 12px 30px rgba(0, 0, 0, .5); transform: rotate(-6deg); }
.lede { font-size: 18px; color: var(--muted); max-width: 46ch; margin: 0; }
.home-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.3fr); gap: 20px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 20px; }
.field { display: grid; gap: 6px; margin-bottom: 14px; color: var(--muted); font-size: 14px; }
.field input { color: var(--ink); }
.or { text-align: center; color: var(--muted); margin: 14px 0 10px; font-size: 14px; }
.how { margin-top: 20px; }
.how summary { cursor: pointer; font-weight: 600; }
.how li { margin: 6px 0; color: var(--muted); }
.deck-list { display: grid; gap: 8px; margin-bottom: 14px; }
.deck-item { display: grid; grid-template-columns: 64px minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 8px; border: 1px solid var(--line); border-radius: 10px; background: #13201a; }
.deck-item img { width: 64px; border-radius: 4px; }
.deck-item .name { font-weight: 600; }
.deck-item .sub { color: var(--muted); font-size: 13px; }
.deck-item .acts { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.deck-item.chosen { border-color: var(--brass); box-shadow: 0 0 0 1px var(--brass) inset; }
.empty { color: var(--muted); padding: 12px; border: 1px dashed var(--line); border-radius: 10px; }

/* BARS */
.bar { display: flex; align-items: center; gap: 10px; padding: 8px max(1.5vw, 10px); background: var(--wood); border-bottom: 1px solid #000; flex-wrap: wrap; }
.deck-name { width: min(280px, 40vw); }
.room b { font-family: "Barlow Condensed"; font-size: 20px; letter-spacing: .08em; color: var(--brass); margin: 0 6px; }
.players { display: flex; gap: 14px; }
.pl { display: flex; align-items: center; gap: 6px; font-weight: 600; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: #666; }
.dot.on { background: #5be37a; }
.toggle { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 14px; }
.toggle input { min-height: 0; }

/* BUILDER */
#builder { display: flex; flex-direction: column; height: 100%; }
.builder-body { flex: 1; display: grid; grid-template-columns: minmax(0, 1fr) 340px; min-height: 0; }
.pool { overflow: auto; padding: 12px max(1.5vw, 10px); }
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; position: sticky; top: -12px; background: var(--felt-2); padding: 10px 0; z-index: 2; }
.filters #search { flex: 1 1 220px; }
.chips { display: flex; gap: 4px; flex-wrap: wrap; }
.chip { border: 1px solid #3f6557; background: #142a22; border-radius: 99px; padding: 4px 10px; cursor: pointer; font-size: 13px; font-weight: 600; }
.chip.on { background: var(--brass); color: var(--brass-ink); border-color: var(--brass); }
.pool-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(128px, 1fr)); gap: 10px; }
.pc { position: relative; cursor: pointer; user-select: none; }
.pc img { width: 100%; border-radius: 6px; display: block; }
.pc.land img { aspect-ratio: 698/500; object-fit: contain; }
.pc .qty { position: absolute; top: 6px; right: 6px; background: var(--brass); color: var(--brass-ink); font-weight: 700; border-radius: 99px; min-width: 26px; height: 26px; display: grid; place-items: center; box-shadow: 0 2px 6px rgba(0, 0, 0, .5); }
.pc.max img { opacity: .55; }
.deck-side { border-left: 1px solid var(--line); background: #10201a; padding: 12px; overflow: auto; }
.lb-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.slot-box { aspect-ratio: 698/500; border: 1px dashed #4f7365; border-radius: 8px; display: grid; place-items: center; color: var(--muted); overflow: hidden; cursor: pointer; }
.slot-box img { width: 100%; height: 100%; object-fit: cover; }
.deck-count { margin: 12px 0 6px; font-size: 16px; }
.deck-count b { font-size: 22px; }
#deckWarn { color: #ffcf7a; font-size: 13px; }
.curve { display: grid; grid-template-columns: repeat(9, 1fr); gap: 3px; align-items: end; height: 54px; margin-bottom: 8px; }
.curve div { background: var(--brass); border-radius: 3px 3px 0 0; position: relative; min-height: 2px; }
.curve span { position: absolute; bottom: -18px; left: 0; right: 0; text-align: center; font-size: 11px; color: var(--muted); }
.deck-cards { margin-top: 24px; display: grid; gap: 3px; }
.dl { display: grid; grid-template-columns: 26px 22px minmax(0, 1fr) auto; gap: 6px; align-items: center; padding: 4px 6px; border-radius: 6px; background: #162a22; cursor: pointer; font-size: 14px; }
.dl:hover { background: #1f3a2f; }
.dl .c { background: #0b1c16; border-radius: 4px; text-align: center; font-weight: 700; }
.dl .n { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dl .x { color: var(--muted); }
.asp { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 2px; }
.asp.Steady { background: var(--blue); } .asp.Pacer { background: var(--lime); } .asp.Rowdy { background: var(--red); } .asp.Chancer { background: #ffd84a; } .asp.Heroism { background: #efe3bf; } .asp.Villainy { background: #222; border: 1px solid #888; }

/* GAME */
#game { display: flex; flex-direction: column; height: 100%; }
.lobby { flex: 1; overflow: auto; padding: 24px max(5vw, 16px); }
.lobby .panel { max-width: 760px; margin: 0 auto; }
#inviteLink { flex: 1; }
.table-wrap { flex: 1; display: grid; grid-template-columns: minmax(0, 1fr) 300px; min-height: 0; }
.table { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; background: radial-gradient(ellipse at center, #1a4a3b 0%, var(--felt) 55%, #0b241d 100%); min-height: 0; overflow: auto; }
.side { padding: 6px 10px; }
.side.opp { border-bottom: 1px solid rgba(0, 0, 0, .35); }
.side.me { border-top: 1px solid rgba(0, 0, 0, .35); background: rgba(0, 0, 0, .15); }
.strip { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 12px; align-items: center; }
.pile-group { display: flex; gap: 8px; }
.pile { width: var(--cw); height: var(--ch); border-radius: 6px; border: 1px dashed rgba(255, 255, 255, .2); position: relative; display: grid; place-items: center; font-size: 12px; color: var(--muted); }
.pile .card { position: absolute; inset: 0; width: 100%; height: 100%; }
.pile .count { position: absolute; bottom: -2px; left: 50%; transform: translate(-50%, 50%); background: #000c; padding: 0 8px; border-radius: 99px; font-weight: 700; font-size: 13px; color: var(--ink); z-index: 3; }
.pile-label { position: absolute; top: -16px; left: 0; right: 0; text-align: center; font-size: 11px; color: var(--muted); }
.side.me .pile-label { top: auto; bottom: -20px; }
.zone { display: flex; gap: 6px; align-items: center; min-height: calc(var(--ch) + 6px); border-radius: 10px; padding: 3px; }
.zone.drop { outline: 2px dashed var(--brass); background: rgba(224, 169, 59, .08); }
.hand { justify-content: center; }
.hand .card { width: var(--hw); height: calc(var(--hw) * 1.396); margin-left: calc(var(--hw) * var(--ov, 0)); transition: transform .12s; }
.hand .card:first-child { margin-left: 0; }
.hand .card:hover { transform: translateY(-14px); z-index: 5; }
.opp-hand .card { width: calc(var(--cw) * .55); height: calc(var(--cw) * .55 * 1.396); }
.opp-hand { min-height: calc(var(--cw) * .55 * 1.396 + 6px); }
.side.opp .pile { width: calc(var(--cw) * .7); height: calc(var(--cw) * .7 * 1.396); }
.resources { justify-content: flex-end; flex-wrap: nowrap; }
.res-pile { display: flex; align-items: center; gap: 8px; }
.res-stack { position: relative; height: calc(var(--cw) * .6 * 1.396); width: calc(var(--cw) * .6 + var(--n, 0) * 7px); }
.res-stack .card { position: absolute; top: 0; width: calc(var(--cw) * .6); height: calc(var(--cw) * .6 * 1.396); }
.res-num { font-family: "Barlow Condensed"; font-size: 20px; line-height: 1; text-align: center; }
.res-num small { display: block; font-family: Barlow; font-size: 11px; color: var(--muted); }
.my-res { display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; max-width: 46vw; }
.my-res { --cw: clamp(36px, min(3.6vw, 6.4vh), 80px); --ch: calc(var(--cw) * 1.396); }

.battlefield { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); gap: 10px; padding: 8px 10px; min-height: 0; }
.arena { position: relative; display: grid; grid-template-rows: 1fr 1fr; gap: 10px; border-radius: 14px; padding: 22px 8px 8px; min-height: 0; }
.arena.space { background: linear-gradient(180deg, rgba(40, 60, 120, .28), rgba(40, 60, 120, .12) 50%, rgba(40, 60, 120, .28)); }
.arena.ground { background: linear-gradient(180deg, rgba(120, 85, 40, .28), rgba(120, 85, 40, .12) 50%, rgba(120, 85, 40, .28)); }
.arena-label { position: absolute; top: 3px; left: 12px; font-family: "Barlow Condensed"; font-weight: 700; letter-spacing: .08em; color: rgba(255, 255, 255, .45); font-size: 14px; }
.units { flex-wrap: wrap; align-content: center; justify-content: center; }
#oppSpace, #oppGround { align-content: flex-end; border-bottom: 1px dashed rgba(255, 255, 255, .12); border-radius: 10px 10px 0 0; }
.center { display: grid; grid-template-rows: auto auto auto; gap: 8px; align-content: center; justify-items: center; }
.lb { display: flex; gap: 8px; }
.round { font-family: "Barlow Condensed"; text-align: center; color: var(--muted); font-size: 15px; line-height: 1.2; }
.round b { color: var(--ink); font-size: 18px; }
.init { display: inline-block; background: var(--brass); color: var(--brass-ink); border-radius: 99px; padding: 1px 10px; font-weight: 700; margin-top: 3px; }

/* CARDS */
.slot { position: relative; width: var(--cw); display: flex; flex-direction: column; align-items: center; transition: width .15s; }
.slot.ex { width: var(--ch); }
.card { position: relative; width: var(--cw); height: var(--ch); border-radius: calc(var(--cw) * .07); background: #000 center/cover no-repeat; box-shadow: 0 2px 6px rgba(0, 0, 0, .55); cursor: pointer; flex: none; user-select: none; -webkit-user-drag: element; }
.card.land { width: var(--ch); height: var(--cw); }
.card.back { background-image: url(extras/card_back.jpg); }
.slot .card { transition: transform .15s; }
.slot.ex > .card { transform: rotate(90deg); margin: calc((var(--ch) - var(--cw)) / -2) 0; }
.card.exl { transform: rotate(90deg); filter: brightness(.7); }
.card.dimx { filter: brightness(.6); }
.card:hover { outline: 2px solid var(--brass); }
.card.sel { outline: 3px solid var(--brass); }
.card.target { outline: 3px solid #5be37a; animation: pulse 1s infinite; }
@keyframes pulse { 50% { outline-color: transparent; } }
.badges { position: absolute; inset: 0; pointer-events: none; }
.badge { position: absolute; min-width: 22px; height: 22px; border-radius: 99px; display: grid; place-items: center; font-weight: 800; font-size: 13px; padding: 0 5px; box-shadow: 0 1px 4px rgba(0, 0, 0, .7); }
.badge.dmg { background: var(--red); color: #fff; top: 30%; left: 50%; transform: translateX(-50%); font-size: 15px; min-width: 28px; height: 28px; }
.badge.sh { background: #9ad3ff; color: #082033; bottom: 4px; left: 4px; }
.badge.xp { background: #ffd84a; color: #2f2400; bottom: 4px; right: 4px; }
.slot.ex .badges { transform: rotate(-90deg); }
.upgrades { display: flex; flex-direction: column; align-items: center; margin-top: 3px; gap: 2px; }
.upgrades .card { width: calc(var(--cw) * .92); height: calc(var(--cw) * .32); background-size: 100% auto; background-position: center 92%; border-radius: 4px; }
.base-card { position: relative; }
.hp { position: absolute; right: -6px; top: -6px; background: #0b1c16; border: 2px solid var(--teal); color: var(--ink); border-radius: 99px; min-width: 40px; height: 32px; display: grid; place-items: center; font-family: "Barlow Condensed"; font-weight: 700; font-size: 20px; padding: 0 6px; z-index: 4; pointer-events: none; }
.hp.low { border-color: var(--red); color: #ffd0d6; }
.base-dmg { position: absolute; left: 50%; bottom: -10px; transform: translateX(-50%); display: flex; gap: 3px; z-index: 4; }
.base-dmg button { width: 28px; height: 24px; min-height: 0; padding: 0; border-radius: 6px; background: #0b1c16e6; border: 1px solid #3f6557; font-weight: 800; cursor: pointer; font-size: 13px; }
.base-dmg button:hover { background: var(--red); }
.empty-slot { width: var(--ch); height: var(--cw); border: 1px dashed rgba(255, 255, 255, .2); border-radius: 6px; display: grid; place-items: center; color: var(--muted); font-size: 12px; }

/* SIDEBAR */
.sidebar { display: grid; grid-template-rows: auto auto minmax(0, 1fr) auto; background: #0f1d18; border-left: 1px solid #000; min-height: 0; }
.preview { aspect-ratio: 500/698; max-height: 44vh; display: grid; place-items: center; padding: 8px; color: var(--muted); font-size: 13px; text-align: center; }
.preview img { max-width: 100%; max-height: calc(44vh - 16px); border-radius: 10px; box-shadow: 0 6px 20px rgba(0, 0, 0, .6); }
.controls { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; padding: 6px 8px; border-top: 1px solid var(--line); }
.controls .btn { min-height: 34px; padding: 4px 8px; font-size: 13px; }
.log { overflow: auto; padding: 8px 10px; font-size: 13px; border-top: 1px solid var(--line); }
.log p { margin: 0 0 5px; color: var(--muted); }
.log p b { color: var(--ink); }
.log p.sys { color: var(--brass); }
.log p.chat { color: var(--ink); }
.log .cn { color: var(--ink); text-decoration: underline dotted; cursor: help; }
.chat { display: flex; gap: 6px; padding: 8px; border-top: 1px solid var(--line); }
.chat input { flex: 1; min-height: 34px; padding: 6px 8px; }

/* MENU / MODAL */
.menu { position: fixed; z-index: 80; background: #1b2d26; border: 1px solid #4b7366; border-radius: 10px; padding: 5px; box-shadow: 0 10px 30px rgba(0, 0, 0, .6); min-width: 190px; max-height: 80vh; overflow: auto; }
.menu .mh { padding: 4px 10px 6px; font-weight: 700; color: var(--brass); font-size: 13px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.menu button { display: block; width: 100%; text-align: left; background: none; border: 0; padding: 7px 10px; border-radius: 6px; cursor: pointer; font-size: 14px; }
.menu button:hover { background: #2d5247; }
.menu .sep { height: 1px; background: var(--line); margin: 4px 0; }
.menu .cnt { display: flex; align-items: center; gap: 4px; padding: 3px 10px; font-size: 14px; }
.menu .cnt span { flex: 1; }
.menu .cnt button { width: 30px; text-align: center; background: #0b1c16; padding: 3px 0; }
.modal { position: fixed; inset: 0; background: rgba(0, 0, 0, .65); z-index: 60; display: grid; place-items: center; padding: 16px; }
.modal-box { background: var(--panel); border: 1px solid #4b7366; border-radius: 14px; padding: 16px; width: min(1000px, 100%); max-height: 90vh; overflow: auto; }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.modal-head h3 { margin: 0; }
.peek-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; }
.peek-grid .pc img { border-radius: 6px; }
.peek-grid .pos { position: absolute; top: 4px; left: 4px; background: #000c; border-radius: 99px; padding: 0 7px; font-size: 12px; font-weight: 700; }
textarea { width: 100%; min-height: 220px; background: #0b1c16; color: var(--ink); border: 1px solid #3c5a4d; border-radius: 8px; padding: 10px; font: 14px/1.4 ui-monospace, monospace; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: #000d; padding: 10px 16px; border-radius: 10px; z-index: 70; max-width: 90vw; }
.attach-hint { position: fixed; top: 60px; left: 50%; transform: translateX(-50%); background: var(--brass); color: var(--brass-ink); font-weight: 700; padding: 8px 16px; border-radius: 99px; z-index: 40; }

@media (max-width: 1100px) {
  .table-wrap { grid-template-columns: minmax(0, 1fr) 240px; }
  .preview { max-height: 30vh; }
  .preview img { max-height: calc(30vh - 16px); }
}
@media (max-width: 820px) {
  :root { --cw: clamp(40px, 9vw, 70px); }
  .side.opp .pile { width: calc(var(--cw) * .6); height: calc(var(--cw) * .84); }
  .home-grid { grid-template-columns: minmax(0, 1fr); }
  .home-hero { flex-direction: column; align-items: flex-start; }
  .builder-body { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) 40vh; }
  .deck-side { border-left: 0; border-top: 1px solid var(--line); }
  .table-wrap { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto; }
  .sidebar { grid-template-rows: auto auto 140px auto; }
  .preview { display: none; }
  .controls { grid-template-columns: repeat(5, 1fr); }
  .battlefield { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .center { grid-column: 1 / -1; grid-row: 1; grid-template-columns: auto auto auto; grid-template-rows: auto; }
}
