/* 共通テンプレート シェル CSS — 設計書 04（固定スケール・部品）と 08（意味トークンは theme.js が注入）。
   作品側は :root の意味トークンだけを上書きする。ここの構造・スケールは変えない。 */
:root {
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s6: 24px; --s8: 32px; --s12: 48px;
  --fs-xs: 11px; --fs-sm: 13px; --fs-md: 15px; --fs-lg: 20px; --fs-xl: 34px;
  --lh: 1.7; --lh-tight: 1.15;
  --r-sm: 4px; --r-md: 8px; --bw: 1px;
  --shadow-board: 0 20px 40px -20px #000a;
  --t-fast: 120ms; --t-base: 220ms; --t-slow: 600ms; --ease: cubic-bezier(.2,.7,.2,1);
  --wrap: 560px; --tap: 44px;
  --safe-b: env(safe-area-inset-bottom, 0px); --safe-t: env(safe-area-inset-top, 0px);
  /* 意味トークンの既定（theme.js が上書き） */
  --bg:#16171a; --bg2:#1e2024; --panel:#26282d; --line:#363940; --ink:#ecebe6; --ink2:#aeada6; --ink3:#77766f;
  --accent:#8a8f9a; --accent2:#b8bcc6; --accent-ink:#111214; --ok:#7fb489; --bad:#b9605a; --mark:#6c6a63;
  --focus:#b8bcc6; --selection:#2c3038; --primary-bg:linear-gradient(180deg,#9096a2,#6e7480); --done-line:#4a4f58;
  --ff-display: serif; --ff-body: sans-serif; --ff-mono: ui-monospace, Menlo, monospace; --fw-display: 600;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--ff-body); font-size: var(--fs-md); line-height: var(--lh); -webkit-font-smoothing: antialiased; overscroll-behavior: none; }
button { font: inherit; color: inherit; }
a { color: var(--accent2); }
.mono { font-family: var(--ff-mono); font-variant-numeric: tabular-nums; }
.display { font-family: var(--ff-display); font-weight: var(--fw-display); }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { :root { --t-fast: 0ms; --t-base: 0ms; --t-slow: 0ms; } }
html[data-motion="reduce"] { --t-fast: 0ms; --t-base: 0ms; --t-slow: 0ms; }

/* ---- 画面の枠 ---- */
#app { position: relative; height: 100%; max-width: var(--wrap); margin: 0 auto; overflow: hidden; }
.screen { position: absolute; inset: 0; display: flex; flex-direction: column; background: var(--bg); padding-top: var(--safe-t); animation: fade var(--t-base) var(--ease); }
@keyframes fade { from { opacity: 0; } }
.backdrop { position: absolute; inset: 0; pointer-events: none; }
.rel { position: relative; }

/* ---- 部品 ---- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 48px; min-width: var(--tap); padding: 0 20px; border-radius: 6px; border: var(--bw) solid var(--line); background: var(--bg2); color: var(--ink); font-weight: 500; font-size: var(--fs-md); letter-spacing: .06em; cursor: pointer; transition: transform var(--t-fast) var(--ease), border-color var(--t-fast), background var(--t-fast); user-select: none; -webkit-user-select: none; touch-action: manipulation; }
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--primary-bg); border-color: var(--accent2); color: var(--accent-ink); font-weight: 700; }
.btn.quiet { background: transparent; border-color: transparent; color: var(--ink2); }
.btn.quiet:hover { color: var(--ink); }
.btn:disabled { opacity: .4; cursor: default; transform: none; }
.btn.primary.check:not(.ready) { background: color-mix(in oklab, var(--accent) 38%, var(--bg2)); border-color: color-mix(in oklab, var(--accent2) 45%, var(--line)); color: color-mix(in oklab, var(--accent2) 80%, var(--ink)); font-weight: 600; }
.btn.primary.check.ready { background: linear-gradient(180deg, color-mix(in oklab, var(--accent2) 55%, var(--accent)), color-mix(in oklab, var(--accent) 80%, #b00)); border-color: var(--accent2); color: var(--accent-ink); font-weight: 800; letter-spacing: .12em; transform: scale(1.03); animation: ready-pulse 1.1s ease-in-out infinite; }
@keyframes ready-pulse { 0%, 100% { filter: brightness(1); box-shadow: 0 0 0 0 color-mix(in oklab, var(--accent2) 60%, transparent); } 50% { filter: brightness(1.18); box-shadow: 0 0 0 5px color-mix(in oklab, var(--accent2) 0%, transparent), 0 0 22px 4px color-mix(in oklab, var(--accent2) 65%, transparent); } }
html[data-motion="reduce"] .btn.primary.ready { animation: none; box-shadow: 0 0 0 3px var(--accent2); }
@media (prefers-reduced-motion: reduce) { .btn.primary.ready { animation: none; box-shadow: 0 0 0 3px var(--accent2); } }
.btn.big { width: 100%; height: 56px; font-size: 17px; letter-spacing: .14em; }
.btn.sm { height: 40px; padding: 0 12px; font-size: var(--fs-sm); }
.row { display: flex; gap: var(--s2); align-items: center; justify-content: center; flex-wrap: wrap; }
.col { display: flex; flex-direction: column; gap: var(--s2); }
.eyebrow { font-family: var(--ff-mono); font-size: var(--fs-xs); letter-spacing: .4em; color: var(--accent2); }
.muted { color: var(--ink2); } .faint { color: var(--ink3); }
.hr { height: 1px; background: var(--line); }
.dot { width: 6px; height: 6px; border-radius: 50%; background: var(--line); flex: none; }
.dot.done { background: var(--accent2); } .dot.cur { background: var(--accent); }
.toast { position: fixed; left: 50%; bottom: calc(24px + var(--safe-b)); transform: translateX(-50%); background: var(--panel); color: var(--ink); border: var(--bw) solid var(--line); border-radius: var(--r-md); padding: 10px 16px; font-size: var(--fs-sm); z-index: 50; animation: fade var(--t-base); }
.overlay { position: absolute; inset: 0; background: #0009; display: flex; align-items: flex-end; justify-content: center; z-index: 20; animation: fade var(--t-base); }
.dialog { width: 100%; max-height: 88%; overflow: auto; background: var(--bg2); border: var(--bw) solid var(--line); border-radius: var(--r-md) var(--r-md) 0 0; padding: var(--s6) var(--s6) calc(var(--s6) + var(--safe-b)); animation: up var(--t-base) var(--ease); }
@keyframes up { from { transform: translateY(24px); opacity: 0; } }
@media (min-width: 600px) { .overlay { align-items: center; } .dialog { width: 520px; border-radius: var(--r-md); max-height: 80%; } }
.dialog.confirm p { font-size: var(--fs-md); margin: 0; }
.dialog.confirm .row { justify-content: flex-end; }
.dialog.confirm .btn { min-width: 96px; }
.dialog h3 { font-family: var(--ff-display); font-weight: var(--fw-display); font-size: var(--fs-lg); letter-spacing: .1em; margin: 0 0 var(--s3); }
.dialog h4 { font-size: var(--fs-sm); letter-spacing: .2em; color: var(--accent2); margin: var(--s6) 0 var(--s2); font-family: var(--ff-mono); font-weight: 500; }
.dialog p, .dialog li { font-size: var(--fs-sm); line-height: 1.8; color: var(--ink); margin: 0 0 var(--s2); }
.dialog ul { padding-left: 1.2em; margin: 0; }
.setting { display: flex; align-items: center; justify-content: space-between; min-height: var(--tap); padding: var(--s1) 0; border-bottom: var(--bw) solid var(--line); font-size: var(--fs-sm); }
.seg { display: inline-flex; border: var(--bw) solid var(--line); border-radius: 6px; overflow: hidden; }
.seg button { height: 36px; padding: 0 12px; border: 0; background: transparent; color: var(--ink2); cursor: pointer; font-size: var(--fs-sm); }
.seg button.on { background: var(--selection); color: var(--ink); }
.switch { width: 44px; height: 26px; border-radius: 13px; border: var(--bw) solid var(--line); background: var(--panel); position: relative; cursor: pointer; padding: 0; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: var(--ink3); transition: transform var(--t-fast), background var(--t-fast); }
.switch.on { background: var(--selection); border-color: var(--accent); } .switch.on::after { transform: translateX(18px); background: var(--accent2); }

/* ---- タイトル ---- */
.title { justify-content: space-between; padding-bottom: calc(40px + var(--safe-b)); }
.title .hero { display: flex; flex-direction: column; align-items: center; gap: var(--s3); padding: 150px var(--s6) 0; text-align: center; }
.title h1 { font-family: var(--ff-display); font-weight: var(--fw-display); font-size: clamp(48px, 18vw, 76px); letter-spacing: .18em; line-height: 1; margin: 0; }
.title .en { font-family: var(--ff-mono); font-size: 12px; letter-spacing: .42em; color: var(--accent2); padding-left: .42em; }
.title .sub { font-size: 14px; color: var(--ink2); letter-spacing: .08em; margin-top: var(--s2); }
.title .menu { display: flex; flex-direction: column; align-items: center; gap: var(--s3); padding: 0 var(--s12); }
.title .menu .btn.quiet { padding: 0 14px; }
.title .where { display: flex; align-items: center; gap: var(--s2); font-size: 12px; color: var(--ink3); letter-spacing: .06em; }
.title .foot { display: flex; justify-content: center; font-family: var(--ff-mono); font-size: var(--fs-xs); color: var(--ink3); letter-spacing: .1em; }

/* ---- 幕間 ---- */
.interlude { background: var(--bg2); cursor: pointer; }
.interlude .top { display: flex; justify-content: flex-end; padding: var(--s4) var(--s4) 0; }
.interlude .body { flex: 1; display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 40px; padding: 0 44px 60px; text-align: center; }
.interlude .head { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.interlude h2 { font-family: var(--ff-display); font-weight: var(--fw-display); font-size: var(--fs-xl); letter-spacing: .2em; line-height: 1.2; margin: 0; }
.interlude .sep { width: 28px; height: 1px; background: var(--line); }
.interlude .text { display: flex; flex-direction: column; gap: 22px; font-family: var(--ff-display); font-weight: var(--fw-display); font-size: 17px; line-height: 2.1; letter-spacing: .06em; }
.interlude .text p { margin: 0; } .interlude .text p + p { color: var(--ink2); }
.interlude .rulesAppend { text-align: left; font-family: var(--ff-body); font-weight: 400; font-size: var(--fs-sm); line-height: 1.8; color: var(--ink); background: var(--panel); border: var(--bw) solid var(--line); border-radius: var(--r-md); padding: var(--s4); max-width: 100%; }
.interlude .note { font-family: var(--ff-mono); font-size: var(--fs-sm); letter-spacing: .12em; color: var(--accent2); border: var(--bw) solid var(--line); border-radius: var(--r-md); padding: 10px 18px; background: var(--panel); }
.interlude .actions2 { width: 100%; padding: 0 var(--s4); gap: var(--s3); flex-wrap: nowrap; }
.interlude .actions2 .btn { flex: 1; height: 52px; letter-spacing: .1em; }
.interlude .foot { display: flex; flex-direction: column; align-items: center; gap: 14px; padding: 0 0 calc(44px + var(--safe-b)); font-size: 12px; color: var(--ink3); letter-spacing: .12em; }

/* ---- 章・面選択 ---- */
.list { overflow: auto; }
.list .top { display: flex; align-items: center; justify-content: space-between; padding: var(--s4) var(--s4) 0; }
.list .head { display: flex; flex-direction: column; gap: 6px; padding: var(--s3) var(--s6) 0; }
.list h2 { font-family: var(--ff-display); font-weight: var(--fw-display); font-size: 26px; letter-spacing: .16em; line-height: 1.2; margin: 0; }
.list .count { font-family: var(--ff-mono); font-size: 12px; color: var(--ink2); }
.list .count b { color: var(--accent2); font-weight: 600; }
.dots { display: flex; gap: 6px; padding-top: 6px; flex-wrap: wrap; }
.dots .dot { width: 7px; height: 7px; }
.grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--s2); padding: 22px var(--s4) 0; }
.tile { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; height: 76px; border-radius: 6px; border: var(--bw) solid var(--line); background: var(--bg2); cursor: pointer; padding: 0; transition: transform var(--t-fast); }
.tile:active { transform: scale(.97); }
.tile .nm { font-family: var(--ff-display); font-weight: var(--fw-display); font-size: 17px; letter-spacing: .1em; line-height: 1.2; color: var(--ink); }
.tile .sb { font-size: 10px; letter-spacing: .06em; color: var(--ink3); height: 14px; line-height: 14px; }
.tile .no { position: absolute; left: 8px; top: 5px; font-family: var(--ff-mono); font-size: 9px; color: var(--ink3); }
.tile .badge { position: absolute; top: 6px; right: 8px; width: 6px; height: 6px; border-radius: 50%; background: var(--accent2); }
.tile .badge.nomiss { background: var(--ok); box-shadow: 0 0 0 2px color-mix(in oklab, var(--ok) 30%, transparent); }
.tile.done { border-color: var(--done-line); } .tile.done .nm { color: var(--accent2); }
.tile.cur { border-color: var(--accent); background: var(--selection); box-shadow: 0 0 0 1px var(--accent) inset; } .tile.cur .sb { color: var(--accent2); }
.tile.locked { opacity: .38; cursor: default; }
.chapterCard { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); padding: var(--s4) var(--s4); border: var(--bw) solid var(--line); border-radius: var(--r-md); background: var(--bg2); cursor: pointer; text-align: left; width: 100%; }
.chapterCard.locked { opacity: .5; cursor: default; }
.chapterCard .nm { font-family: var(--ff-display); font-weight: var(--fw-display); font-size: 17px; letter-spacing: .14em; }
.chapterCard .sb { font-size: var(--fs-xs); color: var(--ink3); letter-spacing: .06em; }
.nextCh { margin-top: auto; display: flex; flex-direction: column; gap: 10px; padding: var(--s6) var(--s6) calc(40px + var(--safe-b)); }
.nextCh .rowx { display: flex; align-items: center; justify-content: space-between; }
.nextCh .nextBtn { width: 100%; background: transparent; border: 0; padding: var(--s2) 0; text-align: left; cursor: pointer; color: inherit; border-radius: var(--r-sm); }
.nextCh .nextBtn:not(.locked):hover .nm { color: var(--ink); }
.nextCh .nextBtn.locked { cursor: default; }

/* ---- プレイ ---- */
.play .head { display: flex; align-items: center; justify-content: space-between; height: 56px; padding: 0 var(--s4); flex: none; }
.play .head .mid { display: flex; flex-direction: column; align-items: center; min-width: 0; }
.play .head .nm { font-family: var(--ff-display); font-weight: var(--fw-display); font-size: var(--fs-lg); letter-spacing: .14em; line-height: 1.2; white-space: nowrap; }
.play .head .ch { font-family: var(--ff-mono); font-size: 10px; letter-spacing: .2em; color: var(--ink3); }
.play .boardbox { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--s2); padding: 0 var(--s4); min-height: 0; }
.play .sum { flex: none; font-family: var(--ff-mono); font-size: var(--fs-sm); letter-spacing: .08em; color: var(--ink2); text-align: center; padding: 2px 12px; border-radius: 999px; border: var(--bw) solid var(--line); background: var(--bg2); }
.play .sum b { color: var(--accent2); font-weight: 600; }
.play .boardwrap { width: 100%; max-width: 100%; flex: 0 1 auto; min-height: 0; display: flex; align-items: center; justify-content: center; }
.play .bottom { flex: none; display: flex; flex-direction: column; gap: 10px; padding: 0 var(--s4) calc(14px + var(--safe-b)); }
/* メッセージ枠は常に同じ高さを確保する（出たり消えたりで盤面の大きさが変わらないように）。長い文は枠の中でスクロール */
:root { --msg-h: clamp(150px, 24vh, 260px); }
.msg { display: flex; flex-direction: column; gap: var(--s2); padding: 14px 16px; border-radius: var(--r-md); background: var(--bg2); border: var(--bw) solid var(--line); height: var(--msg-h); overflow: hidden; transition: opacity var(--t-base); position: relative; }
.msg .body { overflow: auto; min-height: 0; display: flex; flex-direction: column; gap: var(--s2); overscroll-behavior: contain; }
.msg.scrollable .body { padding-bottom: 6px; mask-image: linear-gradient(to bottom, #000 calc(100% - 28px), transparent); -webkit-mask-image: linear-gradient(to bottom, #000 calc(100% - 28px), transparent); }
.msg .act { flex: none; }
.msg.empty { opacity: 0; pointer-events: none; }
.msg .lab { font-family: var(--ff-mono); font-size: 10px; letter-spacing: .3em; color: var(--accent2); }
.msg .txt { font-size: 14px; line-height: 1.75; }
.msg .txt b, .msg .txt .k { color: var(--accent2); font-family: var(--ff-mono); font-weight: 600; }
.msg .act { display: flex; justify-content: flex-end; gap: var(--s2); }
.msg .act .readAll { margin-right: auto; border-color: var(--line); }
.dialog .txt { font-size: 15px; line-height: 1.9; }
.dialog .txt b, .dialog .txt .k { color: var(--accent2); font-family: var(--ff-mono); font-weight: 600; }
.msg.win { border-color: var(--accent); }
.msg.tut { border-color: var(--done-line); }
.msg .goal { display: flex; justify-content: center; padding: var(--s1) 0; flex: none; }
.msg .goalrow { display: flex; gap: var(--s3); align-items: flex-start; flex-wrap: wrap; }
.msg .goalrow .txt { flex: 1; min-width: 160px; }
.actions { display: flex; gap: var(--s2); }
.actions .btn { flex: 1; padding: 0; } .actions .btn.primary { flex: 1.4; }

/* ---- クリア ---- */
.clear .body { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 28px; padding: 0 var(--s8); text-align: center; }
.clear .head { display: flex; flex-direction: column; align-items: center; gap: var(--s2); width: 100%; }
.clear h2 { font-family: var(--ff-display); font-weight: var(--fw-display); font-size: 30px; letter-spacing: .12em; line-height: 1.3; margin: 0; white-space: nowrap; }
.clear .nm { font-family: var(--ff-display); font-weight: var(--fw-display); font-size: 18px; letter-spacing: .16em; color: var(--ink2); }
.clear .mini { max-width: 60%; }
.clear .stats { display: flex; gap: 28px; align-items: center; }
.clear .stat { display: flex; flex-direction: column; align-items: center; gap: 2px; font-family: var(--ff-mono); }
.clear .stat .l { font-size: 10px; letter-spacing: .3em; color: var(--ink3); } .clear .stat .v { font-size: 18px; font-weight: 600; } .clear .stat .v.good { color: var(--accent2); }
.clear .vsep { width: 1px; height: 28px; background: var(--line); }
.clear .foot { display: flex; flex-direction: column; gap: 10px; padding: 0 var(--s12) calc(40px + var(--safe-b)); }

/* ---- 章クリア演出 ---- */
.chapterClear { align-items: center; justify-content: center; gap: var(--s4); text-align: center; background: var(--bg); }
.chapterClear h2 { font-family: var(--ff-display); font-weight: var(--fw-display); font-size: var(--fs-xl); letter-spacing: .2em; margin: 0; animation: rise var(--t-slow) var(--ease); }
@keyframes rise { from { opacity: 0; transform: translateY(12px); } }

/* ---- 開発用 ---- */
.devbar { position: fixed; right: 8px; top: 8px; z-index: 99; font: 11px var(--ff-mono); color: var(--ink3); opacity: .6; }
