@font-face { font-family: Cinzel; src: url(../assets/fonts/Cinzel.ttf); font-display: swap; }
@font-face { font-family: Hud; src: url(../assets/fonts/HudMedium.ttf); font-display: swap; }
@font-face { font-family: Hud; font-weight: 700; src: url(../assets/fonts/HudBold.ttf); font-display: swap; }
@font-face { font-family: "DWSerif"; src: url(../assets/fonts/SerifBody-Regular.ttf); font-display: swap; }
@font-face { font-family: "DWSerif"; font-weight: 700; src: url(../assets/fonts/SerifBody-Bold.ttf); font-display: swap; }

:root {
  --bg: #07060a; --panel: rgba(16, 12, 26, .92); --panel2: rgba(30, 22, 46, .95); --edge: #3d3152; --edge2: #6b52a0;
  --text: #ece6f6; --dim: #a9a2c0; --violet: #9b4dff; --violet2: #c39bff; --gold: #ffd27a; --good: #8dffb0; --bad: #ff8a8a;
  --Umbra: #a77bff; --Ember: #ff8a3d; --Psyche: #ff6fc7; --Void: #6fb6ff; --Fairy: #8dffb0;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: Hud, system-ui, sans-serif; overflow: hidden;
  -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; }
canvas#board { position: fixed; inset: 0; width: 100%; height: 100%; display: block; image-rendering: pixelated; touch-action: none; }
#ui { position: fixed; inset: 0; pointer-events: none; }
#ui > * { pointer-events: auto; }
button { font: inherit; color: inherit; cursor: pointer; }
h1, h2, h3, .cin { font-family: Cinzel, serif; letter-spacing: .06em; margin: 0; }
.serif { font-family: "DWSerif", Georgia, serif; }

/* ── Menus ── */
.screen { position: absolute; inset: 0; overflow-y: auto; display: flex; flex-direction: column; align-items: center; padding: max(16px, env(safe-area-inset-top)) 16px 24px;
  background: radial-gradient(ellipse at 50% 30%, rgba(60, 30, 100, .35), transparent 70%), url(../assets/ui/menu_bg.jpg) center / cover no-repeat, var(--bg); }
.screen.clear { background: rgba(5, 4, 9, .78); }
.wrap { width: 100%; max-width: 1040px; }
.title-logo { width: min(620px, 92vw); margin: 7vh auto 10px; display: block; filter: drop-shadow(0 0 30px rgba(155, 77, 255, .45)); }
.tagline { text-align: center; color: var(--dim); font-family: "DWSerif", serif; font-size: 1.1rem; margin: 0 0 28px; }
.menu { display: flex; flex-direction: column; gap: 12px; width: min(340px, 90vw); margin: 0 auto; }
.btn { background: linear-gradient(180deg, #3a2266, #1f1238); border: 1px solid var(--edge2); padding: 13px 18px; border-radius: 6px; font-family: Cinzel, serif;
  letter-spacing: .1em; font-size: 1rem; text-transform: uppercase; box-shadow: 0 0 16px rgba(155, 77, 255, .2); transition: box-shadow .15s, transform .1s; }
.btn:hover:not(:disabled) { box-shadow: 0 0 24px rgba(176, 107, 255, .55); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn.ghost { background: rgba(20, 14, 32, .7); border-color: var(--edge); box-shadow: none; }
.btn.crimson { background: linear-gradient(180deg, #6a1626, #34080f); border-color: #b0343f; }
.btn.small { padding: 8px 12px; font-size: .8rem; }
.btn:disabled { opacity: .45; cursor: default; }
.foot-note { margin-top: auto; padding-top: 28px; color: var(--dim); font-size: .78rem; text-align: center; }
.foot-note a { color: var(--violet2); }
.head-row { display: flex; align-items: center; gap: 12px; justify-content: space-between; width: 100%; max-width: 1040px; margin-bottom: 16px; flex-wrap: wrap; }
.head-row h2 { font-size: clamp(1.2rem, 3.4vw, 1.7rem); }
.pill { display: inline-flex; align-items: center; gap: 6px; background: var(--panel); border: 1px solid var(--edge); border-radius: 999px; padding: 5px 12px; font-size: .82rem; }
.card { background: var(--panel); border: 1px solid var(--edge); border-radius: 8px; padding: 16px; }
.grid { display: grid; gap: 12px; }
.grid.cols-3 { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.stage { display: flex; gap: 14px; align-items: flex-start; cursor: pointer; transition: border-color .15s; }
.stage:hover { border-color: var(--edge2); }
.stage.locked { opacity: .45; cursor: default; }
.stage .num { font-family: Cinzel, serif; font-size: 1.6rem; color: var(--violet2); min-width: 34px; }
.stage .meta { font-size: .78rem; color: var(--dim); margin-top: 4px; }
.mon { position: relative; text-align: center; cursor: pointer; padding: 10px 8px; }
.mon img { width: 96px; height: 96px; image-rendering: pixelated; display: block; margin: 0 auto; }
.mon.sel { border-color: var(--gold); box-shadow: 0 0 0 1px var(--gold) inset, 0 0 18px rgba(255, 210, 122, .25); }
.mon.unknown img { filter: brightness(0) opacity(.5); }
.mon .nm { font-weight: 700; font-size: .9rem; }
.mon .sub { font-size: .72rem; color: var(--dim); }
.mon .tag { position: absolute; top: 6px; right: 8px; font-size: .66rem; color: var(--good); font-weight: 700; }
.el { display: inline-block; width: 18px; height: 18px; vertical-align: -4px; }
.story { max-width: 760px; font-family: "DWSerif", serif; font-size: 1.12rem; line-height: 1.7; white-space: pre-line; }
.story .bedside { color: #9fd4e8; font-style: italic; border-left: 2px solid #4b7c8f; padding-left: 14px; margin-bottom: 18px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.field { background: #120c1e; border: 1px solid var(--edge); border-radius: 6px; padding: 11px 12px; color: var(--text); font: inherit; width: 100%; }
.seg { display: inline-flex; border: 1px solid var(--edge); border-radius: 6px; overflow: hidden; }
.seg button { background: transparent; border: 0; padding: 9px 16px; }
.seg button.on { background: #3a2266; }
.arch { cursor: pointer; }
.arch.sel { border-color: var(--gold); }
.arch.locked { opacity: .4; cursor: default; }
.arch .trait { color: var(--bad); font-size: .76rem; margin-top: 6px; }
.stats { font-size: .76rem; color: var(--dim); }
.label { font-size: .72rem; text-transform: uppercase; letter-spacing: .12em; color: var(--dim); margin: 18px 0 8px; }

/* ── Battle HUD ── */
.hud-top { position: absolute; top: max(8px, env(safe-area-inset-top)); left: 8px; right: 8px; display: flex; gap: 8px; align-items: center; pointer-events: none; }
.hud-top > * { pointer-events: auto; }
.order { display: flex; gap: 4px; overflow: hidden; flex: 1; justify-content: center; }
.order .p { width: 42px; height: 42px; border-radius: 6px; border: 2px solid #3f6ad0; background: rgba(10, 8, 18, .8) center / 130% no-repeat; image-rendering: pixelated; flex: none; }
.order .p.foe { border-color: #c33c4c; }
.order .p.now { width: 50px; height: 50px; box-shadow: 0 0 12px var(--gold); border-color: var(--gold); }
.round { font-family: Cinzel, serif; background: var(--panel); border: 1px solid var(--edge); border-radius: 6px; padding: 8px 12px; font-size: .85rem; white-space: nowrap; }
.iconbtn { background: var(--panel); border: 1px solid var(--edge); border-radius: 6px; width: 40px; height: 40px; display: grid; place-items: center; font-size: 1.05rem; }
.iconbtn.on { border-color: var(--gold); color: var(--gold); }
.hud-bot { position: absolute; left: 8px; right: 8px; bottom: max(8px, env(safe-area-inset-bottom)); display: flex; gap: 8px; align-items: stretch; pointer-events: none; }
.hud-bot > * { pointer-events: auto; }
.unitcard { background: var(--panel); border: 1px solid var(--edge); border-radius: 8px; padding: 8px 10px; display: flex; gap: 10px; min-width: 230px; max-width: 290px; }
.unitcard > img { width: 64px; height: 64px; image-rendering: pixelated; flex: none; }
.unitcard .nm { font-weight: 700; }
.bar { height: 7px; background: #2a2236; border-radius: 4px; overflow: hidden; margin-top: 4px; }
.bar > i { display: block; height: 100%; background: linear-gradient(90deg, #3ed27a, #8dffb0); }
.bar.weave > i { background: linear-gradient(90deg, #7b4dff, #c39bff); }
.unitcard .small { font-size: .72rem; color: var(--dim); }
.moves { flex: 1; display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 6px; }
.move { text-align: left; background: var(--panel2); border: 1px solid var(--edge); border-radius: 7px; padding: 7px 9px; font-size: .78rem; line-height: 1.25; position: relative; }
.move b { font-size: .86rem; }
.move .t { color: var(--dim); font-size: .68rem; }
.move.ult { border-color: #a0702c; background: linear-gradient(180deg, rgba(70, 44, 12, .9), rgba(30, 18, 6, .95)); }
.move.sel { border-color: var(--gold); box-shadow: 0 0 12px rgba(255, 210, 122, .4); }
.move:disabled { opacity: .42; cursor: default; }
.move .cost { position: absolute; top: 6px; right: 8px; color: var(--violet2); font-weight: 700; }
.actions { display: flex; flex-direction: column; gap: 6px; }
.actions .btn { padding: 9px 12px; font-size: .74rem; }
.waiting { background: var(--panel); border: 1px solid var(--edge); border-radius: 8px; padding: 14px 18px; align-self: center; margin: 0 auto; font-family: Cinzel, serif; }
.logbox { position: absolute; right: 8px; top: 64px; width: min(360px, 60vw); max-height: 42vh; overflow-y: auto; background: var(--panel); border: 1px solid var(--edge); border-radius: 8px; padding: 10px;
  font-size: .76rem; line-height: 1.45; color: var(--dim); }
.logbox div:last-child { color: var(--text); }
.tip { position: absolute; background: var(--panel2); border: 1px solid var(--edge2); border-radius: 7px; padding: 8px 10px; font-size: .76rem; pointer-events: none; max-width: 260px; z-index: 5; }
.banner { position: absolute; left: 0; right: 0; top: 28%; text-align: center; font-family: Cinzel, serif; font-size: clamp(1.4rem, 5vw, 2.6rem); text-shadow: 0 0 24px #000, 0 0 12px var(--violet);
  pointer-events: none; animation: bannerIn 1.6s ease forwards; }
@keyframes bannerIn { 0% { opacity: 0; transform: scale(.9); } 15% { opacity: 1; transform: none; } 75% { opacity: 1; } 100% { opacity: 0; } }
#toast { position: fixed; left: 50%; bottom: 28%; transform: translateX(-50%); background: var(--panel2); border: 1px solid var(--edge2); border-radius: 8px; padding: 10px 16px; font-size: .88rem;
  opacity: 0; transition: opacity .25s; pointer-events: none; max-width: 90vw; text-align: center; z-index: 20; }
#toast.on { opacity: 1; }
.result .big { font-family: Cinzel, serif; font-size: clamp(2rem, 7vw, 3.4rem); text-align: center; margin: 4vh 0 6px; }
.result .vic { color: var(--gold); text-shadow: 0 0 22px rgba(255, 190, 80, .5); }
.result .def { color: var(--bad); }
.result ul { list-style: none; padding: 0; margin: 0; }
.result li { padding: 6px 0; border-bottom: 1px solid rgba(255, 255, 255, .06); }
.result li:last-child { border: 0; }
.mvp { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; margin: 14px 0; }
.mvp .mon { width: 150px; cursor: default; }
@media (max-width: 760px) {
  .hud-bot { flex-wrap: wrap; }
  .unitcard { min-width: 0; max-width: none; flex: 1 1 100%; padding: 6px 8px; }
  .unitcard > img { width: 44px; height: 44px; }
  .moves { grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); flex: 1 1 auto; }
  .move { padding: 5px 7px; } .move .t { display: none; }
  .actions { flex-direction: row; flex-wrap: wrap; }
  .order .p { width: 32px; height: 32px; } .order .p.now { width: 38px; height: 38px; }
  .logbox { top: 52px; }
}
@media (max-height: 520px) and (min-width: 761px) {
  .unitcard { min-width: 0; max-width: 210px; padding: 6px 8px; gap: 6px; }
  .unitcard > img { width: 40px; height: 40px; }
  .unitcard .small { font-size: .64rem; }
  .moves { grid-template-columns: repeat(3, 1fr); gap: 4px; }
  .move { padding: 4px 6px; font-size: .72rem; } .move .t { display: none; } .move b { font-size: .76rem; }
  .actions .btn { padding: 7px 10px; }
  .order .p { width: 32px; height: 32px; } .order .p.now { width: 38px; height: 38px; }
}
@media (max-width: 760px) and (orientation: portrait) { .order { display: none; } .actions { flex-direction: column; } }
/* ── Cutscenes ── */
.screen.cs{position:fixed;inset:0;background:#000;display:grid;place-items:center;padding:0;overflow:hidden;z-index:30}
.cs-frame{position:relative;overflow:hidden;cursor:pointer;user-select:none;-webkit-user-select:none}
.cs-cv{position:absolute;inset:0;width:100%;height:100%;display:block}
.cs-kick{position:absolute;left:2.2%;font-family:Cinzel,serif;letter-spacing:.2em;font-size:.85em;pointer-events:none;transition:none}
.cs-title{top:2.4%;color:#b9a8ff}.cs-sec{top:5.6%;color:#ffe28a}
.cs-mem{position:absolute;left:50%;top:4%;transform:translateX(-50%);min-width:min(440px,70%);padding:.5em 1.2em;text-align:center;background:linear-gradient(180deg,#221a36,#140f22);border:1px solid #5d4a8f;opacity:0;pointer-events:none}
.cs-mem .k{font-family:Cinzel,serif;font-size:.7em;letter-spacing:.25em;color:#ffe28a}.cs-mem b{font-size:1.15em;color:#fff}
.cs-box{position:absolute;left:50%;bottom:3.5%;transform:translateX(-50%);width:min(1040px,92%);min-height:22%;padding:1.1em 1.6em .9em;background:rgba(8,5,20,.88);border-top:2px solid rgba(153,128,242,.7);border-bottom:2px solid rgba(153,128,242,.7);box-shadow:0 -40px 80px rgba(2,2,8,.7)}
.cs-name{position:absolute;top:-1em;left:1.2em;padding:.25em 1.2em;background:#54409e;color:#fff;font-family:Hud,sans-serif;font-weight:700;letter-spacing:.12em;font-size:.8em}
.cs-text{font-family:"DWSerif",Georgia,serif;font-size:1.25em;line-height:1.4;color:#f7f5ff;text-shadow:2px 2px 0 rgba(0,0,0,.85)}
.cs-box.narr .cs-text{color:#dbd6f2;font-style:normal}
.cs-text span{opacity:0}
.cs-skip{position:absolute;top:2.4%;right:1.6%;z-index:2}
.cs-help{position:absolute;right:1.6%;bottom:.6%;font-size:.6em;color:#6f6893;pointer-events:none}
.cs-credits{position:absolute;left:0;right:0;top:0;text-align:center;color:#e8e4ff;font-family:Cinzel,serif;font-size:1.05em;line-height:1.9;display:none;pointer-events:none}
.cs-credits .ck{font-size:.7em;letter-spacing:.25em;color:#a9a2c0}
@media (max-height:500px){.cs-text{font-size:1.05em}.cs-box{min-height:26%;padding:.8em 1.2em .6em}.cs-help{display:none}}
