:root {
  --paper: #fbf3e4; --card: #fffaf0; --ink: #5a4332; --soft: #8a7361; --line: #e3d3b8;
  --accent: #e2553a; --teal: #3f8ea8; --cat: #e9a257; --fish: #f2603c;
  font-family: "Zen Maru Gothic", "Hiragino Maru Gothic ProN", "Yu Gothic UI", system-ui, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--paper); color: var(--ink); overscroll-behavior: none; }
body { touch-action: manipulation; -webkit-user-select: none; user-select: none; font-weight: 500; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
#app { height: 100dvh; max-width: 980px; margin: 0 auto; position: relative; }
.screen { display: none; height: 100%; flex-direction: column; padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
.screen.on { display: flex; }

/* ボタン */
.btn { border: 2px solid var(--ink); background: var(--card); border-radius: 999px; padding: .6em 1.3em; font-weight: 700; box-shadow: 0 3px 0 var(--ink); transition: transform .06s, box-shadow .06s; white-space: nowrap; }
.btn:active { transform: translateY(3px); box-shadow: 0 0 0 var(--ink); }
.btn.primary { background: var(--accent); color: #fff; }
.btn.big { font-size: 1.25rem; padding: .7em 2.4em; }
.btn.sm { font-size: .8rem; padding: .55em .9em; box-shadow: 0 2px 0 var(--ink); }
.btn:disabled { opacity: .35; pointer-events: none; }
.btn kbd { font: inherit; font-size: .7em; margin-left: .5em; opacity: .55; border: 1px solid currentColor; border-radius: 4px; padding: 0 .3em; }
.icon { width: 40px; height: 40px; border-radius: 50%; border: 2px solid var(--ink); background: var(--card); font-weight: 900; font-size: 1.1rem; line-height: 1; flex: none; padding: 0; display: inline-flex; align-items: center; justify-content: center; }
.icon svg { width: 22px; height: 22px; display: block; }
.icon.ghost { visibility: hidden; }

/* はじめの画面 */
#title { overflow-y: auto; }
.title-inner { margin: auto; padding: 24px 20px 32px; max-width: 560px; width: 100%; text-align: center; }
h1 { margin: 0 0 14px; font-weight: 900; font-size: clamp(2.2rem, 10vw, 3.6rem); line-height: 1.12; letter-spacing: .04em; }
h1 > span { display: block; }
h1 > span:first-child { color: var(--ink); }
h1 > span:last-child { color: var(--teal); padding-left: 1.6em; }
.title-art { display: flex; justify-content: center; margin: 0 auto 16px; }
.title-art canvas { border-radius: 18px; border: 2px solid var(--ink); display: block; }
.story { text-align: center; font-size: .92rem; line-height: 1.85; color: var(--soft); }
/* 言葉の途中で行を切らないためのかたまり（game.js の phrase が作る） */
.bs { display: inline-block !important; font: inherit; color: inherit; margin: 0; padding: 0; white-space: nowrap; }
.story p { margin: 0 0 .7em; }
@media (max-width: 420px) { .story { font-size: .84rem; } }
.title-btns { display: flex; flex-direction: column; align-items: center; gap: 12px; margin-top: 22px; }

/* 上の帯 */
.bar { display: flex; align-items: center; gap: 10px; padding: 8px 12px; flex: none; }
.bar-title { flex: 1; text-align: center; font-weight: 900; font-size: 1.05rem; line-height: 40px; height: 40px; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#stageNo { color: var(--accent); margin-right: .5em; }

/* ステージ選び */
/* ステージ選びは、画面の横いっぱいがスクロールする枠（スクロールバーは画面の右端）。中身は真ん中寄せ */
#select.on { display: block; position: fixed; inset: 0; overflow-y: auto; }
#select > .bar, #select > .grid { max-width: 980px; margin: 0 auto; }
/* 広い画面では3列に決めて、列・戻るボタン・見出しを同じ幅で画面の真ん中に置く */
@media (min-width: 680px) {
  #select > .bar, #select > .grid { max-width: 660px; }
  #select > .grid { grid-template-columns: repeat(3, 1fr); }
}
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); grid-auto-rows: auto; align-items: stretch; gap: 12px; padding: 8px 16px 32px; }
.grp { grid-column: 1 / -1; margin: 10px 0 -4px; font-size: .85rem; font-weight: 900; color: var(--teal); }
.grp:first-child { margin-top: 0; }
.cell { border: 2px solid var(--ink); border-radius: 16px; background: var(--card); padding: 12px 12px 10px; text-align: left; box-shadow: 0 3px 0 var(--ink); min-height: 92px; height: auto; display: flex; flex-direction: column; align-items: stretch; justify-content: flex-start; gap: 3px; }
.cell > span { display: block; flex: none; min-width: 0; }
.cell .n { font-weight: 900; font-size: 1.4rem; color: var(--accent); line-height: 1; }
.cell .t { font-weight: 700; font-size: .95rem; line-height: 1.35; overflow-wrap: anywhere; }
.cell .r { font-size: .72rem; line-height: 1.3; color: var(--soft); margin-top: auto; padding-top: 4px; }
.cell.done .n::after { content: " ✓"; color: var(--teal); }
.cell:disabled { opacity: .4; box-shadow: none; }

/* 遊ぶ画面 */
.phase { display: flex; align-items: center; justify-content: center; gap: 6px; padding: 0 10px 8px; flex: none; flex-wrap: wrap; }
.chip { display: flex; align-items: center; gap: .35em; border: 2px solid var(--line); border-radius: 999px; padding: .2em .8em; font-size: .8rem; font-weight: 700; color: var(--soft); background: transparent; white-space: nowrap; }
.chip b { font-size: 1.05rem; margin-left: .3em; font-variant-numeric: tabular-nums; }
.chip.on { border-color: var(--ink); color: var(--ink); background: var(--card); box-shadow: 0 2px 0 var(--ink); }
.chip .dot { width: .7em; height: .7em; border-radius: 50%; background: var(--line); }
.chip.on .dot.cat { background: var(--cat); } .chip.on .dot.fish { background: var(--fish); }
.chip.bell { border-color: #c9a227; color: #7a5d0c; background: #fff6d6; }
.arrow { color: var(--line); font-weight: 900; }

#stage { flex: 1; min-height: 0; position: relative; display: flex; align-items: center; justify-content: center; padding: 0 6px; }
#cv { border-radius: 14px; border: 2px solid var(--ink); display: block; background: #cfe7f1; }
#banner { position: absolute; left: 50%; top: 4px; transform: translate(-50%, 0) scale(.9); background: var(--ink); color: #fff; font-weight: 900; font-size: 1.15rem; padding: .7em 1.5em; border-radius: 999px; opacity: 0; pointer-events: none; transition: opacity .25s, transform .25s; white-space: nowrap; }
#banner.on { opacity: .94; transform: translate(-50%, 0) scale(1); }

#timeline { flex: none; display: flex; align-items: center; gap: 8px; padding: 8px 12px 0; min-height: 38px; }
#tlLabel { font-size: .75rem; font-weight: 700; white-space: nowrap; color: var(--soft); font-variant-numeric: tabular-nums; }
#tlSteps { display: flex; gap: 3px; overflow-x: auto; scrollbar-width: none; padding: 3px 2px; flex: 1; }
#tlSteps::-webkit-scrollbar { display: none; }
.st { flex: none; width: 22px; height: 24px; border-radius: 7px; border: 1.5px solid var(--line); display: grid; place-items: center; font-size: .78rem; font-weight: 900; color: var(--soft); background: var(--card); }
.st.done { opacity: .35; }
.st.next { border-color: var(--ink); background: var(--cat); color: #fff; transform: scale(1.12); }
.st.home { width: auto; padding: 0 .5em; }
.st.bad { border-color: var(--accent); background: var(--accent); color: #fff; animation: shake .35s 2; }
@keyframes shake { 25% { transform: translateX(-2px) scale(1.15); } 75% { transform: translateX(2px) scale(1.15); } }

#msg { flex: none; min-height: 3.3em; padding: 6px 16px 0; font-size: .86rem; line-height: 1.45; text-align: center; color: var(--soft); display: grid; align-items: center; }
#msg.warn { color: var(--accent); font-weight: 700; }

.controls { flex: none; display: flex; align-items: center; justify-content: center; gap: 10px; padding: 8px 8px 14px; }
.side { display: flex; flex-direction: column; gap: 8px; flex: 1; max-width: 190px; }
.side .btn { width: 100%; padding-left: .3em; padding-right: .3em; white-space: normal; line-height: 1.2; min-height: 44px; }
.dpad { display: grid; grid-template: "x u y" 56px "l w r" 56px "z d q" 56px / 56px 56px 56px; gap: 5px; flex: none; }
.pad { border: 2px solid var(--ink); background: var(--card); border-radius: 16px; font-weight: 900; font-size: 1.1rem; box-shadow: 0 3px 0 var(--ink); transition: transform .05s, box-shadow .05s; padding: 0; }
.pad:active, .pad.hit { transform: translateY(3px); box-shadow: 0 0 0 var(--ink); background: #ffe9c7; }
.pad.wait { font-size: .8rem; border-radius: 50%; display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.1; }
.pad kbd { font: inherit; font-size: .55rem; opacity: .6; border: 1px solid currentColor; border-radius: 4px; padding: 0 .3em; margin-top: 2px; }
.row2 { display: flex; gap: 6px; } .row2 .btn { flex: 1; min-width: 0; white-space: nowrap; }
@media (max-width: 560px) { .row2 { flex-direction: column; gap: 8px; } .side .btn { min-height: 38px; padding-top: .35em; padding-bottom: .35em; } }
.snd .slash { display: none; }
.snd.off { background: #efe6d6; border-color: var(--soft); color: #b3a392; }
.snd.off .slash { display: block; stroke: var(--accent); }
.snd.corner { position: absolute; right: 12px; top: calc(10px + env(safe-area-inset-top)); z-index: 2; }
.card.tut { max-width: 400px; padding: 20px 18px 18px; }
.card.tut h2 { color: var(--ink); font-size: 1.35rem; margin-bottom: 12px; }
.tut-step { font-size: .75rem; font-weight: 900; color: var(--accent); margin-bottom: 2px; min-height: 1.2em; }
.tut-art { display: flex; flex-direction: column; align-items: center; }
.tut-art canvas { border-radius: 12px; border: 2px solid var(--ink); display: block; }
.tut-phase { display: block; width: max-content; max-width: 100%; margin: 0 auto 8px; background: var(--ink); color: #fff; font-size: .75rem; font-weight: 900; border-radius: 999px; padding: .15em 1em; white-space: nowrap; }
.tut-phase:empty { display: none !important; }
.card.tut > * { display: block; } .card.tut > .tut-btns { display: flex; } .card.tut > .tut-art { display: flex; } .card.tut > .close { display: inline-flex; }
#tutText { text-align: left; font-size: .9rem; line-height: 1.7; margin: 12px 2px 16px; min-height: 6.8em; }
.tut-btns { display: flex; gap: 10px; } .tut-btns .btn { flex: 1; }
.pad:disabled { opacity: .3; }
/* キーの表示は、キーボードのある端末だけ（game.js が html に keys を付ける） */
html:not(.keys) kbd { display: none; }
@media (max-height: 640px) { .dpad { grid-template-rows: 46px 46px 46px; grid-template-columns: 52px 52px 52px; } #msg { min-height: 2.6em; } }
@media (min-width: 760px) and (min-height: 700px) { .controls { gap: 28px; } .btn.sm { font-size: .9rem; } }

/* 重ねて出す窓 */
.modal { position: fixed; inset: 0; background: rgba(90, 67, 50, .45); display: none; align-items: center; justify-content: center; padding: 16px; z-index: 10; }
.modal.on { display: flex; }
.card { background: var(--card); border: 2px solid var(--ink); border-radius: 24px; padding: 24px 22px; width: 100%; max-width: 380px; text-align: center; box-shadow: 0 6px 0 var(--ink); position: relative; animation: pop .25s; }
.card.wide { max-width: 640px; max-height: 88dvh; display: flex; flex-direction: column; text-align: left; padding: 22px 6px 14px 22px; }
@keyframes pop { from { transform: scale(.92); opacity: 0; } }
.card h2 { margin: 0 0 10px; font-weight: 900; font-size: 1.6rem; color: var(--teal); }
.result { margin: 0 0 14px; font-weight: 700; } .result b { font-size: 1.5rem; color: var(--accent); }
.insight { margin: 0 0 18px; background: #fff3d6; border-radius: 14px; padding: 10px 14px; font-size: .9rem; line-height: 1.6; text-align: left; }
.insight > span { display: block; font-size: .7rem; font-weight: 900; color: var(--soft); }
.insight em { font-style: normal; font-weight: 700; }
.card-btns { display: flex; flex-direction: column; gap: 12px; align-items: stretch; }
.close { position: absolute; right: 12px; top: 12px; }
.help-body { overflow-y: auto; padding-right: 16px; font-size: .9rem; line-height: 1.75; -webkit-user-select: text; user-select: text; }
.help-body h3 { margin: 1.3em 0 .3em; font-size: 1rem; font-weight: 900; color: var(--accent); }
.help-body h3:first-child { margin-top: 0; }
.help-body p { margin: 0 0 .6em; }
.help-body ul, .help-body ol { margin: 0 0 .6em; padding-left: 1.3em; }
.help-body li { margin-bottom: .25em; }
.credit { margin-top: 1.6em !important; padding-top: .9em; border-top: 1px solid var(--line); font-size: .82rem; color: var(--soft); }
.credit a { color: var(--teal); font-weight: 700; }
