/* MTG Companion — dark, thumb-first, built for a phone lying on the table. */
:root {
  --bg: #14101c; --panel: #1d1826; --panel-2: #262031; --line: #352d44;
  --ink: #f2eff7; --dim: #9c93ad; --accent: #a48fff; --warn: #f0a33c; --bad: #f87171; --good: #4ade80;
  --sans: -apple-system, system-ui, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { background: var(--bg); }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.45 var(--sans); min-height: 100vh; display: flex; flex-direction: column; user-select: none; }

.topbar { display: flex; align-items: center; gap: .8rem; padding: .65rem .9rem; }
.hub-link { color: var(--dim); text-decoration: none; font-size: .78rem; font-weight: 700; }
.app-title { font-weight: 800; letter-spacing: -.02em; font-size: .95rem; }
#reset-btn { margin-left: auto; }

main { flex: 1; padding: 0 .8rem calc(4.6rem + env(safe-area-inset-bottom)); max-width: 760px; margin: 0 auto; width: 100%; }
.cpanel.hidden { display: none; }
h2 { font-size: .95rem; margin: .9rem 0 .6rem; color: var(--dim); font-weight: 700; text-transform: uppercase; letter-spacing: .07em; }
.hint { color: var(--dim); font-size: .85rem; }
.hint-sm { color: var(--dim); font-size: .68rem; margin-top: .3rem; }

/* Chips & small buttons */
.chip {
  border: 1px solid var(--line); background: var(--panel); color: var(--dim); border-radius: 999px;
  font: inherit; font-size: .8rem; font-weight: 700; padding: .34rem .8rem; cursor: pointer; min-height: 36px;
}
.chip.on { background: var(--accent); border-color: var(--accent); color: #170f2b; }
.chip.warn { color: var(--warn); border-color: rgba(240,163,60,.5); }
.chip.poison { color: var(--good); border-color: rgba(74,222,128,.5); }
.mini {
  border: 1px solid var(--line); background: var(--panel-2); color: var(--ink); border-radius: 10px;
  font: inherit; font-weight: 800; padding: .3rem .75rem; cursor: pointer; min-height: 38px; min-width: 44px;
}

/* ---- Life seats ---- */
.setup-row { display: flex; gap: .4rem; align-items: center; flex-wrap: wrap; padding: .5rem 0 .7rem; }
.setup-row .sep { flex: 0 0 8px; }
.seats { display: grid; gap: .6rem; }
.seats-2 { grid-template-rows: 1fr 1fr; min-height: 66vh; }
.seats-3 { grid-template-columns: 1fr 1fr; min-height: 66vh; }
.seats-3 .seat:nth-child(3) { grid-column: 1 / -1; }
.seats-4 { grid-template-columns: 1fr 1fr; min-height: 66vh; }

.seat {
  background: linear-gradient(180deg, hsl(var(--hue) 35% 16%), hsl(var(--hue) 30% 12%));
  border: 1px solid hsl(var(--hue) 35% 26%); border-radius: 18px; padding: .55rem .7rem .6rem;
  display: flex; flex-direction: column; position: relative; overflow: hidden;
}
.seat.flip { transform: rotate(180deg); }   /* top seats face the player across the table */
.seat.dead { filter: saturate(.25) brightness(.7); }
.seat-top { display: flex; align-items: center; gap: .4rem; }
.pname { font-size: .74rem; font-weight: 800; color: hsl(var(--hue) 60% 75%); flex: 1; text-align: center; }
.seat-top .chip { font-size: .7rem; padding: .2rem .55rem; min-height: 30px; }

.life-zone { position: relative; flex: 1; display: grid; place-items: center; min-height: 110px; }
.life-num { font-size: clamp(3.2rem, 12vw, 5rem); font-weight: 900; letter-spacing: -.04em; line-height: 1; position: relative; z-index: 1; pointer-events: none; }
.delta { position: absolute; top: -0.4em; right: -1.3em; font-size: .32em; color: var(--accent); font-weight: 800; }
.half { position: absolute; top: 0; bottom: 0; width: 50%; border: none; background: transparent; cursor: pointer; }
.half.minus { left: 0; } .half.plus { right: 0; }
.half:active { background: rgba(255,255,255,.05); }
.half.minus::after, .half.plus::after {
  content: "−"; position: absolute; top: 50%; transform: translateY(-50%); font-size: 1.5rem; color: hsl(var(--hue) 40% 45%);
}
.half.minus::after { left: 12px; }
.half.plus::after { content: "＋"; right: 12px; }
.seat-foot { display: flex; justify-content: space-between; gap: .4rem; }

.cmd-drawer { background: rgba(0,0,0,.25); border-radius: 12px; padding: .5rem .6rem; margin-top: .5rem; }
.cmd-row { display: flex; align-items: center; gap: .5rem; padding: .2rem 0; }
.cmd-from { font-size: .78rem; font-weight: 800; flex: 1; }
.cmd-val { font-weight: 900; min-width: 2ch; text-align: right; }
.cmd-val.lethal { color: var(--bad); }

/* ---- Rows (walkers & tokens) ---- */
.row { display: flex; align-items: center; gap: .55rem; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: .45rem .6rem; margin-bottom: .5rem; }
.row-x { border: none; background: none; color: var(--dim); font-size: .95rem; cursor: pointer; padding: .35rem; }
.row-name { flex: 1; font-weight: 700; font-size: .95rem; }
.row-name .pt { font-style: normal; color: var(--dim); font-size: .8rem; margin-left: .25rem; }
.row-num { font-size: 1.5rem; font-weight: 900; min-width: 2ch; text-align: center; }
.row-num.zero { color: var(--bad); }
.big-btn {
  border: 1px solid var(--line); background: var(--panel-2); color: var(--ink); border-radius: 12px;
  font-size: 1.3rem; font-weight: 800; width: 52px; height: 46px; cursor: pointer;
}
.add-row { display: flex; gap: .45rem; margin-top: .7rem; }
.add-row input {
  flex: 1; min-width: 0; background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px;
  color: var(--ink); font: inherit; font-size: 16px; padding: .55rem .7rem;
}
.add-row input#walker-loy, .add-row input#token-pt { flex: 0 0 5.2rem; }
.preset-grid { display: flex; flex-wrap: wrap; gap: .4rem; margin: .8rem 0; }

/* ---- Dice ---- */
.roll-stage { background: var(--panel); border: 1px solid var(--line); border-radius: 18px; min-height: 120px; display: grid; place-items: center; padding: 1rem; margin-bottom: .8rem; position: relative; }
.roll-die { position: absolute; top: .6rem; left: .9rem; color: var(--dim); font-size: .75rem; font-weight: 800; text-transform: uppercase; }
.roll-big { font-size: clamp(1.6rem, 8vw, 2.6rem); font-weight: 900; letter-spacing: -.02em; text-align: center; }
.roll-big b { color: var(--accent); }
.roll-big.dim { color: var(--dim); font-weight: 600; font-size: 1.1rem; }
.dice-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: .5rem; }
.die-btn {
  border: 1px solid var(--line); background: var(--panel-2); color: var(--ink); border-radius: 14px;
  font: inherit; font-size: 1.05rem; font-weight: 800; padding: .85rem 0; cursor: pointer;
}
.die-btn:active { background: var(--accent); color: #170f2b; }
.count-row { display: flex; align-items: center; gap: .7rem; margin: .8rem 0; color: var(--dim); font-size: .85rem; }
.count-row b { font-size: 1.1rem; color: var(--ink); }
.roll-log { color: var(--dim); font-size: .78rem; display: flex; flex-direction: column; gap: 2px; }

/* ---- Bottom tabs ---- */
.ctabs {
  position: fixed; bottom: 0; left: 0; right: 0; display: flex; background: var(--panel);
  border-top: 1px solid var(--line); padding: .35rem 0 calc(.35rem + env(safe-area-inset-bottom)); z-index: 10;
}
.ctab {
  flex: 1; border: none; background: none; color: var(--dim); font: inherit; font-size: .62rem; font-weight: 700;
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: .3rem 0; cursor: pointer;
  border-top: 3px solid transparent;
}
.ctab .ico { font-size: 1.3rem; line-height: 1.1; }
.ctab.active { color: var(--ink); border-top-color: var(--accent); }

@media (min-width: 700px) { .seats-2 { grid-template-rows: none; grid-template-columns: 1fr 1fr; } .seat.flip { transform: none; } }

.judge-link { margin-left: auto; text-decoration: none; display: inline-flex; align-items: center; }
#reset-btn { margin-left: 0; }

/* ---- Planeswalker lookup ---- */
.wsuggest-list { display: flex; flex-direction: column; gap: .4rem; margin-top: .5rem; }
.wsuggest {
  display: flex; align-items: center; gap: .6rem; text-align: left; font: inherit; cursor: pointer;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px; padding: .4rem .55rem; color: var(--ink);
}
.wsuggest:active { border-color: var(--accent); }
.wsuggest img { width: 52px; height: 38px; object-fit: cover; border-radius: 7px; }
.ws-name { flex: 1; font-weight: 700; font-size: .9rem; }
.ws-loy { color: var(--accent); font-weight: 800; }
.row-art { width: 46px; height: 34px; object-fit: cover; border-radius: 7px; }

/* ---- Full-card overlay ---- */
.card-overlay {
  position: fixed; inset: 0; z-index: 100; background: rgba(10, 6, 18, .82);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: .7rem; padding: 1rem; overflow-y: auto; cursor: pointer;
}
.card-overlay.hidden { display: none; }
.card-overlay img { max-width: min(92vw, 340px); width: 100%; border-radius: 4.5%/3.5%; box-shadow: 0 14px 40px rgba(0,0,0,.6); }
.row-open { display: flex; align-items: center; gap: .55rem; flex: 1; min-width: 0; background: none; border: none; padding: 0; font: inherit; color: inherit; text-align: left; cursor: pointer; }
.row-open:disabled { cursor: default; }

/* ---- Turn counter & name button ---- */
.turnchip { display: inline-flex; align-items: center; gap: .35rem; color: var(--dim); font-size: .8rem; font-weight: 700; }
.turnchip .mini { min-height: 32px; min-width: 36px; padding: .15rem .5rem; }
button.pname { background: none; border: none; cursor: pointer; padding: .2rem; }

/* ---- Ask a Judge popup ---- */
.judge-modal { position: fixed; inset: 0; z-index: 120; background: rgba(10, 6, 18, .7); display: flex; align-items: flex-end; justify-content: center; }
.judge-modal.hidden { display: none; }
.judge-box {
  background: var(--panel); border: 1px solid var(--line); border-radius: 18px 18px 0 0;
  width: 100%; max-width: 640px; height: min(78vh, 640px); display: flex; flex-direction: column;
  padding: .8rem .9rem calc(.8rem + env(safe-area-inset-bottom));
}
.judge-head { display: flex; align-items: center; gap: .6rem; padding-bottom: .5rem; }
.judge-head b { font-size: .95rem; }
.judge-head .hint-sm { margin: 0; flex: 1; }
.judge-log { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: .55rem; padding: .3rem 0; }
.jmsg { max-width: 90%; border-radius: 12px; padding: .55rem .8rem; font-size: .9rem; line-height: 1.5; user-select: text; }
.jmsg.judge { background: var(--panel-2); border: 1px solid var(--line); align-self: flex-start; }
.jmsg.judge p { margin: .35rem 0; } .jmsg.judge p:first-child { margin-top: 0; } .jmsg.judge p:last-child { margin-bottom: 0; }
.jmsg.user { background: rgba(164, 143, 255, .18); align-self: flex-end; }
.judge-inrow { display: flex; gap: .5rem; padding-top: .6rem; }
.judge-inrow textarea {
  flex: 1; min-width: 0; resize: none; background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 12px; color: var(--ink); font: inherit; font-size: 16px; padding: .55rem .7rem;
}
@media (min-width: 700px) { .judge-modal { align-items: center; } .judge-box { border-radius: 18px; } }

/* ---- Token battlefield: cards laid on the table ---- */
.add-token-bar { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; margin-bottom: .8rem; }
#token-select {
  flex: 1; min-width: 200px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px;
  color: var(--ink); font: inherit; font-size: 16px; padding: .6rem .7rem;
}
#custom-fields { display: flex; gap: .45rem; flex: 1; }
#custom-fields.hidden { display: none; }
#custom-fields input {
  min-width: 0; background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px;
  color: var(--ink); font: inherit; font-size: 16px; padding: .55rem .7rem;
}
#token-name { flex: 1; } #token-pt { flex: 0 0 4.6rem; }

.board {
  background: radial-gradient(ellipse 120% 100% at 50% 0%, #2a5238, #17301f 75%);
  border: 1px solid #35533f; border-radius: 18px; min-height: 240px;
  padding: 1rem .9rem 1.1rem; display: flex; flex-wrap: wrap; gap: .8rem .6rem;
  align-content: flex-start; justify-content: center;
  box-shadow: inset 0 2px 18px rgba(0, 0, 0, .45);
}
.board-hint { color: #7fa88d; font-size: .85rem; width: 100%; text-align: center; margin: 3.2rem 0; }

.tcard {
  position: relative; width: 128px; background: #241f18; border: 1px solid #4a4237;
  border-radius: 10px; padding: 5px 5px 4px; transform: rotate(var(--tilt));
  box-shadow: 0 6px 14px rgba(0, 0, 0, .5);
  display: flex; flex-direction: column; gap: 3px;
}
.tcard-face { border: none; background: #14110c; padding: 0; border-radius: 6px; overflow: hidden; cursor: pointer; aspect-ratio: 5/4; display: grid; place-items: center; }
.tcard-face img { width: 100%; height: 100%; object-fit: cover; display: block; -webkit-touch-callout: none; }
.tcard-blank { font-size: 2rem; font-weight: 900; color: #57503f; }
.tcount {
  position: absolute; top: -9px; right: -8px; z-index: 2;
  background: var(--accent); color: #170f2b; font-weight: 900; font-size: .8rem;
  border-radius: 999px; padding: .15rem .5rem; box-shadow: 0 2px 6px rgba(0, 0, 0, .5);
}
.tcard-x {
  position: absolute; top: -9px; left: -8px; z-index: 2; border: none; cursor: pointer;
  background: #3a3244; color: var(--dim); border-radius: 50%; width: 22px; height: 22px; font-size: .7rem;
}
.tbar { text-align: center; line-height: 1.15; padding: 1px 2px; }
.tbar b { display: block; font-size: .66rem; letter-spacing: -.01em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tbar em { font-style: normal; font-size: .62rem; color: var(--dim); }
.tbtns { display: flex; gap: 4px; }
.tbtns .mini { flex: 1; min-height: 34px; min-width: 0; border-radius: 8px; }
@media (min-width: 700px) { .tcard { width: 140px; } }

/* ---- Dice on the felt ---- */
.dice-board { min-height: 190px; align-items: center; position: relative; padding: 1.4rem 1rem; }
.dieface {
  display: grid; place-items: center; position: relative;
  width: 64px; height: 64px; border-radius: 14px;
  font-size: 1.7rem; font-weight: 900; color: #1c1626;
  transform: rotate(var(--tilt));
  box-shadow: 0 6px 14px rgba(0, 0, 0, .5), inset 0 -3px 0 rgba(0, 0, 0, .18);
  animation: dice-in .28s cubic-bezier(.2, 1.6, .4, 1);
}
.dieface em { position: absolute; bottom: 4px; font-style: normal; font-size: .5rem; font-weight: 700; opacity: .55; letter-spacing: .05em; }
@keyframes dice-in { from { transform: rotate(calc(var(--tilt) + 160deg)) scale(.2); opacity: 0; } }
.dieface.d4  { background: #9fe0b0; clip-path: polygon(50% 0%, 100% 92%, 0% 92%); border-radius: 0; padding-top: 14px; height: 70px; }
.dieface.d4 em { bottom: 10px; }
.dieface.d6  { background: #f2eee2; }
.dieface.d8  { background: #9cc7ee; border-radius: 22px; transform: rotate(calc(var(--tilt) + 45deg)); }
.dieface.d8 > em { transform: rotate(-45deg); }
.dieface.d10 { background: #f0a3a3; border-radius: 50% 50% 40% 40%; }
.dieface.d12 { background: #cbb4ec; border-radius: 26px; }
.dieface.d20 { background: linear-gradient(135deg, #f4d67c, #e0a93f); border-radius: 18px; clip-path: polygon(50% 0%, 93% 25%, 93% 75%, 50% 100%, 7% 75%, 7% 25%); }
.dieface.coin {
  width: 62px; height: 62px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #f6dd8e, #d9a53a 70%);
  border: 3px solid #b8862a; font-size: 1.5rem; color: #5d420f;
}
.dice-total {
  position: absolute; bottom: .55rem; right: .8rem;
  background: var(--accent); color: #170f2b; font-weight: 900; border-radius: 999px;
  padding: .2rem .7rem; font-size: .9rem; box-shadow: 0 2px 8px rgba(0, 0, 0, .45);
}
