:root {
  --bg: #0e1016;
  --panel: rgba(20, 24, 36, 0.92);
  --panel-2: rgba(30, 36, 54, 0.95);
  --line: rgba(214, 178, 94, 0.45);
  --gold: #e3c06e;
  --gold-2: #f6dc9a;
  --text: #ece6d8;
  --muted: #9aa0ae;
  --blue: #4f86f7;
  --red: #e2504a;
  --green: #5cc46e;
  --orange: #f0a040;
  --radius: 10px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.55);
  --font: 'Alegreya Sans', system-ui, sans-serif;
  --display: 'Cinzel', Georgia, serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: var(--font); overflow: hidden; }
body { -webkit-font-smoothing: antialiased; user-select: none; }
button { font-family: inherit; }
img { image-rendering: auto; }

#map { position: fixed; inset: 0; width: 100vw; height: 100vh; display: block; opacity: 0; transition: opacity .4s; touch-action: none; }
#map.active { opacity: 1; }
#ui { position: fixed; inset: 0; pointer-events: none; }
#ui > * { pointer-events: auto; }
#ui > .battle-hud { pointer-events: none; }

/* ------------------------------------------------ buttons */
.btn {
  appearance: none; border: 1px solid var(--line); background: linear-gradient(180deg, #2a3048, #1b2032);
  color: var(--text); padding: 8px 16px; border-radius: 8px; cursor: pointer; font-size: 15px; font-weight: 600;
  letter-spacing: .02em; transition: transform .08s, background .2s, border-color .2s; box-shadow: 0 2px 0 rgba(0,0,0,.4);
}
.btn:hover { border-color: var(--gold); background: linear-gradient(180deg, #343b58, #22283f); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: linear-gradient(180deg, #c89a3c, #8c6420); border-color: var(--gold-2); color: #1d1406; }
.btn.primary:hover { background: linear-gradient(180deg, #ddb04c, #9d7226); }
.btn.danger { border-color: #b4483f; color: #ffb4ab; }
.btn.big { font-size: 18px; padding: 12px 26px; font-family: var(--display); }
.btn.small { padding: 4px 9px; font-size: 13px; border-radius: 6px; }
.btn.on { border-color: var(--gold-2); background: linear-gradient(180deg, #4a4024, #2c2614); color: var(--gold-2); }
.close-x { position: absolute; top: 10px; right: 12px; background: none; border: none; color: var(--muted); font-size: 20px; cursor: pointer; z-index: 2; }
.close-x:hover { color: var(--text); }
.tag { display: inline-block; font-size: 11px; padding: 1px 6px; margin-left: 6px; border-radius: 4px; background: #3b4256; color: var(--gold-2); vertical-align: middle; font-weight: 700; }
.tag.boss { background: #7c1e1e; color: #ffd7d2; }
.tag.eq { background: #2c5a2f; color: #c9ffcc; }
.muted { color: var(--muted); }
.good { color: #8fe39b; }
.warn { color: #ffcf7a; }

/* ------------------------------------------------ screens */
.screen { position: fixed; inset: 0; overflow: auto; }
.loading { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; font-family: var(--display); color: var(--gold); background: radial-gradient(circle at 50% 40%, #1d2233, #07080c); }
.spinner { width: 46px; height: 46px; border: 4px solid rgba(227,192,110,.2); border-top-color: var(--gold); border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.title { display: flex; align-items: center; justify-content: center; background: radial-gradient(ellipse at 50% 30%, #2a1d14 0%, #120c09 55%, #050405 100%); }
.title-bg { position: absolute; inset: 0; overflow: hidden; opacity: .34; filter: saturate(.85); display: flex; align-items: flex-end; justify-content: center; }
.title-bg .tb { position: relative; width: 12.5vw; min-width: 120px; aspect-ratio: 3 / 4; object-fit: cover; object-position: center 25%; margin-bottom: 6vh;
  mask-image: radial-gradient(ellipse at center, #000 45%, transparent 75%); -webkit-mask-image: radial-gradient(ellipse at center, #000 45%, transparent 75%); }
.title-bg .tb:nth-child(odd) { margin-bottom: 14vh; }
.title-box { position: relative; text-align: center; padding: clamp(24px, 5vw, 40px) clamp(16px, 5vw, 50px); margin: 0 12px; background: rgba(10,8,8,.55); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); backdrop-filter: blur(3px); }
.title h1 { font-family: var(--display); font-size: clamp(38px, 7vw, 76px); margin: 4px 0; color: var(--gold-2); letter-spacing: .06em; text-shadow: 0 0 24px rgba(255,170,60,.45), 0 4px 0 #3a2208; }
.title-crest { font-size: 40px; color: #ff9b3d; text-shadow: 0 0 20px #ff7b00; animation: glow 2.4s ease-in-out infinite; }
@keyframes glow { 50% { text-shadow: 0 0 40px #ffb347; transform: scale(1.06); } }
.subtitle { font-family: var(--display); color: var(--muted); letter-spacing: .3em; text-transform: uppercase; font-size: 13px; margin-bottom: 28px; }
.title-menu { display: flex; flex-direction: column; gap: 12px; align-items: stretch; width: min(320px, 80vw); margin: 0 auto; }
.title-foot { margin-top: 22px; color: var(--muted); font-size: 12px; }

.chapter-card { display: flex; flex-direction: column; align-items: center; justify-content: center; background: radial-gradient(circle, #241a10, #050403 70%); z-index: 50; animation: fadein .6s; }
.cc-num { font-family: var(--display); color: var(--muted); letter-spacing: .5em; text-transform: uppercase; }
.cc-title { font-family: var(--display); font-size: clamp(32px, 6vw, 64px); color: var(--gold-2); text-shadow: 0 0 30px rgba(255,170,60,.5); margin-top: 12px; text-align: center; }
.story-bg { background: radial-gradient(circle at 50% 30%, #1b2133, #07080c 70%); }
@keyframes fadein { from { opacity: 0; } }
.fade-out { animation: fadeout .25s forwards; }
@keyframes fadeout { to { opacity: 0; } }

/* ------------------------------------------------ dialogue */
.dialogue { position: fixed; inset: 0; z-index: 60; cursor: pointer; animation: fadein .25s; }
.dialogue.full { background: radial-gradient(circle at 50% 35%, rgba(40,48,72,.97), rgba(5,6,10,.99) 75%); background-size: cover; background-position: center; }
.dialogue:not(.full) { background: linear-gradient(to top, rgba(0,0,0,.65), transparent 55%); }
.dlg-title { position: absolute; top: 4vh; left: 0; right: 0; text-align: center; font-family: var(--display); color: var(--gold); font-size: 22px; letter-spacing: .1em; }
.dlg-portrait { position: absolute; bottom: 170px; width: min(30vw, 340px); aspect-ratio: 1; transition: filter .3s, opacity .3s, transform .3s; filter: brightness(.5) saturate(.7); }
.dlg-portrait:empty { display: none; }
.dlg-portrait img { width: 100%; height: 100%; object-fit: cover; object-position: center 30%; border-radius: 16px; border: 2px solid var(--line); box-shadow: 0 18px 40px rgba(0,0,0,.65), 0 0 0 6px rgba(10,12,20,.55); }
.dlg-portrait.left { left: 5vw; }
.dlg-portrait.right { right: 5vw; }
.dlg-portrait.active { filter: none; transform: translateY(-6px); }
.dlg-portrait.active img { border-color: var(--gold); box-shadow: 0 18px 44px rgba(0,0,0,.7), 0 0 26px rgba(227,192,110,.28), 0 0 0 6px rgba(10,12,20,.55); }
.dialogue.narration .dlg-portrait { opacity: .25; }
.dlg-box { position: absolute; left: 50%; bottom: 24px; transform: translateX(-50%); width: min(920px, 94vw); min-height: 124px; padding: 22px 28px 26px; background: linear-gradient(180deg, rgba(24,28,44,.97), rgba(14,16,26,.97)); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); }
.dlg-name { position: absolute; top: -18px; left: 26px; padding: 4px 16px; background: linear-gradient(180deg, #c89a3c, #8c6420); color: #1d1406; font-family: var(--display); font-weight: 700; border-radius: 8px; font-size: 16px; }
.dlg-name.right { left: auto; right: 26px; }
.dlg-text { font-size: 20px; line-height: 1.5; }
.dialogue.narration .dlg-text { font-style: italic; color: #d9d2bf; text-align: center; }
.dlg-hint { position: absolute; right: 18px; bottom: 8px; color: var(--gold); animation: bob 1s infinite; }
@keyframes bob { 50% { transform: translateY(3px); } }
.dlg-skip { position: absolute; top: 16px; right: 16px; }

/* ------------------------------------------------ modal */
.modal-back { position: fixed; inset: 0; background: rgba(4,5,10,.62); display: flex; align-items: center; justify-content: center; z-index: 70; animation: fadein .15s; padding: 12px; }
.modal-box { position: relative; max-height: 92vh; overflow: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); padding: 22px 24px; max-width: min(1100px, 96vw); }
.modal-box h2 { font-family: var(--display); color: var(--gold-2); margin: 0 0 12px; }
.modal-box h4 { margin: 16px 0 8px; color: var(--gold); font-family: var(--display); font-size: 14px; letter-spacing: .06em; }
.modal-actions { display: flex; gap: 12px; justify-content: center; margin-top: 22px; flex-wrap: wrap; }
.choice-row { display: flex; gap: 10px; flex-wrap: wrap; }
.choice { flex: 1 1 160px; text-align: left; display: flex; flex-direction: column; gap: 4px; padding: 12px 14px; border-radius: 10px; border: 1px solid #3b4256; background: #171b29; color: var(--text); cursor: pointer; }
.choice b { font-family: var(--display); font-size: 16px; }
.choice small { color: var(--muted); }
.choice.on { border-color: var(--gold); background: #2a2516; box-shadow: 0 0 0 1px var(--gold) inset; }
.choice.small { flex: 1 1 120px; }
.diff-hard b { color: #ff8a80; } .diff-easy b { color: #a5d6a7; }
.save-slot { padding: 12px 14px; border: 1px solid #3b4256; border-radius: 10px; margin-bottom: 10px; display: flex; flex-direction: column; gap: 6px; min-width: min(560px, 86vw); }
.save-slot.empty { color: var(--muted); }
.slot-actions { display: flex; gap: 8px; }
.options { min-width: min(480px, 86vw); }
.opt-row { display: flex; justify-content: space-between; align-items: center; gap: 20px; padding: 10px 0; border-bottom: 1px solid rgba(255,255,255,.06); }
.opt-row select, .opt-row input[type=range] { width: 220px; }
select { background: #1b2032; color: var(--text); border: 1px solid var(--line); border-radius: 6px; padding: 5px; }
.credits { max-width: 640px; line-height: 1.5; }

/* ------------------------------------------------ prep */
.prep { background: radial-gradient(circle at 30% 0%, #1f2638, #0b0d13 70%); padding: 18px clamp(12px, 3vw, 36px) 40px; }
.prep-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; border-bottom: 1px solid var(--line); padding-bottom: 14px; }
.ph-chapter { color: var(--muted); font-family: var(--display); letter-spacing: .12em; font-size: 13px; }
.ph-title { font-family: var(--display); font-size: 30px; color: var(--gold-2); }
.ph-obj { color: #d8cfb8; margin-top: 4px; }
.ph-right { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.gold { font-family: var(--display); color: var(--gold-2); font-size: 20px; }
.diff { font-size: 12px; padding: 4px 8px; border-radius: 6px; background: #22283b; }
.diff-hard { color: #ff8a80; } .diff-easy { color: #a5d6a7; }
.tabs { display: flex; gap: 6px; margin: 16px 0; flex-wrap: wrap; }
.tab { background: none; border: 1px solid transparent; color: var(--muted); padding: 8px 16px; border-radius: 8px 8px 0 0; cursor: pointer; font-family: var(--display); font-size: 15px; }
.tab.on { color: var(--gold-2); border-color: var(--line); border-bottom-color: transparent; background: rgba(255,255,255,.03); }
.hint { color: var(--muted); margin-bottom: 12px; }
.hero-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 10px; }
.hero-card { display: flex; gap: 10px; align-items: center; padding: 8px 10px; border-radius: 10px; background: #161a27; border: 1px solid #2b3145; cursor: pointer; transition: border-color .15s, background .15s; }
.hero-card:hover { border-color: var(--line); }
.hero-card.on { border-color: var(--blue); background: linear-gradient(90deg, rgba(79,134,247,.22), #161a27); }
.hc-name { font-weight: 700; font-size: 16px; }
.hc-class { color: var(--gold); font-size: 13px; }
.hc-stats { color: var(--muted); font-size: 12px; }
.hc-promo { color: #8fe39b; font-size: 12px; }
.fallen { margin-top: 14px; color: #ff9e9e; }
.portrait { object-fit: cover; object-position: center 30%; border-radius: 8px; background: linear-gradient(180deg, #2b3042, #12141c); border: 1px solid #3b4256; }
.portrait.small { width: 64px; height: 64px; }
.portrait.tiny { width: 30px; height: 30px; border-radius: 6px; }
.portrait.large { width: 132px; height: 132px; }
.portrait.sprite { object-fit: contain; object-position: center; }
.equip { display: grid; grid-template-columns: 200px minmax(280px, 1fr) minmax(300px, 1.1fr); gap: 14px; }
@media (max-width: 960px) { .equip { grid-template-columns: 1fr; } }
.eq-heroes { display: flex; flex-direction: column; gap: 4px; max-height: 70vh; overflow: auto; }
.eq-hero { display: flex; align-items: center; gap: 8px; padding: 5px 8px; border-radius: 8px; background: #161a27; border: 1px solid #2b3145; color: var(--text); cursor: pointer; text-align: left; }
.eq-hero.dep { border-left: 3px solid var(--blue); }
.eq-hero.on { border-color: var(--gold); background: #2a2516; }
.eq-hero small { margin-left: auto; color: var(--muted); }
.eq-panel { background: #121520; border: 1px solid #2b3145; border-radius: 10px; padding: 10px 12px; }
.eq-panel h4 { margin: 4px 0 8px; font-family: var(--display); color: var(--gold); font-size: 14px; }
.convoy-list { max-height: 56vh; overflow: auto; }
.cats { display: flex; gap: 4px; margin-bottom: 8px; flex-wrap: wrap; }
.inv-row, .gear-row { display: flex; align-items: center; gap: 8px; padding: 4px 6px; border-radius: 6px; min-height: 34px; }
.inv-row:nth-child(odd), .gear-row:nth-child(odd) { background: rgba(255,255,255,.025); }
.inv-row.equipped { background: rgba(92,196,110,.12); }
.inv-row.nowield .inv-name { color: #8a8f9c; }
.inv-row.empty { opacity: .5; }
.inv-name { flex: 1; }
.inv-uses { color: var(--muted); font-size: 12px; min-width: 40px; text-align: right; }
.price { color: var(--gold-2); min-width: 64px; text-align: right; font-size: 13px; }
.ico { width: 28px; height: 28px; object-fit: contain; flex: none; }
.ico.big { width: 56px; height: 56px; }
.slot { text-transform: capitalize; color: var(--muted); width: 56px; font-size: 12px; }
.eq-stats { margin-top: 16px; }
.eq-stats .status-window, .status-holder .status-window { position: static; transform: none; max-width: none; }
.shop { display: grid; grid-template-columns: 1.4fr 1fr; gap: 14px; }
@media (max-width: 860px) { .shop { grid-template-columns: 1fr; } }
.shop-panel { background: #121520; border: 1px solid #2b3145; border-radius: 10px; padding: 10px 12px; max-height: 70vh; overflow: auto; }
.shop-panel h5 { margin: 10px 0 4px; color: var(--gold); }

/* ------------------------------------------------ battle HUD */
.battle-hud { position: fixed; inset: 0; z-index: 10; }
.battle-hud > * { pointer-events: auto; }
.hud-tl { position: absolute; top: 10px; left: 10px; }
.hud-tr { position: absolute; top: 10px; right: 10px; display: flex; gap: 8px; }
.hud-bl { position: absolute; bottom: 10px; left: 10px; pointer-events: none; }
.hud-br { position: absolute; bottom: 10px; right: 10px; pointer-events: none; }
.hud-center { position: absolute; top: 64px; left: 50%; transform: translateX(-50%); }
.hud-center.left { left: 12px; right: auto; transform: translateY(-50%); top: 50%; }
.hud-center.right { right: 12px; left: auto; transform: translateY(-50%); top: 50%; }
@media (max-width: 900px) { .hud-center.left, .hud-center.right { left: 50%; right: auto; top: 64px; transform: translateX(-50%); } }
.hud-center:empty { display: none; }
.hud-btn.on { border-color: #c06ae0; color: #f1c9ff; }
.objective-card, .terrain-card, .unit-card, .tooltip-box, .forecast, .menu, .popup, .exp-pop {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
}
.objective-card { padding: 8px 14px; max-width: 360px; }
.oc-turn { font-family: var(--display); color: var(--gold-2); display: flex; align-items: center; gap: 8px; }
.oc-text { font-size: 14px; color: #d8cfb8; }
.phase-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.phase-dot.player { background: var(--blue); } .phase-dot.enemy { background: var(--red); } .phase-dot.ally { background: var(--green); }
.terrain-card { padding: 8px 14px; min-width: 120px; }
.tc-name { font-family: var(--display); color: var(--gold-2); margin-bottom: 4px; }
.tc-row { display: flex; justify-content: space-between; gap: 18px; font-size: 14px; }
.tc-row.heal b { color: var(--green); }
.tc-coord { color: var(--muted); font-size: 11px; text-align: right; }
.unit-card { display: flex; gap: 10px; padding: 8px 12px 8px 8px; min-width: 280px; align-items: center; }
.unit-card.team-player { border-color: rgba(79,134,247,.7); }
.unit-card.team-enemy { border-color: rgba(226,80,74,.7); }
.unit-card.team-ally { border-color: rgba(92,196,110,.7); }
.uc-name { font-weight: 700; font-size: 17px; }
.uc-class { color: var(--gold); font-size: 13px; }
.uc-hp { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.uc-weapon { display: flex; align-items: center; gap: 6px; font-size: 13px; color: #cfd3dc; }
.uc-weapon .ico { width: 22px; height: 22px; }
.uc-status { color: #b9f6ca; margin-left: 6px; }
.hpbar { flex: 1; height: 7px; background: #2a2f3f; border-radius: 4px; overflow: hidden; min-width: 90px; }
.hpfill { height: 100%; border-radius: 4px; transition: width .3s; }
.hpfill.hi { background: linear-gradient(90deg, #3fbf5a, #7ce68e); } .hpfill.mid { background: linear-gradient(90deg, #d4a017, #f2c94c); } .hpfill.lo { background: linear-gradient(90deg, #c62828, #ef5350); }

.menu { position: absolute; min-width: 180px; padding: 6px; display: flex; flex-direction: column; z-index: 20; animation: pop .12s ease-out; }
@keyframes pop { from { transform: scale(.94); opacity: 0; } }
.menu-title { font-family: var(--display); color: var(--gold); padding: 4px 10px 6px; font-size: 13px; }
.menu-item { display: flex; align-items: center; gap: 8px; background: none; border: none; color: var(--text); text-align: left; padding: 8px 12px; border-radius: 6px; font-size: 16px; cursor: pointer; font-weight: 600; }
.menu-item.focus { background: linear-gradient(90deg, rgba(227,192,110,.25), rgba(227,192,110,.05)); color: var(--gold-2); }
.menu-item.disabled { opacity: .4; cursor: default; }
.menu-item .ico { width: 22px; height: 22px; }
.mi-label { flex: 1; }
.mi-hint { color: var(--muted); font-size: 12px; }
.tooltip-box { padding: 10px 14px; max-width: 420px; font-size: 14px; }

.forecast { padding: 10px 14px 12px; width: min(460px, 94vw); animation: pop .12s ease-out; }
.fc-title { text-align: center; font-family: var(--display); color: var(--gold); font-size: 13px; letter-spacing: .1em; margin-bottom: 6px; }
.fc-sides { display: flex; gap: 10px; align-items: stretch; }
.fc-vs { align-self: center; font-family: var(--display); color: var(--muted); }
.fc-side { flex: 1; padding: 8px 10px; border-radius: 8px; background: rgba(255,255,255,.03); }
.fc-side.team-player { box-shadow: inset 3px 0 0 var(--blue); } .fc-side.team-enemy { box-shadow: inset 3px 0 0 var(--red); } .fc-side.team-ally { box-shadow: inset 3px 0 0 var(--green); }
.fc-name { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 16px; }
.fc-weapon { display: flex; align-items: center; gap: 6px; color: #cfd3dc; font-size: 13px; margin: 4px 0; }
.fc-weapon .ico { width: 22px; height: 22px; }
.tri.up { color: #7ce68e; } .tri.down { color: #ff7d73; }
.fc-grid { display: grid; grid-template-columns: auto 1fr auto 1fr; gap: 2px 10px; font-size: 14px; }
.fc-grid span { color: var(--muted); }
.fc-grid b { font-size: 18px; }
.fc-labels { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.fc-label { font-size: 11px; padding: 2px 6px; border-radius: 4px; background: #3a3220; color: var(--gold-2); }
.fc-kill { margin-top: 6px; color: #ff8a80; font-weight: 700; font-size: 13px; }
.weapon-switch { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; justify-content: center; }
.weapon-switch .ico { width: 18px; height: 18px; margin-right: 4px; vertical-align: middle; }
.fc-actions { display: flex; gap: 8px; justify-content: center; margin-top: 10px; }

.phase-banner { position: fixed; left: 0; right: 0; top: 40%; z-index: 40; text-align: center; padding: 18px 0; animation: slidein .35s ease-out; pointer-events: none; }
.phase-banner.player { background: linear-gradient(90deg, transparent, rgba(40,90,200,.82), transparent); }
.phase-banner.enemy { background: linear-gradient(90deg, transparent, rgba(190,40,40,.82), transparent); }
.phase-banner.ally { background: linear-gradient(90deg, transparent, rgba(40,150,60,.82), transparent); }
.phase-banner.out { animation: slideout .3s forwards; }
.pb-text { font-family: var(--display); font-size: clamp(30px, 5vw, 52px); font-weight: 900; color: #fff; text-shadow: 0 3px 0 rgba(0,0,0,.4); letter-spacing: .08em; }
.pb-turn { color: rgba(255,255,255,.8); font-family: var(--display); }
@keyframes slidein { from { transform: translateX(-100%); opacity: 0; } }
@keyframes slideout { to { transform: translateX(100%); opacity: 0; } }
.big-banner { position: fixed; left: 50%; top: 38%; transform: translate(-50%, -50%); z-index: 80; font-family: var(--display); font-size: clamp(30px, 6vw, 64px); font-weight: 900; padding: 16px 40px; border-radius: 12px; animation: pop .3s; pointer-events: none; text-align: center; }
.big-banner.gold { color: var(--gold-2); text-shadow: 0 0 30px rgba(255,190,80,.7), 0 4px 0 #3a2208; }
.big-banner.red { color: #ff8a80; text-shadow: 0 0 30px rgba(255,60,60,.6); }
.big-banner.blue { color: #a8c8ff; text-shadow: 0 0 30px rgba(80,140,255,.7); font-size: clamp(24px, 4vw, 42px); background: rgba(10,14,30,.7); }
.big-banner.out { animation: fadeout .4s forwards; }

.popup { position: fixed; left: 50%; top: 30%; transform: translateX(-50%); z-index: 45; padding: 12px 20px; animation: pop .2s; }
.gain-pop { display: flex; align-items: center; gap: 12px; font-size: 18px; }
.gain-pop small { display: block; color: var(--muted); font-size: 13px; }
.exp-pop { position: fixed; left: 50%; bottom: 120px; transform: translateX(-50%); z-index: 45; padding: 10px 16px; min-width: 300px; display: flex; flex-direction: column; gap: 6px; }
.ep-name { font-family: var(--display); color: var(--gold-2); }
.expbar { height: 10px; background: #2a2f3f; border-radius: 5px; overflow: hidden; }
.expfill { height: 100%; background: linear-gradient(90deg, #e3c06e, #fff2b8); }

.levelup { position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 75; background: var(--panel-2); border: 1px solid var(--gold); border-radius: 14px; padding: 16px 22px; min-width: 320px; box-shadow: 0 0 40px rgba(227,192,110,.25), var(--shadow); animation: pop .25s; cursor: pointer; }
.lu-title { font-family: var(--display); font-size: 30px; color: var(--gold-2); text-align: center; text-shadow: 0 0 20px rgba(255,190,80,.5); }
.lu-head { display: flex; gap: 10px; align-items: center; margin: 8px 0; }
.lu-name { font-weight: 700; font-size: 18px; }
.lu-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 18px; }
.lu-row { display: flex; gap: 8px; align-items: center; padding: 3px 6px; border-radius: 6px; }
.lu-row span { flex: 1; color: var(--muted); }
.lu-row b { min-width: 24px; text-align: right; }
.lu-row em { color: #8fe39b; font-style: normal; font-weight: 700; min-width: 26px; opacity: 0; transform: translateY(6px); transition: all .25s; }
.lu-row.up.show { background: rgba(143,227,155,.12); }
.lu-row.up.show em { opacity: 1; transform: none; }

/* ------------------------------------------------ status window */
.status-window { position: relative; width: min(1000px, 94vw); }
.status-modal .modal-box { padding: 18px; }
.sw-head { display: flex; gap: 16px; align-items: center; }
.sw-id { flex: 1; }
.sw-name { font-family: var(--display); font-size: 28px; color: var(--gold-2); }
.sw-class { color: var(--gold); font-size: 16px; }
.sw-class .tier { margin-left: 8px; font-size: 12px; padding: 2px 8px; border-radius: 6px; background: #3a3220; }
.sw-lv { display: flex; align-items: center; gap: 10px; margin-top: 4px; }
.sw-lv .expbar { width: 160px; }
.sw-hp { display: flex; align-items: center; gap: 10px; margin-top: 4px; }
.sw-desc { color: var(--muted); font-size: 14px; margin-top: 6px; max-width: 520px; }
.sw-sprite { width: 96px; height: 96px; }
.sw-cols { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; margin-top: 14px; }
@media (max-width: 860px) { .sw-cols { grid-template-columns: 1fr; } .sw-head { flex-wrap: wrap; } }
.sw-col h4 { margin: 8px 0 6px; font-family: var(--display); color: var(--gold); font-size: 13px; letter-spacing: .06em; }
.stat-row { display: grid; grid-template-columns: 82px 1fr 48px; gap: 8px; align-items: center; padding: 3px 0; font-size: 14px; }
.st-name { color: var(--muted); }
.st-bar { position: relative; height: 8px; background: #2a2f3f; border-radius: 4px; overflow: hidden; }
.st-fill { height: 100%; background: linear-gradient(90deg, #4f86f7, #8fb5ff); }
.st-bonus { position: absolute; top: 0; height: 100%; background: #8fe39b; }
.st-bonus.neg { background: #ff7d73; }
.st-val { text-align: right; }
.st-val.capped { color: var(--gold-2); }
.st-val small { color: #8fe39b; margin-left: 2px; font-size: 11px; }
.derived { display: grid; grid-template-columns: 1fr 1fr; gap: 3px 14px; }
.dv { display: flex; justify-content: space-between; font-size: 14px; }
.dv span { color: var(--muted); }
.sw-formula { font-size: 11px; color: var(--muted); margin-top: 6px; line-height: 1.4; }
.wtype, .skill { display: inline-block; padding: 2px 8px; margin: 2px; border-radius: 6px; background: #22283b; font-size: 13px; }
.skill { background: #2c2a1b; color: var(--gold-2); cursor: help; }
.sw-match { font-size: 13px; margin-top: 8px; }
.sw-match.good { color: #8fe39b; } .sw-match.bad { color: #ff9e9e; }
.sw-status { color: #b9f6ca; margin-top: 8px; font-size: 13px; }

.map-menu { min-width: min(520px, 90vw); }
.map-menu h3 { font-family: var(--display); color: var(--gold-2); margin: 0 0 6px; }
.mm-obj { color: #d8cfb8; margin-bottom: 12px; }
.mm-units { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px; max-height: 40vh; overflow: auto; }
.mm-unit { display: flex; flex-direction: column; text-align: left; background: #161a27; border: 1px solid #2b3145; color: var(--text); border-radius: 8px; padding: 6px 8px; cursor: pointer; }
.mm-unit.acted { opacity: .55; }
.mm-unit small { color: var(--muted); }
.mm-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.mm-help { margin-top: 12px; color: var(--muted); font-size: 12px; }
.trade { min-width: min(600px, 90vw); }
.trade h3 { font-family: var(--display); color: var(--gold); font-size: 16px; }
.trade-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.trade-col h4 { margin: 0 0 6px; }
.trade-item { display: flex; align-items: center; gap: 8px; width: 100%; background: #161a27; border: 1px solid #2b3145; color: var(--text); padding: 6px; border-radius: 6px; margin-bottom: 4px; cursor: pointer; }
.trade-item:hover { border-color: var(--gold); }

/* ------------------------------------------------ battle scene */
.battle-scene { position: fixed; inset: 0; z-index: 55; background: rgba(0,0,0,.72); display: flex; align-items: center; justify-content: center; animation: fadein .2s; }
.bs-wrap { display: flex; flex-direction: column; align-items: center; border: 2px solid var(--line); border-radius: 12px; overflow: hidden; box-shadow: 0 0 60px rgba(0,0,0,.8); background: #000; }
.bs-canvas { display: block; }
.bs-panel { display: grid; grid-template-columns: 1fr 1fr; background: linear-gradient(180deg, #1b2032, #0f121c); }
.bs-side { padding: 10px 16px; display: grid; grid-template-columns: 1fr auto; gap: 4px 14px; align-items: center; }
.bs-side.bs-left { border-right: 1px solid var(--line); }
.bs-side.team-player { background: linear-gradient(90deg, rgba(79,134,247,.18), transparent); }
.bs-side.team-enemy { background: linear-gradient(90deg, rgba(226,80,74,.18), transparent); }
.bs-side.team-ally { background: linear-gradient(90deg, rgba(92,196,110,.18), transparent); }
.bs-name { font-family: var(--display); font-size: 20px; color: var(--gold-2); }
.bs-weapon { display: flex; align-items: center; gap: 6px; color: #cfd3dc; font-size: 14px; justify-self: end; }
.bs-weapon img { width: 24px; height: 24px; }
.bs-stats { display: flex; gap: 12px; font-size: 13px; color: var(--muted); }
.bs-stats b { color: var(--text); font-size: 15px; }
.bs-hp { display: flex; align-items: center; gap: 8px; grid-column: 1 / -1; }
.bs-hpnum { font-family: var(--display); font-size: 22px; min-width: 36px; }
.bs-hpbar { flex: 1; height: 12px; background: #2a2f3f; border-radius: 6px; overflow: hidden; }
.bs-hpfill { height: 100%; border-radius: 6px; }
.bs-hpfill.hi { background: linear-gradient(90deg, #3fbf5a, #7ce68e); } .bs-hpfill.mid { background: linear-gradient(90deg, #d4a017, #f2c94c); } .bs-hpfill.lo { background: linear-gradient(90deg, #c62828, #ef5350); }

/* ------------------------------------------------ results / game over */
.results, .gameover, .ending { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 30px 16px; background: radial-gradient(circle at 50% 30%, #262014, #07080c 70%); }
.results h1, .ending h1 { font-family: var(--display); color: var(--gold-2); font-size: clamp(32px, 5vw, 54px); margin: 0; text-shadow: 0 0 24px rgba(255,190,80,.45); }
.results h3 { color: var(--muted); font-family: var(--display); }
.res-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 14px; width: min(1000px, 96vw); }
.res-box { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px 16px; line-height: 1.6; }
.res-box h4 { margin: 0 0 6px; font-family: var(--display); color: var(--gold); }
.res-hero.dead { color: #ff9e9e; }
.res-item { display: inline-flex; align-items: center; gap: 4px; margin-right: 8px; }
.res-item .ico { width: 22px; height: 22px; }
.gameover { background: radial-gradient(circle at 50% 30%, #2a0c0c, #050304 70%); }
.gameover h1 { font-family: var(--display); color: #ff8a80; font-size: clamp(36px, 6vw, 64px); margin: 0; }
.go-reason { color: #e0c4c0; margin: 10px 0 20px; font-size: 18px; }
.ending p { font-size: 20px; color: #e7dcc0; text-align: center; max-width: 700px; }
.end-stats { color: var(--muted); line-height: 1.7; text-align: center; }

#toasts { position: fixed; top: 64px; right: 14px; z-index: 90; display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
.toast { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 10px 14px; box-shadow: var(--shadow); animation: pop .2s; max-width: 340px; }
.toast-error { border-color: #b4483f; } .toast-warn { border-color: #c79a2b; } .toast-good { border-color: #4caf50; }
.toast.out { animation: fadeout .4s forwards; }

@media (max-width: 700px) {
  .unit-card { min-width: 0; }
  .hud-br { display: none; }
  .dlg-portrait { width: 40vw; bottom: 190px; }
  .dlg-text { font-size: 17px; }
  .objective-card { max-width: 52vw; font-size: 12px; }
  .hud-tr .btn { padding: 6px 10px; font-size: 13px; }
}
