:root {
  --ink: #3b2414;
  --paper: #f4e7c8;
  --paper2: #ead6a8;
  --red: #b8461d;
  --red2: #a83c1a;
  --blue: #3c6fb4;
  --blue2: #274d85;
  --sage: #8fae6a;
  --gold: #e7b13c;
  --font: "MpFontDisplay", "MpFontBody", "PingFang SC", "Hiragino Sans GB", "Hiragino Sans", "Microsoft YaHei", "Noto Sans CJK SC", "Noto Sans CJK JP", "Source Han Sans SC", "Yu Gothic", sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; width: 100%; height: 100%; overflow: hidden; background: #d9c69a url(assets/tiles/paper.jpg); background-size: 384px; font-family: var(--font); color: var(--ink); user-select: none; -webkit-user-select: none; touch-action: none; }
#app { position: fixed; inset: 0; touch-action: none; }
#app canvas { display: block; touch-action: none; }
#ui { position: fixed; inset: 0; pointer-events: none; z-index: 10; font-family: var(--font); }
#ui > * { pointer-events: auto; }
#ui .pe-none { pointer-events: none; }

.card { background: var(--paper) url(assets/tiles/paper.jpg); background-size: 300px; border: 3px solid var(--ink); border-radius: 16px 11px 18px 10px; box-shadow: 0 4px 0 rgba(59,36,20,.45); }
.btn { font-family: var(--font); font-size: 18px; min-height: 48px; min-width: 48px; padding: 8px 16px; border: 3px solid var(--ink); border-radius: 14px 10px 15px 9px; background: var(--paper); color: var(--ink); box-shadow: 0 4px 0 var(--ink); cursor: pointer; line-height: 1.15; display: inline-flex; align-items: center; justify-content: center; gap: 6px; transition: transform .06s; white-space: nowrap; }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.btn.red { background: var(--red); color: #fff7e6; text-shadow: 0 2px 0 var(--red2); }
.btn.blue { background: var(--blue); color: #f2f6ff; text-shadow: 0 2px 0 var(--blue2); }
.btn.sage { background: var(--sage); color: #fffbe8; text-shadow: 0 2px 0 #5b7a3c; }
.btn[disabled] { opacity: .45; filter: grayscale(.6); pointer-events: none; }
.btn.on { background: var(--gold); }
.btn.big { font-size: 22px; min-height: 56px; padding: 10px 26px; }
.btn.small { font-size: 15px; padding: 6px 12px; }

.langs { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.langs .btn { font-size: 16px; padding: 6px 14px; }

/* loading handled in canvas */

/* title */
.title-wrap { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; padding: 16px; }
.title-card { padding: 10px 34px 12px; text-align: center; transform: rotate(-1.2deg); }
.title-card h1 { margin: 0; font-size: clamp(34px, 7vw, 64px); letter-spacing: 2px; color: var(--red); text-shadow: 3px 3px 0 var(--ink); -webkit-text-stroke: 1.5px var(--ink); line-height: 1.1; }
.title-card .sub { font-size: clamp(14px, 2.2vw, 20px); margin-top: 2px; }
.title-menu { display: flex; flex-direction: column; gap: 10px; align-items: stretch; min-width: 220px; }
.title-bottom { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; justify-content: center; padding: 8px 12px; }
.vol { display: flex; align-items: center; gap: 8px; font-size: 16px; }
.vol input { width: 110px; accent-color: var(--red); height: 32px; background: var(--paper); border: 2px solid var(--ink); border-radius: 10px; padding: 0 6px; }

.panel-screen { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; padding: 16px 24px; gap: 10px; overflow: auto; background: rgba(60,40,20,.25); }
.panel-screen h2 { margin: 6px 0; font-size: 28px; color: var(--ink); background: var(--paper); border: 3px solid var(--ink); padding: 4px 22px; border-radius: 14px 10px 16px 9px; }
.levels { flex-shrink: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; width: min(980px, 100%); }
.level { padding: 10px 12px; display: flex; flex-direction: column; gap: 4px; cursor: pointer; min-height: 96px; position: relative; text-align: left; font-family: var(--font); color: var(--ink); }
.level .n { font-size: 14px; opacity: .75; }
.level .nm { font-size: 20px; color: var(--red2); }
.level .d { font-size: 14px; }
.level .rk { position: absolute; right: 10px; top: 8px; font-size: 26px; color: var(--gold); -webkit-text-stroke: 1px var(--ink); }
.level.locked { opacity: .5; pointer-events: none; }
.topbar { display: flex; width: min(980px,100%); justify-content: space-between; align-items: center; gap: 10px; }

.sk-grid { flex-shrink: 0; display: grid; grid-template-columns: max-content 1fr; gap: 10px 14px; align-items: center; width: min(980px, 100%); padding: 14px; }
.sk-grid .lbl { font-size: 18px; }
.opts { display: flex; flex-wrap: wrap; gap: 8px; }
.opts .btn { font-size: 16px; }
.co-btn img { width: 34px; height: 34px; border-radius: 50%; background: #fff3; }

/* battle HUD */
.hud-co { position: absolute; left: max(10px, env(safe-area-inset-left)); top: 10px; display: flex; gap: 8px; align-items: center; padding: 6px 12px 6px 6px; cursor: pointer; transform: rotate(-.6deg); min-height: 60px; }
.hud-co.t1 .portrait { background: #c9d7ef; }
.portrait { width: 56px; height: 56px; border-radius: 12px 9px 13px 8px; border: 3px solid var(--ink); background: #f7c9a5; overflow: hidden; flex: none; }
.portrait img { width: 100%; height: 100%; object-fit: cover; object-position: top; }
.hud-co .info { display: flex; flex-direction: column; gap: 2px; min-width: 120px; }
.hud-co .row { display: flex; gap: 10px; align-items: center; font-size: 16px; white-space: nowrap; }
.hud-co .nm { font-size: 17px; }
.meter { display: flex; gap: 3px; align-items: center; }
.meter .seg { width: 13px; height: 13px; border: 2px solid var(--ink); border-radius: 50%; background: #fff6; position: relative; overflow: hidden; }
.meter .seg.big { width: 17px; height: 17px; }
.meter .seg i { position: absolute; left: 0; bottom: 0; width: 100%; background: var(--gold); }
.meter.ready .seg i { background: #ffdc4a; animation: glow .6s infinite alternate; }
.hud-co .pw { font-size: 13px; padding: 1px 6px; border-radius: 8px; background: var(--gold); border: 2px solid var(--ink); }
@keyframes glow { from { filter: brightness(1); } to { filter: brightness(1.4); } }
.coin { width: 18px; height: 18px; display: inline-block; vertical-align: -3px; }

.hud-enemy { position: absolute; right: calc(max(10px, env(safe-area-inset-right)) + 64px); top: 10px; display: flex; gap: 6px; align-items: center; padding: 4px 10px 4px 4px; transform: rotate(.6deg); }
.hud-enemy .portrait { width: 44px; height: 44px; background: #c9d7ef; }
.hud-enemy .info { font-size: 14px; display: flex; flex-direction: column; gap: 2px; }
.hud-pause { position: absolute; right: max(16px, env(safe-area-inset-right)); top: 12px; width: 52px; height: 52px; font-size: 22px; padding: 0; }

.hud-info { position: absolute; right: max(10px, env(safe-area-inset-right)); bottom: 10px; display: flex; gap: 8px; align-items: stretch; pointer-events: none; }
.hud-info .box { padding: 6px 10px; font-size: 14px; min-width: 96px; display: flex; flex-direction: column; gap: 2px; }
.hud-info .box .h { font-size: 16px; color: var(--red2); white-space: nowrap; }
.hud-info .stars { color: var(--gold); -webkit-text-stroke: .6px var(--ink); letter-spacing: 1px; font-size: 15px; }
.hud-info .kv { display: flex; justify-content: space-between; gap: 8px; white-space: nowrap; }

.hud-btns { position: absolute; left: max(16px, env(safe-area-inset-left)); bottom: 16px; display: flex; gap: 10px; }
.action-menu { position: absolute; right: max(16px, env(safe-area-inset-right)); top: 50%; transform: translateY(-50%); display: flex; flex-direction: column; gap: 8px; padding: 10px; }
.action-menu .btn { min-width: 128px; justify-content: flex-start; }
.forecast { position: absolute; left: 50%; top: 12px; transform: translateX(-50%); padding: 8px 14px; display: flex; gap: 14px; align-items: center; font-size: 16px; }
.forecast .pct { font-size: 26px; color: var(--red2); }
.forecast .cpct { font-size: 18px; color: var(--blue2); }
.hint { position: absolute; left: 50%; top: 84px; transform: translateX(-50%); max-width: min(560px, 70vw); padding: 8px 12px; font-size: 16px; display: flex; gap: 10px; align-items: center; }
.hint b { color: var(--red2); white-space: nowrap; }
.toast { position: absolute; left: 50%; top: 40%; transform: translate(-50%, -50%); padding: 10px 22px; font-size: 22px; pointer-events: none; animation: pop .25s ease-out; white-space: nowrap; }
@keyframes pop { from { transform: translate(-50%, -50%) scale(.6); opacity: 0; } to { transform: translate(-50%, -50%) scale(1); opacity: 1; } }
.banner { position: absolute; left: 0; right: 0; top: 50%; transform: translateY(-50%); display: flex; justify-content: center; pointer-events: none; }
.banner .card { padding: 10px 40px; font-size: clamp(24px, 5vw, 40px); animation: slide 1.3s ease-in-out forwards; display: flex; align-items: center; gap: 14px; }
.banner.t0 .card { background-color: #f6c6a2; }
.banner.t1 .card { background-color: #bcd0ef; }
@keyframes slide { 0% { transform: translateX(-120vw) rotate(-2deg); } 25% { transform: translateX(0) rotate(-1deg); } 75% { transform: translateX(0) rotate(-1deg); } 100% { transform: translateX(120vw) rotate(2deg); } }

.modal { position: absolute; inset: 0; background: rgba(40,25,10,.45); display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal .card { padding: 16px 20px; max-width: min(640px, 94vw); max-height: 92vh; overflow: auto; display: flex; flex-direction: column; gap: 10px; align-items: stretch; }
.modal h3 { margin: 0; font-size: 22px; text-align: center; }
.build-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.build-item { display: flex; align-items: center; gap: 6px; padding: 4px 8px; justify-content: flex-start; font-size: 15px; min-height: 56px; }
.build-item img { width: 44px; height: 44px; object-fit: contain; }
.build-item .c { margin-left: auto; font-size: 14px; display: flex; align-items: center; gap: 3px; }
.power-opt { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; padding: 10px 14px; white-space: normal; text-align: left; }
.power-opt .d { font-size: 14px; opacity: .9; }
.row-btns { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

.dialog { position: absolute; left: 0; right: 0; bottom: 0; display: flex; align-items: flex-end; gap: 10px; padding: 12px 16px 16px; background: linear-gradient(transparent, rgba(40,25,10,.35)); cursor: pointer; }
.dialog .face { width: 120px; height: 120px; flex: none; border-radius: 16px 12px 18px 11px; border: 3px solid var(--ink); overflow: hidden; background: #f7c9a5; }
.dialog .face.t1 { background: #c9d7ef; }
.dialog .face img { width: 100%; height: 100%; object-fit: cover; object-position: top; }
.dialog .box { flex: 1; padding: 10px 16px; min-height: 96px; font-size: 19px; line-height: 1.45; position: relative; }
.dialog .box .who { font-size: 16px; color: var(--red2); margin-bottom: 2px; }
.dialog .box .who.t1 { color: var(--blue2); }
.dialog .skip { position: absolute; right: 16px; bottom: calc(100% - 4px); }

.result { padding: 18px 26px; min-width: min(420px, 92vw); align-items: center !important; }
.result .big { font-size: 40px; color: var(--red); -webkit-text-stroke: 1.2px var(--ink); text-shadow: 2px 2px 0 var(--ink); }
.result .rank { font-size: 64px; color: var(--gold); -webkit-text-stroke: 2px var(--ink); line-height: 1; }
.result table { font-size: 17px; border-collapse: collapse; }
.result td { padding: 2px 12px; }
.detail { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 18px; font-size: 16px; }
.unit-pic { width: 96px; height: 96px; object-fit: contain; align-self: center; }
.save-warn { position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%); padding: 6px 12px; font-size: 14px; display: flex; gap: 8px; align-items: center; }

@media (max-height: 460px) {
  .portrait { width: 46px; height: 46px; }
  .hud-co { min-height: 50px; padding: 4px 10px 4px 4px; }
  .hud-co .row { font-size: 14px; }
  .hud-enemy .portrait { width: 36px; height: 36px; }
  .dialog .face { width: 84px; height: 84px; }
  .dialog .box { font-size: 16px; min-height: 70px; }
  .hint { top: 70px; font-size: 14px; }
  .title-menu { gap: 8px; }
  .btn.big { min-height: 50px; font-size: 19px; padding: 6px 20px; }
  .hud-info .box { font-size: 13px; padding: 4px 8px; min-width: 84px; }
  .action-menu { gap: 6px; padding: 8px; }
}
html.lang-ja { --font: "Hiragino Maru Gothic ProN", "Hiragino Sans", "Yu Gothic", "Meiryo", "Noto Sans CJK JP", "MpFontBody", sans-serif; }
@media (max-height: 460px) { .sk-grid { gap: 6px 10px; padding: 10px; } .panel-screen { padding: 10px 20px 20px; } }
.modal .card:has(.build-list) { width: min(640px, 94vw); }
.build-list { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
.modal .card > * { flex-shrink: 0; }
.inspect-card { min-width: 150px; }
.inspect-card .insp-h { display: flex; align-items: center; gap: 6px; font-size: 17px; }
.inspect-card .insp-h img { width: 40px; height: 40px; }
.inspect-card .insp-l { display: flex; align-items: center; gap: 8px; font-size: 15px; }
.inspect-card .sw { display: inline-block; width: 18px; height: 18px; border-radius: 5px; border: 2px solid var(--ink); }
.hud-btns { flex-wrap: wrap; max-width: calc(100vw - 32px - 300px); }
.threat-btn.on { background: #e8836a; color: #2a140a; }
html.hl .threat-btn { display: none; }
.hud-zoom { position: absolute; top: 12px; left: 50%; transform: translateX(-50%); display: flex; gap: 8px; }
.hud-zoom .zbtn { width: 50px; height: 50px; min-width: 50px; padding: 0; font-size: 26px; line-height: 1; justify-content: center; }
html.hl .hud-zoom, html.hl [data-testid="next-unit"] { display: none; }
.hud-btns .btn[data-testid="next-unit"] .cnt { font-size: .8em; opacity: .75; margin-left: 4px; }
.hint-toast { position: fixed; left: 50%; top: 74px; transform: translateX(-50%); width: max-content; max-width: min(92vw, 520px); padding: 10px 16px; z-index: 40; pointer-events: none; text-align: center; font-size: 16px; line-height: 1.35; color: #3b2414; animation: hintIn .18s ease-out; }
@keyframes hintIn { from { opacity: 0; transform: translate(-50%, -8px); } to { opacity: 1; transform: translate(-50%, 0); } }
.cutscene { position: fixed; inset: 0; z-index: 60; touch-action: none; cursor: pointer; }
.cutscene canvas { display: block; }
.anim-row { align-items: center; margin-top: 6px; }
.anim-row .anim-lbl { font-size: 15px; margin-right: 4px; }
.pause-main { display: flex; flex-direction: column; gap: 10px; }
@media (max-height: 460px) {
  .pause-main { flex-direction: row; flex-wrap: wrap; }
  .pause-main > .btn { flex: 1 1 0; min-width: 120px; min-height: 48px; font-size: 17px; padding: 6px 10px; }
  .pause-lang-lbl { display: none; }
  .modal .card { gap: 6px; padding: 10px 16px; }
  .modal .card h3 { margin: 0; }
}
body:has(.modal) .hint, body:has(.modal) .hint-toast { display: none; }
/* ---- title key-art screen ---- */
.ttl { justify-content: space-between; padding: 14px 16px 16px; gap: 8px; pointer-events: none; }
.ttl > * { pointer-events: auto; }
.ttl-banner { position: relative; text-align: center; margin-top: 4px; filter: drop-shadow(0 5px 0 rgba(59,36,20,.45)); }
.ttl-banner h1 { position: relative; margin: 0; padding: 6px 46px 8px; font-size: clamp(36px, 6.4vw, 72px); line-height: 1.05; letter-spacing: 3px;
  color: #fff6de; -webkit-text-stroke: 2px var(--ink); paint-order: stroke fill; text-shadow: 0 4px 0 var(--ink);
  background: var(--red); border: 4px solid var(--ink); border-radius: 10px; }
.ttl-banner h1::before, .ttl-banner h1::after { content: ''; position: absolute; top: 14px; width: 34px; height: 100%; background: #8e3315; border: 4px solid var(--ink); z-index: -1; }
.ttl-banner h1::before { left: -26px; clip-path: polygon(0 0, 100% 0, 100% 100%, 0 100%, 35% 50%); }
.ttl-banner h1::after { right: -26px; clip-path: polygon(0 0, 100% 0, 65% 50%, 100% 100%, 0 100%); }
.ttl-banner .sub { display: inline-block; margin-top: 8px; padding: 3px 14px; font-size: clamp(14px, 1.8vw, 19px); color: #fff6de; background: rgba(59,36,20,.88); border-radius: 999px; }
.ttl-menu { display: flex; flex-direction: column; gap: 10px; align-items: stretch; width: min(320px, 40vw); }
.tag { position: relative; display: flex; align-items: center; gap: 10px; min-height: 56px; padding: 4px 16px 4px 26px; font-family: var(--font); text-align: left; cursor: pointer;
  border: 3px solid var(--ink); border-radius: 8px 16px 16px 8px; box-shadow: 0 4px 0 var(--ink); background: var(--paper) url(assets/tiles/paper.jpg); background-size: 260px; color: var(--ink); transition: transform .08s; }
.tag::before { content: ''; position: absolute; left: 8px; top: 50%; width: 10px; height: 10px; margin-top: -5px; border-radius: 50%; background: #f4e7c8; border: 2.5px solid var(--ink); }
.tag:nth-child(odd) { transform: rotate(-1.2deg); } .tag:nth-child(even) { transform: rotate(1deg); }
.tag:hover { transform: translateX(4px) rotate(0); }
.tag:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.tag img { width: 46px; height: 46px; object-fit: contain; flex: none; filter: drop-shadow(0 2px 0 rgba(0,0,0,.25)); }
.tag .tag-txt { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.tag b { font-size: 22px; font-weight: normal; }
.tag small { font-size: 13px; opacity: .92; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tag.red { background-color: var(--red); background-blend-mode: multiply; color: #fff7e6; text-shadow: 0 2px 0 var(--red2); }
.tag.blue { background-color: var(--blue); background-blend-mode: multiply; color: #f2f6ff; text-shadow: 0 2px 0 var(--blue2); }
.tag.sage { background-color: #5a7434; background-blend-mode: multiply; color: #fffbe8; text-shadow: 0 2px 0 #34481c; }
.tag.gold { background-color: var(--gold); background-blend-mode: multiply; }
.ttl-bottom { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; justify-content: center; padding: 6px 12px; max-width: min(760px, 62vw); }
.vol.mini { display: inline-flex; align-items: center; gap: 4px; font-size: 20px; }
.vol.mini input { width: 90px; }
.guide-card { width: min(760px, 94vw); }
.g-intro { font-size: 15px; text-align: center; }
.g-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 8px; }
.g-row { padding: 6px 10px; display: flex; flex-direction: column; gap: 2px; box-shadow: 0 2px 0 rgba(59,36,20,.35); border-width: 2px; }
.g-top { display: flex; align-items: center; gap: 6px; }
.g-top img { width: 44px; height: 44px; object-fit: contain; }
.g-arrow { color: var(--red); font-size: 20px; }
.g-t { display: inline-flex; flex-direction: column; align-items: center; }
.g-t img { width: 38px; height: 38px; }
.g-t i { font-style: normal; font-size: 12px; background: var(--ink); color: #fff6de; border-radius: 6px; padding: 0 5px; margin-top: -4px; }
.g-txt { font-size: 14px; }
@media (max-height: 460px) {
  .ttl { padding: 8px 16px 16px; gap: 6px; }
  .ttl-banner h1 { font-size: 34px; padding: 3px 34px 5px; }
  .ttl-banner h1::before, .ttl-banner h1::after { top: 9px; width: 26px; }
  .ttl-banner h1::before { left: -20px; } .ttl-banner h1::after { right: -20px; }
  .ttl-banner .sub { margin-top: 4px; font-size: 13px; padding: 1px 12px; }
  .ttl-menu { flex-direction: row; flex-wrap: wrap; justify-content: center; width: min(520px, 62vw); gap: 8px; }
  .tag { flex: 1 1 150px; min-height: 52px; padding: 3px 10px 3px 22px; gap: 6px; }
  .tag img { width: 38px; height: 38px; }
  .tag b { font-size: 18px; } .tag small { font-size: 11px; }
  .ttl-bottom { padding: 4px 10px; gap: 8px; }
  .vol.mini input { width: 70px; }
}
@media (max-height: 460px) {
  .ttl-bottom { flex-wrap: nowrap; max-width: 70vw; }
  .ttl-bottom .langs { flex-wrap: nowrap; gap: 6px; }
  .ttl-bottom .langs .btn { padding: 4px 10px; font-size: 15px; }
  .ttl-bottom .set-lbl { display: none; }
  .vol.mini input { width: 64px; }
}
.guide-card .g-grid { grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); }
.guide-card [data-testid="guide-close"] { position: sticky; bottom: 0; z-index: 2; }
@media (max-height: 460px) {
  .guide-card { padding: 8px 12px; gap: 5px; }
  .g-row { padding: 3px 8px; }
  .g-top img { width: 36px; height: 36px; } .g-t img { width: 32px; height: 32px; }
  .g-txt { font-size: 13px; } .g-intro { font-size: 13px; }
}
.modal .card.guide-card { width: min(820px, 94vw); max-width: min(820px, 94vw); }
.guide-card .g-grid { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
