/* 最強しりとりAI ── クイズ番組のスタジオ */
:root {
  --navy: #081437;
  --navy-light: #1a3469;
  --ink: #0c193b;
  --ink-muted: #495675;
  --cream: #fff6da;
  --paper: linear-gradient(160deg, #fffefa, var(--cream));
  --yellow: #ffdc26;
  --yellow-ink: #171936;
  --pink: #cf0052;
  --pink-light: #ff3888;
  --pink-shadow: #830638;
  --signal: #ff9cba;
  --good: #95f1c8;
  --gold: #ffbd13;
  --gold-light: #fff49a;
  --gold-dark: #a45a06;
  --lamp: #ffffed;
  --glow: #ffec74;
  --sky: #12bfeb;
  --sky-middle: #008fce;
  --sky-deep: #073d80;
  --dot: #b4f8ff69;
  --beam: #cefff789;
  --vvh: 100dvh;
  --vvtop: 0px;
}
html.mode-ultra {
  --navy: #16090f;
  --navy-light: #481324;
  --ink: #2a111a;
  --ink-muted: #684550;
  --cream: #ffeadf;
  --yellow: #ce1637;
  --yellow-ink: #fff;
  --pink: #b0092d;
  --pink-light: #f44451;
  --pink-shadow: #670d21;
  --signal: #ffa7a4;
  --gold: #eb3546;
  --gold-light: #ffb5a8;
  --gold-dark: #79132b;
  --lamp: #ffe0d5;
  --glow: #ff6a66;
  --sky: #a9213e;
  --sky-middle: #6b102a;
  --sky-deep: #1b0b17;
  --dot: #ffbecd48;
  --beam: #ff9c985e;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--navy); color: white; }
body {
  font-family: "Hiragino Maru Gothic ProN", "Hiragino Kaku Gothic ProN", "Yu Gothic UI", "Meiryo", system-ui, sans-serif;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}
button, input { font: inherit; color: inherit; }
button:focus-visible, input:focus-visible { outline: 3px solid #078ac5; outline-offset: 2px; }

/* 画面は決まった大きさの舞台（縦長 390×844 / 横長 1280×720）で作り、窓に合わせて丸ごと拡大・縮小する。
   どの窓の大きさでも同じ見た目（キャラの大きさも同じ割合）になる。大きさ・倍率・位置は js/stage-fit.js が決める。
   中の大きさは cqw/cqh（舞台の幅・高さ基準）で書く。vw/vh（窓基準）は使わない。 */
body {
  background:
    radial-gradient(circle, var(--dot) 1.2px, transparent 1.7px) 0 0 / 9px 9px,
    radial-gradient(ellipse at 50% 40%, var(--sky-middle), var(--sky-deep) 70%, var(--navy));
}
#app {
  position: fixed; left: 0; top: 0;
  width: var(--stage-w, 390px); height: var(--stage-h, 844px);
  transform-origin: 0 0; transform: translate(var(--stage-x, 0px), var(--stage-y, 0px)) scale(var(--stage-s, 1));
  container: app / size;
  display: flex; overflow: hidden;
  box-shadow: 0 0 0 1px #ffffff22, 0 10px 40px #0008;
}
.screen { display: none; flex: 1; min-width: 0; min-height: 0; flex-direction: column; }
.screen.active { display: flex; }

.btn, .mode-btn {
  background: linear-gradient(var(--navy-light), var(--navy));
  border: 2px solid #e6edff; color: white; border-radius: 12px;
  padding: 9px 16px; min-height: 44px; font-weight: 800; white-space: nowrap; cursor: pointer;
  box-shadow: inset 0 1px 0 #ffffff29, 0 3px 0 #020a2099;
  transition: transform .12s, box-shadow .12s;
}
.btn.primary, .mode-btn.sel {
  background: linear-gradient(var(--gold-light), var(--yellow) 65%);
  color: var(--yellow-ink); border-color: var(--gold-dark);
  box-shadow: inset 0 2px 0 #ffffff8a, 0 4px 0 var(--gold-dark);
}
.btn.warn, #btnSend {
  background: linear-gradient(165deg, var(--pink-light), var(--pink) 74%);
  color: white; border-color: var(--pink-shadow);
  box-shadow: inset 0 2px 0 #ffffff70, 0 4px 0 var(--pink-shadow);
  text-shadow: 0 1px 2px #580626;
}
@media (hover: hover) {
  .btn:enabled:hover, .mode-btn:enabled:hover, .chara-card:hover { transform: translateY(-1px); }
}
.btn:active, .mode-btn:enabled:active { transform: translateY(2px); }
.btn:disabled, .mode-btn:disabled { opacity: .6; cursor: default; }
.btn.big { font-size: 1.25rem; padding: 12px 30px; min-height: 54px; }
.btn.small { padding: 5px 12px; min-height: 36px; font-size: .9rem; border-radius: 10px; }
.btn.icon { min-width: 36px; padding: 4px; }
.btn.dev { position: fixed; bottom: 6px; left: 6px; z-index: 20; background: #444; border-style: dashed; opacity: .8; }
.btn.dev[hidden] { display: none; }
.mode-badge {
  display: inline-block; padding: .22em .75em; border-radius: 999px; vertical-align: middle;
  background: var(--yellow); color: var(--yellow-ink); font-weight: 900; font-size: .85rem;
}
.mode-badge:empty { display: none; }
html.mode-ultra .mode-badge { background: var(--yellow); color: white; }
html.mode-ultra .btn.primary { color: white; }
html.mode-ultra .btn.primary, html.mode-ultra .mode-btn.sel { background: linear-gradient(#d82c46, #af0e29); }

/* クリーム色の札と、四辺に沿って並ぶ電球。中央の紙は電球の列だけを残して覆う。 */
.aiword, .title-box, .chara-card, .result-box, .modal-card {
  --rim: 10px;
  --pitch: calc(var(--rim) * 1.9);
  --bulb: radial-gradient(circle closest-side, var(--lamp) 0 49%, var(--glow) 64%, transparent 93%);
  color: var(--ink);
  border: var(--rim) solid transparent;
  border-radius: calc(var(--rim) * 2.5);
  background:
    var(--paper) padding-box,
    var(--bulb) left top / var(--pitch) var(--rim) repeat-x border-box,
    var(--bulb) left bottom / var(--pitch) var(--rim) repeat-x border-box,
    var(--bulb) left top / var(--rim) var(--pitch) repeat-y border-box,
    var(--bulb) right top / var(--rim) var(--pitch) repeat-y border-box,
    linear-gradient(145deg, var(--gold), var(--gold-light) 19%, var(--gold) 27% 57%, var(--gold-light) 67%, var(--gold) 78%) border-box;
  box-shadow: inset 0 0 0 1.5px var(--gold-dark), 0 0 0 1px var(--gold-dark), 0 4px 0 #030a2780;
}

#scr-title, #scr-select, #scr-result, .stage {
  --studio:
    radial-gradient(circle, var(--dot) 1.2px, transparent 1.7px) 0 0 / 9px 9px,
    radial-gradient(ellipse at 50% 50%, var(--sky) 4%, var(--sky-middle) 62%, var(--sky-deep));
  background: var(--studio);
}
#scr-title, #scr-result {
  align-items: center; overflow: auto; padding: clamp(14px, 4cqw, 38px);
  padding-bottom: max(16px, env(safe-area-inset-bottom)); text-align: center;
}
#scr-title, html.mode-ultra #scr-title {
  background:
    conic-gradient(from 144deg at 0 0, transparent, var(--beam) 12deg, transparent 28deg),
    conic-gradient(from 189deg at 100% 0, transparent, var(--beam) 16deg, transparent 28deg), var(--studio);
}
.title-box {
  width: min(100%, 740px); margin: auto; padding: clamp(20px, 5cqw, 60px) clamp(12px, 4cqw, 46px);
  display: flex; flex-direction: column; align-items: center; gap: clamp(10px, 2cqh, 22px);
}
.title-sub, #aiLabel {
  background: var(--pink); color: white; border-radius: 8px 3px;
  padding: .18em .8em .24em; font-weight: 900;
}
.title-sub { margin: 0; letter-spacing: .12em; }
.title-logo {
  margin: 0; font-weight: 900; font-size: clamp(1.9rem, 6.8cqw, 4.6rem); line-height: 1.17;
  letter-spacing: -.055em; text-shadow: 0 3px 0 var(--gold);
}
html.mode-ultra .title-logo { text-shadow: 0 3px 0 var(--gold-light); }
.title-logo small { font-size: .35em; letter-spacing: 0; color: var(--ink-muted); text-shadow: none; }
.title-best, .load-status { margin: 0; color: var(--ink-muted); font-size: .88rem; font-weight: 700; }
.title-best:empty { display: none; }
.load-status.ok, .chara-note.ok { color: #006341; }
.load-status.ng { color: var(--pink); }
.mode-row, .title-row, .rec-btns, .result-btns { display: flex; justify-content: center; flex-wrap: wrap; gap: 10px; }
.mode-btn { border-radius: 999px; padding: 6px 18px; }
.mode-btn:disabled { letter-spacing: .12em; }

/* キャラクター選択 */
.bar, .hud, .select-foot { background: linear-gradient(110deg, var(--navy), var(--navy-light)); }
.bar { display: flex; align-items: center; gap: 12px; padding: 9px 14px; border-bottom: 2px solid white; }
.bar h2 { margin: 0; font-size: 1.15rem; font-weight: 900; }
.bar-note { margin-left: auto; font-size: .85rem; }
.select-list {
  flex: 1; min-height: 0; display: grid; align-items: center; gap: clamp(12px, 2cqw, 32px);
  grid-template-columns: repeat(3, minmax(0, 1fr)); padding: 16px max(16px, 4cqw); overflow: auto;
}
.chara-card {
  --rim: 6px;
  height: min(100%, 460px); min-width: 0; min-height: 0; padding: 14px; text-align: center; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  transition: transform .12s;
}
.chara-card.sel { outline: 4px solid var(--pink); box-shadow: 0 0 0 7px white, inset 0 0 0 2px var(--gold); }
.chara-face {
  display: grid; place-items: center; flex: none; width: min(65%, 168px); aspect-ratio: 1;
  border: 3px solid white; border-radius: 50%; box-shadow: 0 0 0 2px var(--gold-dark);
  font-size: 2rem; font-weight: 900; color: var(--ink);
}
.chara-face.img { overflow: hidden; }
.chara-face.img img { width: 100%; height: 100%; object-fit: cover; object-position: center; }
.chara-name { font-weight: 900; font-size: 1.18rem; }
.chara-type, .chara-note { color: var(--ink-muted); font-size: .88rem; }
.chara-note { display: inline-block; font-size: .78rem; font-weight: 700; }
.chara-note.loading { color: #884604; }
.chara-note.ng, .chara-note.wip { color: var(--pink); }
.select-foot { display: flex; align-items: center; gap: 12px; padding: 12px 16px calc(14px + env(safe-area-inset-bottom)); }
.select-intro { flex: 1; margin: 0; padding: 10px 14px; border-radius: 12px; background: var(--paper); color: var(--ink); font-weight: 700; }

/* 得点、舞台、操作卓 */
#scr-battle { background: var(--navy); container: arena / size; }
.hud {
  display: flex; align-items: center; justify-content: space-between; gap: clamp(10px, 1.6cqw, 28px);
  padding: clamp(5px, .8cqh, 12px) clamp(12px, 2cqw, 32px); border-bottom: 2px solid #e4ecff;
}
.hud-mode { white-space: nowrap; font-size: clamp(.95rem, 2.1cqw, 1.9rem); }
.hud-item { display: flex; align-items: baseline; gap: .4em; line-height: 1.1; white-space: nowrap; }
.hud-item + .hud-item { border-left: 1px solid #c3d4f5a8; padding-left: clamp(10px, 2cqw, 32px); }
.hud-item span { font-size: clamp(.8rem, 1.6cqw, 1.5rem); font-weight: 800; }
.hud-item b { font-size: clamp(1.3rem, 3.15cqw, 3rem); font-weight: 900; font-variant-numeric: tabular-nums; }
.hud-btns { display: flex; gap: clamp(6px, 1cqw, 16px); }
.hud-btns .btn.small { min-height: clamp(36px, 3.6cqw, 54px); min-width: clamp(36px, 4.5cqw, 68px); padding: .12em .65em; font-size: clamp(.88rem, 1.8cqw, 1.7rem); }
.battle { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, .96fr) minmax(380px, 1.04fr); }
.stage {
  position: relative; isolation: isolate; min-width: 0; min-height: 0; overflow: hidden;
  display: grid; grid-template-rows: max-content max-content 1fr; justify-items: center;
  --lens: clamp(7px, 1.25cqw, 19px);
  --fixture: #ffffe5 0 58%, var(--glow) 62%, var(--gold-dark) 71%, #35425a 74% 89%, #16243b 95%, transparent;
  --housing: #405673 0 61%, #21344d 64% 86%, transparent 91%;
  --bracket: transparent 35%, #16263b 37% 52%, #475b72 53% 60%, #23344d 61% 70%, transparent 72%;
  --dot-pitch: clamp(7px, .7cqw, 11px);
  --studio:
    radial-gradient(circle closest-side, var(--dot) 0 29%, transparent 43%) 0 0 / var(--dot-pitch) var(--dot-pitch),
    linear-gradient(160deg, var(--sky-deep), var(--sky-middle) 22%, var(--sky) 60%, var(--sky-middle));
  --confetti: linear-gradient(124deg, transparent 24%, var(--pink-light) 26% 73%, transparent 75%);
  --foil: linear-gradient(126deg, transparent 24%, var(--gold-light) 26% 73%, transparent 75%);
  --scenery:
    radial-gradient(circle var(--lens) at 3% 6%, var(--fixture)),
    radial-gradient(circle var(--lens) at 97% 6%, var(--fixture)),
    radial-gradient(ellipse var(--lens) calc(var(--lens) * 1.4) at 3.3% 4.5%, var(--housing)),
    radial-gradient(ellipse var(--lens) calc(var(--lens) * 1.4) at 96.7% 4.5%, var(--housing)),
    linear-gradient(110deg, var(--bracket)) 3% 0 / 4% 5% no-repeat,
    linear-gradient(250deg, var(--bracket)) 97% 0 / 4% 5% no-repeat,
    var(--confetti) 5% 30% / 3.4% 1.8% no-repeat, var(--foil) 8% 35% / 2.8% 1.4% no-repeat,
    var(--foil) 94% 26% / 3% 1.7% no-repeat, var(--confetti) 89% 20% / 2.7% 1.5% no-repeat,
    var(--confetti) 96% 80% / 3.5% 1.6% no-repeat, var(--foil) 12% 76% / 2.8% 1.25% no-repeat,
    conic-gradient(from 140deg at 3% 6%, transparent 0deg, var(--beam) 9deg 18deg, transparent 32deg),
    conic-gradient(from 188deg at 97% 6%, transparent 0deg, var(--beam) 14deg 23deg, transparent 32deg),
    var(--studio);
  background: var(--scenery);
}
html.mode-ultra .stage { background: var(--scenery); }
/* 楕円の一部を両袖に見せ、電球は金縁の中心線に並べる。 */
.stage::before {
  content: ""; position: absolute; inset: 0; z-index: -1; pointer-events: none;
  --size: clamp(3px, .52cqw, 8px);
  --light: var(--lamp) 0 63%, var(--glow) 76%, transparent;
  --arch: var(--sky-deep) 0 60%, var(--sky) 61% 75%, var(--sky-middle) 76% 84%,
    var(--gold-dark) 85%, var(--gold-light) 87%, var(--gold) 91% 97%, var(--gold-dark) 99%, transparent;
  background:
    radial-gradient(circle var(--size) at 3.5% 45.8%, var(--light)), radial-gradient(circle var(--size) at 96.5% 45.8%, var(--light)),
    radial-gradient(circle var(--size) at 9.4% 50.3%, var(--light)), radial-gradient(circle var(--size) at 90.6% 50.3%, var(--light)),
    radial-gradient(circle var(--size) at 14.3% 58%, var(--light)), radial-gradient(circle var(--size) at 85.7% 58%, var(--light)),
    radial-gradient(circle var(--size) at 18.3% 68.5%, var(--light)), radial-gradient(circle var(--size) at 81.7% 68.5%, var(--light)),
    radial-gradient(circle var(--size) at 21% 81.2%, var(--light)), radial-gradient(circle var(--size) at 79% 81.2%, var(--light)),
    radial-gradient(circle var(--size) at 22.2% 94.3%, var(--light)), radial-gradient(circle var(--size) at 77.8% 94.3%, var(--light)),
    radial-gradient(ellipse 24% 59% at 0 100%, var(--arch)), radial-gradient(ellipse 24% 59% at 100% 100%, var(--arch));
}
#charaCanvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#charaGL { position: absolute; display: block; } /* 寸法と位置は fitCanvas が決める。 */
#charaCanvas[hidden], #charaGL[hidden] { display: none; }
.bubble {
  grid-row: 1; position: relative; z-index: 2; margin-top: 10px; max-width: min(88%, 660px);
  padding: 8px 18px; background: white; color: #101a32; border-radius: 2em;
  outline: 3px solid #101a32; font-size: clamp(1rem, 2cqw, 1.65rem); font-weight: 900;
  text-align: center; line-height: 1.35; overflow-wrap: anywhere; pointer-events: none;
  opacity: 0; transform: translateY(-3px); transition: opacity .15s, transform .15s;
}
.bubble.show { opacity: 1; transform: none; }
/* しっぽを次のグリッド行に置くと、本文の overflow と行数制限を維持できる。 */
.stage:has(.bubble.show)::after {
  content: ""; grid-row: 2; position: relative; z-index: 2; justify-self: center; margin: -1px 12% 0 0;
  width: 17px; height: 11px; background: linear-gradient(49deg, transparent 41%, white 42%) 3px -2px / 12px 10px no-repeat, #101a32;
  clip-path: polygon(0 0, 94% 0, 100% 100%); pointer-events: none;
}
/* 上下の白枠は行の切れ端を隠す。本文・輪郭・しっぽをすべて専用帯内に収める。 */
.stage:has(#charaGL:not([hidden])) .bubble {
  margin-top: 6px; padding: 0 18px; border-block: 5px solid white; overflow: hidden;
  font-size: clamp(1.12rem, 2cqw, 1.375rem); line-height: 1.16;
  max-height: min(calc(2.32em + 10px), calc(var(--bubble-band, 78px) - 16px));
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2;
}
.stage.band-1line:has(#charaGL:not([hidden])) .bubble {
  margin-top: 4px; -webkit-line-clamp: 1; font-size: .85rem; line-height: 1.35; padding: 0 12px;
  border-block-width: 4px; max-height: calc(1.35em + 8px);
}
.stage.band-1line:has(.bubble.show)::after { width: 12px; height: 6px; }

.panel {
  min-width: 0; min-height: 0; display: flex; flex-direction: column; justify-content: safe center;
  gap: clamp(7px, 1.5cqh, 18px); padding: clamp(12px, 1.9cqw, 32px);
  background: radial-gradient(ellipse at 65% 0%, var(--navy-light), var(--navy) 74%); overflow-y: auto;
}
.aiword {
  --rim: clamp(11px, 1.05cqw, 17px);
  padding: clamp(7px, 1.5cqh, 17px) clamp(12px, 1.5cqw, 24px);
  min-height: 0; overflow: auto; text-align: center; overflow-wrap: anywhere;
}
.aiword-label { display: flex; justify-content: space-between; align-items: baseline; gap: 6px; text-align: left; }
#aiLabel { flex: none; font-size: clamp(.72rem, 1.3cqw, 1.28rem); }
.think { color: var(--ink-muted); font-size: .72rem; font-weight: 700; text-align: right; font-variant-numeric: tabular-nums; }
.aiword-main { font-size: clamp(2.5rem, min(7cqw, 11cqh), 7.2rem); line-height: 1.08; font-weight: 900; letter-spacing: -.045em; }
.aiword-reading { font-size: clamp(1.25rem, 2.6cqw, 2.7rem); font-weight: 800; line-height: 1.3; }
.aiword-reading .tail { display: inline-block; padding: 0 .16em .05em; line-height: 1.12; background: var(--pink); color: white; border-radius: .22em; font-weight: 900; }
.aiword-tier { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: .73rem; font-weight: 800; color: #184369; background: #d5eaff; }
.aiword-tier.tier-C { background: #ffdae3; color: #811739; }
.aiword-tier[hidden] { display: none; }
.aiword-meaning { color: var(--ink-muted); font-size: .82rem; }
.aiword-attack { margin-top: .18em; color: var(--pink); font-size: clamp(.83rem, 1.55cqw, 1.55rem); line-height: 1.35; font-weight: 900; }
.aiword-attack:empty { margin: 0; }
.aiword-attack .atk-kana { display: inline-block; padding: 0 .25em; border-radius: .3em; background: var(--pink); color: white; }
/* 攻める文字が変わった手: 文字の札が下から跳ねて光る（拡大・回転は使わない） */
.aiword-attack.swap .atk-kana { animation: atk-swap .55s cubic-bezier(.3,1.6,.5,1); }
@keyframes atk-swap {
  0% { transform: translateY(.5em); opacity: 0; box-shadow: 0 0 0 0 #fff0; }
  45% { opacity: 1; box-shadow: 0 0 0 .25em #ffffffcc, 0 0 1em .3em var(--pink); }
  100% { transform: none; box-shadow: 0 0 0 0 #fff0; }
}
@media (prefers-reduced-motion: reduce) { .aiword-attack.swap .atk-kana { animation: none; } }
.aiword.pop { animation: pop .22s; }
@keyframes pop { from { transform: translateY(8px); opacity: .3; } to { transform: none; opacity: 1; } }

.turnrow { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; line-height: 1.12; }
.nexthead { font-size: clamp(1rem, 2cqw, 2rem); font-weight: 800; }
.nexthead b { color: var(--yellow); font-size: 1.45em; font-weight: 900; }
.timetext { font-size: clamp(1.8rem, 4cqw, 4rem); font-weight: 900; font-variant-numeric: tabular-nums; }
.timebar { flex: none; height: clamp(14px, 3.6cqh, 40px); padding: 3px; border: 2px solid #fff; border-radius: 99px; background: #354158; overflow: hidden; }
.timebar i { display: block; width: 100%; height: 100%; border-radius: inherit; background: var(--yellow); transform-origin: left; }
.hurry .timebar i { background: var(--pink-light); }
.hurry .timetext { color: var(--signal); }
html.mode-ultra .nexthead b, html.mode-ultra .hinttext { color: var(--signal); }
.msgrow { display: flex; align-items: center; gap: 8px; }
.msgrow:has(.msg:empty):has(#btnReport[hidden]) { display: none; }
.msg { min-width: 0; flex: 1; font-weight: 700; font-size: .9rem; overflow-wrap: anywhere; }
.msg.bad { color: var(--signal); }
.msg.good { color: var(--good); }
.inputrow { display: flex; gap: 8px; }
#wordInput, #btnSend { height: clamp(52px, 9.5cqh, 100px); border-radius: 14px; }
#wordInput { flex: 1; min-width: 0; background: var(--paper); color: var(--ink); border: 2px solid #f1e4c4; padding: 0 .7em; font-size: clamp(1.2rem, 2.25cqw, 2.25rem); font-weight: 800; }
#wordInput::placeholder { color: #67696e; opacity: 1; }
#wordInput:focus { border-color: var(--gold); outline: 2px solid var(--gold); outline-offset: 0; }
#wordInput.shake { animation: shake .25s; }
@keyframes shake { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
#btnSend { flex: 0 0 27%; min-width: 68px; font-size: clamp(1.3rem, 2.65cqw, 2.8rem); font-weight: 900; }
.helpers { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
#helpTime, #helpHint { min-height: clamp(36px, 6.8cqh, 72px); padding-inline: .9em; font-size: clamp(.86rem, 1.85cqw, 1.8rem); }
.hinttext { color: var(--yellow); font-weight: 800; letter-spacing: .06em; }
.history-wrap {
  display: flex; align-items: center; gap: 8px; min-width: 0; padding: clamp(8px, 1.25cqh, 16px) .85em;
  background: var(--paper); border-radius: 13px; color: var(--ink);
}
.history-label { flex: none; font-size: clamp(.8rem, 1.65cqw, 1.65rem); font-weight: 900; }
.history-label b { font-size: .8em; color: var(--ink-muted); }
.history { min-width: 0; max-height: 4em; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; overflow: auto; scrollbar-width: thin; }
.chip { flex: none; border-radius: 999px; padding: .24em .76em; white-space: nowrap; font-size: clamp(.82rem, 1.45cqw, 1.45rem); font-weight: 800; color: white; background: var(--navy); }
.chip.you { background: #087944; }
.chip.ai { background: #c42941; }

/* 結果と窓 */
.result-box { margin: auto; width: min(660px, 100%); padding: clamp(15px, 3cqw, 36px); }
.result-mode { margin: 0 0 8px; }
.result-cause { margin: 0; font-size: 1.12rem; color: var(--pink); font-weight: 900; }
.result-cause.win { color: #006743; }
.result-count { margin: 6px 0; }
.result-count b { font-size: clamp(4rem, 18cqw, 7rem); font-weight: 900; line-height: 1; text-shadow: 0 3px 0 var(--gold); }
.result-count span { font-size: 1.3rem; font-weight: 800; }
.result-best, .result-review { margin: 8px 0; color: var(--ink-muted); }
.result-review { border-radius: 12px; padding: 10px 14px; background: #fff; color: var(--ink); }
.result-review:empty { display: none; }
.result-btns { margin: 18px 0; }
.result-words-label { text-align: left; font-weight: 800; }
.result-words { margin: 6px 0 0; padding: 0; list-style: none; display: flex; flex-wrap: wrap; gap: 6px; }
.result-words .chip { max-width: 100%; white-space: normal; overflow-wrap: anywhere; }
.unlock-box { margin: 10px 0; padding: 14px; border: 2px solid #ef5661; border-radius: 14px; background: linear-gradient(135deg, #4b1021, #1b0810); animation: pop .4s; }
.unlock-box[hidden] { display: none; }
.unlock-title { margin: 0 0 6px; color: #ffadb3; font-size: 1.2rem; font-weight: 900; }
.unlock-text { margin: 0 0 10px; color: #fff0ea; font-size: .9rem; }
.modal { position: fixed; inset: 0; top: var(--vvtop); height: var(--vvh); z-index: 10; display: grid; place-items: center; padding: 14px; background: #030a20c9; }
.modal[hidden] { display: none; }
.modal-card { width: min(520px, 100%); max-height: 100%; min-height: 0; overflow: auto; padding: clamp(12px, 3cqw, 24px); display: flex; flex-direction: column; gap: 12px; }
.modal-card h3 { margin: 0; font-size: 1.35rem; font-weight: 900; }
.help-list { margin: 0; padding-left: 1.3em; display: grid; gap: 7px; line-height: 1.5; font-size: .95rem; }
.help-list b { color: var(--pink); }
.vol { display: grid; grid-template-columns: 4em minmax(0, 1fr) 2.5em; align-items: center; gap: 8px; font-weight: 800; }
.vol input { width: 100%; height: 32px; accent-color: var(--pink); }
.vol output { text-align: right; font-variant-numeric: tabular-nums; color: var(--ink-muted); }
.modal-note { margin: 0; color: var(--ink-muted); font-size: .86rem; }
/* クレジット（長いので窓の中でスクロール。✕は上に固定） */
.credits { width: min(620px, 100%); font-size: .85rem; line-height: 1.55; gap: 8px; overscroll-behavior: contain; }
.credits-head { position: sticky; top: calc(-1 * clamp(12px, 3cqw, 24px)); margin: calc(-1 * clamp(12px, 3cqw, 24px)) calc(-1 * clamp(12px, 3cqw, 24px)) 0;
  padding: clamp(12px, 3cqw, 24px) clamp(12px, 3cqw, 24px) 8px; display: flex; align-items: center; justify-content: space-between; background: inherit; z-index: 1; }
.credits h4 { margin: 8px 0 0; font-size: 1rem; font-weight: 900; }
.credits p { margin: 0; }
.credit-list { margin: 0; padding-left: 1.2em; display: grid; gap: 8px; }
.credits a { color: #0a63b8; overflow-wrap: anywhere; }
.credit-links { color: var(--ink-muted); }
.rec-btns { justify-content: flex-start; }

@container app (max-width: 820px) {
  .battle { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(70px, 1fr) auto; }
  .panel { padding: 7px 10px calc(8px + env(safe-area-inset-bottom)); gap: 7px; }
  .hud { gap: 7px; padding: 4px 6px; }
  .hud-mode { padding: .25em .6em; font-size: .82rem; }
  .hud-item { flex-direction: column; gap: 1px; line-height: 1.05; }
  .hud-item + .hud-item { padding-left: 7px; }
  .hud-item span { font-size: .63rem; }
  .hud-item b { font-size: 1.06rem; }
  .hud-btns { gap: 4px; }
  .hud-btns .btn.small { min-height: 32px; min-width: 29px; padding: 3px 6px; font-size: .8rem; }
  .aiword { --rim: clamp(8px, 2cqw, 12px); padding: 5px 9px 7px; max-height: 33cqh; }
  .aiword-main { font-size: clamp(2rem, 10.6cqw, 3.8rem); }
  .aiword-reading { font-size: clamp(1.2rem, 5.3cqw, 2rem); }
  .turnrow { padding-inline: 3px; }
  .timebar { height: 17px; padding: 2px; }
  #wordInput, #btnSend { height: 48px; }
  #helpTime, #helpHint { min-height: 36px; }
  .history-wrap { padding: 5px 8px; }
  .history { flex-wrap: nowrap; overflow-y: hidden;
    /* 新しい言葉が右端に来るよう横に流すので、左で切れた札はぼかして「続きがある」と分かるようにする */
    -webkit-mask-image: linear-gradient(90deg, transparent, #000 22px); mask-image: linear-gradient(90deg, transparent, #000 22px); }
  .select-list { grid-template-columns: 1fr; grid-auto-rows: minmax(84px, 1fr); padding: 12px; gap: 10px; }
  .chara-card { --rim: 5px; height: 100%; flex-direction: row; justify-content: flex-start; padding: 5px 12px; text-align: left; }
  .chara-face { width: auto; height: min(85%, 110px); min-height: 45px; }
  .select-foot { flex-direction: column; align-items: stretch; gap: 6px; padding: 8px 12px calc(10px + env(safe-area-inset-bottom)); }
  .bar { gap: 7px; padding: 6px 8px; }
  .bar h2 { font-size: 1rem; }
  .bar-note { font-size: .73rem; }
}
/* 一部の端末ではキーボードで visualViewport だけが縮むため、操作卓の実寸も見る。 */
@container arena (max-width: 820px) and (max-height: 520px) {
  .battle { grid-template-rows: minmax(40px, 1fr) auto; }
  .panel { gap: 4px; padding-top: 4px; }
  .aiword { --rim: 6px; display: flex; flex-wrap: wrap; justify-content: center; align-items: baseline; gap: 0 8px; padding: 3px 7px; max-height: 23cqh; }
  .aiword-label { width: 100%; }
  .aiword-main { font-size: 1.45rem; }
  .aiword-reading { font-size: 1rem; }
  .aiword-meaning { display: none; }
  .aiword-attack { width: 100%; font-size: .75rem; }
  .nexthead b { font-size: 1.25em; }
  .timetext { font-size: 1.4rem; }
  .timebar { height: 10px; padding: 1px; }
  #wordInput, #btnSend { height: 44px; }
  .msg { font-size: .78rem; }
  #helpTime, #helpHint { min-height: 31px; }
}
@container arena (max-width: 820px) and (max-height: 400px) {
  .history-wrap { display: none; }
}

/* スマホでキーボードが出ている間（js/stage-fit.js が html[data-stage] に keyboard を付ける）:
   使った言葉の帯は隠し（結果画面で全部見られる）、その分をキャラの舞台に回す */
html[data-stage~="keyboard"] .history-wrap { display: none; }
html[data-stage~="keyboard"] .panel { justify-content: flex-start; }

/* 選択カードの札イラスト（名前と紹介文も絵の中）。金の電球の縁の内側いっぱいに出す */
.chara-card.has-art { --rim: 6px; position: relative; padding: 0; overflow: hidden; display: block; }
.chara-card.has-art .card-art {
  position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; object-position: center;
  border-radius: calc(var(--rim) * 1.6); pointer-events: none; user-select: none;
}
.chara-card.has-art .card-art.wide { display: none; }
/* 横長の舞台: カードを縦長の札の絵と同じ 2:3 にして、絵が切れないようにする */
.chara-card.has-art { aspect-ratio: 2 / 3; width: auto; max-width: 100%; justify-self: center; }
.chara-card.has-art .chara-note:not(:empty) {
  position: absolute; right: 8px; top: 8px; z-index: 1; padding: 3px 10px; border-radius: 99px;
  background: #ffffffe6; box-shadow: 0 2px 0 #0003;
}
@container app (max-width: 820px) {
  .chara-card.has-art { aspect-ratio: auto; width: 100%; }
  .chara-card.has-art .card-art.wide { display: block; }
  .chara-card.has-art .card-art.tall { display: none; }
}

/* ── タイトルと結果のイラスト（css/screens/。横長の舞台は -landscape、縦長は -portrait、裏モードは ultra）──
   タイトルのロゴ・3人は絵の中。HTML の見出しは読み上げ用に残して見た目だけ隠す。ボタンは絵の空いた所に重ねる */
#app #scr-title { background: #0a2a6b url(screens/title-normal-landscape.webp) center / cover no-repeat; }
html.mode-ultra #app #scr-title { background: #100406 url(screens/title-ultra-landscape.webp) center / cover no-repeat; }
#app #scr-result { background: #0a2a6b url(screens/result-normal-landscape.webp) center / cover no-repeat; }
html.mode-ultra #app #scr-result { background: #100406 url(screens/result-ultra-landscape.webp) center / cover no-repeat; }
#app #scr-title .title-sub, #app #scr-title .title-logo {
  position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap;
}
#app #scr-title .title-box {
  /* 横長: 絵の左下の空いた所（ロゴの下・3人の左） */
  width: 40%; margin: auto auto 7% 5%; gap: 14px; padding: 22px 24px;
  border: 2px solid #ffffff55; border-radius: 22px; color: white;
  background: linear-gradient(#061a4ccc, #04103acc); box-shadow: 0 8px 30px #0008;
  backdrop-filter: blur(2px);
}
html.mode-ultra #app #scr-title .title-box { background: linear-gradient(#2a0610d9, #120306d9); border-color: #ff6a6655; }
#app #scr-title .title-best, #app #scr-title .load-status { color: #dbe6ff; }
#app #scr-title .load-status.ok { color: var(--good); }
#app #scr-title .load-status.ng { color: var(--signal); }
@container app (max-width: 820px) {
  #app #scr-title { background-image: url(screens/title-normal-portrait.webp); }
  html.mode-ultra #app #scr-title { background-image: url(screens/title-ultra-portrait.webp); }
  #app #scr-result { background-image: url(screens/result-normal-portrait.webp); }
  html.mode-ultra #app #scr-result { background-image: url(screens/result-ultra-portrait.webp); }
  /* 縦長: 絵の下 1/3（3人の下の床） */
  #app #scr-title .title-box { width: 100%; margin: auto 0 0; padding: 16px 16px 18px; gap: 10px; }
}
/* 舞台を拡大している窓（js/stage-fit.js が data-res="hd" を付ける）では大きな絵。AIで4倍に拡大した原画から作った -hd */
html[data-res="hd"][data-stage~="landscape"] #app #scr-title { background-image: url(screens/title-normal-landscape-hd.webp); }
html[data-res="hd"][data-stage~="landscape"].mode-ultra #app #scr-title { background-image: url(screens/title-ultra-landscape-hd.webp); }
html[data-res="hd"][data-stage~="landscape"] #app #scr-result { background-image: url(screens/result-normal-landscape-hd.webp); }
html[data-res="hd"][data-stage~="landscape"].mode-ultra #app #scr-result { background-image: url(screens/result-ultra-landscape-hd.webp); }
html[data-res="hd"][data-stage~="portrait"] #app #scr-title { background-image: url(screens/title-normal-portrait-hd.webp); }
html[data-res="hd"][data-stage~="portrait"].mode-ultra #app #scr-title { background-image: url(screens/title-ultra-portrait-hd.webp); }
html[data-res="hd"][data-stage~="portrait"] #app #scr-result { background-image: url(screens/result-normal-portrait-hd.webp); }
html[data-res="hd"][data-stage~="portrait"].mode-ultra #app #scr-result { background-image: url(screens/result-ultra-portrait-hd.webp); }
