:root {
  --bg: #0b0d10;
  --ink: #efe8d8;
  --ink-dim: #b8b0a0;
  --gold: #d8b25a;
  --sa: #e2b53c;
  --sb: #7f9fe0;
  --panel: rgba(12, 14, 17, 0.72);
  --line: rgba(216, 178, 90, 0.35);
  --mincho: "Shippori Mincho B1", "Hiragino Mincho ProN", serif;
  --gothic: "Zen Kaku Gothic New", "Hiragino Sans", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--ink); font-family: var(--gothic); }
button { font: inherit; color: inherit; cursor: pointer; }

#stage { position: fixed; inset: 0; }
#stage canvas { display: block; }

#labels { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }
.lbl { position: absolute; left: 0; top: 0; white-space: nowrap; transform-origin: 0 0; will-change: transform; }
.lbl .in { transform: translate(-50%, -100%); display: flex; flex-direction: column; align-items: center; }
.lbl.place .in { font-family: var(--mincho); font-weight: 700; font-size: 13px; color: #f5efe0; text-shadow: 0 1px 3px #000, 0 0 8px rgba(0,0,0,.8); }
.lbl.place .tag { font-family: var(--gothic); font-size: 10px; font-weight: 500; opacity: .85; letter-spacing: .05em; }
.lbl.place.sa .tag { color: var(--sa); }
.lbl.place.sb .tag { color: var(--sb); }
.lbl.place.fallen .tag { color: #ff9b7a; }
.lbl.place.nature.peak .in { color: #efe6cf; letter-spacing: .12em; }
.lbl.place.nature .in { font-size: 12px; color: #cfe6ef; font-weight: 500; letter-spacing: .3em; opacity: .85; }
.lbl.place.village .in { font-size: 11px; color: #e8dcc0; font-weight: 500; opacity: .8; }
.lbl.place .pin { width: 1px; height: 10px; background: rgba(255,255,255,.55); margin-top: 2px; }

.lbl.unit { pointer-events: auto; cursor: pointer; }
.lbl.unit .in { background: rgba(10, 12, 15, .78); border-left: 3px solid var(--c); padding: 3px 8px 3px 7px; border-radius: 2px; box-shadow: 0 2px 10px rgba(0,0,0,.4); }
.lbl.unit .in { align-items: flex-start; transform: translate(-50%, calc(-100% - 8px)); }
.lbl.unit .n { font-family: var(--mincho); font-weight: 700; font-size: 13px; line-height: 1.25; }
.lbl.unit .m { font-size: 11px; color: var(--c); font-weight: 700; font-variant-numeric: tabular-nums; }
.lbl.unit.sa { --c: var(--sa); }
.lbl.unit.sb { --c: var(--sb); }
.lbl.unit.gone .in { opacity: .45; }
.lbl.event .in { font-family: var(--mincho); font-weight: 800; font-size: 14px; color: #fff; background: rgba(120, 18, 18, .85); padding: 4px 10px; border: 1px solid rgba(255,190,160,.5); }

#vignette { position: fixed; inset: 0; pointer-events: none; background: radial-gradient(ellipse at center, transparent 55%, rgba(0,0,0,.55) 100%); }
#grain { position: fixed; inset: -50%; pointer-events: none; opacity: .07; mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  animation: grain 1s steps(6) infinite; }
@keyframes grain { 0%{transform:translate(0,0)} 20%{transform:translate(-3%,2%)} 40%{transform:translate(2%,-3%)} 60%{transform:translate(-2%,-1%)} 80%{transform:translate(3%,3%)} 100%{transform:translate(0,0)} }
#flash { position: fixed; inset: 0; pointer-events: none; background: #dfe8ff; opacity: 0; }

/* ---------- top HUD ---------- */
#hudTop { position: fixed; top: 0; left: 0; right: 0; display: flex; align-items: flex-start; gap: 18px; padding: 16px 20px; pointer-events: none;
  background: linear-gradient(to bottom, rgba(0,0,0,.55), transparent); }
#hudTop > * { pointer-events: auto; }
.back { color: var(--ink-dim); text-decoration: none; font-size: 12px; border: 1px solid rgba(255,255,255,.18); padding: 5px 10px; border-radius: 2px; background: rgba(0,0,0,.3); }
.back:hover { color: var(--ink); border-color: var(--gold); }
.docTitle .eyebrow, .introInner .eyebrow { font-size: 11px; letter-spacing: .25em; color: var(--gold); }
.docTitle h1 { margin: 2px 0 0; font-family: var(--mincho); font-weight: 800; font-size: 24px; letter-spacing: .12em; }
#clock { margin-left: auto; text-align: right; }
#clock .date { font-family: var(--mincho); font-size: 13px; color: var(--ink-dim); }
#clock .date span { font-family: var(--gothic); font-size: 11px; margin-left: 4px; opacity: .8; }
#clock .time { font-family: var(--mincho); font-weight: 700; font-size: 30px; line-height: 1.1; font-variant-numeric: tabular-nums; }
#clock .koku { font-size: 15px; margin-left: 10px; color: var(--gold); }
#clock .weather { font-size: 12px; color: var(--ink-dim); }

/* ---------- forces panel ---------- */
#forces { position: fixed; right: 20px; top: 110px; width: 232px; padding: 12px 14px 10px; background: var(--panel); border: 1px solid rgba(255,255,255,.08); border-top: 2px solid var(--gold); backdrop-filter: blur(6px); font-size: 12px; }
.fx-head { font-family: var(--mincho); font-weight: 700; font-size: 13px; margin-bottom: 6px; }
.fx-head span { font-family: var(--gothic); font-weight: 400; font-size: 10px; color: var(--ink-dim); margin-left: 6px; }
.fx-head.sub { margin-top: 10px; padding-top: 8px; border-top: 1px solid rgba(255,255,255,.08); }
.fx-row { display: grid; grid-template-columns: 64px 1fr 54px; align-items: center; gap: 6px; margin: 3px 0; }
.fx-row .nm { white-space: nowrap; font-size: 11.5px; }
.fx-row .bar { height: 7px; background: rgba(255,255,255,.07); position: relative; }
.fx-row .bar i { position: absolute; left: 0; top: 0; bottom: 0; width: 0; transition: width .25s linear; }
.fx-row.sa .bar i { background: var(--sa); }
.fx-row.sb .bar i { background: var(--sb); }
.fx-row b { text-align: right; font-variant-numeric: tabular-nums; font-size: 13px; }
.fx-row.sa .nm { color: var(--sa); }
.fx-row.sb .nm { color: var(--sb); }
.legend { margin-top: 10px; padding-top: 8px; border-top: 1px solid rgba(255,255,255,.08); color: var(--ink-dim); font-size: 11px; line-height: 1.7; }
.fig { display: inline-block; width: 6px; height: 11px; border-radius: 3px 3px 1px 1px; margin-right: 2px; vertical-align: -1px; }
.fig.sa { background: var(--sa); } .fig.sb { background: var(--sb); }
#inset { width: 100%; margin-top: 8px; background: rgba(214, 200, 164, .08); border: 1px solid rgba(255,255,255,.08); }
#inset .sea { fill: rgba(80, 120, 140, .45); }
#inset .area { fill: rgba(216,178,90,.12); stroke: var(--gold); stroke-width: 1; stroke-dasharray: 3 2; }
#inset .pt circle { fill: var(--sa); }
#inset .pt.sb circle { fill: var(--sb); }
#inset text { fill: var(--ink); font-size: 9px; font-family: var(--mincho); }
#inset .cap { fill: var(--ink-dim); font-size: 8px; font-family: var(--gothic); }
#inset .route { fill: none; stroke-width: 1.6; stroke-dasharray: 4 2; }
#inset .route.sa { stroke: var(--sa); } #inset .route.sb { stroke: var(--sb); }
#inset .ridge { fill: rgba(120, 110, 90, .35); }
#inset .fld { fill: rgba(216,178,90,.12); stroke: var(--gold); stroke-width: 1; stroke-dasharray: 3 2; }

/* ---------- narration ---------- */
#narration { position: fixed; left: 24px; bottom: 96px; width: min(560px, calc(100vw - 300px)); padding: 16px 20px 14px; background: linear-gradient(to right, rgba(8,10,12,.86), rgba(8,10,12,.62)); border-left: 3px solid var(--gold); backdrop-filter: blur(4px); transition: opacity .6s; }
#narration.swap { opacity: 0; }
.chNo { font-size: 11px; letter-spacing: .3em; color: var(--gold); }
#chTitle { margin: 4px 0 8px; font-family: var(--mincho); font-weight: 800; font-size: 26px; letter-spacing: .08em; }
#chBody { margin: 0; font-family: var(--mincho); font-size: 15px; line-height: 1.9; }
.chNote { margin: 8px 0 0; font-size: 11.5px; line-height: 1.6; color: var(--ink-dim); }
.chNote:empty { display: none; }
.chNote::before { content: "注　"; color: var(--gold); }

/* ---------- unit card ---------- */
#unitCard { position: fixed; right: 20px; bottom: 96px; width: 260px; padding: 12px 14px; background: var(--panel); border: 1px solid rgba(255,255,255,.1); backdrop-filter: blur(6px); }
#unitCard .close { position: absolute; right: 6px; top: 4px; background: none; border: 0; font-size: 18px; color: var(--ink-dim); }
#unitCard .side { font-size: 11px; letter-spacing: .15em; }
#unitCard .name { font-family: var(--mincho); font-weight: 800; font-size: 19px; margin: 2px 0; }
#unitCard .men { font-size: 13px; font-weight: 700; }
#unitCard p { margin: 6px 0 0; font-size: 12.5px; line-height: 1.7; color: var(--ink-dim); }

/* ---------- controls ---------- */
#controls { position: fixed; left: 0; right: 0; bottom: 0; display: flex; align-items: center; gap: 12px; padding: 12px 20px 14px; background: linear-gradient(to top, rgba(0,0,0,.8), rgba(0,0,0,.35)); }
#controls > button { flex: none; height: 34px; min-width: 34px; padding: 0 10px; background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.18); border-radius: 2px; font-size: 13px; }
#controls > button:hover { border-color: var(--gold); }
#camBtn.on { background: var(--gold); color: #111; border-color: var(--gold); }
#scrubWrap { position: relative; flex: 1; padding-top: 2px; }
#scrub { width: 100%; margin: 0; accent-color: var(--gold); height: 18px; }
#chapterTicks { position: absolute; left: 0; right: 0; top: 10px; height: 0; pointer-events: none; }
#chapterTicks i { position: absolute; top: -5px; width: 1px; height: 10px; background: rgba(255,255,255,.35); }
#chapterList { position: relative; height: 18px; font-size: 10.5px; }
#chapterList button { position: absolute; top: 0; transform: translateX(0); background: none; border: 0; padding: 1px 2px; color: var(--ink-dim); white-space: nowrap; font-family: var(--mincho); }
#chapterList button.on { color: var(--gold); font-weight: 700; }
#chapterList button:hover { color: var(--ink); }

/* ---------- intro ---------- */
#intro { position: fixed; inset: 0; display: grid; place-items: center; background: radial-gradient(ellipse at 50% 60%, rgba(16,18,22,.55), rgba(5,6,8,.94)); transition: opacity 1.2s; z-index: 10; }
#intro.hide { opacity: 0; pointer-events: none; }
.introInner { max-width: 560px; padding: 24px; text-align: center; }
.introInner h1 { font-family: var(--mincho); font-weight: 800; font-size: 54px; letter-spacing: .2em; margin: 10px 0 18px; }
.introInner .lead { font-family: var(--mincho); font-size: 16px; line-height: 2.1; color: var(--ink); }
#startBtn { margin-top: 18px; padding: 12px 34px; font-family: var(--mincho); font-weight: 700; font-size: 16px; letter-spacing: .15em; background: transparent; border: 1px solid var(--gold); color: var(--gold); }
#startBtn:not([disabled]):hover { background: var(--gold); color: #111; }
#startBtn[disabled] { opacity: .5; cursor: wait; }
.introInner .fine { font-size: 11px; color: var(--ink-dim); line-height: 1.7; margin-top: 18px; }

@media (max-width: 760px) {
  #hudTop { padding: 10px 12px; gap: 10px; }
  .docTitle h1 { font-size: 18px; }
  .back { display: none; }
  #clock .time { font-size: 22px; }
  #clock .date span { display: none; }
  #forces { top: auto; bottom: 64px; right: 8px; width: 150px; padding: 8px 9px; font-size: 11px; }
  #forces .legend, #inset, #forces .fx-head.sub, #forces .fx-head.sub ~ .fx-row { display: none; }
  .fx-row { grid-template-columns: 50px 1fr 44px; }
  .fx-row .nm { font-size: 10px; }
  #narration { left: 8px; right: 166px; width: auto; bottom: 64px; padding: 10px 12px; }
  #chTitle { font-size: 18px; margin: 2px 0 4px; }
  #chBody { font-size: 12.5px; line-height: 1.7; }
  .chNote { display: none; }
  #controls { padding: 8px 10px 10px; gap: 8px; }
  #chapterList { display: none; }
  #unitCard { right: 8px; left: 8px; width: auto; bottom: 64px; z-index: 5; }
  .introInner h1 { font-size: 38px; }
  .introInner .lead { font-size: 14px; }
  .lbl.unit .n { font-size: 11px; }
  .lbl.place .in { font-size: 11px; }
}
