/* Colours: the dark theme by default, the light one when the system or the ◐ button asks. Text
   colours keep at least 4.5:1 contrast against their backgrounds in both. */
:root {
  --bg: #15171c;
  --panel: #1e2229;
  --panel2: #282d37;
  --line: #3a414e;
  --text: #e6e8ec;
  --dim: #a3abb9;
  --accent: #e8ae3e;
  --accent-bg: #4a3a17;
  --hp: #ef7a74;
  --hp-bar: #c8433d;
  --block: #7fb3e6;
  --energy: #f0cf55;
  --good: #6cc56c;
  --bad: #e0605b;
  --upgraded: #7ad67a;
  --attack: #e0605b;
  --skill: #5fa8e0;
  --power: #e3b341;
  --status: #8a8f99;
  --Red: #b8423a;
  --Green: #3f9a52;
  --Blue: #3b7cc4;
  --Purple: #8d5cc6;
  --Colorless: #8c8f96;
  --Curse: #5b4a66;
  --card-bg: #23272f;
  --bar-bg: #2f3540;
  --shadow: 0 4px 18px rgba(0, 0, 0, 0.45);
  color-scheme: dark;
  font-family: ui-sans-serif, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
}
:root[data-theme="light"] {
  --bg: #f4f2ee;
  --panel: #ffffff;
  --panel2: #ece9e3;
  --line: #cfcac0;
  --text: #1d1f24;
  --dim: #5a606b;
  --accent: #865700;
  --accent-bg: #fbe7bd;
  --hp: #b42b25;
  --hp-bar: #bf3f39;
  --block: #1f5f9e;
  --energy: #765b00;
  --good: #246824;
  --bad: #b42b25;
  --upgraded: #1f6e26;
  --attack: #c2413a;
  --skill: #285f96;
  --power: #a87a10;
  --status: #7b808a;
  --Red: #c0463e;
  --Green: #3d9150;
  --Blue: #3a77bd;
  --Purple: #8a58c2;
  --Colorless: #8a8d94;
  --Curse: #6e5a7a;
  --card-bg: #fbfaf7;
  --bar-bg: #5b5f68;
  --shadow: 0 4px 18px rgba(0, 0, 0, 0.18);
  color-scheme: light;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f4f2ee; --panel: #ffffff; --panel2: #ece9e3; --line: #cfcac0; --text: #1d1f24; --dim: #5a606b;
    --accent: #865700; --accent-bg: #fbe7bd; --hp: #b42b25; --hp-bar: #bf3f39; --block: #1f5f9e; --energy: #765b00;
    --good: #246824; --bad: #b42b25; --upgraded: #1f6e26; --attack: #c2413a; --skill: #285f96; --power: #a87a10;
    --status: #7b808a; --Red: #c0463e; --Green: #3d9150; --Blue: #3a77bd; --Purple: #8a58c2; --Colorless: #8a8d94;
    --Curse: #6e5a7a; --card-bg: #fbfaf7; --bar-bg: #5b5f68; --shadow: 0 4px 18px rgba(0, 0, 0, 0.18);
    color-scheme: light;
  }
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); min-height: 100vh; display: flex; flex-direction: column; }
body.busy { cursor: progress; }
/* The viewer fills the window and its three columns scroll on their own (not on phones). */
body.viewing { height: 100vh; }
button, .button, select, input { font: inherit; color: var(--text); background: var(--panel2); border: 1px solid var(--line); border-radius: 6px; padding: 4px 10px; min-height: 30px; }
button:hover:not(:disabled), .button:hover { border-color: var(--accent); cursor: pointer; }
button:disabled { opacity: 0.45; cursor: default; }
button.primary { background: var(--accent-bg); border-color: var(--accent); }
button.link { background: none; border: 0; color: var(--dim); text-decoration: underline; padding: 2px 4px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
input[type=number] { width: 4.5em; }
a { color: var(--accent); }
kbd { font: 11px ui-monospace, monospace; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; padding: 0 4px; color: var(--dim); background: var(--panel); }
.dim { color: var(--dim); }
.small { font-size: 12px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
h3 { margin: 12px 0 6px; font-size: 12px; color: var(--dim); text-transform: uppercase; letter-spacing: 0.06em; }
.gold { color: var(--energy); }
.hp { color: var(--hp); }

header { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 6px 12px; background: var(--panel); border-bottom: 1px solid var(--line); }
.brand { color: var(--accent); font-weight: 700; text-decoration: none; margin-right: 6px; }
#runtitle { color: var(--dim); }
.spacer { flex: 1; }
#banner { display: flex; gap: 10px; align-items: center; justify-content: space-between; background: var(--accent-bg); color: var(--text); border-bottom: 1px solid var(--accent); padding: 8px 12px; }
#banner[hidden] { display: none; }

/* ---- Start screen ---- */
#home { max-width: 980px; margin: 0 auto; padding: 24px 16px 40px; width: 100%; }
.hero h1 { margin: 8px 0 6px; font-size: 26px; }
.hero p { color: var(--dim); max-width: 46em; line-height: 1.45; margin: 0 0 8px; }
.loading { color: var(--accent) !important; }
.loading::before { content: ""; display: inline-block; width: 10px; height: 10px; margin-right: 8px; border: 2px solid var(--accent); border-right-color: transparent; border-radius: 50%; animation: spin 0.8s linear infinite; vertical-align: -1px; }
@keyframes spin { to { transform: rotate(360deg); } }
.choices { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin: 18px 0; }
.choice { display: flex; flex-direction: column; gap: 6px; text-align: left; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; margin: 0; color: var(--text); cursor: pointer; }
.choice:hover:not(:disabled) { border-color: var(--accent); }
.choice b { font-size: 16px; }
.choice span { color: var(--dim); line-height: 1.4; }
#watch:not(:disabled) { border-color: var(--accent); background: linear-gradient(160deg, var(--accent-bg), var(--panel) 70%); }
form.choice { cursor: default; }
.fields { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; margin-top: 4px; }
.fields label { display: flex; flex-direction: column; gap: 2px; font-size: 12px; color: var(--dim); }
#continue { display: flex; gap: 10px; align-items: center; margin-bottom: 18px; }
#continue[hidden] { display: none; }
.choice.wide { flex: 1; }
#gallerybox h2 { font-size: 16px; margin: 8px 0 10px; }
#gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 10px; }
#gallery a.run { display: flex; flex-direction: column; gap: 4px; padding: 12px 14px; background: var(--panel); border: 1px solid var(--line); border-left: 5px solid var(--line); border-radius: 8px; color: var(--text); text-decoration: none; }
#gallery a.run:hover { border-color: var(--accent); }
#gallery a.run span { color: var(--dim); line-height: 1.4; }
#gallery a.run em { font-style: normal; font-size: 12px; color: var(--dim); }
#gallery a.run.c-Red { border-left-color: var(--Red); }
#gallery a.run.c-Green { border-left-color: var(--Green); }
#gallery a.run.c-Blue { border-left-color: var(--Blue); }
#gallery a.run.c-Purple { border-left-color: var(--Purple); }

/* ---- The new-run page ---- */
#setup { max-width: 980px; margin: 0 auto; padding: 24px 16px 40px; width: 100%; }
#setup[hidden] { display: none; }
#setup h1 { font-size: 26px; margin: 4px 0 16px; text-align: center; }
.chars { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.char { --c: var(--line); position: relative; display: flex; flex-direction: column; gap: 6px; padding: 16px 14px; border-radius: 12px;
  background: linear-gradient(170deg, color-mix(in srgb, var(--c) 22%, var(--panel)), var(--panel)); border: 2px solid var(--line); cursor: pointer; }
.char.c-Red { --c: #d9493f; } .char.c-Green { --c: #45b45c; } .char.c-Blue { --c: #3f8be0; } .char.c-Purple { --c: #a46ee0; }
.char input { position: absolute; opacity: 0; pointer-events: none; }
.char b { font-size: 18px; color: var(--c); }
.char span { color: var(--text); font-weight: 600; font-size: 13px; }
.char em { color: var(--dim); font-style: normal; line-height: 1.4; }
.char:hover { border-color: var(--c); }
.char:has(input:checked) { border-color: var(--c); box-shadow: 0 0 0 2px var(--c), 0 6px 18px rgba(0, 0, 0, 0.35); transform: translateY(-3px); }
.char:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 3px; }
.setuprow { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin: 22px 0; }
.asc, .seedbox { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px 16px; }
.stepper { display: flex; gap: 6px; align-items: center; }
.stepper button { min-width: 40px; font-size: 18px; font-weight: 800; }
.stepper input { width: 4em; text-align: center; font-size: 20px; font-weight: 800; }
#ascdesc { min-height: 2.8em; margin: 8px 0 0; }
.seedbox input { font-size: 16px; width: 12em; }
.setupbuttons { display: flex; justify-content: space-between; gap: 10px; }
.setupbuttons button { padding: 10px 22px; font-size: 16px; }
#embark { font-weight: 800; min-width: 160px; }

/* ---- The viewer ---- */
#viewer { flex: 1; display: flex; flex-direction: column; min-height: 0; }
#viewer[hidden], #home[hidden] { display: none; }
nav#controls { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 6px 12px; background: var(--panel); border-bottom: 1px solid var(--line); }
nav#controls form { display: flex; gap: 6px; align-items: center; margin: 0; }
nav#controls button { min-width: 38px; }
#pos { min-width: 16em; color: var(--text); }
.speed { display: inline-flex; align-items: center; gap: 4px; }
.speed button { min-width: 32px; font-weight: 800; }
#speedval { min-width: 4.2em; text-align: center; font-variant-numeric: tabular-nums; }
main { flex: 1; display: grid; grid-template-columns: 250px 1fr 290px; min-height: 0; }
/* Middling widths: the decisions go under the run, so the table gets the width. */
@media (min-width: 821px) and (max-width: 1279px) {
  main { grid-template-columns: 240px 1fr; grid-template-rows: auto minmax(0, 1fr); }
  #run { grid-column: 1; grid-row: 1; border-bottom: 1px solid var(--line); }
  #side { grid-column: 1; grid-row: 2; border-left: 0; border-right: 1px solid var(--line); }
  main > section { grid-column: 2; grid-row: 1 / span 2; }
}
main > aside, main > section { overflow: auto; padding: 10px 14px; }
main > section { padding: 18px 28px; }
aside { background: var(--panel); }
#run { border-right: 1px solid var(--line); }
#side { border-left: 1px solid var(--line); position: relative; }

/* Run panel */
#run h3:first-child { margin-top: 2px; text-transform: none; letter-spacing: 0; font-size: 15px; color: var(--text); }
.stats { margin: 8px 0; }
.stat { display: flex; justify-content: space-between; padding: 3px 0; border-bottom: 1px dashed var(--line); }
.stat b { font-weight: 600; text-align: right; }
.keys .key { margin-left: 4px; font-size: 15px; opacity: 0.4; cursor: help; }
.key.on { opacity: 1; }
.key.ruby { color: #e0485a; }
.key.emerald { color: #3dbb6e; }
.key.sapphire { color: #4c8fe8; }
.buttons2 { display: flex; gap: 6px; margin: 10px 0 4px; }
.buttons2 button { flex: 1; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; margin: 4px 0 10px; }
.chip { background: var(--panel2); border: 1px solid var(--line); border-radius: 12px; padding: 2px 8px; font-size: 12px; cursor: help; }
.chip.relic { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); }
.chip.potion { border-color: color-mix(in srgb, var(--skill) 50%, var(--line)); }
.chip.empty { color: var(--dim); border-style: dashed; }
.chip.used { opacity: 0.5; }
.chip .n { color: var(--accent); margin-left: 4px; font-weight: 700; }

.hpbar { position: relative; height: 18px; background: var(--bar-bg); border: 1px solid var(--line); border-radius: 9px; overflow: hidden; margin: 6px 0; }
.hpbar i { position: absolute; inset: 0 auto 0 0; background: var(--hp-bar); }
.hpbar span { position: relative; display: block; text-align: center; font-size: 12px; line-height: 16px; font-weight: 700; color: #fff; text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8); }
.hpbar.big { height: 22px; border-radius: 11px; }
.hpbar.big span { line-height: 20px; font-size: 13px; }
.hpbar.blocked { border-color: var(--block); box-shadow: 0 0 0 1px var(--block); }
.blockbadge { position: absolute; right: 3px; top: 0; font-style: normal; font-size: 12px; font-weight: 700; line-height: 16px; color: #fff; background: #2f6fae; padding: 0 6px; border-radius: 8px; }

/* The AI's advice */
#advice { border-bottom: 1px solid var(--line); padding-bottom: 10px; margin-bottom: 8px; }
.advhead { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.advhead h3 { margin: 4px 0 6px; }
.advhead label { color: var(--dim); cursor: pointer; display: inline-flex; flex-direction: row; align-items: center; gap: 5px; }
.advhead label input { margin: 0; }
.advlist { list-style: none; margin: 4px 0 6px; padding: 0; }
.advrow { display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; padding: 5px 6px; border-radius: 5px; cursor: pointer; border: 1px solid transparent; }
.advrow:hover, .advrow:focus-visible { border-color: var(--skill); }
.advrow .bar { grid-column: 1 / span 2; height: 4px; background: var(--bar-bg); border-radius: 2px; overflow: hidden; }
.advrow .bar i { display: block; height: 100%; background: var(--skill); }
.advrow .lbl { font-size: 13px; }
.advrow b { font-variant-numeric: tabular-nums; }
.advrow.top .lbl { font-weight: 600; }
.advrow .tag { font-size: 10px; font-weight: 700; text-transform: uppercase; color: var(--accent); margin-left: 4px; }
.advrow .tag.own { color: var(--skill); }
.verdict { border-left: 3px solid var(--line); padding: 2px 8px; margin: 4px 0 8px; }
.verdict.same { border-left-color: var(--good); }
.verdict.differ { border-left-color: var(--accent); }
.advplay { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.advplay button { padding: 3px 8px; font-size: 12px; }
/* The AI's likeliest move, outlined where the screen draws it. */
.advised { outline: 2px dashed var(--skill) !important; outline-offset: 3px; }
svg.map .node.advised { outline: none !important; }
svg.map .node.advised circle:not(.hit) { stroke: var(--skill); stroke-width: 4; stroke-dasharray: 4 3; }
.advised-target { outline: 2px dashed var(--skill); outline-offset: 2px; }

/* Decision log */
#logbox > summary { list-style: none; cursor: pointer; }
#logbox > summary::-webkit-details-marker { display: none; }
#logbox > summary h3 { display: inline; }
#logbox > summary h3::before { content: "▸ "; }
#logbox[open] > summary h3::before { content: "▾ "; }
#log { font-size: 12px; }
#log details.floor { border-top: 1px solid var(--line); }
#log details.floor > summary { padding: 5px 2px; margin: 0; color: var(--text); display: flex; gap: 6px; align-items: baseline; }
#log details.floor > summary .f { font-weight: 600; min-width: 5.2em; }
#log ol { margin: 0 0 6px; padding: 0; list-style: none; }
#log li { padding: 3px 6px; border-radius: 4px; cursor: pointer; display: flex; gap: 6px; align-items: baseline; border-left: 3px solid transparent; }
#log li:hover { background: var(--panel2); }
#log li.now { background: var(--accent-bg); }
#log li.by-you { border-left-color: var(--good); }
#log.onekind .who { display: none; }
.who { display: inline-block; min-width: 2.3em; font-size: 10px; font-weight: 700; color: var(--dim); text-transform: uppercase; }
.who.by-network, #log li.by-network .who { color: var(--skill); }
.who.by-you, #log li.by-you .who { color: var(--good); }

/* Screens */
#screen { min-height: 300px; }
main > section { display: flex; flex-direction: column; }
main > section > * { flex-shrink: 0; }
#screen.s-combat { flex: 1 0 auto; display: flex; flex-direction: column; }
#screen.s-combat > .battle { flex: 1; }
.title { font-size: 19px; margin: 2px 0 10px; }
.title small { color: var(--dim); font-size: 13px; margin-left: 8px; font-weight: 400; }
.title.won { color: var(--good); }
.title.lost { color: var(--bad); }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-start; margin-bottom: 12px; }
.box { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
.relicbox { max-width: 260px; cursor: help; }
.relicbox p { margin: 4px 0 0; color: var(--dim); font-size: 12px; line-height: 1.35; }
.rewardcards { flex-basis: 100%; }
.rewardcards .row { margin: 8px 0 0; }
.choicebox { margin-bottom: 12px; border-color: var(--accent); }
.choicebox .row { margin: 8px 0 0; }
.list { margin: 0 0 8px; padding-left: 22px; line-height: 1.7; }
.list .disabled { color: var(--dim); text-decoration: line-through; }
.num { font-weight: 700; color: var(--text); }
.num.up { color: var(--upgraded); }
.num.down { color: var(--bad); }

/* Fights */
.units { align-items: stretch; }
.unit { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; min-width: 180px; flex: 0 1 220px; }
.unit.dead { opacity: 0.4; }
.unit.player { max-width: 460px; margin-bottom: 4px; border-color: color-mix(in srgb, var(--good) 40%, var(--line)); }
.unithead { display: flex; gap: 8px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.intent { display: inline-flex; gap: 4px; align-items: center; padding: 1px 8px; border-radius: 10px; background: var(--panel2); border: 1px solid var(--line); cursor: help; font-size: 13px; }
.intent .icon { font-size: 14px; }
.intent.i-Attack, .intent.i-AttackBuff, .intent.i-AttackDebuff, .intent.i-AttackDefend { color: var(--attack); border-color: var(--attack); }
.intent.i-Defend, .intent.i-DefendBuff, .intent.i-DefendDebuff { color: var(--block); }
.intent.i-Buff { color: var(--good); }
.intent.i-Debuff, .intent.i-StrongDebuff { color: var(--power); }
.intent b { color: inherit; }
.energy { color: var(--energy); font-weight: 700; font-size: 16px; cursor: help; }
.stance { padding: 1px 8px; border-radius: 10px; border: 1px solid var(--line); font-size: 12px; cursor: help; }
.stance.s-Wrath { color: var(--bad); border-color: var(--bad); }
.stance.s-Calm { color: var(--skill); border-color: var(--skill); }
.stance.s-Divinity { color: var(--power); border-color: var(--power); }
.powers, .orbs { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.power { font-size: 11px; background: var(--panel2); border: 1px solid var(--line); border-radius: 4px; padding: 1px 6px; cursor: help; }
.power.debuff { border-color: color-mix(in srgb, var(--bad) 60%, var(--line)); }
.power b { color: var(--accent); }
.orb { font-size: 11px; border-radius: 10px; padding: 1px 8px; border: 1px solid var(--line); cursor: help; }
.orb.o-Lightning { border-color: var(--energy); }
.orb.o-Frost { border-color: var(--block); }
.orb.o-Dark { border-color: var(--Purple); }
.orb.o-Plasma { border-color: var(--power); }
.piles { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }
.pile b { color: var(--accent); }

/* Cards, drawn like the game's: a coloured frame, the cost in a gem, a name banner, an art panel
   with the type, the text below. */
/* The border is the character's colour, the card's body the type's: Attack red, Skill blue, Power
   gold, Status grey, Curse dark purple. */
.card { --frame: #9a9da4; --body: #5d6068; --body-dark: #24262b; position: relative; flex: none; width: 150px; height: 206px; border-radius: 12px;
  background: linear-gradient(170deg, var(--body), var(--body-dark));
  border: 4px solid var(--frame); outline: 1px solid rgba(0, 0, 0, 0.6); outline-offset: -5px; box-shadow: 0 3px 8px rgba(0, 0, 0, 0.45);
  display: flex; flex-direction: column; align-items: stretch; padding: 22px 8px 8px; gap: 4px; color: #f3efe6; cursor: help;
  transition: transform 0.12s ease, box-shadow 0.12s ease; user-select: none; }
.card.c-Red { --frame: #d9493f; }
.card.c-Green { --frame: #45b45c; }
.card.c-Blue { --frame: #3f8be0; }
.card.c-Purple { --frame: #a46ee0; }
.card.c-Colorless { --frame: #b9bcc3; }
.card.c-Curse { --frame: #6f5a7d; }
.card.t-Attack { --body: #8a3a2c; --body-dark: #36140f; }
.card.t-Skill { --body: #2f5f8f; --body-dark: #10243a; }
.card.t-Power { --body: #8f7224; --body-dark: #3a2c0a; }
.card.t-Status { --body: #6a6e76; --body-dark: #26282c; }
.card.t-Curse { --body: #4a3656; --body-dark: #170f1c; }
.card .cost { position: absolute; top: -10px; left: -10px; width: 32px; height: 32px; border-radius: 50%; z-index: 2;
  background: radial-gradient(circle at 35% 30%, #fff6c4, var(--frame) 55%, #111 120%); border: 2px solid var(--frame);
  color: #fff; font-weight: 800; font-size: 17px; line-height: 28px; text-align: center; text-shadow: 0 1px 2px #000, 0 0 3px #000; }
.card .cost.changed { color: #8dff8d; }
.card .banner { position: absolute; top: 4px; left: 14px; right: 6px; text-align: center; font-weight: 800; font-size: 13px; line-height: 1.1;
  padding: 3px 4px; border-radius: 4px; background: rgba(0, 0, 0, 0.35); text-shadow: 0 1px 2px #000; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .banner { border: 1px solid color-mix(in srgb, var(--frame) 70%, transparent); }
.card .banner.upgraded { color: #8dff8d; }
/* Rarity, as in the game: the name banner (and the art panel's rim) is grey for starter and common
   cards, blue for uncommon ones, gold for rare ones. */
.card.r-Common .banner, .card.r-Basic .banner { background: linear-gradient(#6a6d74, #44474d); }
.card.r-Uncommon .banner { background: linear-gradient(#3b82c4, #1f4f80); }
.card.r-Rare .banner { background: linear-gradient(#e7c35a, #a57a1c); color: #2a1d00; text-shadow: 0 1px 0 rgba(255, 255, 255, 0.35); }
.card.r-Rare .banner.upgraded { color: #0d5e0d; }
.card.r-Uncommon .art { border-color: #5fa2e0; }
.card.r-Rare .art { border-color: #f0cd63; }
.card .art { height: 64px; margin-top: 6px; border-radius: 6px; border: 2px solid rgba(0, 0, 0, 0.45);
  background: radial-gradient(circle at 50% 40%, color-mix(in srgb, var(--body) 65%, #fff 35%), color-mix(in srgb, var(--body) 70%, #000) 75%);
  display: flex; align-items: center; justify-content: center; font-size: 30px; color: rgba(255, 255, 255, 0.75); text-shadow: 0 2px 4px rgba(0, 0, 0, 0.6); }
.card.t-Attack .art { border-radius: 6px 6px 30px 30px; }
.card.t-Power .art { border-radius: 50% 50% 10px 10px / 40% 40% 10px 10px; }
.card .type { align-self: center; white-space: nowrap; margin-top: -11px; font-size: 9px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.08em;
  padding: 1px 7px; border-radius: 6px; background: #2b2b2b; color: #eee; border: 1px solid rgba(255, 255, 255, 0.25); position: relative; }
.card .desc { flex: 1; font-size: 11.5px; line-height: 1.3; text-align: center; padding: 4px 3px; border-radius: 6px;
  background: rgba(0, 0, 0, 0.32); color: #e9e4d8; display: flex; flex-direction: column; justify-content: center; }
.card .desc .num { color: #fff; }
.card .desc .num.up { color: #8dff8d; }
.card .desc .num.down { color: #ff8f8a; }
.card .kw { color: #ffe08a; font-weight: 700; }
.card .price { position: absolute; bottom: -12px; left: 50%; transform: translateX(-50%); background: var(--panel); border: 1px solid var(--energy);
  color: var(--energy); font-weight: 800; padding: 0 8px; border-radius: 8px; white-space: nowrap; }
.card.unplayable { filter: saturate(0.4) brightness(0.75); }
.card[data-act], .card[data-hand], .card[data-pick] { cursor: pointer; }
.card[data-act]:hover, .card[data-pick]:hover, .card.playable:hover { transform: translateY(-10px) scale(1.04); z-index: 5; box-shadow: 0 10px 22px rgba(0, 0, 0, 0.55); }
.card.selected { transform: translateY(-26px) scale(1.06); z-index: 6; box-shadow: 0 0 0 3px #fff, 0 12px 26px rgba(0, 0, 0, 0.6); }
.card.picked { box-shadow: 0 0 0 4px var(--good), 0 8px 18px rgba(0, 0, 0, 0.5); transform: translateY(-6px); }
.card.cant, .box.cant { opacity: 0.5; }
.card.shake { animation: shake 0.3s; }
@keyframes shake { 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }

/* The run's next move (the AI's, when watching) glows. */
.ai { box-shadow: 0 0 0 3px var(--accent), 0 0 18px 4px color-mix(in srgb, var(--accent) 70%, transparent) !important; }
.card.ai { animation: aiglow 1.4s ease-in-out infinite; }
@keyframes aiglow { 50% { box-shadow: 0 0 0 3px var(--accent), 0 0 28px 8px color-mix(in srgb, var(--accent) 80%, transparent); } }
.aikey { color: var(--accent); font-weight: 700; }
svg.map .node.ai circle:not(.hit) { stroke: var(--accent); stroke-width: 5; filter: drop-shadow(0 0 5px var(--accent)); }

.cardrow { display: flex; flex-wrap: wrap; gap: 16px 12px; justify-content: center; padding: 14px 4px 18px; }
.cardrow.big .card { width: 170px; height: 232px; }
.cardgrid { display: flex; flex-wrap: wrap; gap: 16px 12px; justify-content: center; padding: 12px 4px; }
.title.center { text-align: center; }

/* The fight */
.battle { display: flex; flex-direction: column; gap: 10px; min-height: 100%; }
.turn { color: var(--dim); font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; }
/* The stage, as in the game: you on the left, the enemies on the right one above the other, both
   in the middle of the space above the hand. */
.stage { flex: 1; display: grid; grid-template-columns: 1fr 1fr; gap: 24px; align-items: center; padding: 8px 0; }
.side-you { display: flex; justify-content: center; }
.stage .unit { flex: none; }
.enemies { display: flex; flex-direction: column; gap: 10px; align-items: center; }
.monster { width: min(100%, 300px); flex: none; }
.monster.target { cursor: crosshair; border-color: var(--bad); box-shadow: 0 0 0 2px var(--bad); }
.monster.target:hover { background: color-mix(in srgb, var(--bad) 18%, var(--panel)); }
.monster.ai-target { outline: 3px dashed var(--accent); outline-offset: 2px; }
.hint { text-align: center; color: var(--bad); font-weight: 700; }
.unit.player { flex: none; width: min(100%, 300px); }
.table { margin-top: auto; display: grid; grid-template-columns: auto 1fr auto; align-items: end; gap: 10px; padding-top: 34px; }
.table .left, .table .right { display: flex; flex-direction: column; gap: 8px; align-items: center; }
.hand { display: flex; justify-content: center; align-items: flex-end; min-height: 190px; min-width: 0; padding: 0 12px; }
.hand .card { width: 132px; height: 182px; }
.hand .card .art { height: 52px; }
.hand .card + .card { margin-left: var(--ov, -14px); }
.hand .card { transform-origin: 50% 120%; }
.energy { width: 54px; height: 54px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 24px; font-weight: 900;
  color: #fff; text-shadow: 0 1px 3px #000; background: radial-gradient(circle at 35% 30%, #ffe9a0, #e0902a 55%, #6a3a08); border: 3px solid #f6d77c; cursor: help; }
.pile { display: flex; flex-direction: column; align-items: center; min-width: 64px; padding: 4px 8px; }
.pile b { font-size: 16px; color: var(--accent); }
.pile span { font-size: 11px; color: var(--dim); }
.endturn { background: linear-gradient(#3d7bbf, #24527f); color: #fff; font-weight: 800; border-color: #8ec1f2; padding: 10px 14px; min-width: 96px; }
.choicebox { border: 1px solid var(--accent); border-radius: 10px; padding: 8px 10px; background: color-mix(in srgb, var(--accent-bg) 50%, var(--panel)); }
.choicebox h3 { margin: 2px 0; }
.confirm { display: flex; justify-content: center; margin: 4px 0 8px; }
.confirm button { padding: 8px 24px; font-weight: 700; }

/* Events and other choices, the game's way: a title, a line, buttons for the options. */
.event { max-width: 680px; margin: 0 auto; }
.event .lore { color: var(--dim); font-style: italic; line-height: 1.5; }
.options { display: flex; flex-direction: column; gap: 8px; margin: 14px 0; }
.option { text-align: left; padding: 12px 16px; font-size: 15px; border-radius: 8px; border: 2px solid var(--line);
  background: linear-gradient(90deg, var(--panel2), var(--panel)); }
.option:hover:not(:disabled) { border-color: var(--accent); background: linear-gradient(90deg, var(--accent-bg), var(--panel)); }
.option.small { padding: 8px 14px; font-size: 14px; }
.rewards { display: flex; flex-wrap: wrap; gap: 10px; margin: 10px 0; }
.reward { min-width: 220px; display: flex; flex-direction: column; gap: 3px; background: var(--panel); border: 2px solid var(--line); border-radius: 8px; padding: 10px 12px; cursor: pointer; }
[data-act].reward:hover, [data-act].buy:hover, .box[data-act]:hover { border-color: var(--accent); }
.buy, .box[data-act] { cursor: pointer; }
#actions .bar { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin: 12px 0; }

/* Map */
svg.map { display: block; width: 100%; max-width: 360px; height: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; }
/* The map screen: the map as tall as the window allows, in the middle, the legend under it. */
#screen.s-map { text-align: center; min-height: 0; }
#screen.s-map svg.map { max-width: none; width: auto; height: max(320px, calc(100vh - 260px)); margin: 0 auto; }
#screen.s-map .legend { margin: 8px auto; justify-content: center; max-width: 560px; }
#modal svg.map { max-width: none; width: auto; height: min(70vh, 760px); }
svg.map line { stroke: var(--line); stroke-width: 2; stroke-dasharray: 3 4; }
svg.map line.taken { stroke: var(--accent); stroke-width: 3.5; stroke-dasharray: none; }
svg.map .node circle { fill: var(--panel2); stroke: var(--line); stroke-width: 2; }
svg.map .node text { fill: var(--text); font-size: 17px; text-anchor: middle; dominant-baseline: central; pointer-events: none; }
svg.map .node.boss text { font-size: 22px; }
svg.map .node.past { opacity: 0.45; }
svg.map .node.visited circle { fill: var(--accent-bg); stroke: var(--accent); }
svg.map .node.here circle { fill: var(--accent); stroke: var(--text); stroke-width: 3; }
svg.map .node.here text { fill: #1a1a1a; }
svg.map .node.next circle { stroke: var(--good); stroke-width: 3.5; }
svg.map .node[data-x] { cursor: pointer; }
svg.map .node circle.hit { fill: transparent; stroke: none; }
svg.map .node[data-x]:hover circle:not(.hit), svg.map .node[data-x]:focus circle:not(.hit) { fill: color-mix(in srgb, var(--good) 35%, var(--panel2)); }
svg.map .node[data-x]:focus { outline: none; }
svg.map .r-Elite text { fill: var(--bad); }
svg.map .r-Rest text { fill: var(--good); }
svg.map .r-Shop text { fill: var(--energy); }
svg.map .r-Treasure text { fill: var(--power); }
svg.map .r-Boss text { fill: var(--bad); }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; margin: 8px 0; font-size: 12px; color: var(--dim); max-width: 420px; }
.legend i { font-style: normal; display: inline-block; width: 1.3em; text-align: center; color: var(--text); }
.legend i.r-Elite, .legend i.r-Boss { color: var(--bad); }
.legend i.r-Rest { color: var(--good); }
.legend i.r-Shop { color: var(--energy); }
.legend i.r-Treasure { color: var(--power); }
.here-dot, .next-dot { width: 12px !important; height: 12px; border-radius: 50%; vertical-align: -1px; }
.here-dot { background: var(--accent); }
.next-dot { border: 3px solid var(--good); }

/* Tooltip and modal */
#tip { position: fixed; z-index: 50; max-width: 290px; background: var(--panel); color: var(--text); border: 1px solid var(--accent); border-radius: 8px; padding: 8px 10px; box-shadow: var(--shadow); font-size: 13px; line-height: 1.4; pointer-events: none; }
#tip[hidden] { display: none; }
#tip p { margin: 4px 0 0; }
#tip .dim { font-size: 12px; }
#tip .upgraded { color: var(--upgraded); }
#tip dl { margin: 6px 0 0; padding-top: 6px; border-top: 1px solid var(--line); font-size: 12px; }
#tip dt { font-weight: 700; display: inline; }
#tip dt::after { content: ": "; }
#tip dd { display: inline; margin: 0; color: var(--dim); }
#tip dd::after { content: ""; display: block; margin-bottom: 3px; }
#tip .kw { font-weight: 600; }
#modal { position: fixed; inset: 0; z-index: 40; background: rgba(0, 0, 0, 0.55); display: flex; align-items: center; justify-content: center; padding: 16px; }
#modal[hidden] { display: none; }
.modalbox { background: var(--bg); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); max-width: 900px; width: 100%; max-height: 90vh; overflow: auto; padding: 14px 16px; }
.modalhead { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 8px; }
.modalhead h2 { margin: 0; font-size: 18px; }
#modalbody p { line-height: 1.45; }
#modalbuttons { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; margin-top: 10px; }
#modalbuttons:empty { display: none; }
#modal svg.map { margin: 0 auto; }
dl.keys { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; align-items: baseline; }
dl.keys dt { text-align: right; white-space: nowrap; }
dl.keys dd { margin: 0; }
input.copy { width: 100%; }
.upgtoggle { display: inline-flex; gap: 6px; align-items: center; cursor: pointer; font-weight: 600; }
.upgtoggle input { min-height: 0; width: 18px; height: 18px; }
.card.zoomable { cursor: pointer; }
.card.zoomable:hover { transform: translateY(-6px); }
.compare { display: flex; align-items: center; justify-content: center; gap: 22px; flex-wrap: wrap; padding: 18px 0; }
.compare .card.big { width: 200px; height: 274px; padding-top: 28px; }
.compare .card.big .banner { font-size: 16px; }
.compare .card.big .art { height: 86px; font-size: 40px; }
.compare .card.big .desc { font-size: 14px; }
.compare .arrow { font-size: 34px; color: var(--accent); }
p.center { text-align: center; }

/* Phones and narrow windows: one column (the screen and its moves first, then the run, then the
   decisions), the step buttons pinned to the bottom, bigger tap targets. */
@media (max-width: 820px) {
  body { padding-bottom: 150px; }
  body.viewing { height: auto; }
  header { gap: 6px; padding: 6px 10px; }
  #runtitle { order: 9; flex-basis: 100%; font-size: 12px; }
  header button, header .button { padding: 6px 10px; min-height: 40px; }
  .choices { grid-template-columns: 1fr; }
  .chars { grid-template-columns: 1fr 1fr; }
  .setuprow { grid-template-columns: 1fr; }
  #setup { padding: 14px 16px 30px; }
  .hero h1 { font-size: 22px; }
  #home { padding: 14px 16px 30px; }
  main { display: flex; flex-direction: column; height: auto; }
  main > section { order: 1; padding: 10px 12px; overflow: visible; }
  #run { order: 2; border-right: 0; border-top: 1px solid var(--line); }
  #side { order: 3; border-left: 0; border-top: 1px solid var(--line); max-height: 60vh; }
  main > aside { overflow: auto; padding: 10px 12px; }
  nav#controls { position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; gap: 6px; padding: 6px 8px calc(6px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); border-bottom: 0; }
  nav#controls button { min-width: 44px; min-height: 44px; flex: 1; }
  nav#controls #jump { display: none; }
  nav#controls label { font-size: 0; }
  #pos { min-width: 0; flex: 1 1 100%; order: -1; font-size: 12px; }
  #screen { min-height: 0; }
  .title { font-size: 17px; }
  .row { gap: 6px; }
  .unit { min-width: 0; flex: 1 1 150px; }
  .card { width: 104px; height: 146px; padding: 18px 5px 5px; gap: 3px; border-width: 2px; }
  .card .banner { font-size: 11px; left: 12px; }
  .card .art { height: 30px; font-size: 18px; }
  .card .desc { font-size: 9.5px; padding: 2px; }
  .card .cost { width: 26px; height: 26px; line-height: 22px; font-size: 14px; }
  .cardrow.big .card { width: 112px; height: 160px; }
  .table { grid-template-columns: 1fr 1fr; padding-top: 10px; }
  .table .left, .table .right { flex-direction: row; grid-row: 2; }
  .table .right { justify-content: flex-end; }
  .hand { grid-column: 1 / -1; min-height: 170px; padding: 28px 16px 4px; }
  .hand .card { width: 104px; height: 146px; }
  .hand .card .art { height: 30px; }
  .stage { grid-template-columns: 1fr; gap: 10px; }
  .side-you { order: 2; }
  .monster, .unit.player { width: 100%; }
  .chip { font-size: 12px; padding: 4px 9px; }
  .power { font-size: 12px; padding: 2px 7px; }
  #log li { padding: 7px 6px; min-height: 40px; align-items: center; }
  button, .button, select, input { min-height: 40px; }
  #log details.floor > summary { padding: 9px 2px; }
  svg.map, #screen.s-map svg.map, #modal svg.map { max-width: 100%; width: 100%; height: auto; }
  #tip { max-width: calc(100vw - 24px); }
  .modalbox { padding: 12px; max-height: 94vh; }
  #modal { padding: 8px; }
}
@media (prefers-reduced-motion: reduce) {
  .loading::before { animation: none; }
}
