/* 忍びの英語修行 — novel-game stage.
   One full-viewport stage: background art → characters → content board → dialog window → HUD → overlays.
   Deliberately single (night) theme: the scenes are painted art, so every colour is set explicitly here. */
:root {
  color-scheme: dark;
  --panel: rgba(14, 18, 38, .84);
  --panel-2: rgba(24, 30, 58, .92);
  --panel-line: rgba(216, 178, 90, .55);
  --gold: #d8b25a;
  --gold-hi: #f3dc9a;
  --text: #f4efe4;
  --text-dim: #b9b2a3;
  --paper: #f6eedb;
  --paper-2: #efe3c6;
  --paper-ink: #2b2118;
  --paper-dim: #7a6a55;
  --wood: #5a3a22;
  --wood-dark: #3a2414;
  --vermilion: #c8382c;
  --good: #3fae74;
  --bad: #d65a4a;
  --S: #3f7fd6; --V: #d9443a; --O: #2f9e6a; --X: #8a7a5a;
  --c-sakuya: #d9546e; --c-anne: #5f8f45; --c-uka: #e0922a; --c-naruka: #8a5a34;
  --font-brush: "Yuji Syuku", "Zen Old Mincho", "Hiragino Mincho ProN", serif;
  --font-body: "Zen Kaku Gothic New", "Hiragino Sans", "Yu Gothic", "Meiryo", sans-serif;
  --font-en: "Outfit", "Segoe UI", system-ui, sans-serif;
  --ease-out: cubic-bezier(.2, .8, .2, 1);
  --ease-spring: cubic-bezier(.34, 1.56, .64, 1);
  --dialog-h: clamp(140px, 22vh, 200px);
}
* { box-sizing: border-box; }
body { background: #070912; color: var(--text); font-family: var(--font-body); font-size: 16px; line-height: 1.7; margin: 0; overflow: hidden; }
button { font: inherit; color: inherit; }
button:focus-visible, input:focus-visible { outline: 2px solid var(--gold-hi); outline-offset: 2px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- stage ---------- */
#stage { position: fixed; inset: 0; overflow: hidden; user-select: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent; }
.bg { position: absolute; inset: -3%; background-size: cover; background-position: center; opacity: 0; transition: opacity 1s ease; animation: drift 40s ease-in-out infinite alternate; }
.bg.on { opacity: 1; }
@keyframes drift { from { transform: scale(1) translate(0, 0); } to { transform: scale(1.06) translate(-1.2%, -.8%); } }
.shade { position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(ellipse at 50% 35%, transparent 40%, rgba(5, 7, 18, .55) 100%), linear-gradient(to top, rgba(5, 7, 18, .75), transparent 45%); }
.shade.dim::after { content: ""; position: absolute; inset: 0; background: rgba(5, 7, 18, .45); }
.petals { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.petals i { position: absolute; top: -20px; width: 10px; height: 8px; border-radius: 80% 0 80% 0; background: #f7c6d6; opacity: .75; animation: fall linear infinite; }
@keyframes fall { to { transform: translate(var(--dx, -120px), 110vh) rotate(540deg); } }

/* ---------- characters ---------- */
.chars { position: absolute; inset: 0; pointer-events: none; }
.char { position: absolute; bottom: 0; height: min(96vh, 1000px); aspect-ratio: 17 / 20; /* portraits are 1088x1280 (64 px clear margin each side) */ left: var(--x, 50%); transform: translateX(-50%); transition: left .7s var(--ease-out), filter .4s ease; }
.char .body { position: absolute; inset: 0; transform-origin: 50% 100%; animation: breathe 4.6s ease-in-out infinite; }
/* moved frame by frame from js/app.js (Motion) while the character's voice plays */
.char .sway { position: absolute; inset: 0; transform-origin: 50% 96%; }
.char.speaking .sway { will-change: transform; }
/* lip-flap patch (assets/chars/mouth): placed in % of the 1088x1280 picture, same light filter as the portrait */
.char img.mouth { inset: auto; object-fit: fill; transition: none; filter: var(--char-filter, none); pointer-events: none; }
.char img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; object-position: center bottom; transition: opacity .28s ease; }
.char img.off { opacity: 0; }
.char img { filter: var(--char-filter, none) drop-shadow(0 0 18px rgba(0, 0, 0, .35)); }
/* scene light laid over the character only (masked by the portrait itself) so it sits in the painted background */
.char .tint { position: absolute; inset: 0; pointer-events: none; background: var(--tint, none); mix-blend-mode: soft-light;
  -webkit-mask: var(--m) center bottom / contain no-repeat; mask: var(--m) center bottom / contain no-repeat; }
.char .rim { position: absolute; inset: 0; pointer-events: none; background: var(--rim, none); mix-blend-mode: screen;
  -webkit-mask: var(--m) center bottom / contain no-repeat; mask: var(--m) center bottom / contain no-repeat; }
#stage[data-scene="village"] { --char-filter: brightness(.94) saturate(.96); --tint: linear-gradient(200deg, rgba(110, 130, 255, .55), rgba(60, 70, 160, .25) 45%, rgba(255, 170, 90, .35)); --rim: linear-gradient(90deg, rgba(255, 160, 80, .14), transparent 30%); }
#stage[data-scene="dojo"] { --char-filter: brightness(.97) saturate(1.02); --tint: linear-gradient(250deg, rgba(255, 180, 90, .6), rgba(200, 120, 60, .3) 50%, rgba(80, 50, 30, .35)); --rim: linear-gradient(270deg, rgba(255, 190, 110, .18), transparent 35%); }
#stage[data-scene="yard"] { --char-filter: brightness(.98) saturate(1.04); --tint: linear-gradient(110deg, rgba(255, 130, 60, .6), rgba(255, 170, 90, .3) 50%, rgba(120, 60, 120, .3)); --rim: linear-gradient(90deg, rgba(255, 140, 70, .22), transparent 30%); }
#stage[data-scene="tower"] { --char-filter: brightness(.9) saturate(.92); --tint: linear-gradient(160deg, rgba(130, 160, 255, .65), rgba(60, 80, 170, .35) 55%, rgba(30, 40, 90, .4)); --rim: linear-gradient(270deg, rgba(170, 200, 255, .22), transparent 32%); }
.char.enter .body { animation: charIn .7s var(--ease-out) both, breathe 4.6s ease-in-out .7s infinite; }
.char.leave { animation: charOut .45s ease forwards; }
/* no body motion while talking (user's choice): .talking only marks the speaker */
.char.talking .body { }
.char.hop .body { animation: hop .5s var(--ease-spring); }
.char.shake .body { animation: shakeX .45s ease; }
.char.muted { filter: brightness(.55) saturate(.7); }
.char.group { height: min(78vh, 820px); }   /* 修行の締めくくり: four on stage at once */
@keyframes charIn { from { opacity: 0; transform: translateY(6%) scale(.97); } to { opacity: 1; transform: none; } }
@keyframes charOut { to { opacity: 0; transform: translateX(-50%) translateY(4%); } }
@keyframes breathe { 0%, 100% { transform: scale(1, 1); } 50% { transform: scale(1.004, 1.012); } }
@keyframes talk { 0%, 100% { transform: translateY(0) scale(1, 1); } 50% { transform: translateY(-.5%) scale(1.004, 1.01); } }
@keyframes hop { 0% { transform: none; } 35% { transform: translateY(-4%); } 70% { transform: translateY(.5%); } 100% { transform: none; } }
@keyframes shakeX { 20% { transform: translateX(-2%); } 40% { transform: translateX(2%); } 60% { transform: translateX(-1.2%); } 80% { transform: translateX(1%); } }

/* ---------- HUD ---------- */
.hud { position: absolute; top: 0; left: 0; right: 0; display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
  padding: max(12px, env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px)) 0 max(16px, env(safe-area-inset-left, 0px)); pointer-events: none; z-index: 30; }
.hud > * { pointer-events: auto; }
.plate { background: var(--panel); border: 1px solid var(--panel-line); border-radius: 12px; box-shadow: 0 6px 20px rgba(0, 0, 0, .35), inset 0 0 0 3px rgba(14, 18, 38, .9), inset 0 0 0 4px rgba(216, 178, 90, .25); backdrop-filter: blur(6px); }
.scene-tag { display: flex; align-items: center; gap: 10px; padding: 6px 14px 6px 10px; font-size: 14px; }
.scene-tag .seal { width: 28px; height: 28px; border-radius: 6px; background: var(--vermilion); color: #fff; display: grid; place-items: center; font-family: var(--font-brush); font-size: 15px; transform: rotate(-6deg); }
.scene-tag b { font-weight: 700; letter-spacing: .04em; }
.scene-tag span { color: var(--text-dim); font-size: 12.5px; }
.tools { display: flex; gap: 6px; }
.tool { min-width: 44px; height: 40px; padding: 0 12px; border-radius: 10px; cursor: pointer; font-size: 13px; font-weight: 700; letter-spacing: .04em; display: inline-flex; align-items: center; gap: 6px; }
.tool[aria-pressed="true"] { background: var(--gold); color: #1a1408; border-color: var(--gold); }
.tool svg { width: 18px; height: 18px; }
.status { display: flex; gap: 14px; align-items: center; padding: 8px 16px; }
.status .rank { font-family: var(--font-brush); font-size: 22px; line-height: 1; color: var(--gold-hi); }
.status .xpbar { width: 120px; height: 6px; border-radius: 3px; background: rgba(255, 255, 255, .15); overflow: hidden; }
.status .xpbar span { display: block; height: 100%; background: linear-gradient(90deg, var(--gold), var(--gold-hi)); transition: width .8s var(--ease-out); }
.status small { display: block; font-size: 11.5px; color: var(--text-dim); }
.status .fire { font-family: var(--font-en); font-weight: 700; font-size: 18px; color: #ffb36b; display: flex; align-items: center; gap: 4px; }

/* ---------- dialog window ---------- */
.dialog { position: absolute; left: 50%; transform: translateX(-50%); bottom: max(14px, env(safe-area-inset-bottom, 0px)); width: min(1120px, calc(100% - 32px)); min-height: var(--dialog-h);
  padding: 26px 34px 20px; z-index: 20; cursor: pointer; transition: opacity .3s ease, transform .3s var(--ease-out); }
.dialog.hide { opacity: 0; transform: translateX(-50%) translateY(16px); pointer-events: none; }
.dialog::before { content: ""; position: absolute; inset: 7px; border: 1px solid rgba(216, 178, 90, .28); border-radius: 8px; pointer-events: none; }
.nameplate { position: absolute; top: -18px; left: 26px; padding: 3px 22px 4px; border-radius: 8px; background: var(--who, var(--wood)); color: #fff; font-weight: 700; font-size: 17px; letter-spacing: .12em;
  box-shadow: 0 4px 12px rgba(0, 0, 0, .4), inset 0 0 0 2px rgba(255, 255, 255, .25); }
.nameplate:empty { display: none; }
.say { font-size: clamp(17px, 1.55vw, 21px); line-height: 1.85; letter-spacing: .03em; min-height: 3.7em; text-wrap: pretty; }
.say .en-inline { font-family: var(--font-en); font-weight: 600; color: var(--gold-hi); }
.next-mark { position: absolute; right: 26px; bottom: 16px; width: 14px; height: 14px; color: var(--gold-hi); animation: bob 1s ease-in-out infinite; opacity: 0; }
.dialog.ready .next-mark { opacity: 1; }
@keyframes bob { 50% { transform: translateY(4px); } }
.dialog .hint { position: absolute; right: 48px; bottom: 12px; font-size: 11.5px; color: var(--text-dim); opacity: 0; transition: opacity .3s; }
.dialog.ready .hint { opacity: .8; }

/* ---------- content board (hanging scroll) ---------- */
.board-wrap { position: absolute; z-index: 15; right: max(4vw, 24px); top: calc(76px + env(safe-area-inset-top, 0px)); bottom: calc(var(--dialog-h) + 36px); width: min(46vw, 640px); display: flex; align-items: center; justify-content: center; pointer-events: none; }
.board { position: relative; width: 100%; max-height: 100%; pointer-events: auto; transform-origin: 50% 0; animation: unroll .6s var(--ease-out) both; }
.board.out { animation: rollup .35s ease forwards; }
@keyframes unroll { from { clip-path: inset(0 0 100% 0); transform: translateY(-10px); } to { clip-path: inset(0 0 0 0); transform: none; } }
@keyframes rollup { to { clip-path: inset(0 0 100% 0); opacity: 0; } }
.rod { height: 18px; margin: 0 -14px; border-radius: 9px; background: linear-gradient(180deg, #7a5232, var(--wood-dark) 60%, #2a190d); box-shadow: 0 3px 8px rgba(0, 0, 0, .4); position: relative; z-index: 2; }
.rod::before, .rod::after { content: ""; position: absolute; top: 2px; width: 22px; height: 14px; border-radius: 4px; background: linear-gradient(180deg, #e0c070, #9a7a30); }
.rod::before { left: -6px; } .rod::after { right: -6px; }
.paper { background:
    repeating-linear-gradient(90deg, rgba(120, 90, 50, .03) 0 2px, transparent 2px 7px),
    radial-gradient(ellipse at 30% 20%, rgba(255, 255, 255, .5), transparent 60%),
    linear-gradient(180deg, var(--paper), var(--paper-2));
  color: var(--paper-ink); padding: 22px 28px 20px; margin: 0 4px; box-shadow: 0 10px 30px rgba(0, 0, 0, .45); display: flex; flex-direction: column; gap: 12px; max-height: calc(100vh - var(--dialog-h) - 150px); overflow: auto; }
/* never squeeze the board's blocks to fit; a board taller than the space scrolls instead */
.paper > * { flex-shrink: 0; }
.paper .kicker { display: flex; justify-content: space-between; align-items: center; gap: 10px; font-size: 13px; color: var(--paper-dim); letter-spacing: .08em; }
.paper .kicker b { color: var(--vermilion); font-weight: 700; }
.paper h2 { margin: 0; font-family: var(--font-brush); font-weight: 400; font-size: clamp(24px, 2.4vw, 32px); line-height: 1.35; text-wrap: balance; }
.paper .big-ja { font-size: clamp(24px, 2.5vw, 34px); font-weight: 700; line-height: 1.5; text-align: center; text-wrap: balance; }
.paper .note { font-size: 14.5px; color: var(--paper-dim); border-top: 1px dashed rgba(120, 90, 50, .35); padding-top: 10px; }
.paper .ja { font-size: 16px; color: var(--paper-dim); text-align: center; }
.rule { height: 1px; background: linear-gradient(90deg, transparent, rgba(120, 90, 50, .4), transparent); }

/* S / V / O chunks */
.chunks { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px 10px; }
.chunk { display: inline-flex; flex-direction: column; align-items: center; gap: 4px; opacity: 0; transform: translateY(14px) scale(.9); animation: chunkIn .5s var(--ease-spring) forwards; animation-delay: calc(var(--i) * .28s + .25s); }
.chunk .w { font-family: var(--font-en); font-weight: 600; font-size: clamp(26px, 2.8vw, 40px); line-height: 1.15; padding: 4px 14px 6px; border-radius: 10px; background: #fff; border: 2px solid var(--c); box-shadow: 0 3px 0 var(--c); color: var(--paper-ink); }
.chunk .t { font-size: 12.5px; font-weight: 700; color: #fff; background: var(--c); border-radius: 6px; padding: 0 9px; letter-spacing: .06em; }
.chunk.S { --c: var(--S); } .chunk.V { --c: var(--V); } .chunk.O { --c: var(--O); } .chunk.extra { --c: var(--X); }   /* not ".X": in quirks mode it would match the .x close button */
@keyframes chunkIn { to { opacity: 1; transform: none; } }
.order-ja { display: flex; justify-content: center; gap: 8px; flex-wrap: wrap; font-size: 15px; color: var(--paper-dim); }
.order-ja::before { content: "日本語の順"; align-self: center; font-size: 12px; letter-spacing: .08em; margin-right: 4px; }
.order-arrow { margin: -4px 0 -2px; text-align: center; font-size: 13px; font-weight: 700; color: var(--vermilion); }
.order-ja span { padding: 2px 10px; border-radius: 6px; background: rgba(120, 90, 50, .1); border-bottom: 3px solid var(--c); }
.listen { align-self: center; display: inline-flex; align-items: center; gap: 8px; border: 0; border-radius: 999px; padding: 8px 18px; background: var(--paper-ink); color: var(--paper); font-weight: 700; font-size: 14px; cursor: pointer; }
.listen svg { width: 16px; height: 16px; }

/* fuse timer (瞬間英作文) */
.fuse { position: relative; height: 6px; border-radius: 3px; background: rgba(120, 90, 50, .2); margin: 4px 6px; }
.fuse > span { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 3px; background: linear-gradient(90deg, #e0a040, #c8382c); width: var(--w, 100%); }
.fuse > i { position: absolute; top: 50%; left: var(--w, 100%); width: 18px; height: 18px; margin: -9px 0 0 -9px; border-radius: 50%; background: radial-gradient(circle, #fff6c0, #ffb040 45%, rgba(255, 90, 0, 0) 70%); animation: spark .15s steps(2) infinite; }
@keyframes spark { 50% { transform: scale(1.35) rotate(45deg); } }
.count { font-family: var(--font-en); font-weight: 700; font-size: 15px; color: var(--paper-dim); font-variant-numeric: tabular-nums; }

/* answer flip */
.flip { perspective: 1000px; }
.flip .card { transition: transform .6s var(--ease-out); transform-style: preserve-3d; }
.flip.done .card { animation: flipIn .6s var(--ease-out); }
@keyframes flipIn { from { transform: rotateX(-80deg); opacity: 0; } to { transform: none; opacity: 1; } }
.typed { font-size: 14px; color: var(--paper-dim); text-align: center; }
.typed b { font-family: var(--font-en); color: var(--paper-ink); }
.field { width: 100%; border: 2px solid rgba(120, 90, 50, .3); border-radius: 10px; padding: 10px 14px; font-family: var(--font-en); font-size: 18px; background: #fffdf6; color: var(--paper-ink); }
.field::placeholder { color: #b0a088; }
.type-toggle { align-self: center; background: none; border: 0; color: var(--paper-dim); font-size: 13px; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }

/* order tiles */
.slots { min-height: 60px; display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; padding: 10px; border-radius: 12px; border: 2px dashed rgba(120, 90, 50, .35); }
.tiles { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }
.tile { font-family: var(--font-en); font-weight: 600; font-size: 20px; padding: 8px 16px 10px; border-radius: 9px; cursor: pointer; border: 0; color: #fff8e8;
  background: linear-gradient(180deg, #8a5a34, var(--wood)); box-shadow: 0 4px 0 var(--wood-dark), 0 6px 10px rgba(0, 0, 0, .25); transition: transform .15s var(--ease-spring), opacity .2s; }
.tile:hover { transform: translateY(-2px); }
.tile:active { transform: translateY(2px); box-shadow: 0 2px 0 var(--wood-dark); }
.tile.used { opacity: 0; pointer-events: none; transform: scale(.6); }
.slots .tile { animation: pop .3s var(--ease-spring); }
@keyframes pop { from { transform: scale(.6); } to { transform: none; } }

/* option plates (4-choice) */
.opts { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 10px; }
.opt { text-align: left; border: 2px solid rgba(120, 90, 50, .25); background: #fffdf6; color: var(--paper-ink); border-radius: 12px; padding: 10px 14px; font-family: var(--font-en); font-size: 17px; line-height: 1.35; font-weight: 500; cursor: pointer; transition: transform .15s, border-color .15s, background .15s; display: flex; gap: 12px; align-items: center; }
.opt:hover { border-color: var(--gold); transform: translateX(4px); }
.opt .k { flex: none; width: 26px; height: 26px; border-radius: 6px; background: var(--paper-ink); color: var(--paper); display: grid; place-items: center; font-size: 13px; font-weight: 700; }
.opt.sel { border-color: var(--gold); background: #fff3d0; }
.opt.right { border-color: var(--good); background: #e2f4e8; }
.opt.wrong { border-color: var(--bad); background: #fbe4df; }

/* ---------- choice plaques (novel-style) ---------- */
.choices { position: absolute; z-index: 25; left: 50%; transform: translateX(-50%); bottom: calc(var(--dialog-h) + 30px); display: flex; gap: 14px; flex-wrap: wrap; justify-content: center; width: min(760px, calc(100% - 32px)); }
.choice { min-width: 220px; flex: 1; padding: 14px 22px; border-radius: 12px; cursor: pointer; font-size: 18px; font-weight: 700; letter-spacing: .06em; color: var(--text);
  background: linear-gradient(180deg, rgba(40, 48, 90, .95), rgba(18, 22, 46, .95)); border: 1px solid var(--panel-line); box-shadow: 0 8px 24px rgba(0, 0, 0, .4), inset 0 1px 0 rgba(255, 255, 255, .12);
  opacity: 0; transform: translateY(12px); animation: rise .4s var(--ease-out) forwards; animation-delay: calc(var(--i, 0) * .08s); transition: background .15s, transform .15s; display: flex; align-items: center; justify-content: center; gap: 10px; }
.choice:hover { background: linear-gradient(180deg, rgba(70, 60, 30, .95), rgba(40, 30, 12, .95)); transform: translateY(-2px); }
.choice.main { background: linear-gradient(180deg, #e4c06a, #b98b2c); color: #1d1406; border-color: #f3dc9a; }
.choice.main:hover { background: linear-gradient(180deg, #f0d080, #c99a3a); }
.choice small { font-weight: 500; font-size: 13px; opacity: .8; letter-spacing: 0; }
.choice kbd { font-family: var(--font-en); font-size: 11px; border: 1px solid currentColor; border-radius: 4px; padding: 0 5px; opacity: .6; }
@keyframes rise { to { opacity: 1; transform: none; } }

/* ---------- home menu (wooden plaques) ---------- */
.menu { position: absolute; z-index: 15; right: max(4vw, 24px); top: calc(84px + env(safe-area-inset-top, 0px)); bottom: calc(var(--dialog-h) + 36px); width: min(380px, 40vw); display: flex; flex-direction: column; gap: 12px; justify-content: center; }
.fuda { position: relative; text-align: left; cursor: pointer; border: 0; border-radius: 10px; padding: 14px 20px 14px 64px; color: #fff8e8;
  background: linear-gradient(180deg, #7a4e2c, #4e3019); box-shadow: 0 6px 0 #2a190d, 0 10px 22px rgba(0, 0, 0, .4), inset 0 1px 0 rgba(255, 255, 255, .15);
  opacity: 0; transform: translateX(30px); animation: slideIn .5s var(--ease-out) forwards; animation-delay: calc(var(--i) * .07s + .2s); transition: transform .15s; }
.fuda:hover { transform: translateX(-6px); }
.fuda:active { transform: translateY(3px); box-shadow: 0 3px 0 #2a190d; }
.fuda .ic { position: absolute; left: 16px; top: 50%; width: 34px; height: 34px; margin-top: -17px; border-radius: 8px; display: grid; place-items: center; background: rgba(0, 0, 0, .25); font-family: var(--font-brush); font-size: 20px; color: var(--gold-hi); }
.fuda b { display: block; font-size: 18px; letter-spacing: .08em; }
.fuda small { display: block; font-size: 12.5px; color: #e8d6b8; opacity: .85; }
.fuda .badge { position: absolute; right: 14px; top: 50%; transform: translateY(-50%); min-width: 26px; height: 26px; padding: 0 8px; border-radius: 13px; background: var(--vermilion); color: #fff; font-family: var(--font-en); font-weight: 700; font-size: 14px; display: grid; place-items: center; }
.fuda.main { padding-block: 20px; background: linear-gradient(180deg, #e4c06a, #a97a22); color: #1d1406; box-shadow: 0 6px 0 #6a4a10, 0 10px 22px rgba(0, 0, 0, .4); }
.fuda.main .ic { background: rgba(255, 255, 255, .3); color: #6a2a10; }
.fuda.main small { color: #4a3510; }
.fuda:disabled { filter: grayscale(.7) brightness(.7); cursor: default; }
@keyframes slideIn { to { opacity: 1; transform: none; } }

/* ---------- title ---------- */
.title-screen { position: absolute; inset: 0; z-index: 15; display: flex; flex-direction: column; align-items: center; justify-content: flex-start; gap: 8px; text-align: center; padding: calc(7vh + env(safe-area-inset-top, 0px)) 16px 0; pointer-events: none; }
.title-screen button { pointer-events: auto; }
.logo-sub { text-shadow: 0 2px 8px rgba(0, 0, 0, .8); }
.logo { font-family: var(--font-brush); font-size: clamp(54px, 8.5vw, 120px); line-height: 1.05; letter-spacing: .06em; color: #fff;
  text-shadow: 0 0 30px rgba(255, 200, 120, .45), 0 4px 0 rgba(0, 0, 0, .5); animation: logoIn 1.4s var(--ease-out) both; }
.logo-sub { font-family: var(--font-en); font-weight: 600; letter-spacing: .5em; font-size: clamp(12px, 1.2vw, 16px); color: var(--gold-hi); animation: fadeUp 1s ease .6s both; padding-left: .5em; }
.logo-kicker { font-size: 14px; letter-spacing: .3em; color: var(--text-dim); animation: fadeUp 1s ease .3s both; }
.tap { position: absolute; left: 50%; bottom: calc(58px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); z-index: 2; font-size: 20px; font-weight: 700; letter-spacing: .3em; padding: 14px 44px 14px calc(44px + .3em); border-radius: 12px; cursor: pointer;
  background: linear-gradient(180deg, #e4c06a, #b98b2c); color: #1d1406; border: 1px solid #f3dc9a; box-shadow: 0 0 0 4px rgba(14, 18, 38, .6), 0 10px 30px rgba(0, 0, 0, .5), 0 0 40px rgba(255, 200, 100, .35);
  animation: tapIn 1s ease 1.4s both, glow 2.4s ease-in-out 2.4s infinite; }
@keyframes tapIn { from { opacity: 0; transform: translateX(-50%) translateY(14px); } to { opacity: 1; transform: translateX(-50%); } }
@keyframes glow { 50% { box-shadow: 0 0 0 4px rgba(14, 18, 38, .6), 0 10px 30px rgba(0, 0, 0, .5), 0 0 60px rgba(255, 210, 120, .7); } }
.notice { position: absolute; bottom: 0; left: 0; right: 0; text-align: center; font-size: 11.5px; color: rgba(244, 239, 228, .75); padding: 28px 16px max(12px, env(safe-area-inset-bottom, 0px)); z-index: 16; line-height: 1.6; background: linear-gradient(to top, rgba(5, 7, 18, .9), transparent); }
@keyframes logoIn { from { opacity: 0; letter-spacing: .4em; filter: blur(8px); } to { opacity: 1; letter-spacing: .06em; filter: none; } }
@keyframes fadeUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes blink { 50% { opacity: .35; } }
.btn { border-radius: 10px; padding: 10px 22px; cursor: pointer; font-weight: 700; letter-spacing: .06em; }
.btn.gold { background: linear-gradient(180deg, #e4c06a, #b98b2c); color: #1d1406; border: 1px solid #f3dc9a; }
.btn.ghost { background: var(--panel); border: 1px solid var(--panel-line); }
.btn:disabled { opacity: .5; cursor: default; }

/* ---------- effects ---------- */
.fx { position: absolute; inset: 0; pointer-events: none; z-index: 40; overflow: hidden; }
.burst { position: absolute; left: 50%; top: 42%; transform: translate(-50%, -50%); font-family: var(--font-brush); font-size: clamp(64px, 9vw, 130px); color: #fff; white-space: nowrap;
  text-shadow: 0 0 24px var(--glow, rgba(255, 200, 80, .9)), 0 4px 0 rgba(0, 0, 0, .45); animation: burst 1.1s var(--ease-out) forwards; }
.burst.ng { --glow: rgba(120, 160, 255, .8); font-size: clamp(44px, 6vw, 84px); }
@keyframes burst { 0% { opacity: 0; transform: translate(-50%, -50%) scale(1.8) rotate(-6deg); } 18% { opacity: 1; transform: translate(-50%, -50%) scale(1) rotate(-6deg); } 75% { opacity: 1; } 100% { opacity: 0; transform: translate(-50%, -60%) scale(1.04) rotate(-6deg); } }
.spark { position: absolute; width: 8px; height: 8px; border-radius: 50%; background: var(--sc, #ffd36b); box-shadow: 0 0 10px var(--sc, #ffd36b); animation: sparkFly .9s var(--ease-out) forwards; }
@keyframes sparkFly { from { transform: translate(0, 0) scale(1); opacity: 1; } to { transform: translate(var(--tx), var(--ty)) scale(.2); opacity: 0; } }
.flash { position: absolute; inset: 0; background: var(--fc, rgba(255, 240, 200, .35)); animation: flash .5s ease forwards; }
@keyframes flash { to { opacity: 0; } }
#stage.quake { animation: quake .4s ease; }
@keyframes quake { 25% { transform: translate(-6px, 2px); } 50% { transform: translate(5px, -2px); } 75% { transform: translate(-3px, 1px); } }

/* hanko stamp + score (result) */
.result-card { gap: 16px; align-items: center; text-align: center; }
.score { font-family: var(--font-en); font-weight: 700; font-size: clamp(60px, 6vw, 88px); line-height: 1; color: var(--paper-ink); font-variant-numeric: tabular-nums; }
.score small { font-size: .3em; color: var(--paper-dim); font-weight: 600; }
.hanko { width: 128px; height: 128px; border: 5px solid var(--vermilion); border-radius: 14px; color: var(--vermilion); font-family: var(--font-brush); font-size: 34px; line-height: 1.1; display: grid; place-items: center; text-align: center;
  transform: rotate(-12deg); opacity: 0; animation: stamp .45s var(--ease-out) forwards; animation-delay: var(--d, .6s); background: rgba(200, 56, 44, .05); box-shadow: inset 0 0 0 3px rgba(200, 56, 44, .2); }
.hanko.part { border-color: #a87a1f; color: #a87a1f; }
@keyframes stamp { 0% { opacity: 0; transform: rotate(-12deg) scale(2.4); } 60% { opacity: 1; transform: rotate(-12deg) scale(.92); } 100% { opacity: 1; transform: rotate(-12deg) scale(1); } }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; width: 100%; }
.stat { border-radius: 10px; background: rgba(120, 90, 50, .08); padding: 10px 6px; }
.stat b { display: block; font-family: var(--font-en); font-size: 24px; color: var(--paper-ink); line-height: 1.2; }
.stat span { font-size: 12px; color: var(--paper-dim); }
.wrong-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; width: 100%; text-align: left; }
.wrong-list li { font-size: 14px; background: rgba(120, 90, 50, .08); border-radius: 8px; padding: 6px 12px; }

/* practice end (演習場の締め): sumi band with the brushed 「演習終了」, then the record board */
.endban { position: absolute; left: 0; right: 0; top: 40%; transform: translateY(-50%); display: grid; justify-items: center; gap: 8px; padding: 28px 0 24px; }
.endban.out { animation: endOut .5s ease forwards; }
.endban .band { position: absolute; inset: 0; background: linear-gradient(90deg, transparent, rgba(10, 8, 18, .88) 14%, rgba(10, 8, 18, .9) 86%, transparent);
  border-block: 1px solid rgba(216, 178, 90, .55); clip-path: inset(0 100% 0 0); animation: inkWipe .55s var(--ease-out) forwards; }
.endban b { position: relative; font-family: var(--font-brush); font-weight: 400; font-size: clamp(56px, 8vw, 112px); line-height: 1; letter-spacing: .14em; color: #fff;
  text-shadow: 0 0 22px rgba(255, 200, 80, .75), 0 4px 0 rgba(0, 0, 0, .5); clip-path: inset(0 100% 0 0); animation: inkWipe .75s .25s var(--ease-out) forwards; }
.endban span { position: relative; font-size: clamp(13px, 1.3vw, 16px); letter-spacing: .24em; color: var(--gold-hi); opacity: 0; animation: endSub .4s .85s ease forwards; }
.endban .seal { position: absolute; left: calc(50% + clamp(150px, 21vw, 290px)); top: 18px; width: 58px; height: 58px; border: 3px solid var(--vermilion); border-radius: 10px;
  background: rgba(255, 245, 230, .94); color: var(--vermilion); font-family: var(--font-brush); font-style: normal; font-size: 30px; display: grid; place-items: center;
  transform: rotate(-12deg); opacity: 0; animation: stamp .4s 1s var(--ease-out) forwards; }
@keyframes inkWipe { to { clip-path: inset(0 0 0 0); } }
@keyframes endSub { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes endOut { to { opacity: 0; transform: translateY(-58%); } }
.tally { display: flex; flex-wrap: wrap; gap: 6px; }
.tally .tl { position: relative; width: 40px; height: 46px; border-radius: 6px; display: grid; place-items: center; font-family: var(--font-brush); font-size: 24px; line-height: 1;
  background: rgba(120, 90, 50, .08); color: #55627e; opacity: 0; animation: tileIn .35s var(--ease-out) forwards; animation-delay: calc(.2s + var(--i) * .07s); }
.tally .tl small { position: absolute; top: 3px; left: 5px; font-family: var(--font-en); font-size: 10px; color: var(--paper-dim); }
.tally .tl.ok { color: var(--vermilion); background: rgba(216, 178, 90, .24); box-shadow: inset 0 0 0 1px rgba(216, 178, 90, .65); }
@keyframes tileIn { from { opacity: 0; transform: translateY(8px) rotateX(70deg); } to { opacity: 1; transform: none; } }
.meter { position: relative; height: 12px; margin: 22px 0 4px; border-radius: 6px; background: rgba(120, 90, 50, .15); }
.meter i { position: absolute; inset: 0 auto 0 0; width: 0; border-radius: 6px; background: linear-gradient(90deg, var(--gold), var(--vermilion)); animation: meterFill .9s .7s var(--ease-out) forwards; }
.meter em { position: absolute; left: var(--p); top: -19px; transform: translateX(-50%); font-style: normal; font-size: 11px; color: var(--paper-dim); white-space: nowrap; }
.meter em::after { content: ""; position: absolute; left: 50%; top: 15px; width: 2px; height: 20px; margin-left: -1px; background: var(--paper-ink); opacity: .45; }
@keyframes meterFill { to { width: var(--p); } }
.stat b small { font-size: .55em; color: var(--paper-dim); font-weight: 600; }
@media (min-aspect-ratio: 1/1) and (max-height: 540px) {
  .tally .tl { width: 30px; height: 34px; font-size: 18px; }
  .meter { margin-top: 18px; }
  .endban { padding: 16px 0 14px; }
  .endban .seal { width: 44px; height: 44px; font-size: 22px; top: 10px; }
}
@media (prefers-reduced-motion: reduce) {
  .endban .band, .endban b { clip-path: none; animation: none; }
  .endban span, .endban .seal, .tally .tl { opacity: 1; animation: none; }
  .meter i { width: var(--p); animation: none; }
}
.wrong-list b { font-family: var(--font-en); }

/* ---------- shoji transition ---------- */
.shoji { position: absolute; inset: 0; z-index: 60; pointer-events: none; display: flex; }
.shoji i { flex: 1; transform: translateX(-102%);
  background:
    linear-gradient(90deg, #3a2414 0 6px, transparent 6px calc(100% - 6px), #3a2414 calc(100% - 6px)),
    repeating-linear-gradient(90deg, transparent 0 calc(25% - 3px), #5a3a22 calc(25% - 3px) 25%),
    repeating-linear-gradient(180deg, transparent 0 calc(12.5vh - 3px), #5a3a22 calc(12.5vh - 3px) 12.5vh),
    linear-gradient(180deg, #f3ead6, #e6d9bb); box-shadow: 0 0 30px rgba(0, 0, 0, .5); transition: transform .45s cubic-bezier(.7, 0, .3, 1); }
.shoji i + i { transform: translateX(102%); }
.shoji.close i { transform: none; }
.shoji .crest { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%) scale(.6); width: 90px; height: 90px; border-radius: 50%; border: 4px solid var(--vermilion); color: var(--vermilion);
  font-family: var(--font-brush); font-size: 44px; display: grid; place-items: center; background: #f3ead6; opacity: 0; transition: opacity .2s ease .25s, transform .3s var(--ease-spring) .25s; }
.shoji.close .crest { opacity: 1; transform: translate(-50%, -50%) scale(1); }

/* ---------- overlay panels (巻物 / 図鑑 / 設定 / ログ) ---------- */
.overlay { position: absolute; inset: 0; z-index: 50; background: rgba(5, 7, 18, .6); backdrop-filter: blur(3px); display: flex; align-items: center; justify-content: center; padding: 70px 16px 16px; animation: fadeIn .25s ease; }
.overlay.right { justify-content: flex-end; padding-right: max(4vw, 16px); }
@keyframes fadeIn { from { opacity: 0; } }
.sheet { position: relative; width: min(860px, 100%); max-height: calc(100vh - 100px); display: flex; flex-direction: column; animation: sheetIn .4s var(--ease-out); }
.overlay.right .sheet { width: min(560px, 100%); }
@keyframes sheetIn { from { opacity: 0; transform: translateY(24px) scale(.98); } }
.sheet .paper { max-height: none; overflow: auto; flex: 1; min-height: 0; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.sheet-head h2 { font-size: 30px; }
.x { width: 40px; height: 40px; border-radius: 50%; border: 0; background: var(--paper-ink); color: var(--paper); cursor: pointer; font-size: 20px; line-height: 1; flex: none; }
.tabs { display: flex; gap: 4px; border-bottom: 2px solid rgba(120, 90, 50, .2); }
.tab { flex: 1; background: none; border: 0; border-bottom: 3px solid transparent; margin-bottom: -2px; padding: 8px 4px; font-size: 15px; color: var(--paper-dim); cursor: pointer; font-weight: 700; }
.tab[aria-selected="true"] { color: var(--paper-ink); border-color: var(--vermilion); }
.rows { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.rows li { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 12px; align-items: center; background: rgba(255, 255, 255, .55); border: 1px solid rgba(120, 90, 50, .18); border-radius: 10px; padding: 10px 14px; animation: fadeUp .3s ease both; animation-delay: calc(var(--i, 0) * .03s); }
.rows .ja-s { font-size: 13px; color: var(--paper-dim); }
.rows .en-s { font-family: var(--font-en); font-weight: 600; font-size: 18px; overflow-wrap: anywhere; }
.rows .meta { font-size: 12px; color: var(--paper-dim); }
.rows .side { grid-row: 1 / span 3; grid-column: 2; display: flex; gap: 6px; }
.mini { border: 1.5px solid var(--paper-ink); background: none; color: var(--paper-ink); border-radius: 999px; padding: 4px 14px; font-size: 13px; font-weight: 700; cursor: pointer; white-space: nowrap; }
.mini:hover { background: var(--paper-ink); color: var(--paper); }
.empty { border: 2px dashed rgba(120, 90, 50, .3); border-radius: 12px; padding: 26px; text-align: center; color: var(--paper-dim); font-size: 14px; }
/* 検証ログ (devbar): one row per lecture, scrolls sideways inside the sheet on narrow screens */
.stage-dots { font-family: var(--font-en); letter-spacing: 2px; color: var(--vermilion); }

/* character book */
.book { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.card-c { position: relative; border: 0; border-radius: 12px; padding: 0; cursor: pointer; overflow: hidden; isolation: isolate; -webkit-mask-image: -webkit-radial-gradient(white, black); box-shadow: 0 0 0 1px rgba(216, 178, 90, .35), 0 6px 16px rgba(0, 0, 0, .3); aspect-ratio: 3 / 4.2; background: linear-gradient(180deg, #2a3366, #121630); color: #fff; text-align: left; animation: fadeUp .4s ease both; animation-delay: calc(var(--i) * .07s); transition: transform .2s var(--ease-out); }
.card-c:hover { transform: translateY(-4px); }
.card-c img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; object-position: center 8%; border-radius: inherit; }
.card-c::after { content: ""; position: absolute; inset: 0; background: linear-gradient(to top, rgba(0, 0, 0, .8), transparent 50%); }
.card-c b, .card-c span { position: absolute; left: 12px; z-index: 1; }
.card-c b { bottom: 26px; font-size: 20px; letter-spacing: .1em; }
.card-c span { bottom: 8px; font-size: 12px; color: #e8dcc4; }
.card-c .band { position: absolute; top: 0; left: 0; right: 0; height: 5px; background: var(--cc); z-index: 1; }
.profile { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.profile li { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 0 12px; align-items: center; border-bottom: 1px dashed rgba(120, 90, 50, .3); padding-bottom: 8px; }
.profile .en-s { font-family: var(--font-en); font-weight: 600; font-size: 19px; }
.profile .ja-s { font-size: 13px; color: var(--paper-dim); }
.profile .mini { grid-row: 1 / span 2; grid-column: 2; }
.seg { display: inline-flex; border: 1.5px solid rgba(120, 90, 50, .4); border-radius: 10px; overflow: hidden; flex-wrap: wrap; }
.seg button { border: 0; background: transparent; color: var(--paper-ink); font-size: 14px; padding: 6px 14px; cursor: pointer; }
.seg button + button { border-left: 1.5px solid rgba(120, 90, 50, .25); }
.seg button[aria-pressed="true"] { background: var(--paper-ink); color: var(--paper); font-weight: 700; }
.seg button:disabled { color: var(--paper-dim); cursor: default; }
.set { display: flex; flex-direction: column; gap: 14px; }
.set .row { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.set .row > span { font-weight: 700; }
.set .row small { display: block; font-weight: 400; font-size: 12.5px; color: var(--paper-dim); }
.set h3 { margin: 6px 0 0; font-size: 13px; letter-spacing: .14em; color: var(--vermilion); }
input[type=range] { accent-color: var(--paper-ink); width: 180px; }
.log { display: flex; flex-direction: column; gap: 12px; }
.log li { list-style: none; display: grid; grid-template-columns: 80px minmax(0, 1fr) auto; gap: 10px; align-items: start; border-bottom: 1px dashed rgba(120, 90, 50, .25); padding-bottom: 10px; }
.log .who { font-weight: 700; color: var(--lc, var(--paper-ink)); }
.log ul { margin: 0; padding: 0; }
.lv { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; width: 100%; }
.lv div { border: 2px solid rgba(120, 90, 50, .2); border-radius: 12px; padding: 10px; text-align: center; }
.lv div.on { border-color: var(--vermilion); background: rgba(200, 56, 44, .06); }
.lv b { display: block; font-family: var(--font-en); font-size: 22px; }
.lv span { display: block; font-size: 12px; color: var(--paper-dim); line-height: 1.5; }
.toast { position: absolute; z-index: 70; left: 50%; top: calc(70px + env(safe-area-inset-top, 0px)); transform: translateX(-50%); padding: 8px 18px; font-size: 14px; animation: fadeUp .3s ease; }
.devbar { position: absolute; z-index: 35; left: max(16px, env(safe-area-inset-left, 0px)); bottom: 2px; display: flex; gap: 12px; font-size: 11px; color: rgba(244, 239, 228, .45); }
.guide-btn { position: absolute; top: calc(16px + env(safe-area-inset-top, 0px)); right: max(16px, env(safe-area-inset-right, 0px)); z-index: 3; display: flex; align-items: center; gap: 10px; padding: 10px 16px 10px 12px; border-radius: 12px; cursor: pointer; text-align: left; color: #f4efe4; background: rgba(12, 14, 30, .78); border: 1.5px solid rgba(232, 196, 120, .85); box-shadow: 0 6px 18px rgba(0, 0, 0, .35); }
.guide-btn:hover { background: rgba(28, 26, 48, .92); border-color: #f2d08a; }
.guide-btn .g-mark { flex: none; width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-weight: 800; font-size: 15px; color: #1a1408; background: #e8c478; }
.guide-btn .g-txt { display: flex; flex-direction: column; gap: 2px; line-height: 1.3; }
.guide-btn b { font-size: 15px; letter-spacing: .04em; }
.guide-btn small { font-size: 12px; color: rgba(244, 239, 228, .8); }
.credits h3 { margin-top: 14px; }
.credits p { margin: 4px 0 0; line-height: 1.7; }
.guide-links { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 8px; }
.guide-link { flex: 1 1 220px; display: flex; flex-direction: column; gap: 2px; padding: 12px 14px; border-radius: 10px; border: 1.5px solid var(--vermilion); text-decoration: none !important; }
.guide-link:hover { background: rgba(190, 60, 40, .08); }
.guide-link small { font-size: 12px; opacity: .75; }
.guide-keep { margin: 10px 0 0; padding-left: 1.2em; line-height: 1.8; }
@media (max-height: 540px) { .guide-btn { top: calc(8px + env(safe-area-inset-top, 0px)); padding: 6px 12px 6px 8px; gap: 8px; } .guide-btn .g-mark { width: 20px; height: 20px; font-size: 12px; } .guide-btn b { font-size: 12.5px; } .guide-btn small { font-size: 10.5px; } }
.credit-tag { position: absolute; z-index: 35; right: max(16px, env(safe-area-inset-right, 0px)); bottom: 2px; background: none; border: 0; padding: 0; cursor: pointer; font-size: 11px; color: rgba(244, 239, 228, .6); text-decoration: underline; text-underline-offset: 2px; }
#layer:has(.title-screen) ~ .credit-tag { display: none; }   /* the title has its own guideline button */
.credit-tag:hover { color: rgba(244, 239, 228, .9); }
.credits .credit-lead { line-height: 1.8; margin: 4px 0 0; }
.credits dl { display: grid; grid-template-columns: max-content 1fr; gap: 10px 18px; margin: 6px 0 0; line-height: 1.7; }
.credits dt { font-weight: 700; color: var(--vermilion); font-size: 13px; padding-top: 2px; }
.credits dd { margin: 0; min-width: 0; }
.credits a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }
@media (max-width: 560px) { .credits dl { grid-template-columns: 1fr; gap: 2px; } .credits dd { margin-bottom: 8px; } }
/* small screens (phone held sideways, or upright): the dialog reaches the bottom corner, so the tag waits until no line is shown */
@media (max-height: 540px), (max-aspect-ratio: 1/1) { .credit-tag { font-size: 10px; } #dialog:not(.hide) ~ .credit-tag { display: none; } }
.devbar button { background: none; border: 0; color: inherit; cursor: pointer; text-decoration: underline; text-underline-offset: 2px; padding: 0; font-size: 11px; }

.paper.swap > * { animation: fadeUp .4s ease both; }
.paper.swap > *:nth-child(2) { animation-delay: .05s; } .paper.swap > *:nth-child(3) { animation-delay: .1s; } .paper.swap > *:nth-child(n+4) { animation-delay: .15s; }
.char.cast { height: min(56vh, 600px); }
.overlay.clear { background: none; backdrop-filter: none; pointer-events: none; padding-bottom: calc(var(--dialog-h) + 36px); }
.overlay.clear .sheet { pointer-events: auto; max-height: calc(100vh - var(--dialog-h) - 120px); }
.progress { display: flex; gap: 5px; flex-wrap: wrap; }
.progress i { width: 10px; height: 10px; border-radius: 50%; background: rgba(120, 90, 50, .2); }
.progress i.ok { background: var(--gold); box-shadow: 0 0 0 2px rgba(216, 178, 90, .35); }
.progress i.ng { background: var(--bad); }
.progress i.now { background: var(--paper-ink); transform: scale(1.25); }
.fb { border-radius: 12px; padding: 12px 16px; display: flex; flex-direction: column; gap: 2px; animation: fadeUp .35s ease both; }
.fb.ok { background: #e2f4e8; } .fb.ng { background: #fbe4df; }
.fb b { font-size: 16px; } .fb.ok b { color: #23764a; } .fb.ng b { color: #ad3434; }
.fb span { font-size: 14px; color: var(--paper-ink); }
.fb .ans { font-family: var(--font-en); font-weight: 600; font-size: 17px; }
.inline-btns { display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; }

/* bigger text setting */
body.big .say { font-size: clamp(20px, 1.9vw, 25px); }
body.big .paper { font-size: 18px; }
body.big .chunk .w { font-size: clamp(30px, 3.2vw, 46px); }

/* landscape: choices float in front of the character, leaving the board on the right uncovered */
@media (min-aspect-ratio: 1/1) {
  .choices.side { left: 27%; width: min(520px, 44vw); }
}

/* ---------- phones held sideways (short landscape screens, e.g. 844×390) ---------- */
@media (min-aspect-ratio: 1/1) and (max-height: 540px) {
  :root { --dialog-h: 92px; }
  .char { height: 100vh; height: 100dvh; }
  .char.cast { height: 54vh; height: 54dvh; }
  .hud { padding-top: max(8px, env(safe-area-inset-top, 0px)); padding-left: max(12px, env(safe-area-inset-left, 0px)); padding-right: max(12px, env(safe-area-inset-right, 0px)); }
  .tool { height: 32px; min-width: 36px; padding: 0 9px; border-radius: 8px; }
  .tool .lbl { display: none; }
  .tool svg { width: 16px; height: 16px; }
  .scene-tag { padding: 3px 10px 3px 6px; font-size: 12.5px; gap: 7px; }
  .scene-tag .seal { width: 22px; height: 22px; font-size: 12px; }
  .scene-tag span { display: none; }
  .status { padding: 4px 12px; gap: 10px; }
  .status .rank { font-size: 17px; }
  .status .xpbar { width: 70px; }
  .status small { display: none; }
  .status .fire { font-size: 15px; }
  .dialog { bottom: max(6px, env(safe-area-inset-bottom, 0px)); padding: 14px 20px 8px; width: min(1120px, calc(100% - 24px)); }
  .dialog::before { inset: 4px; }
  .nameplate { top: -13px; left: 18px; font-size: 13px; padding: 1px 14px 2px; }
  .say { font-size: 14.5px; line-height: 1.6; min-height: 3.2em; letter-spacing: .02em; }
  .next-mark { right: 16px; bottom: 8px; width: 11px; height: 11px; }
  .dialog .hint { display: none; }
  .board-wrap { top: calc(44px + env(safe-area-inset-top, 0px)); bottom: calc(var(--dialog-h) + 12px); right: max(12px, env(safe-area-inset-right, 0px)); width: min(54vw, 560px); }
  .rod { height: 9px; margin: 0 -8px; }
  .rod::before, .rod::after { top: 1px; width: 12px; height: 7px; }
  .paper { padding: 8px 16px; gap: 5px; max-height: calc(100vh - var(--dialog-h) - 74px); max-height: calc(100dvh - var(--dialog-h) - 74px); }
  .inline-btns { gap: 6px; }
  .paper .kicker { font-size: 11.5px; }
  .paper h2 { font-size: 19px; }
  .paper .big-ja { font-size: 19px; line-height: 1.4; }
  .paper .note, .paper .ja { font-size: 12.5px; }
  .paper p { margin: 0; font-size: 13.5px; line-height: 1.6; }
  .chunks { gap: 8px 6px; }
  .chunk .w { font-size: 21px; padding: 2px 9px 3px; border-radius: 8px; box-shadow: 0 2px 0 var(--c); }
  .chunk .t { font-size: 10.5px; padding: 0 6px; }
  .order-ja { font-size: 12.5px; gap: 5px; }
  .order-arrow { font-size: 11.5px; margin: -3px 0; }
  .listen, .mini { padding: 3px 12px; font-size: 12px; }
  .opts { gap: 6px; grid-template-columns: 1fr 1fr; }
  .opt { padding: 6px 10px; font-size: 14px; gap: 8px; border-radius: 9px; }
  .opt .k { width: 20px; height: 20px; font-size: 11px; }
  .tile { font-size: 16px; padding: 5px 12px 7px; }
  .slots { min-height: 44px; padding: 6px; }
  .field { padding: 6px 10px; font-size: 15px; }
  .btn { padding: 6px 16px; font-size: 14px; }
  .fb { padding: 7px 12px; } .fb b { font-size: 14px; } .fb span { font-size: 12.5px; }
  .progress i { width: 8px; height: 8px; }
  .choices { bottom: calc(var(--dialog-h) + 12px); gap: 8px; }
  .choices.side { left: 25%; width: min(400px, 44vw); }
  .choice { min-width: 0; padding: 8px 12px; font-size: 14.5px; border-radius: 9px; }
  .choice kbd { display: none; }
  .menu { top: calc(46px + env(safe-area-inset-top, 0px)); bottom: calc(var(--dialog-h) + 16px); right: max(12px, env(safe-area-inset-right, 0px)); width: min(44vw, 360px); gap: 6px; }
  .fuda { padding: 6px 14px 6px 48px; border-radius: 8px; box-shadow: 0 4px 0 #2a190d, 0 6px 14px rgba(0, 0, 0, .4); }
  .fuda .ic { left: 10px; width: 28px; height: 28px; margin-top: -14px; font-size: 16px; }
  .fuda b { font-size: 15px; }
  .fuda small { display: none; }
  .fuda.main { padding-block: 8px; }
  .fuda.main small { display: block; font-size: 11.5px; line-height: 1.45; }
  .fuda .badge { min-width: 22px; height: 22px; font-size: 12px; }
  .logo { font-size: clamp(40px, 10vh + 2vw, 76px); }
  .logo-kicker { font-size: 11.5px; }
  .logo-sub { font-size: 11px; }
  .title-screen { padding-top: calc(4vh + env(safe-area-inset-top, 0px)); gap: 4px; }
  .tap { bottom: calc(40px + env(safe-area-inset-bottom, 0px)); font-size: 16px; padding: 9px 32px 9px calc(32px + .3em); }
  .notice { font-size: 10px; padding: 16px 12px max(6px, env(safe-area-inset-bottom, 0px)); }
  .overlay { padding: 46px 12px 8px; }
  .sheet { max-height: calc(100vh - 54px); max-height: calc(100dvh - 54px); }
  .overlay.clear { padding-bottom: calc(var(--dialog-h) + 14px); }
  .overlay.clear .sheet { max-height: calc(100dvh - var(--dialog-h) - 64px); }
  .sheet-head h2 { font-size: 22px; }
  .x { width: 32px; height: 32px; font-size: 16px; }
  .book { gap: 8px; }
  .card-c b { font-size: 15px; bottom: 22px; } .card-c span { font-size: 10.5px; }
  .rows li { padding: 6px 10px; } .rows .en-s { font-size: 15px; }
  .profile .en-s { font-size: 15px; } .profile li { padding-bottom: 5px; }
  .set { gap: 9px; } .seg button { padding: 4px 10px; font-size: 13px; }
  .score { font-size: 44px; }
  .hanko { width: 84px; height: 84px; font-size: 22px; border-width: 4px; }
  .stats { gap: 6px; } .stat { padding: 5px 4px; } .stat b { font-size: 17px; } .stat span { font-size: 10.5px; }
  .wrong-list li { font-size: 12px; padding: 3px 10px; }
  .burst { font-size: clamp(48px, 16vh, 90px); }
  .devbar { display: none; }
  body.big .say { font-size: 17px; }
  body.big .chunk .w { font-size: 25px; }
}

/* phones held upright: ask to turn sideways (the layout below still works if they keep it upright) */
.rotate { display: none; }
@media (max-aspect-ratio: 1/1) and (max-width: 900px) {
  body:not(.portrait-ok) .rotate { display: flex; position: fixed; inset: 0; z-index: 100; flex-direction: column; align-items: center; justify-content: center; gap: 18px; padding: 24px; text-align: center;
    background: radial-gradient(ellipse at 50% 40%, #1d2550, #070912); color: var(--text); }
  .rotate .phone { width: 64px; height: 104px; border: 4px solid var(--gold-hi); border-radius: 12px; animation: turn 2.4s ease-in-out infinite; position: relative; }
  .rotate .phone::after { content: ""; position: absolute; bottom: 6px; left: 50%; width: 14px; height: 4px; margin-left: -7px; border-radius: 2px; background: var(--gold-hi); }
  .rotate b { font-family: var(--font-brush); font-size: 26px; font-weight: 400; color: #fff; }
  .rotate p { margin: 0; color: var(--text-dim); font-size: 14px; }
  @keyframes turn { 0%, 25% { transform: rotate(0); } 55%, 85% { transform: rotate(-90deg); } 100% { transform: rotate(0); } }
}

/* ---------- portrait (fallback when kept upright) ---------- */
@media (max-aspect-ratio: 1/1) {
  :root { --dialog-h: clamp(140px, 24vh, 190px); }
  .char { height: min(70vh, 720px); }
  .board-wrap, .menu { left: 16px; right: 16px; width: auto; top: calc(64px + env(safe-area-inset-top, 0px)); bottom: auto; max-height: calc(100vh - var(--dialog-h) - 220px); align-items: flex-start; }
  .menu { bottom: calc(var(--dialog-h) + 30px); top: auto; max-height: none; gap: 8px; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); align-items: stretch; }
  .menu .fuda { padding: 34px 6px 8px; text-align: center; }
  .menu .fuda .ic { left: 50%; top: 8px; margin: 0 0 0 -13px; width: 26px; height: 26px; font-size: 15px; }
  .menu .fuda b { font-size: 14px; letter-spacing: .02em; }
  .menu .fuda small { display: none; }
  .menu .fuda .badge { top: 6px; right: 6px; transform: none; min-width: 22px; height: 22px; font-size: 12px; }
  .menu .fuda.main { grid-column: 1 / -1; padding: 12px 16px 12px 58px; text-align: left; }
  .menu .fuda.main .ic { left: 14px; top: 50%; margin: -15px 0 0; width: 30px; height: 30px; }
  .menu .fuda.main small { display: block; }
  .paper { padding: 18px 18px 16px; max-height: calc(100vh - var(--dialog-h) - 240px); }
  .dialog { padding: 26px 20px 18px; }
  .say { font-size: 16px; }
  .choices { bottom: calc(var(--dialog-h) + 22px); }
  .choice { min-width: 0; font-size: 16px; padding: 12px 14px; }
  .status .xpbar { width: 70px; }
  .tool .lbl { display: none; }
  .book { grid-template-columns: repeat(2, 1fr); }
  .char.cast { height: min(38vh, 360px); }
  /* a board fills the top: the speaking character peeks in from the lower right, face between board and dialog */
  #stage.has-board .char:not(.cast) { height: min(54vh, 480px); left: 76% !important; }
  .overlay.clear { padding-top: 64px; align-items: flex-start; }
  .overlay.clear .sheet { max-height: calc(100vh - var(--dialog-h) - 110px); }
  .scene-tag span { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
