:root {
  --ink: #f3ead8;
  --ink-dim: rgba(243, 234, 216, 0.72);
  --red: #b3261e;
  --gold: #d4a64a;
  --shade: rgba(12, 10, 9, 0.78);
  --title: 'Shippori Mincho B1', 'Yu Mincho', 'Hiragino Mincho ProN', Georgia, serif;
  --body: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #0d0b0a; color: var(--ink); font-family: var(--body); user-select: none; }
#view { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
.hidden { display: none !important; }

.screen { position: fixed; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 28px; text-align: center; z-index: 10; }
#loading { background: radial-gradient(ellipse at center, #2a1d17 0%, #0d0b0a 70%); }
#title { background: linear-gradient(180deg, rgba(10,8,7,0.15) 0%, rgba(10,8,7,0.55) 60%, rgba(10,8,7,0.85) 100%); cursor: pointer; }
#pause { background: var(--shade); backdrop-filter: blur(3px); }
#filewarn { background: #0d0b0a; padding: 24px; }
#filewarn p { max-width: 560px; line-height: 1.6; color: var(--ink-dim); }

.brand { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.brand h1 { font-family: var(--title); font-weight: 800; letter-spacing: 0.18em; font-size: clamp(34px, 6vw, 76px); margin: 10px 0 0; text-shadow: 0 3px 24px rgba(0,0,0,0.6); }
.brand .kanji { font-family: var(--title); font-size: clamp(16px, 2vw, 22px); letter-spacing: 0.6em; color: var(--gold); margin-left: 0.6em; }
.brand .sub { margin-top: 14px; font-size: 14px; letter-spacing: 0.3em; text-transform: uppercase; color: var(--ink-dim); }
.mon { width: 74px; height: 74px; border-radius: 50%; border: 6px solid var(--red); position: relative; box-shadow: 0 0 30px rgba(179,38,30,0.35); }
.mon::before, .mon::after { content: ''; position: absolute; left: 10px; right: 10px; height: 8px; background: var(--red); border-radius: 2px; }
.mon::before { top: 21px; } .mon::after { bottom: 21px; }

.bar { width: min(360px, 70vw); height: 3px; background: rgba(255,255,255,0.12); overflow: hidden; }
#loadbar { height: 100%; width: 0%; background: var(--gold); transition: width 0.2s; }
.small { font-size: 13px; color: var(--ink-dim); letter-spacing: 0.05em; }

.prompt { font-size: 18px; letter-spacing: 0.12em; animation: pulse 2.2s ease-in-out infinite; }
.prompt .or { display: block; margin-top: 8px; font-size: 13px; color: var(--ink-dim); letter-spacing: 0.06em; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.45; } }

#pause h2, #filewarn h2 { font-family: var(--title); font-size: 40px; letter-spacing: 0.2em; margin: 0; }
button { font: 600 16px var(--body); color: var(--ink); background: var(--red); border: 0; padding: 12px 40px; letter-spacing: 0.15em; text-transform: uppercase; cursor: pointer; border-radius: 2px; }
button:hover { background: #cf3328; }
.controls table { border-collapse: collapse; font-size: 14px; }
.controls th { font-weight: 600; color: var(--gold); padding: 6px 18px; text-align: left; letter-spacing: 0.05em; }
.controls td { padding: 6px 18px; border-top: 1px solid rgba(255,255,255,0.08); text-align: left; color: var(--ink-dim); }
.controls td:first-child { color: var(--ink); }

#hud { position: fixed; inset: 0; pointer-events: none; z-index: 5; }
#ko { position: absolute; top: 18px; right: 26px; display: flex; align-items: baseline; gap: 10px; font-family: var(--title); text-shadow: 0 2px 10px rgba(0,0,0,0.8); }
#ko .label { font-size: 20px; color: var(--gold); letter-spacing: 0.2em; }
#konum { font-size: 54px; font-weight: 800; min-width: 1.2em; text-align: right; display: inline-block; }
#konum.pop { animation: pop 0.25s ease-out; }
@keyframes pop { 0% { transform: scale(1.5); color: #ffd98a; } 100% { transform: scale(1); } }
#stance { position: absolute; left: 24px; top: 26px; font-family: var(--title); font-size: 18px; letter-spacing: 0.2em; text-shadow: 0 2px 8px rgba(0,0,0,0.9); }
#hints { position: absolute; left: 50%; bottom: 20px; transform: translateX(-50%); font-size: 13px; color: var(--ink-dim); background: rgba(0,0,0,0.35); padding: 8px 16px; border-radius: 3px; transition: opacity 1.5s; white-space: nowrap; }
#hints b { color: var(--ink); font-weight: 600; }
#hints .pad { display: none; }
#hud.gamepad #hints .kb { display: none; }
#hud.gamepad #hints .pad { display: block; }
#hints.fade { opacity: 0; }
#toast { position: absolute; top: 22px; left: 50%; transform: translateX(-50%); font-size: 14px; background: rgba(0,0,0,0.5); padding: 8px 16px; border-radius: 3px; opacity: 0; transition: opacity 0.4s; }
#toast.show { opacity: 1; }
#fps { position: absolute; top: 12px; left: 14px; font: 12px monospace; color: #9f9; }
@media (max-width: 900px) { #hints { white-space: normal; width: 92vw; text-align: center; } }

/* ---- menus */
.menu { display: flex; flex-direction: column; gap: 10px; align-items: center; }
.menu.row { flex-direction: row; flex-wrap: wrap; justify-content: center; }
.menu button { min-width: 260px; }
#title { cursor: default; }
#title .or { position: absolute; bottom: 22px; }
button.ghost { background: rgba(0,0,0,0.25); color: var(--ink); border: 1px solid rgba(243,234,216,0.6); }
button.focus { outline: 2px solid var(--gold); outline-offset: 3px; }
#battleCard { background: rgba(14,11,9,0.72); padding: 22px 28px; border-radius: 3px; max-width: min(520px, calc(100vw - 32px)); }
#battleCard h2 { font-family: var(--title); font-size: 30px; letter-spacing: 0.14em; margin: 4px 0 0; }
#battleCard p { color: var(--ink-dim); line-height: 1.55; margin: 4px 0 8px; }
#battleCard .vs { display: flex; gap: 16px; align-items: center; font-family: var(--title); font-size: 26px; color: #e05a4a; }
#battleCard .vs img { width: 64px; height: 64px; }

/* ---- HUD */
#objective { position: absolute; top: 20px; left: 50%; transform: translateX(-50%); font-family: var(--title); font-size: 16px; letter-spacing: 0.14em;
  text-shadow: 0 2px 8px rgba(0,0,0,0.9); color: var(--ink); }
#bars { position: absolute; left: 24px; bottom: 26px; display: flex; flex-direction: column; gap: 7px; width: min(300px, 40vw); }
.bar { position: relative; height: 12px; background: rgba(0,0,0,0.5); border: 1px solid rgba(243,234,216,0.35); border-radius: 2px; overflow: hidden; }
.bar > div { height: 100%; width: 100%; transition: width 0.15s; }
.bar.hp > div { background: linear-gradient(90deg, #8c1d16, #d23a2c); }
.bar.musou { height: 9px; }
.bar.musou > div { background: linear-gradient(90deg, #7a5a1c, #e0b14a); }
.bar.musou span { position: absolute; right: 6px; top: -3px; font-size: 10px; font-family: var(--title); color: rgba(243,234,216,0.5); }
#musou.full { box-shadow: 0 0 12px rgba(240,190,80,0.9); border-color: #f0c860; }
#musou.full span { color: #fff2c0; }
#boss { position: absolute; top: 56px; left: 50%; transform: translateX(-50%); width: min(460px, 70vw); text-align: center; }
#bossname { font-family: var(--title); letter-spacing: 0.12em; font-size: 15px; text-shadow: 0 2px 8px rgba(0,0,0,0.9); margin-bottom: 4px; }
#boss .bar > div { background: linear-gradient(90deg, #5a1a14, #b3261e); }
#stance { top: 22px; bottom: auto; font-size: 14px; }
#hurt { position: fixed; inset: 0; pointer-events: none; z-index: 4; opacity: 0; background: radial-gradient(ellipse at center, rgba(0,0,0,0) 45%, rgba(160,10,0,0.55) 100%); }
#hurt.flash { animation: hurt 0.6s ease-out; }
@keyframes hurt { 0% { opacity: 1; } 100% { opacity: 0; } }

/* ---- settings */
#settingsModal { background: rgba(10,8,7,0.7); z-index: 30; }
#settingsModal .card { background: #16110e; border: 1px solid rgba(243,234,216,0.2); padding: 22px 26px; border-radius: 3px; width: min(520px, calc(100vw - 32px)); display: flex; flex-direction: column; gap: 14px; }
#settingsModal h2 { font-family: var(--title); letter-spacing: 0.2em; margin: 0; }
.settings { display: flex; flex-direction: column; gap: 10px; text-align: left; }
.presets { display: flex; gap: 6px; flex-wrap: wrap; }
.presets button { min-width: 0; flex: 1; padding: 8px 10px; font-size: 12px; }
.presets button.on { background: var(--red); }
.srow { display: grid; grid-template-columns: 1fr 150px 56px; gap: 10px; align-items: center; font-size: 13px; color: var(--ink-dim); }
.srow input[type=range] { width: 100%; accent-color: #b3261e; }
.srow select { background: #2a211c; color: var(--ink); border: 1px solid rgba(243,234,216,0.3); padding: 4px; }
.sval { text-align: right; color: var(--ink); font-variant-numeric: tabular-nums; }
.snote { font-size: 12px; color: var(--ink-dim); }
@media (max-width: 520px) { .srow { grid-template-columns: 1fr 1fr; } .sval { display: none; } }

/* ---- victory / defeat */
#over { background: rgba(10,8,7,0.62); z-index: 25; }
#over .kanji.big { font-size: 48px; letter-spacing: 0.3em; color: var(--gold); }
#over p { color: var(--ink-dim); }

#hints { white-space: normal; max-width: min(900px, 92vw); text-align: center; bottom: 70px; line-height: 1.6; }

#toast { top: 96px; }

/* ---- army panel (hero view) */
#army { position: absolute; right: 24px; bottom: 26px; width: min(270px, 36vw); font-size: 11px; background: rgba(0,0,0,0.38); border: 1px solid rgba(243,234,216,0.18); border-radius: 3px; padding: 8px 10px; }
#army .ahead { display: flex; flex-direction: column; gap: 2px; margin-bottom: 6px; }
#aOrder { font-family: var(--title); font-size: 14px; letter-spacing: 0.1em; color: var(--gold); }
#army .akeys { color: var(--ink-dim); font-size: 11px; }
#army .akeys.pad { display: none; }
#hud.gamepad #army .akeys.kb { display: none; }
#hud.gamepad #army .akeys.pad { display: inline; }
.sq { display: grid; grid-template-columns: minmax(0, 1fr) 46px 62px; gap: 6px; align-items: center; padding: 1px 0; }
.sq .nm { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sq .hb { height: 5px; background: rgba(255,255,255,0.12); border-radius: 2px; overflow: hidden; }
.sq .hb i { display: block; height: 100%; background: #4fae62; }
.sq .od { text-align: right; color: var(--ink-dim); white-space: nowrap; overflow: hidden; }
.sq.sel .nm { color: var(--gold); }
.sq.dead { opacity: 0.35; }

/* ---- Shogun mode */
#shogun { position: absolute; inset: 0; }
#hud.shogun #hints, #hud.shogun #stance { display: none; }
#hud.shogun #army { pointer-events: auto; }
.shbar { position: absolute; top: 0; left: 0; right: 0; display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 8px 14px; background: linear-gradient(180deg, rgba(10,8,7,0.8), rgba(10,8,7,0.35)); pointer-events: auto; }
.shtitle { font-family: var(--title); font-size: 18px; letter-spacing: 0.12em; color: var(--gold); }
.shtitle b { color: var(--ink); font-weight: 600; font-size: 14px; margin-left: 6px; }
.shcmds { display: flex; gap: 6px; flex-wrap: wrap; }
.shcmds button { min-width: 0; padding: 5px 10px; font-size: 11px; letter-spacing: 0.06em; }
.shcmds button i { font-style: normal; opacity: 0.6; margin-left: 4px; font-size: 11px; }
.shcmds button.on { background: #d4a64a; color: #1a120c; }
#hud.shogun #objective { top: 56px; }
#hud.shogun #boss { top: 84px; }
.shhelp { position: absolute; bottom: 20px; left: 50%; transform: translateX(-50%); font-size: 12px; color: var(--ink-dim); background: rgba(0,0,0,0.4); padding: 6px 14px; border-radius: 3px; white-space: nowrap; }
.shhelp b { color: var(--ink); }
.shhelp.pad { display: none; }
#hud.gamepad .shhelp.kb { display: none; }
#hud.gamepad .shhelp.pad { display: block; }
#shLabels { position: absolute; inset: 0; overflow: hidden; }
.shl { position: absolute; transform: translate(-50%, -100%); font-size: 11px; white-space: nowrap; padding: 2px 7px 3px; border-radius: 2px; pointer-events: auto; cursor: pointer;
  background: rgba(12,40,20,0.78); border: 1px solid rgba(120,220,140,0.55); color: #e8f5e6; }
.shl b { font-family: var(--title); font-weight: 600; margin-right: 4px; }
.shl.sel { background: rgba(80,58,14,0.9); border-color: #f0c860; color: #fff4d0; }
.shl.me { background: rgba(60,20,16,0.85); border-color: rgba(240,140,110,0.7); cursor: default; }
.shl.foe { background: rgba(70,12,10,0.7); border-color: rgba(230,90,80,0.6); cursor: default; pointer-events: none; }
#shBox { position: absolute; border: 1px solid #f0c860; background: rgba(240,200,96,0.12); }
#shReticle { position: absolute; left: 50%; top: 50%; width: 26px; height: 26px; margin: -13px 0 0 -13px; border: 2px solid rgba(240,200,96,0.9); border-radius: 50%; }
@media (max-width: 900px) { .shhelp { white-space: normal; width: 92vw; text-align: center; } }
@media (max-height: 560px) { #army .akeys { display: none !important; } }
