:root {
  --bg: #070a12;
  --bg2: #0e1424;
  --panel: #131b2e;
  --panel2: #1a2438;
  --line: #2b3a55;
  --fg: #e8eefb;
  --dim: #8e9bb4;
  --accent: #ffd75e;
  --blue: #3f8fe0;
  --red: #e4483e;
  --green: #48c06b;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: "MS Gothic", "Hiragino Kaku Gothic ProN", "Noto Sans JP", monospace;
  -webkit-font-smoothing: none;
  font-size: 14px;
}

#app { max-width: 1600px; margin: 0 auto; padding: 10px 14px 40px; }

#topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 2px solid var(--line);
  padding: 8px 0 10px;
  margin-bottom: 14px;
}

#topbar h1 {
  font-size: 20px;
  margin: 0;
  letter-spacing: 2px;
  color: var(--accent);
  text-shadow: 2px 2px 0 #6b3b00;
}
#topbar h1 span { color: var(--fg); }
.topActions { display: flex; gap: 6px; }

button {
  font-family: inherit;
  font-size: 13px;
  color: var(--fg);
  background: var(--panel2);
  border: 2px solid var(--line);
  border-radius: 0;
  padding: 6px 10px;
  cursor: pointer;
  box-shadow: 0 2px 0 #05070c;
}
button:hover { background: #24314a; border-color: #45597d; }
button:active { transform: translateY(2px); box-shadow: none; }
button.on { background: var(--accent); color: #241a00; border-color: #fff0a8; }
button.big { font-size: 16px; padding: 12px 18px; min-width: 190px; }
button.big.alt { background: var(--panel); }

.screen.hidden { display: none; }

.hero .tag { color: var(--accent); font-size: 16px; margin: 4px 0 8px; letter-spacing: 1px; }
.hero .blurb { color: var(--dim); max-width: 780px; line-height: 1.7; }
.hero strong { color: var(--fg); }

.pickers { display: flex; gap: 22px; flex-wrap: wrap; margin: 18px 0 12px; }
.picker h2 { font-size: 13px; margin: 0 0 6px; color: var(--dim); letter-spacing: 1px; }
.picknote { color: var(--dim); font-size: 11px; margin: 8px 0 0; max-width: 360px; line-height: 1.7; }
.btnrow { display: flex; gap: 6px; flex-wrap: wrap; }
.btnrow.center { justify-content: center; margin: 18px 0; }
.mainActions { display: flex; gap: 12px; flex-wrap: wrap; margin: 22px 0 10px; }
.best { color: var(--dim); }
.keyhint { color: var(--dim); line-height: 1.9; padding-left: 18px; }

/* ---------- game ---------- */
.gamehead { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 6px; }
#matchTitle { font-weight: bold; }
.deckinfo { color: var(--accent); font-size: 12px; }

#stageWrap { display: flex; justify-content: center; background: #04060c; padding: 4px; border: 2px solid var(--line); }
#stage { image-rendering: pixelated; image-rendering: crisp-edges; display: block; touch-action: none; }

/* The hand, the public strip and the log sit beside the stage so the canvas can
   claim the whole viewport height instead of sharing it with the chrome. */
.gamegrid { display: flex; gap: 12px; align-items: flex-start; }
.gamegrid #stageWrap { flex: 1 1 auto; min-width: 0; }
#sidePanel { flex: 0 0 300px; display: flex; flex-direction: column; gap: 8px; }
#sidePanel .hand { grid-template-columns: repeat(2, 1fr); margin: 0; }
#sidePanel .card { min-height: 78px; padding-bottom: 26px; }
#sidePanel .card .ctext { font-size: 10px; }
#sidePanel .card .ctag { display: none; }
#sidePanel .actionbar { flex-direction: column; }
#sidePanel .ult { min-width: 0; }
#sidePanel .log { flex: none; border-left: none; padding-left: 0; border-top: 2px solid var(--line); padding-top: 6px; max-height: 150px; overflow: auto; }
#sidePanel .public { flex-direction: column; gap: 6px; border-top: 2px solid var(--line); padding-top: 8px; margin-top: 0; }

@media (max-width: 1180px) {
  .gamegrid { flex-direction: column; }
  .gamegrid #stageWrap { flex: none; width: 100%; }
  #sidePanel { flex: none; width: 100%; }
  #sidePanel .hand { grid-template-columns: repeat(5, 1fr); margin: 8px 0; }
  #sidePanel .actionbar { flex-direction: row; }
  #sidePanel .log { flex: 1; border-left: 2px solid var(--line); border-top: none; padding-left: 10px; padding-top: 0; max-height: none; }
  #sidePanel .public { margin-top: 10px; }
}

.gamebar { color: var(--dim); font-size: 12px; padding: 6px 2px; display: flex; gap: 14px; flex-wrap: wrap; }
.runetip { color: var(--blue); font-size: 11px; }
.runechip { display: inline-block; margin-right: 10px; }
.beastchip { color: #3fd0c0; border: 1px solid #1d5b55; padding: 1px 5px; margin-bottom: 3px; }

.hand {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  margin: 8px 0;
}
.card {
  --fc: #8e9bb4;
  position: relative;
  text-align: left;
  min-height: 84px;
  padding: 22px 8px 8px;
  background: linear-gradient(180deg, #1a2438 0%, #10182a 100%);
  border: 2px solid var(--fc);
  box-shadow: 0 3px 0 #05070c, inset 0 0 0 1px rgba(255, 255, 255, 0.05);
}
.card:hover { background: #223050; }
.card.disabled { opacity: 0.45; border-color: #3a455c; }
.card.reactable { border-color: #8fd0ff; box-shadow: 0 3px 0 #05070c, 0 0 8px rgba(143, 208, 255, 0.5); }
.card.chanelling { border-color: #ff8f3d; box-shadow: 0 3px 0 #05070c, 0 0 10px rgba(255, 143, 61, 0.55); }
/* Prepared by the operator: the machine will take it the moment it is legal. */
.card.armed { border-color: #5ce08a; box-shadow: 0 3px 0 #05070c, 0 0 10px rgba(92, 224, 138, 0.5); }
.card .cplan { position: absolute; bottom: 4px; left: 6px; font-size: 10px; color: #5ce08a; }
.card .key {
  position: absolute; top: 4px; left: 6px;
  font-size: 11px; color: var(--dim);
}
.card .cost { position: absolute; top: 3px; right: 6px; display: flex; gap: 4px; }
.card .cost b { font-size: 11px; padding: 1px 4px; }
.card .ce { background: #1f4f80; color: #cfe6ff; }
.card .cs { background: #7a5a10; color: #ffeab0; }
.card .tmark {
  position: absolute; bottom: 6px; right: 8px;
  font-size: 12px; font-weight: bold;
  padding: 1px 5px; border: 1px solid currentColor;
}
.tsorcery { color: #ffd75e; }
.tinstant { color: #9bebab; }
.treaction { color: #8fd0ff; }
.ttrigger { color: #cfa8ff; }
.ttrap { color: #ff8f7a; }
.tchannel { color: #ff8f3d; }
.card .cname { display: block; font-weight: bold; font-size: 14px; margin-bottom: 4px; }
.card .ctext { display: block; font-size: 11px; color: var(--dim); line-height: 1.5; }
.card .ctag {
  position: absolute; bottom: 8px; left: 8px;
  font-size: 10px; color: var(--fc);
}
.card .chint { position: absolute; top: 20px; right: 8px; font-size: 10px; color: #8fd0ff; }
.card .ccd { position: absolute; bottom: 24px; right: 8px; font-size: 10px; color: #ff9a9a; }
.card .cbar {
  --p: 0%;
  position: absolute; left: 0; bottom: 0; width: var(--p); height: 3px;
  background: #ff8f3d; display: block;
}

.public { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 10px; border-top: 2px solid var(--line); padding-top: 8px; }
.pubrow { display: flex; gap: 10px; flex-wrap: wrap; font-size: 11px; color: var(--dim); align-items: baseline; }
.pubrow b { color: var(--fg); }
.pubrow .pubmach { color: #8fd0ff; }
.pubused { color: var(--accent); }

.actionbar { display: flex; gap: 12px; align-items: stretch; }
.ult {
  --fill: 0%;
  position: relative;
  min-width: 220px;
  text-align: left;
  overflow: hidden;
  border-color: #5b2f85;
  background: linear-gradient(90deg, #3a2a5a var(--fill), #12192a var(--fill));
}
.ult.ready { border-color: var(--accent); box-shadow: 0 0 10px rgba(255, 215, 94, 0.45); }
.ult .uname { display: block; font-weight: bold; }
.ult .usub { display: block; font-size: 11px; color: var(--accent); }
.ult .utext { display: block; font-size: 11px; color: var(--dim); }
.log { flex: 1; font-size: 12px; color: var(--dim); border-left: 2px solid var(--line); padding-left: 10px; }
.logline.l0 { color: var(--fg); }
.logline.l1 { opacity: 0.8; }
.logline.l2 { opacity: 0.6; }
.logline.l3, .logline.l4 { opacity: 0.4; }

/* ---------- deck builder ---------- */
.deckHead { display: flex; align-items: center; gap: 14px; margin-bottom: 10px; }
.deckHead h2 { margin: 0; }
.saved { color: var(--green); font-size: 12px; }

.deckwrap { display: grid; grid-template-columns: 1fr 340px; gap: 14px; }
.pool { border: 2px solid var(--line); background: var(--panel); padding: 10px; max-height: 70vh; overflow: auto; }
.poolhead { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 8px; }
.poolgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 8px; }
.pcard { --fc: #8e9bb4; border: 2px solid var(--fc); background: #10182a; padding: 8px; font-size: 12px; }
.pcard.used { background: #17263f; }
.pcard.maxed { opacity: 0.75; }
.pch { display: flex; justify-content: space-between; align-items: baseline; gap: 6px; }
.pch b { font-size: 13px; }
.pch .prar, .drow .prar { color: #8fb2ff; font-size: 11px; }
.drow .prar { justify-self: start; }
.ptiming { font-size: 11px; margin: 2px 0; }
.cnt { color: var(--dim); font-size: 11px; }
.ptext { color: var(--dim); font-size: 11px; margin: 4px 0 6px; min-height: 30px; line-height: 1.45; }
.pfoot { display: flex; justify-content: space-between; align-items: center; }
.pcost { color: var(--dim); font-size: 11px; }
.padd { padding: 2px 12px; font-size: 15px; }

.side { border: 2px solid var(--line); background: var(--panel); padding: 10px; display: flex; flex-direction: column; gap: 8px; }
.deckcount { font-size: 16px; }
.synrow { --fc: #8e9bb4; display: grid; grid-template-columns: 44px 1fr 22px; align-items: center; gap: 6px; font-size: 11px; color: var(--dim); }
.synrow.on { color: var(--fc); }
.synbar { height: 8px; background: #0c1220; border: 1px solid var(--line); }
.synbar i { display: block; height: 100%; background: var(--fc); }
.chassis { border: 2px solid #2c4a6b; background: #0d1524; padding: 6px 8px; font-size: 11px; }
.chassis .chhead { color: #cfe6ff; margin-bottom: 4px; }
.chassis .chsub { color: var(--dim); font-size: 10px; }
.chassis .chrow { display: grid; grid-template-columns: 34px 1fr 26px; align-items: center; gap: 6px; color: var(--dim); }
.chassis .chbar { height: 7px; background: #0a1020; border: 1px solid var(--line); }
.chassis .chbar i { display: block; height: 100%; background: linear-gradient(90deg, #3f8fe0, #5ce08a); }
.chassis .chnum { text-align: right; color: #cfe6ff; }
.chassis .chhint { color: var(--dim); font-size: 10px; margin-top: 4px; }
/* The machine is chosen, not derived: the choice has to be as cheap to make as
   the deck edit itself, so it is one row of buttons beside the axes it sets. */
.chassis .chpick { gap: 4px; margin: 2px 0; }
.chassis .chpick button { font-size: 11px; padding: 3px 7px; }
.chassis .chpick button i { font-style: normal; color: #ffd27a; margin-left: 3px; font-size: 9px; }
/* The measured win rate for *this* deck rides on each machine button, so the choice
   carries its price tag where the choice is made. A dimmed button is a machine that
   cannot run the deck's ability cards — that column is not a cheaper option, it is a
   different deck. */
.chassis .chpick button u { text-decoration: none; color: #8fd3ff; margin-left: 4px; font-size: 9px; }
.chassis .chpick button.no { opacity: 0.42; }
.chassis .chpick button.no u { color: #8a94a6; }
.chassis .chguide { color: #9fb4cc; }
.chassis .chhint b { color: #cfe6ff; }
/* A built-in ability is part of the machine, so it is shown with the axes rather
   than hidden in a tooltip — and a card that needs an ability the chosen machine
   lacks is called out here, where the choice is still free. */
.chassis .chab { color: var(--dim); font-size: 10px; margin-top: 4px; }
.chassis .chab b { color: #ffd27a; }
.chassis .chab.none { color: #6b7a92; }
.chassis .chwarn { color: #ff8a7a; font-size: 10px; margin-top: 3px; }
.chassis .chwarn b { color: #ffb3a7; }
/* The deck's cost shape, shown while you are still choosing: energy is a clock
   and shards are broken blocks, so a curve pushed to the right is cards that
   exist in the deck but never resolve in the set. */
.costrow { color: var(--dim); font-size: 11px; margin: 2px 0 4px; }
.costrow b { color: #cfe6ff; }
.costcurve { display: flex; gap: 4px; align-items: flex-end; }
.ccell { flex: 1; text-align: center; }
.ccbar { height: 26px; background: #0a1020; border: 1px solid var(--line); display: flex; align-items: flex-end; }
.ccbar i { display: block; width: 100%; background: linear-gradient(180deg, #ffd75e, #7a5a10); }
.cclab { font-size: 9px; color: var(--dim); margin-top: 2px; }
.ultbox { border: 2px solid #5b2f85; background: #16101f; padding: 6px 8px; font-size: 11px; }
.ultbox b { color: var(--accent); margin-right: 6px; }
.ultbox span { color: var(--dim); display: block; }
.decklist { max-height: 26vh; overflow: auto; border-top: 1px solid var(--line); }
.drow { --fc: #8e9bb4; display: grid; grid-template-columns: 1fr auto auto auto auto; gap: 8px; align-items: center; padding: 3px 0; border-bottom: 1px solid #1c2740; font-size: 12px; }
.drow b { color: var(--fc); }
.dcost, .dn { color: var(--dim); font-size: 11px; }
.errs { min-height: 18px; font-size: 11px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }
.errs .ok { color: var(--green); }
.errs .bad { display: block; color: #ff8f8f; }
.errs .chwarn { display: block; margin-top: 4px; color: #ffc27a; font-size: 11px; line-height: 1.5; }
.io-note { margin: 4px 0 0; color: #ffdf9f; font-size: 12px; line-height: 1.5; }
.io-note:empty { display: none; }
.dbActions { display: flex; gap: 6px; flex-wrap: wrap; }
.presets { display: flex; gap: 6px; flex-wrap: wrap; }
#dbIo { width: 100%; height: 54px; background: #0c1220; color: var(--fg); border: 1px solid var(--line); font-family: inherit; font-size: 11px; }

/* ---------- result / help ---------- */
.restitle { font-size: 34px; letter-spacing: 3px; color: var(--accent); margin: 12px 0 4px; text-align: center; }
.resub { text-align: center; color: var(--dim); margin-bottom: 16px; }
.restable { width: 100%; max-width: 760px; margin: 0 auto; border-collapse: collapse; font-size: 12px; }
.restable th, .restable td { border: 1px solid var(--line); padding: 6px 8px; text-align: center; }
.restable th { background: var(--panel2); color: var(--dim); }

.helpgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 14px; }
.helpgrid h3 { margin: 0 0 6px; color: var(--accent); }
.helpgrid p { margin: 0 0 8px; color: var(--dim); line-height: 1.7; }
.helpgrid strong { color: var(--fg); }

@media (max-width: 900px) {
  .deckwrap { grid-template-columns: 1fr; }
  .hand { grid-template-columns: repeat(3, 1fr); }
}

/* Rift expansion: read the decision at the point of play. */
.rift-intro { display:flex; flex-wrap:wrap; gap:10px 20px; margin:18px 0; padding:16px; border:1px solid #386476; background:#10232c; color:#a6eede; }
.rift-intro b { color:#ffd75e; }
.rift-rules { padding:18px; margin:12px 0 24px; background:#10232c; border:1px solid #386476; line-height:1.8; }
.rift-builder-note { padding:10px; color:#a6eede; background:#10232c; font-size:12px; line-height:1.7; }
.card { min-height:83px; height:auto; padding-bottom:7px; }
.card .cdescription { display:block; white-space:normal; font-size:11px; line-height:1.45; color:#c5d6e7; margin:5px 0 3px; }
#hand { max-height:62vh; overflow-y:auto; }
@media (max-width:1180px) { #sidePanel .hand { grid-template-columns:repeat(auto-fit,minmax(145px,1fr)); } }

.frontier-panel { white-space:pre-line; color:#b2ed95; font-size:12px; line-height:1.65; background:#13251e; padding:8px; border-left:3px solid #91cb70; }
.frontier-panel:empty { display:none; }
.crequirement { display:block; color:#ffcb93; font-size:10px; line-height:1.4; }
.crequirement:empty { display:none; }

.council-panel { white-space:pre-line; color:#efd4ff; font-size:12px; line-height:1.6; background:#281e36; border-left:3px solid #bd8cdf; padding:8px; margin-bottom:6px; }
.council-panel:empty { display:none; }

.world-panel {white-space:pre-line;color:#ffe0a0;font-size:12px;line-height:1.6;background:#302518;border-left:3px solid #ffc66a;padding:8px;margin-bottom:6px;}
.world-panel:empty {display:none;}

.arcana-panel:empty{display:none}.arcana-panel{background:#172b31;border-left:3px solid #76d2bc;color:#d7f6ee;font-size:11px;line-height:1.55;padding:8px;margin-bottom:7px}.arcana-panel button{font-size:11px;padding:4px 6px;margin:2px}.arcana-panel .selected{outline:2px solid #ffcf71}.arc-res{white-space:pre-line;margin:4px 0}.arc-stack{display:flex;flex-direction:column;max-height:125px;overflow:auto}.arc-stack button{text-align:left}.arc-pin{color:#b0c8cf;font-size:10px}.arcana-panel details{border-top:1px solid #38545c;margin-top:5px;padding-top:3px}.arc-graves{display:grid;grid-template-columns:1fr 1fr;gap:5px;max-height:220px;overflow:auto}.arc-grave-row{display:flex;flex-wrap:wrap}.arc-scry{background:#283b40;padding:4px}.arcana-options{display:flex;flex-wrap:wrap;gap:4px;margin-bottom:8px}.arcana-options button{font-size:10px;padding:4px}.arcana-options.hidden{display:none}

.vein-builder{padding:12px;background:#182b30;border:1px solid #4d8883;font-size:12px;line-height:1.6}.vein-inputs{display:flex;gap:6px}.vein-inputs label{display:flex;flex-direction:column;flex:1;min-width:0}.vein-inputs input{width:100%;background:#0c1d22;color:#e3ffef;border:1px solid #527976;padding:5px}.arc-res{font-size:12px!important;line-height:1.6}.gamegrid{flex-wrap:nowrap}.gamegrid #stageWrap{flex:1 1 0}#sidePanel{flex-basis:350px}#sidePanel .hand{grid-template-columns:repeat(2,1fr)}@media(min-width:1181px){#sidePanel{max-height:calc(100vh - 100px);overflow-y:auto;padding-right:5px}#stageWrap{position:sticky;top:12px}}

@media(max-width:1180px){.gamegrid #stageWrap{flex:none}#sidePanel{flex-basis:auto;max-height:none}#sidePanel .hand{grid-template-columns:repeat(auto-fit,minmax(145px,1fr))}}

#sidePanel > *{flex-shrink:0}#sidePanel #hand{max-height:none;overflow:visible}


.raid-panel{background:#263343;border:1px solid #566c80;padding:6px;margin:7px 0;color:#fff2c7}.raid-panel button{display:inline-block}.raid-panel details{max-height:120px;overflow:auto}

.risk-debt{color:#ffb4a5;font-weight:bold;border-left:3px solid #e85a44;padding-left:7px}.combo-hint{font-size:11px;color:#82d8b0;margin-top:5px}

.deckwrap>.deck-ultimate-visible{grid-column:1/-1;min-width:0;padding:14px 18px;border:1px solid #806b49;border-radius:6px;background:#17232c}
.deck-ultimate-visible label{display:block;color:#f0d6a0;margin-bottom:6px}
.deck-ultimate-visible select{min-height:40px;max-width:100%}
.deck-ultimate-visible .ultimate-description{margin:7px 0}
