/*
VOICE: an old illuminated war-chronicle, solemn and warm, never cute.
IDEA: the Third Age console menus: ornate gilt frames over painted scenes, a glowing bar on the chosen line.
PICTURE: Spencer's own campaign paintings, full-bleed behind every screen, framed like museum plates.
COLOUR and TYPE: near-black slate, aged gold filigree, parchment for the war table; Cinzel Decorative, Cinzel, EB Garamond.
LAYOUT: battle = enemies standing in arched frames above, party roster and command menu in gilt panels below.
*/
:root {
  --scale: 1;
  --ink: #efe6d2; --ink-dim: #c2b495; --ink-faint: #8e826a;
  --gold: #e2c27a; --gold-2: #b8934a; --gold-3: #7d6330; --gold-glow: rgba(226, 194, 122, 0.35);
  --slate: rgba(14, 12, 10, 0.9); --slate-2: rgba(24, 20, 16, 0.92); --slate-solid: #14110d;
  --hp: #b8382c; --hp2: #e0644a; --sp: #3c6fb4; --sp2: #79aee8; --fate: #f2d58a;
  --focus: #ffe9a8;
  --radius: 4px;
  --font-display: "Cinzel Decorative", "Cinzel", "Trajan Pro", Palatino, serif;
  --font-title: "Cinzel", "Trajan Pro", "Palatino Linotype", Palatino, Georgia, serif;
  --font-body: "EB Garamond", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --fs: calc(16px * var(--scale));
  --corner: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='34' height='34' viewBox='0 0 34 34'><g fill='none' stroke='%23d9b86e' stroke-width='1.3'><path d='M2 32V8a6 6 0 0 1 6-6h24'/><path d='M6 32V12a6 6 0 0 1 6-6h20' opacity='.55'/><path d='M10 10c4 0 6 2 6 6M10 10c0 4 2 6 6 6' /><circle cx='10' cy='10' r='2.2' fill='%23d9b86e'/><path d='M18 2c0 3 2 5 5 5M2 18c3 0 5 2 5 5' opacity='.7'/></g></svg>");
  color-scheme: dark;
}
html.contrast { --ink: #fff; --ink-dim: #eee; --ink-faint: #d0d0d0; --slate: rgba(0,0,0,0.96); --slate-2: rgba(0,0,0,0.96); --focus: #ffee00; }
* { box-sizing: border-box; min-width: 0; }
html, body { margin: 0; height: 100%; background: #070605; overflow: hidden; }
body { font-family: var(--font-body); font-size: var(--fs); color: var(--ink); line-height: 1.4; -webkit-font-smoothing: antialiased; user-select: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
button { font: inherit; color: inherit; }
#app { position: fixed; inset: 0; overflow: hidden; }

/* ---------- backdrop: painted plate + ambient particles ---------- */
#bgimg { position: absolute; inset: -2%; background-size: cover; background-position: center; filter: saturate(0.92) brightness(0.62); transform: scale(1.04); transition: opacity 0.8s; }
#bgimg.dim { filter: saturate(0.75) brightness(0.38) blur(2px); }
#bg { position: absolute; inset: 0; width: 100%; height: 100%; }
#fx { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
#vignette { position: absolute; inset: 0; pointer-events: none; background: radial-gradient(ellipse at 50% 42%, transparent 38%, rgba(0,0,0,0.72) 100%), linear-gradient(180deg, rgba(0,0,0,0.35), transparent 20%, transparent 70%, rgba(0,0,0,0.6)); }
#grain { position: absolute; inset: 0; pointer-events: none; opacity: 0.16; mix-blend-mode: overlay; background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='220' height='220'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='3' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.6  0 0 0 0 0.5  0 0 0 0 0.35  0 0 0 0.9 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>"); }
#screen { position: absolute; inset: 0; display: flex; flex-direction: column; overflow: hidden; padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left); }
.scroll { overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch; scrollbar-width: thin; scrollbar-color: var(--gold-3) transparent; }

/* ---------- the gilt frame ---------- */
.frame { position: relative; background: linear-gradient(180deg, var(--slate-2), var(--slate)); border: 1px solid rgba(217, 184, 110, 0.55); border-radius: var(--radius); box-shadow: 0 0 0 1px rgba(0,0,0,0.85), inset 0 0 0 3px rgba(0,0,0,0.55), inset 0 0 0 4px rgba(217, 184, 110, 0.16), 0 14px 40px rgba(0,0,0,0.6); }
.frame::before, .frame::after { content: ''; position: absolute; width: 34px; height: 34px; pointer-events: none; background: var(--corner) no-repeat; opacity: 0.95; }
.frame::before { left: -3px; top: -3px; }
.frame::after { right: -3px; bottom: -3px; transform: rotate(180deg); }
.frame.plain::before, .frame.plain::after { display: none; }
.rule { height: 1px; background: linear-gradient(90deg, transparent, var(--gold-2), transparent); margin: 0.4em 0; border: 0; }
h1, h2, h3, .logo { font-feature-settings: "liga" 0, "dlig" 0, "clig" 0; }
h1, h2, h3 { font-family: var(--font-title); font-weight: 600; letter-spacing: 0.06em; margin: 0; color: var(--gold); text-shadow: 0 1px 0 #000, 0 0 14px rgba(226, 194, 122, 0.15); }
.muted { color: var(--ink-dim); }
.faint { color: var(--ink-faint); }
.gold { color: var(--gold); }
.chip { display: inline-flex; align-items: center; gap: 0.25em; font-size: 0.72em; padding: 0.02em 0.45em; border-radius: 2px; border: 1px solid rgba(217, 184, 110, 0.3); background: rgba(0,0,0,0.45); white-space: nowrap; font-family: var(--font-title); letter-spacing: 0.04em; }
.chip.bad { border-color: #a0483c; color: #ffb6a8; }
.chip.good { border-color: #6b9a5c; color: #cdf0bd; }

/* ---------- Third Age menu lines ---------- */
.btn { position: relative; display: flex; align-items: center; gap: 0.6em; width: 100%; min-height: 2.7em; padding: 0.35em 0.9em 0.35em 1.7em; border: 0; border-radius: 2px; background: transparent; color: var(--ink); cursor: pointer; text-align: left; font-family: var(--font-title); letter-spacing: 0.06em; font-size: 0.98em; outline: none; transition: background 0.15s, color 0.15s; }
.btn::before { content: '◆'; position: absolute; left: 0.55em; color: var(--gold-2); font-size: 0.7em; opacity: 0; transition: opacity 0.15s; }
.btn:hover, .btn.focus { background: linear-gradient(90deg, rgba(226, 194, 122, 0.30), rgba(226, 194, 122, 0.10) 70%, transparent); color: #fff8e4; text-shadow: 0 0 10px rgba(255, 220, 150, 0.6); }
.btn:hover::before, .btn.focus::before { opacity: 1; }
.btn[disabled], .btn.disabled { color: var(--ink-faint); cursor: default; text-shadow: none; }
.btn .k { margin-left: auto; color: var(--ink-faint); font-family: var(--font-body); letter-spacing: 0; font-size: 0.86em; white-space: nowrap; }
.btn.primary { color: var(--gold); }
.btn.danger { color: #f0a090; }
.btn.boxed { border: 1px solid rgba(217, 184, 110, 0.45); background: rgba(0,0,0,0.35); padding-left: 1.7em; }
body.kbd .btn.focus { box-shadow: inset 0 0 0 1px var(--focus); }
body.kbd [data-nav].focus:not(.btn) { outline: 2px solid var(--focus); outline-offset: 2px; }
[data-nav]:focus { outline: none; }
.list { display: flex; flex-direction: column; gap: 0.15em; }

#hint { position: absolute; left: 0; right: 0; bottom: 0; display: flex; gap: 1.2em; justify-content: center; padding: 0.25em 0.8em calc(0.25em + env(safe-area-inset-bottom)); font-size: 0.76em; color: var(--ink-faint); pointer-events: none; z-index: 30; font-family: var(--font-title); letter-spacing: 0.05em; }
#hint .key { display: inline-block; min-width: 1.6em; padding: 0 0.35em; border: 1px solid var(--ink-faint); border-radius: 4px; text-align: center; margin-right: 0.35em; color: var(--ink-dim); font-family: var(--font-body); }
#hint .key.a { border-radius: 99px; background: #2f6a3a; color: #fff; border-color: #5fa86a; }
#hint .key.b { border-radius: 99px; background: #7a2f2a; color: #fff; border-color: #c0605a; }
#hint .key.x { border-radius: 99px; background: #2a4a7a; color: #fff; border-color: #5f86c6; }
#hint .key.y { border-radius: 99px; background: #7a6a2a; color: #fff; border-color: #c6b05f; }
body.touch #hint { display: none; }
#toast { position: absolute; top: 1em; left: 50%; transform: translateX(-50%); z-index: 50; pointer-events: none; display: flex; flex-direction: column; gap: 0.4em; align-items: center; }
.toast { padding: 0.5em 1.1em; background: var(--slate-solid); border: 1px solid var(--gold-2); border-radius: 3px; box-shadow: 0 8px 26px rgba(0,0,0,0.6); font-family: var(--font-title); letter-spacing: 0.04em; animation: fadeIn 0.25s ease-out; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(-6px); } }

/* ---------- title ---------- */
.title-screen { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1.6em; padding: 1.5em; text-align: center; }
.logo { line-height: 1; }
.logo .a { display: block; font-family: var(--font-title); font-size: clamp(0.9em, 2.4vw, 1.25em); letter-spacing: 0.6em; color: var(--ink-dim); margin-bottom: 0.4em; }
.logo .b { display: block; font-family: var(--font-display); font-weight: 700; font-size: clamp(2em, 7.2vw, 4.6em); letter-spacing: 0.03em; background: linear-gradient(180deg, #fff3cf 0%, #e8c77e 45%, #9d7a36 100%); -webkit-background-clip: text; background-clip: text; color: transparent; filter: drop-shadow(0 2px 0 #000) drop-shadow(0 0 22px rgba(232, 199, 126, 0.35)); }
.logo .c { display: block; margin-top: 0.6em; font-style: italic; font-size: clamp(1em, 2.4vw, 1.3em); color: var(--ink-dim); text-shadow: 0 1px 6px #000; }
.title-menu { min-width: min(22em, 86vw); padding: 0.8em 0.6em; }
.sync { font-size: 0.82em; color: var(--ink-faint); min-height: 1.2em; text-shadow: 0 1px 4px #000; max-width: 34em; }

/* ---------- narration ---------- */
.narr { flex: 1; display: grid; grid-template-rows: 1fr auto; padding: 1.2em max(1em, 4vw) 2.4em; gap: 1em; min-height: 0; }
.narr-head { align-self: start; text-align: center; padding-top: 4vh; }
.narr-head .num { font-family: var(--font-title); letter-spacing: 0.5em; color: var(--ink-dim); font-size: 0.85em; }
.narr-head h1 { font-family: var(--font-display); font-size: clamp(1.6em, 5vw, 3em); margin-top: 0.15em; }
.narr-head .sess { font-style: italic; color: var(--ink-dim); margin-top: 0.4em; text-shadow: 0 1px 4px #000; }
.narr-box { max-width: 56em; width: 100%; margin: 0 auto; padding: 1em 1.3em 0.9em; display: grid; grid-template-columns: auto 1fr; gap: 1.1em; align-items: start; }
.narr-portrait { width: clamp(4em, 9vw, 6.5em); aspect-ratio: 2/3; border: 1px solid var(--gold-2); box-shadow: 0 0 0 3px rgba(0,0,0,0.6); background-size: cover; background-position: center 25%; }
.narr-speaker { font-family: var(--font-title); color: var(--gold); font-size: 0.82em; letter-spacing: 0.18em; margin-bottom: 0.35em; }
.narr-text { font-size: 1.2em; min-height: 4.6em; line-height: 1.5; }
.narr-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 0.6em; gap: 0.6em; }
.narr-foot .row { display: flex; gap: 0.3em; }
.narr-foot .btn { width: auto; }
.narr-dots { color: var(--ink-faint); font-size: 0.8em; font-family: var(--font-title); }

/* ---------- war table ---------- */
.table { flex: 1; display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr); gap: 0.9em; padding: 0.9em max(0.9em, 2vw) 2.3em; min-height: 0; }
.mapwrap { position: relative; padding: 0.6em; display: flex; flex-direction: column; gap: 0.5em; min-height: 0; }
.maphead { display: flex; align-items: baseline; gap: 0.8em; padding: 0 0.3em; flex-wrap: wrap; }
.maphead h2 { font-family: var(--font-display); font-size: 1.35em; }
.maphead .sess { font-style: italic; color: var(--ink-dim); font-size: 0.9em; }
.map { position: relative; flex: 1; min-height: 14em; border: 1px solid var(--gold-3); box-shadow: inset 0 0 40px rgba(60, 40, 10, 0.55); overflow: hidden; border-radius: 2px; }
.map canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.seal { position: absolute; transform: translate(-50%, -50%); display: flex; flex-direction: column; align-items: center; gap: 0.1em; cursor: pointer; border: 0; background: none; padding: 0; z-index: 2; }
.seal .dot { width: 1.9em; height: 1.9em; border-radius: 50%; display: grid; place-items: center; font-size: 0.95em; font-family: var(--font-title); color: #fff4d6; border: 2px solid #3a240c; box-shadow: 0 2px 4px rgba(0,0,0,0.5), inset 0 -3px 6px rgba(0,0,0,0.35); background: radial-gradient(circle at 35% 30%, #d4553f, #8a1f14 70%); }
.seal.side .dot { background: radial-gradient(circle at 35% 30%, #4a7ab0, #1d3a66 70%); }
.seal.boss .dot { width: 2.4em; height: 2.4em; background: radial-gradient(circle at 35% 30%, #2a2a2a, #000 70%); border-color: #8a1f14; color: #ff9a80; }
.seal.done .dot { background: radial-gradient(circle at 35% 30%, #9a8a6a, #5a4a32 70%); color: #2a1e0e; }
.seal.locked { opacity: 0.45; filter: grayscale(0.7); }
.seal .lbl { font-family: var(--font-title); font-size: 0.7em; color: #2b1a08; background: rgba(240, 222, 180, 0.82); padding: 0.05em 0.4em; border-radius: 2px; white-space: nowrap; letter-spacing: 0.03em; }
.seal.focus .dot, .seal:hover .dot { box-shadow: 0 0 0 3px #fff2c8, 0 0 18px #ffd88a; }
.opside { display: flex; flex-direction: column; gap: 0.7em; min-height: 0; }
.oplist { padding: 0.4em 0.3em; flex: none; max-height: 40%; }
.oplist .btn .kind { font-size: 0.72em; font-family: var(--font-title); letter-spacing: 0.12em; margin-left: auto; }
.oplist .btn .kind.main { color: #f0a08a; } .oplist .btn .kind.side { color: #9cc0ec; } .oplist .btn .kind.boss { color: #ff7a60; } .oplist .btn .kind.done { color: var(--ink-faint); }
.opdetail { padding: 0.8em 1em 0.7em; display: flex; flex-direction: column; gap: 0.5em; min-height: 0; flex: 1; }
.opbody { display: flex; flex-direction: column; gap: 0.4em; min-height: 0; flex: 1; }
#opgo-wrap { flex: none; }
.oplist .btn, .tablemenu .btn { min-height: 2.15em; font-size: 0.9em; }
.tablemenu { display: grid; grid-template-columns: 1fr 1fr; gap: 0 0.2em; }
.tablemenu .btn .k { font-size: 0.8em; }
.opdetail h3 { font-size: 1.15em; }
.opdetail .region { font-style: italic; color: var(--ink-dim); }
.opdetail .brief { font-size: 1.02em; }
.foe-line { display: flex; align-items: center; gap: 0.5em; font-size: 0.9em; margin: 0.15em 0; }
.foe-line img, .foe-line .emb { width: 2em; height: 2em; border-radius: 2px; object-fit: cover; border: 1px solid var(--gold-3); flex: none; }
.rewards { display: flex; flex-wrap: wrap; gap: 0.35em; }
.tablemenu { padding: 0.4em 0.3em; flex: none; }

/* ---------- portraits / emblems ---------- */
.emb { display: grid; place-items: center; background: radial-gradient(circle at 35% 30%, color-mix(in srgb, var(--c) 70%, #fff 30%), var(--c) 45%, color-mix(in srgb, var(--c) 40%, #000 60%)); }
.emb svg { width: 62%; height: 62%; fill: rgba(255, 248, 230, 0.95); filter: drop-shadow(0 1px 1px rgba(0,0,0,0.6)); }
.face { width: 2.6em; height: 2.6em; flex: none; border-radius: 50%; border: 2px solid var(--gold-2); box-shadow: 0 0 0 2px rgba(0,0,0,0.7); background-size: cover; background-position: center 18%; overflow: hidden; }
.face.sm { width: 1.9em; height: 1.9em; }
.face.lg { width: 4em; height: 4em; }
.face .emb { width: 100%; height: 100%; }

/* ---------- party screen ---------- */
.party-scr { flex: 1; display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); gap: 0.9em; padding: 0.9em max(0.9em, 2vw) 2.3em; min-height: 0; }
.party-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(8.5em, 1fr)); gap: 0.6em; align-content: start; padding: 0.3em; }
.pcard { position: relative; display: flex; flex-direction: column; border: 1px solid rgba(217, 184, 110, 0.35); background: #0e0c0a; border-radius: 2px; cursor: pointer; padding: 0; overflow: hidden; text-align: left; }
.pcard .art { aspect-ratio: 2/3; background-size: cover; background-position: center 20%; position: relative; }
.pcard .art .emb { position: absolute; inset: 0; }
.pcard .art .emb svg { width: 45%; height: 45%; }
.pcard .cap { padding: 0.35em 0.5em 0.45em; background: linear-gradient(180deg, rgba(0,0,0,0.2), #0b0a08); }
.pcard .nm { font-family: var(--font-title); font-size: 0.92em; letter-spacing: 0.04em; }
.pcard .sub { font-size: 0.72em; color: var(--ink-faint); }
.pcard .role { position: absolute; top: 0.4em; left: 0.4em; font-family: var(--font-title); font-size: 0.62em; letter-spacing: 0.14em; padding: 0.1em 0.45em; background: rgba(0,0,0,0.7); border: 1px solid var(--ink-faint); color: var(--ink-faint); }
.pcard.active { border-color: var(--gold); box-shadow: 0 0 0 1px var(--gold), 0 0 18px rgba(226, 194, 122, 0.25); }
.pcard.active .role { color: var(--gold); border-color: var(--gold); }
.pcard.reserve { border-color: #6f8fb0; }
.pcard.reserve .role { color: #a9c6ea; border-color: #6f8fb0; }
.pcard.bench .art { filter: grayscale(0.6) brightness(0.7); }
body.kbd .pcard.focus { outline: 2px solid var(--focus); outline-offset: 2px; }
.pcard:hover { border-color: var(--gold); }
.detail { padding: 0.9em 1.1em; display: flex; flex-direction: column; gap: 0.55em; min-height: 0; }
.detail .hd { display: flex; gap: 0.9em; align-items: center; }
.detail .blurb { font-style: italic; color: var(--ink-dim); font-size: 0.95em; }
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0.2em 0.9em; font-size: 0.86em; }
.stats div { display: flex; justify-content: space-between; border-bottom: 1px dotted rgba(217, 184, 110, 0.25); }
.stats span:first-child { color: var(--ink-faint); font-family: var(--font-title); font-size: 0.9em; letter-spacing: 0.05em; }
.sklist { display: flex; flex-direction: column; gap: 0.35em; font-size: 0.88em; }
.sk { padding: 0.3em 0.6em; border-left: 2px solid var(--gold-2); background: rgba(0,0,0,0.3); }
.sk.locked { opacity: 0.45; border-left-color: var(--ink-faint); }
.sk b { font-weight: 600; font-family: var(--font-title); font-size: 0.95em; letter-spacing: 0.03em; }
.sk.ult { border-left-color: var(--fate); }
.sk.relic { border-left-color: #8ac0a0; }

/* ---------- pages ---------- */
.page { flex: 1; display: flex; flex-direction: column; gap: 0.8em; padding: 0.9em max(0.9em, 3vw) 2.3em; min-height: 0; max-width: 62em; margin: 0 auto; width: 100%; }
.page-head { display: flex; align-items: center; gap: 1em; padding: 0.7em 1em; }
.page-head h2 { font-size: 1.35em; font-family: var(--font-display); }
.page-head .grow { flex: 1; }
.shop-item .ds { display: block; font-size: 0.82em; color: var(--ink-dim); font-family: var(--font-body); letter-spacing: 0; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(16em, 1fr)); gap: 0.7em; }
.ccard { padding: 0.9em 1em; display: flex; flex-direction: column; gap: 0.3em; }
.ccard h3 { font-size: 1em; }
.ccard .sess { font-size: 0.72em; color: var(--ink-faint); font-family: var(--font-title); letter-spacing: 0.12em; }
.ccard p { margin: 0; font-size: 0.93em; color: var(--ink-dim); }
.ccard.locked { opacity: 0.4; }
.setting .lbl { flex: 1; }
.setting .lbl small { display: block; color: var(--ink-faint); font-size: 0.8em; font-family: var(--font-body); letter-spacing: 0; }
.setting .val { font-family: var(--font-body); color: var(--gold); letter-spacing: 0; white-space: nowrap; }
.howto { padding: 1em 1.3em; font-size: 0.98em; }
.howto p { margin: 0.4em 0; }
.howto h3 { font-size: 1em; margin-top: 0.9em; }
.renames { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 0.15em 1.2em; font-size: 0.88em; }
.renames div:nth-child(odd) { color: var(--gold); }
.renames div:nth-child(even) { color: var(--ink-dim); font-style: italic; }

/* ---------- battle ---------- */
.battle { flex: 1; display: grid; grid-template-rows: auto minmax(0, 1fr) auto auto; gap: 0.45em; padding: 0.5em max(0.6em, 1.4vw) 2.1em; min-height: 0; }
.bt-top { display: flex; align-items: center; gap: 0.8em; flex-wrap: wrap; }
.bt-name { font-family: var(--font-title); color: var(--gold); letter-spacing: 0.1em; font-size: 0.95em; text-shadow: 0 1px 4px #000; }
.bt-round { color: var(--ink-faint); font-size: 0.8em; font-family: var(--font-title); }
.fate { display: flex; align-items: center; gap: 0.5em; min-width: 9em; flex: 1; max-width: 22em; }
.fate .lbl { font-family: var(--font-title); font-size: 0.72em; letter-spacing: 0.2em; color: var(--fate); }
.fate .bar { flex: 1; height: 0.62em; background: rgba(0,0,0,0.65); border: 1px solid var(--gold-3); overflow: hidden; border-radius: 1px; }
.fate .bar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #7d5c1e, #e7c46e, #fff2c4); transition: width 0.3s; }
.fate.full .bar { box-shadow: 0 0 14px var(--fate); animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 26px var(--fate); } }
.bt-tools { display: flex; gap: 0.3em; margin-left: auto; }
.bt-tools .btn { width: auto; min-height: 2.2em; padding: 0.15em 0.8em; font-size: 0.8em; border: 1px solid rgba(217, 184, 110, 0.4); background: rgba(0,0,0,0.45); }
.bt-tools .btn::before { display: none; }
.bt-tools .btn.on { color: var(--gold); border-color: var(--gold); }
.order { display: flex; gap: 0.25em; align-items: center; font-size: 0.7em; color: var(--ink-faint); overflow: hidden; white-space: nowrap; flex-basis: 100%; font-family: var(--font-title); letter-spacing: 0.03em; }
.order .o { padding: 0.05em 0.45em; border: 1px solid rgba(217, 184, 110, 0.3); background: rgba(0,0,0,0.5); border-radius: 1px; }
.order .o.e { border-color: rgba(200, 80, 70, 0.6); color: #f0b0a8; }
.order .o.now { border-color: var(--focus); color: var(--focus); }

/* Staged battlefield: party on the left, foes on the right, in depth. */
.stage { position: relative; min-height: 0; margin: 0 calc(-1 * max(0.6em, 1.4vw)); container-type: size; overflow: hidden; }
.stage .ground { position: absolute; left: -10%; right: -10%; bottom: 0; height: 64%; pointer-events: none; background: radial-gradient(ellipse 46% 34% at 50% 70%, rgba(255, 214, 150, 0.14), transparent 72%), linear-gradient(180deg, transparent, rgba(0,0,0,0.3) 30%, rgba(0,0,0,0.72)); }
.stage .mist { position: absolute; left: -25%; right: -25%; bottom: -2%; height: 26%; pointer-events: none; z-index: 2; background: radial-gradient(ellipse 22% 55% at 20% 70%, rgba(210, 205, 200, 0.12), transparent 70%), radial-gradient(ellipse 26% 50% at 62% 60%, rgba(210, 205, 200, 0.09), transparent 70%), radial-gradient(ellipse 18% 45% at 88% 75%, rgba(210, 205, 200, 0.1), transparent 70%); animation: mist 24s ease-in-out infinite alternate; }
@keyframes mist { to { transform: translateX(9%); } }
.stage.ult::after { content: ''; position: absolute; inset: 0; z-index: 3; pointer-events: none; background: radial-gradient(ellipse 60% 70% at 50% 55%, rgba(255, 215, 130, 0.12), rgba(0,0,0,0.6)); animation: fadeIn 0.3s; }
.stage.quake { animation: shake 0.3s; }
.cam { position: absolute; inset: 0; z-index: 1; transition: transform 0.5s cubic-bezier(0.2, 0.7, 0.2, 1); transform-origin: 50% 60%; }
.cam > div { position: absolute; inset: 0; }
.fig { --w: min(46cqh, 17cqw); position: absolute; transform: translateX(-50%); width: calc(var(--w) * var(--s, 1)); display: flex; flex-direction: column; align-items: center; transition: opacity 0.45s, filter 0.45s; cursor: default; }
.fig.hero { width: calc(var(--w) * 0.88 * var(--s, 1)); }
.fig.big { width: calc(var(--w) * 1.3 * var(--s, 1)); }
.fig .body { position: relative; width: 100%; z-index: 1; transition: filter 0.25s, transform 0.45s, opacity 0.45s; }
.fig .plate { position: relative; width: 100%; aspect-ratio: 4/5; animation: bob 3.4s ease-in-out infinite; animation-delay: var(--d, 0s); -webkit-mask-image: radial-gradient(ellipse 50% 50% at 50% 50%, #000 55%, transparent 100%); mask-image: radial-gradient(ellipse 50% 50% at 50% 50%, #000 55%, transparent 100%); }
.fig.hero .plate { aspect-ratio: 3/4; }
.fig .plate .art { position: absolute; inset: 0; background-size: cover; background-position: center 30%; }
.fig .plate .emb { position: absolute; inset: 0; }
.fig .plate .emb svg { width: 46%; height: 46%; }
.fig.foe .plate .emb { animation: wisp 2.6s ease-in-out infinite; }
@keyframes wisp { 50% { filter: brightness(1.25) saturate(1.2); } }
.fig .shadow { position: absolute; left: 50%; bottom: -5%; width: 92%; height: 15%; transform: translateX(-50%); border-radius: 50%; background: radial-gradient(ellipse at center, rgba(0,0,0,0.8), rgba(0,0,0,0.35) 45%, transparent 70%); }
@keyframes bob { 50% { transform: translateY(-2.5%); } }
.fig.boss .body { filter: drop-shadow(0 0 16px rgba(200, 60, 40, 0.5)); }
.fig.turn::before, .fig.aim::before { content: '\25BC'; position: absolute; left: 50%; top: -1.3em; transform: translateX(-50%); z-index: 5; color: var(--focus); font-size: 0.95em; text-shadow: 0 0 6px #000, 0 0 14px var(--gold); animation: mark 0.9s ease-in-out infinite; }
.fig.aim::before { color: #fff; text-shadow: 0 0 6px #000, 0 0 16px #fff2c8; }
@keyframes mark { 50% { margin-top: -0.3em; } }
.fig.turn .shadow { background: radial-gradient(ellipse at center, rgba(255, 226, 150, 0.55), rgba(120, 90, 30, 0.35) 40%, transparent 70%); }
.fig.targetable { cursor: pointer; }
.fig.targetable .body { filter: drop-shadow(0 0 6px rgba(240, 192, 112, 0.55)); }
.fig.aim .body, .fig.targetable:hover .body { filter: drop-shadow(0 0 14px rgba(255, 236, 180, 0.95)) brightness(1.12); }
.fig.foe.tell .body { animation: tellGlow 0.9s ease-in-out infinite; }
@keyframes tellGlow { 0%, 100% { filter: drop-shadow(0 0 8px rgba(255, 80, 40, 0.6)); } 50% { filter: drop-shadow(0 0 24px rgba(255, 80, 40, 1)); } }
.fig.hero.ko .body { filter: grayscale(0.9) brightness(0.45); opacity: 0.6; transform: translateY(10%) rotate(-7deg); }
.fig.hero.ko .plate { animation: none; }
.fig.foe.ko { opacity: 0; filter: blur(5px) brightness(2.2); pointer-events: none; }
.fig .nameplate { order: -1; position: relative; z-index: 3; width: max(100%, 7.6em); margin-bottom: 0.15em; padding: 0.2em 0.45em 0.25em; text-align: center; background: linear-gradient(180deg, rgba(28, 23, 18, 0.88), rgba(10, 9, 7, 0.88)); border: 1px solid var(--gold-3); box-shadow: 0 4px 10px rgba(0,0,0,0.6); }
.fig.boss .nameplate { border-color: #c8543c; }
.bolt { position: absolute; z-index: 4; width: 1.5em; height: 1.5em; border-radius: 50%; pointer-events: none; transform: translate(-50%, -50%); background: radial-gradient(circle, #fff 0 18%, var(--c) 45%, transparent 72%); box-shadow: 0 0 18px 6px var(--c); }
.impact { position: absolute; left: 50%; top: 52%; width: 0; height: 0; z-index: 6; pointer-events: none; }
.impact::before { content: ''; position: absolute; left: -3em; top: -3em; width: 6em; height: 6em; border-radius: 50%; background: radial-gradient(circle, rgba(255,255,255,0.95), var(--c) 28%, transparent 66%); mix-blend-mode: screen; animation: boom 0.45s ease-out forwards; }
.impact.crit::before { left: -4.5em; top: -4.5em; width: 9em; height: 9em; }
.impact i { position: absolute; left: 0; top: -1px; width: 2.4em; height: 2px; transform-origin: 0 50%; background: linear-gradient(90deg, #fff, var(--c), transparent); box-shadow: 0 0 6px var(--c); animation: spark 0.5s ease-out forwards; }
.impact.heal::before { background: radial-gradient(circle, rgba(220, 255, 210, 0.7), rgba(120, 230, 120, 0.35) 34%, transparent 66%); }
.impact.heal i { width: 0.35em; height: 0.35em; border-radius: 50%; background: #d8ffc8; animation: mote 0.7s ease-out forwards; }
.impact.slash::after { content: ''; position: absolute; left: -3.6em; top: -2px; width: 7.2em; height: 3px; background: linear-gradient(90deg, transparent, #fff 40%, #fff 60%, transparent); box-shadow: 0 0 10px #fff, 0 0 20px var(--c); animation: slash 0.3s ease-out forwards; }
@keyframes boom { 0% { transform: scale(0.2); opacity: 1; } 100% { transform: scale(1.4); opacity: 0; } }
@keyframes spark { 0% { opacity: 1; transform: rotate(var(--a)) translateX(0.4em) scaleX(0.2); } 100% { opacity: 0; transform: rotate(var(--a)) translateX(2.8em) scaleX(1); } }
@keyframes mote { 0% { opacity: 1; transform: rotate(var(--a)) translateX(0.6em); } 100% { opacity: 0; transform: rotate(var(--a)) translateX(2em) translateY(-1.5em); } }
@keyframes slash { 0% { opacity: 1; transform: rotate(calc(-38deg + var(--r))) scaleX(0); } 55% { opacity: 1; transform: rotate(calc(-38deg + var(--r))) scaleX(1); } 100% { opacity: 0; transform: rotate(calc(-38deg + var(--r))) scaleX(1.1); } }
@container (max-aspect-ratio: 5/4) { .fig { --w: min(30cqh, 25cqw); } }
.fig .nameplate .weak:empty, .fig .nameplate .stat-row:empty { display: none; }
@container (max-width: 600px) { .fig .nameplate { width: max(100%, 5.4em); font-size: 0.74em; padding: 0.1em 0.3em 0.15em; } .fig .nameplate .stat-row { display: none; } }
html.reduce .fig .plate, html.reduce .stage .mist, html.reduce .fig.turn::before { animation: none; }
html.reduce .cam { transition: none; }
.foe .nm { font-family: var(--font-title); font-size: 0.74em; letter-spacing: 0.03em; line-height: 1.15; }
.foe .weak { font-size: 0.66em; color: var(--ink-faint); min-height: 1em; }
.foe .weak b { color: #ffd27a; font-weight: 600; }
.foe .stat-row { display: flex; gap: 0.2em; flex-wrap: wrap; justify-content: center; margin-top: 0.15em; }
.fig.foe.targetable .nameplate { border-color: #f0c070; }
.fig.foe.aim .nameplate, .fig.foe.targetable:hover .nameplate { border-color: #fff2c8; box-shadow: 0 0 14px rgba(255, 230, 160, 0.6); }
.bar2 { position: relative; height: 0.55em; background: rgba(0,0,0,0.7); overflow: hidden; border: 1px solid rgba(217, 184, 110, 0.22); border-radius: 1px; }
.bar2 i { position: absolute; left: 0; top: 0; bottom: 0; width: 100%; transition: width 0.35s ease-out; }
.bar2 .ghost { background: rgba(255, 240, 200, 0.55); transition: width 0.8s ease-in 0.2s; }
.bar2.hp i.v { background: linear-gradient(90deg, var(--hp), var(--hp2)); }
.bar2.sp i.v { background: linear-gradient(90deg, var(--sp), var(--sp2)); }
.bar2.hp .sh { background: repeating-linear-gradient(45deg, rgba(190, 220, 255, 0.85) 0 4px, rgba(150, 190, 240, 0.85) 4px 8px); left: auto; right: 0; }
.hit { animation: shake 0.32s; }
.flash { animation: flash 0.5s; }
@keyframes shake { 20% { transform: translateX(-6px); } 40% { transform: translateX(5px); } 60% { transform: translateX(-3px); } 80% { transform: translateX(2px); } }
@keyframes flash { 30% { filter: brightness(1.8); } }
html.reduce .hit, html.reduce .flash, html.reduce .fig.foe.tell .body { animation: none; }
.float { position: absolute; left: 50%; top: 28%; transform: translateX(-50%); font-family: var(--font-title); font-weight: 700; font-size: 1.45em; text-shadow: 0 2px 0 #000, 0 0 8px #000; pointer-events: none; animation: floatUp 1.1s ease-out forwards; white-space: nowrap; z-index: 6; }
.float.heal { color: #9cf08a; }
.float.crit { font-size: 1.8em; }
.float small { font-size: 0.5em; display: block; text-align: center; letter-spacing: 0.12em; }
@keyframes floatUp { 0% { opacity: 0; transform: translate(-50%, 6px) scale(0.8); } 15% { opacity: 1; transform: translate(-50%, -6px) scale(1.1); } 100% { opacity: 0; transform: translate(-50%, -48px) scale(1); } }
html.reduce .float { animation: floatFade 1.1s forwards; }
@keyframes floatFade { 0%, 70% { opacity: 1; } 100% { opacity: 0; } }

.descbar { min-height: 2.4em; padding: 0.35em 1em; display: flex; flex-direction: column; justify-content: center; font-size: 0.9em; text-align: center; }
.descbar .desc { color: var(--ink-dim); }
.descbar .desc b { color: var(--ink); font-family: var(--font-title); letter-spacing: 0.03em; }
.descbar .log { font-size: 0.86em; }
.log .good { color: #b6e6a6; } .log .bad { color: #ffb0a4; } .log .warn { color: #ffcf8a; font-style: italic; } .log .boss { color: #ff9c86; font-style: italic; } .log .card { color: #f2dc9a; } .log .muted { color: var(--ink-faint); }
.bt-bottom { display: grid; grid-template-columns: minmax(0, 0.95fr) minmax(0, 1.3fr); gap: 0.6em; }
.cmd { padding: 0.45em 0.4em; display: flex; flex-direction: column; gap: 0.2em; min-height: 9.6em; }
.cmd-head { font-family: var(--font-title); font-size: 0.8em; letter-spacing: 0.14em; color: var(--gold); display: flex; align-items: center; gap: 0.5em; padding: 0.1em 0.5em 0.3em; border-bottom: 1px solid rgba(217, 184, 110, 0.2); }
.cmd-list { display: grid; grid-template-columns: 1fr 1fr; gap: 0.05em 0.3em; overflow-y: auto; min-height: 0; max-height: 12.5em; padding: 2px; }
.cmd-list.one { grid-template-columns: 1fr; }
.cmd-list .btn { min-height: 2.3em; font-size: 0.86em; padding-right: 0.6em; }
.cmd-list .btn .cost { margin-left: auto; color: var(--sp2); font-family: var(--font-body); letter-spacing: 0; font-size: 0.92em; }
.cmd-list .btn.fatebtn { color: var(--fate); text-shadow: 0 0 10px rgba(242, 213, 138, 0.7); }
.roster { padding: 0.45em 0.6em; display: flex; flex-direction: column; gap: 0.35em; }
.rrow { position: relative; display: grid; grid-template-columns: auto minmax(0, 7.5em) minmax(0, 1fr); gap: 0.6em; align-items: center; padding: 0.25em 0.4em; border: 1px solid transparent; border-radius: 2px; transition: background 0.2s; }
.rrow .nm { font-family: var(--font-title); font-size: 0.9em; letter-spacing: 0.04em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rrow .nm small { color: var(--ink-faint); font-family: var(--font-body); letter-spacing: 0; }
.rrow .bars { display: grid; grid-template-columns: 2.1em minmax(0, 1fr) 4.6em; gap: 0.15em 0.4em; align-items: center; font-size: 0.74em; }
.rrow .bars .lb { font-family: var(--font-title); color: var(--ink-faint); letter-spacing: 0.08em; }
.rrow .bars .num { text-align: right; font-variant-numeric: tabular-nums; color: var(--ink-dim); white-space: nowrap; }
.rrow .stat-row { grid-column: 2 / 4; display: flex; gap: 0.2em; flex-wrap: wrap; min-height: 0; }
.rrow.turn { background: linear-gradient(90deg, rgba(255, 233, 168, 0.2), transparent 80%); border-color: rgba(255, 233, 168, 0.45); }
.rrow.ko { opacity: 0.45; filter: grayscale(0.85); }
.rrow.targetable { cursor: pointer; border-color: rgba(240, 192, 112, 0.6); }
.rrow.targetable.focus, .rrow.targetable:hover { background: rgba(240, 192, 112, 0.18); border-color: #fff2c8; }
.reserve-row { display: flex; gap: 0.3em; flex-wrap: wrap; font-size: 0.74em; color: var(--ink-faint); align-items: center; padding-top: 0.25em; border-top: 1px solid rgba(217, 184, 110, 0.18); font-family: var(--font-title); letter-spacing: 0.04em; }
.reserve-row .r { display: inline-flex; align-items: center; gap: 0.3em; padding: 0.1em 0.45em 0.1em 0.1em; border: 1px solid rgba(217, 184, 110, 0.25); background: rgba(0,0,0,0.4); }
.reserve-row .r.ko { opacity: 0.4; }

.banner { position: absolute; left: 0; right: 0; top: 11%; text-align: center; pointer-events: none; z-index: 20; }
.banner span { display: inline-block; padding: 0.4em 2em; font-family: var(--font-title); font-size: clamp(1.1em, 3.2vw, 1.8em); letter-spacing: 0.14em; color: #fff6dc; background: linear-gradient(90deg, transparent, rgba(10, 8, 6, 0.92) 15%, rgba(10, 8, 6, 0.92) 85%, transparent); border-top: 1px solid var(--gold-2); border-bottom: 1px solid var(--gold-2); text-shadow: 0 0 14px rgba(255, 220, 150, 0.6); animation: bannerIn 1.4s ease-out forwards; }
.banner.ult span { color: var(--fate); border-color: var(--fate); }
.banner.enemy span { border-color: #c8543c; color: #ffd0c4; }
.banner span small { display: block; font-family: var(--font-body); letter-spacing: 0.02em; font-size: 0.55em; color: var(--ink-dim); margin-top: 0.15em; font-style: italic; }
@keyframes bannerIn { 0% { opacity: 0; transform: scaleX(0.6); } 15% { opacity: 1; transform: scaleX(1); } 80% { opacity: 1; } 100% { opacity: 0; } }

/* ---------- results / modal ---------- */
.results { flex: 1; display: flex; align-items: center; justify-content: center; padding: 1em 1em 2.5em; min-height: 0; }
.results .frame { max-width: 46em; width: 100%; padding: 1.2em 1.4em; display: flex; flex-direction: column; gap: 0.7em; max-height: 100%; }
.results h2 { text-align: center; font-size: 1.7em; font-family: var(--font-display); }
.lvup { display: flex; align-items: center; gap: 0.6em; padding: 0.25em 0; border-bottom: 1px dotted rgba(217, 184, 110, 0.22); }
.lvup .new { color: #b6e6a6; font-size: 0.88em; }
.newcard { border: 1px solid var(--gold-2); padding: 0.8em 1em; background: rgba(60, 46, 20, 0.35); }
.newcard .sess { font-size: 0.74em; color: var(--gold); font-family: var(--font-title); letter-spacing: 0.14em; }
.modal-bg { position: absolute; inset: 0; background: rgba(0,0,0,0.65); display: grid; place-items: center; z-index: 40; padding: 1em; }
.modal { max-width: 30em; width: 100%; padding: 1.2em 1.1em 0.9em; display: flex; flex-direction: column; gap: 0.6em; }
.modal h3 { font-size: 1.15em; font-family: var(--font-display); }
.modal .mb p { margin: 0.35em 0; }

/* ---------- responsive ---------- */
@media (max-width: 860px), (max-height: 540px) {
  .table, .party-scr { grid-template-columns: 1fr; overflow-y: auto; }
  .table { display: flex; flex-direction: column; }
  .mapwrap { flex: none; }
  .map { flex: none; height: 46vh; min-height: 15em; }
  .opside, .opdetail, .opbody { flex: none; }
  .oplist { max-height: none; }
  .bt-bottom { grid-template-columns: 1fr; }
  .roster { order: -1; }
  .cmd { min-height: 0; }
}
@media (max-width: 560px) {
  :root { --fs: calc(15px * var(--scale)); }
  .rrow { grid-template-columns: auto minmax(0, 5.4em) minmax(0, 1fr); gap: 0.4em; }
  .bt-tools .btn span.lbl { display: none; }
  .cmd-list { max-height: 10.5em; }
  .narr-box { grid-template-columns: 1fr; }
  .narr-portrait { display: none; }
  .narr-text { font-size: 1.08em; }
  .party-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-height: 700px) and (min-width: 861px) {
  .battle { gap: 0.3em; }
  .cmd-list { max-height: 9.5em; }
  .cmd { min-height: 8.5em; }
}
