:root {
  --pink: #FF97BF;
  --pink-d: #f06a9f;
  --pink-l: #FFE6F0;
  --cream: #FFF3E4;
  --blue: #2F79F7;
  --blue-d: #1f5ed0;
  --ink: #2a1a2e;
  --ink-2: #6b5870;
  --paper: #fffdf8;
  --line: #e9dccf;
  --ok: #2F79F7;
  --ng: #8b4dff;
  --gold: #ffc53d;
  --bg1: #ffe3ef;
  --bg2: #fff6d8;
  --E: 0;
  --motion: 1;
  --vh: 100dvh;
  --key-h: clamp(48px, 8.2vh, 64px);
  --font-num: 'Dela Gothic One', 'Zen Maru Gothic', system-ui, sans-serif;
  --font: 'Zen Maru Gothic', 'Hiragino Maru Gothic ProN', 'Hiragino Sans', 'Meiryo', system-ui, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg1); color: var(--ink); font-family: var(--font); font-weight: 700; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; touch-action: manipulation; }
button:focus-visible, [tabindex]:focus-visible, input:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; }
svg { display: block; }

#app { position: relative; width: 100%; max-width: 560px; height: var(--vh); margin: 0 auto; overflow: hidden; }

/* ---------- 背景 ---------- */
#bg { position: fixed; inset: 0; z-index: 0; overflow: hidden; background: radial-gradient(circle at 50% 30%, var(--bg2), var(--bg1) 70%); transition: filter 0.6s; }
#bg .rays {
  position: absolute; left: 50%; top: 28%; width: 260vmax; height: 260vmax; margin: -130vmax 0 0 -130vmax;
  background: repeating-conic-gradient(from 0deg, rgba(255, 255, 255, 0.55) 0deg 7deg, rgba(255, 255, 255, 0) 7deg 15deg);
  animation: spin calc(90s - 60s * min(var(--E), 1.3)) linear infinite;
  opacity: calc(0.35 + 0.5 * min(var(--E), 1));
}
#bg .glow { position: absolute; inset: 0; background: radial-gradient(circle at 50% 110%, rgba(255, 151, 191, calc(0.15 + 0.4 * var(--E))), transparent 60%); }
body.extra #bg { filter: hue-rotate(0deg) saturate(1.3); animation: hue 6s linear infinite; }
body.lights #app::after {
  content: ''; position: fixed; inset: 0; pointer-events: none; z-index: 40;
  background:
    radial-gradient(circle, #fff 0 3px, var(--gold) 3px 5px, transparent 6px) 0 0 / 28px 28px repeat-x,
    radial-gradient(circle, #fff 0 3px, var(--pink) 3px 5px, transparent 6px) 14px 100% / 28px 28px repeat-x;
  background-size: 28px 14px, 28px 14px;
  background-position: 0 0, 14px 100%;
  animation: blink 0.5s steps(2) infinite;
  opacity: 0.9;
}
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes hue { to { filter: hue-rotate(360deg) saturate(1.3); } }
@keyframes blink { 50% { background-position: 14px 0, 0 100%; } }

/* ---------- 画面 ---------- */
.screen { position: absolute; inset: 0; z-index: 1; display: none; flex-direction: column; }
.screen.on { display: flex; }

/* ---------- 共通ボタン ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 52px; padding: 10px 22px; border-radius: 18px;
  background: #fff; color: var(--ink); font-size: 18px; font-weight: 900;
  border: 3px solid var(--ink); box-shadow: 0 5px 0 var(--ink);
  transition: transform 0.08s, box-shadow 0.08s;
}
.btn:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--ink); }
.btn.primary { background: var(--pink); }
.btn.blue { background: var(--blue); color: #fff; }
.btn.gold { background: var(--gold); }
.btn[disabled] { opacity: 0.45; pointer-events: none; }
.btn small { display: block; font-size: 12px; font-weight: 700; opacity: 0.8; }
.icon-btn { width: 40px; height: 40px; display: grid; place-items: center; border-radius: 12px; background: rgba(255, 255, 255, 0.85); border: 2px solid var(--ink); }
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: var(--ink); stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- タイトル ---------- */
#scr-title { overflow-y: auto; padding: max(12px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom)); align-items: center; gap: 10px; }
.logo { font-family: var(--font-num); font-size: clamp(44px, 14vw, 68px); line-height: 1; margin: 6px 0 0; color: var(--pink); letter-spacing: 0.02em;
  -webkit-text-stroke: 3px var(--ink); paint-order: stroke fill; text-shadow: 0 5px 0 var(--ink); transform: rotate(-3deg); }
.logo span { color: var(--blue); }
.title-mascot { width: min(58vw, 230px); height: min(46vw, 180px); margin: -4px 0 -6px; }
.title-mascot svg { width: 100%; height: 100%; overflow: visible; }
.title-stats { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; font-size: 13px; }
.chip { padding: 4px 10px; border-radius: 999px; background: #fff; border: 2px solid var(--ink); }
.title-main { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 10px; }
.btn-level { min-height: 74px; font-size: 26px; font-family: var(--font-num); font-weight: 400; flex-direction: column; gap: 0; }
.btn-level small { font-family: var(--font); font-weight: 700; }
.grades { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; width: 100%; max-width: 380px; }
.grades .btn { min-height: 48px; font-size: 16px; padding: 6px; }
.title-sub { display: grid; grid-template-columns: 1fr 1fr 48px; gap: 8px; width: 100%; max-width: 380px; margin-top: 4px; }
.title-sub .btn { min-height: 48px; font-size: 16px; padding: 6px 8px; }
.sec-lbl { font-size: 13px; color: var(--ink-2); margin: 4px 0 -4px; }

/* ---------- プレイ ---------- */
#scr-play { padding-bottom: env(safe-area-inset-bottom); }
.hud { display: flex; align-items: center; gap: 6px; padding: max(6px, env(safe-area-inset-top)) 8px 4px; z-index: 5; }
.hud-item { flex: 1; min-width: 0; background: rgba(255, 255, 255, 0.88); border: 2px solid var(--ink); border-radius: 12px; padding: 2px 4px; text-align: center; line-height: 1.1; }
.hud-lbl { display: block; font-size: 10px; color: var(--ink-2); }
.hud-item b { font-family: var(--font-num); font-weight: 400; font-size: 16px; white-space: nowrap; }
.hud-dopa { flex: 1.4; background: #fff4b8; }
.hud-clock.over b { color: var(--ink-2); }
.hud-clock.hurry { background: #ffd6d6; animation: pulse 0.5s infinite alternate; }
@keyframes pulse { to { transform: scale(1.06); } }
.progress { display: flex; gap: 4px; padding: 2px 12px 0; z-index: 5; }
.progress i { flex: 1; height: 7px; border-radius: 4px; background: rgba(42, 26, 46, 0.15); transition: background 0.3s; }
.progress i.done { background: var(--pink-d); }
.progress i.first { background: var(--blue); }
.progress i.cur { background: var(--gold); animation: pulse 0.6s infinite alternate; }

.stage { position: relative; flex: 0 0 clamp(86px, 19vh, 170px); z-index: 3; }
.mascot-slot { position: absolute; left: 50%; bottom: -6px; width: clamp(110px, 24vh, 190px); height: 100%; transform: translateX(-50%); }
.mascot-slot svg { position: absolute; bottom: 0; left: 0; width: 100%; height: auto; max-height: 118%; overflow: visible; }
.combo { position: absolute; right: 10px; top: 8px; text-align: right; opacity: 0; transition: opacity 0.2s, transform 0.2s; transform-origin: right top; }
.combo.on { opacity: 1; }
.combo-num b { font-family: var(--font-num); font-weight: 400; font-size: 34px; color: var(--pink-d); -webkit-text-stroke: 2px var(--ink); paint-order: stroke fill; }
.combo-num span { font-size: 14px; margin-left: 2px; }
.combo.max .combo-num span { color: #e0006e; }
.combo-bar { width: 96px; height: 7px; margin-left: auto; border-radius: 4px; background: rgba(0, 0, 0, 0.15); overflow: hidden; }
.combo-bar i { display: block; height: 100%; width: 100%; background: var(--blue); transform-origin: left; }
.combo-bar i.low { background: #ff4d6d; }
.extra-score { position: absolute; left: 10px; top: 8px; font-family: var(--font-num); font-size: 26px; color: var(--blue); -webkit-text-stroke: 2px var(--ink); paint-order: stroke fill; display: none; }
body.extra .extra-score { display: block; }
.crowd { position: absolute; left: 0; right: 0; bottom: -4px; height: 46px; display: flex; justify-content: space-between; padding: 0 4px; opacity: 0; transition: opacity 0.6s; pointer-events: none; }
body.crowd-on .crowd { opacity: 1; }
.crowd svg { width: 40px; height: 40px; animation: bob 0.5s ease-in-out infinite alternate; }
.crowd svg:nth-child(2n) { animation-delay: 0.25s; }
@keyframes bob { to { transform: translateY(-6px) rotate(4deg); } }

.paper-wrap { flex: 1 1 auto; min-height: 0; padding: 4px 10px 8px; z-index: 2; display: flex; }
.paper { position: relative; flex: 1; min-height: 0; display: flex; flex-direction: column; background: var(--paper); border: 3px solid var(--ink); border-radius: 20px; box-shadow: 0 6px 0 var(--ink);
  background-image: linear-gradient(var(--line) 1px, transparent 1px), linear-gradient(90deg, var(--line) 1px, transparent 1px); background-size: 22px 22px; background-position: -1px -1px; overflow: hidden; }
.paper.capsule { border-color: #ff8a00; box-shadow: 0 6px 0 #ff8a00; }
.ptitle { display: flex; justify-content: space-between; align-items: center; padding: 6px 12px 0; font-size: 13px; color: var(--ink-2); }
#p-tag { font-size: 11px; padding: 1px 8px; border-radius: 999px; background: var(--pink-l); color: var(--pink-d); }
#p-tag:empty { display: none; }
.pnote { text-align: center; font-size: 15px; padding: 2px 10px 0; min-height: 0; }
.pnote:empty { display: none; }
.pbody { position: relative; flex: 1; min-height: 0; display: grid; place-items: center; padding: 6px 10px; }
.phint { display: none; margin: 0 8px 8px; padding: 6px 10px; border-radius: 12px; background: #f1e8ff; border: 2px dashed var(--ng); font-size: 14px; text-align: center; }
.phint.on { display: block; animation: reveal 0.25s ease-out; }
.paper .hanamaru { position: absolute; inset: 0; pointer-events: none; }

/* 問題の描画 */
.prob { font-family: var(--font-num); font-weight: 400; line-height: 1; color: var(--ink); white-space: nowrap; }
.pline { display: flex; align-items: center; justify-content: center; gap: 0.22em; flex-wrap: nowrap; }
.pline .row { display: flex; align-items: center; gap: 0.22em; }
.plines { display: flex; flex-direction: column; align-items: center; gap: 0.35em; }
.tok.op { color: var(--pink-d); }
.tok.paren { color: var(--ink-2); }
.tok.var { font-family: 'Times New Roman', serif; font-style: italic; font-weight: 700; }
.tok.word { font-family: var(--font); font-weight: 900; font-size: 0.6em; }
.ans { display: inline-flex; align-items: flex-end; gap: 0.06em; }
.ans .pt { width: 0.3em; text-align: center; }
.frac { display: inline-flex; align-items: center; gap: 0.12em; }
.frac .fr { display: inline-flex; flex-direction: column; align-items: center; font-size: 0.8em; }
.frac .bar { width: 100%; min-width: 1em; height: 0.08em; background: currentColor; margin: 0.08em 0; border-radius: 1px; }

.cell { position: relative; display: inline-grid; place-items: center; width: 0.92em; height: 1.18em; border-radius: 0.14em; }
.cell.input { border: 0.06em dashed rgba(42, 26, 46, 0.35); background: rgba(255, 255, 255, 0.8); }
.cell.input.active { border: 0.07em solid var(--blue); background: #eaf2ff; box-shadow: 0 0 0 0.08em rgba(47, 121, 247, 0.25); animation: act 0.9s ease-in-out infinite alternate; }
@keyframes act { to { box-shadow: 0 0 0 0.16em rgba(47, 121, 247, 0.12); } }
.cell.input.ok { border-color: transparent; background: transparent; color: var(--ok); }
.cell.input.ng { border: 0.07em dotted var(--ng); background: #f4ecff; color: var(--ng); }
.cell.incoming > span { opacity: 0; }
.cell.land > span { animation: land 0.28s cubic-bezier(.3, 1.6, .5, 1); }
@keyframes land { from { transform: scale(1.6) translateY(-0.2em); } }
.cell.auto { color: #7a6a80; }
.cell.hidden { visibility: hidden; }
.cell.reveal { animation: reveal 0.35s ease-out; }
@keyframes reveal { from { opacity: 0; transform: translateY(-0.3em); } }
.cell.helper { font-size: 0.5em; width: 1.84em; height: 1.1em; color: #ff5a8a; font-family: var(--font); font-weight: 900; }
.cell.strike::after { content: ''; position: absolute; left: 10%; right: 10%; top: 50%; height: 0.07em; background: #ff5a8a; transform: rotate(-20deg); }
.cell.ref { background: #fff2a8 !important; border-radius: 0.2em; box-shadow: 0 0 0 0.08em var(--gold); }
.cell.flash { animation: flash 0.6s; }
@keyframes flash { 30% { background: #fff2a8; } }

.pgrid { position: relative; }
.pgrid > .gi { position: absolute; display: grid; place-items: center; }
.pgrid .hl { position: absolute; height: 0.07em; background: var(--ink); border-radius: 1px; }
.pgrid .hl.hidden { visibility: hidden; }
.pgrid .gi.op { color: var(--pink-d); }
.pgrid .gi.bracket { font-family: var(--font); font-weight: 500; transform: scaleY(1.35) translateX(0.12em); }

/* テンキー */
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); grid-auto-rows: var(--key-h); gap: 7px; padding: 4px 10px 10px; z-index: 5; }
.keypad button { border-radius: 16px; background: #fff; border: 3px solid var(--ink); box-shadow: 0 4px 0 var(--ink); font-family: var(--font-num); font-size: 28px; user-select: none; -webkit-user-select: none; }
.keypad button.press, .keypad button:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); background: var(--pink-l); }
.keypad .k-zero { grid-column: span 2; }
.keypad .k-back { background: #efe7f3; }
.keypad .k-back svg { width: 30px; height: 30px; margin: auto; fill: none; stroke: var(--ink); stroke-width: 2.2; stroke-linejoin: round; stroke-linecap: round; }

/* 運ばれる数字 */
.fly { position: fixed; z-index: 30; pointer-events: none; font-family: var(--font-num); color: var(--blue); -webkit-text-stroke: 1px #fff; paint-order: stroke fill; transform: translate(-50%, -50%); }
.fly.ng { color: var(--ng); }

/* ---------- 結果 ---------- */
.result-scroll { flex: 1; overflow-y: auto; padding: max(16px, env(safe-area-inset-top)) 16px 12px; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.result-actions { flex: 0 0 auto; display: grid; gap: 8px; padding: 10px 16px max(12px, env(safe-area-inset-bottom)); background: linear-gradient(transparent, rgba(255, 227, 239, 0.95) 22%); }
.result-actions .row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.result-actions .btn { min-height: 50px; font-size: 16px; padding: 6px 10px; }
.result-actions .btn.primary.big { min-height: 62px; font-size: 22px; font-family: var(--font-num); font-weight: 400; }
.score-big { font-family: var(--font-num); font-size: clamp(64px, 22vw, 110px); line-height: 1; color: #ff3b7f; -webkit-text-stroke: 4px var(--ink); paint-order: stroke fill; text-shadow: 0 6px 0 var(--ink); margin-top: 8px; }
.score-big small { font-size: 0.4em; }
.card { width: 100%; max-width: 420px; background: #fff; border: 3px solid var(--ink); border-radius: 18px; padding: 12px 14px; box-shadow: 0 5px 0 var(--ink); }
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.stat { background: var(--cream); border-radius: 12px; padding: 6px 10px; }
.stat span { display: block; font-size: 12px; color: var(--ink-2); }
.stat b { font-family: var(--font-num); font-weight: 400; font-size: 22px; }
.news { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.news li { display: flex; gap: 8px; align-items: center; font-size: 15px; padding: 6px 8px; border-radius: 10px; background: var(--pink-l); }
.news li.star { background: #fff4c2; }
.news li.blue { background: #e3eeff; }
.card h3 { margin: 0 0 8px; font-size: 15px; }
.extra-hint { font-size: 13px; color: var(--ink-2); text-align: center; }

/* ---------- スキルツリー ---------- */
.subhead { display: flex; align-items: center; gap: 10px; padding: max(10px, env(safe-area-inset-top)) 12px 8px; }
.subhead h2 { margin: 0; font-size: 20px; flex: 1; }
.tree-legend { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 12px 6px; font-size: 11px; }
.tree-scroll { flex: 1; overflow: auto; padding: 0 0 20px; -webkit-overflow-scrolling: touch; }
.tree { position: relative; margin: 0 8px; }
.tree svg.links { position: absolute; inset: 0; pointer-events: none; overflow: visible; }
.tree .fam { position: absolute; top: 0; height: 26px; display: grid; place-items: center; font-size: 12px; border-radius: 8px; color: #fff; }
.tree .band { position: absolute; left: 0; right: 0; border-top: 2px dashed rgba(42, 26, 46, 0.15); font-size: 11px; color: var(--ink-2); padding-left: 2px; }
.node { position: absolute; width: 104px; min-height: 58px; padding: 4px 6px; border-radius: 12px; border: 2.5px solid var(--ink); background: #fff; font-size: 11px; line-height: 1.2; text-align: left; box-shadow: 0 3px 0 var(--ink); user-select: none; -webkit-user-select: none; }
.node .nm { display: block; font-weight: 900; }
.node .st { display: flex; justify-content: space-between; align-items: center; margin-top: 3px; font-size: 10px; }
.node .stars { color: #e6a700; letter-spacing: -1px; font-size: 11px; }
.node.lock { background: #eee7ee; color: #9a8da0; border-color: #9a8da0; box-shadow: 0 3px 0 #9a8da0; }
.node.new { background: #fffbe0; }
.node.practice { background: #e8f1ff; }
.node.master { background: var(--pink-l); }
.node .badge { padding: 0 5px; border-radius: 6px; background: var(--ink); color: #fff; font-size: 9px; }
.node.new .badge { background: #ff9d00; }
.node.practice .badge { background: var(--blue); }
.node.master .badge { background: var(--pink-d); }
.node .rust { position: absolute; top: -8px; right: -6px; padding: 0 5px; border-radius: 6px; background: #a0522d; color: #fff; font-size: 9px; }
.node.pressing { transform: scale(0.96); }

/* ---------- 設定 ---------- */
.settings { flex: 1; overflow-y: auto; padding: 4px 16px 24px; display: flex; flex-direction: column; gap: 12px; }
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.set-row label { font-size: 16px; }
.seg { display: flex; border: 3px solid var(--ink); border-radius: 14px; overflow: hidden; }
.seg button { padding: 8px 14px; background: #fff; font-weight: 900; }
.seg button[aria-pressed="true"] { background: var(--pink); }
.seg button + button { border-left: 2px solid var(--ink); }
input[type=range] { width: 160px; accent-color: var(--pink-d); }
.set-row output { width: 44px; text-align: right; font-size: 14px; }

/* ---------- ダイアログ ---------- */
.dlg-back { position: fixed; inset: 0; z-index: 60; background: rgba(42, 26, 46, 0.45); display: grid; place-items: center; padding: 16px; animation: fade 0.15s; }
.dlg { width: 100%; max-width: 380px; max-height: 86vh; overflow-y: auto; background: #fff; border: 3px solid var(--ink); border-radius: 20px; padding: 16px; box-shadow: 0 6px 0 var(--ink); animation: pop 0.2s cubic-bezier(.3, 1.5, .5, 1); }
.dlg h3 { margin: 0 0 8px; font-size: 20px; }
.dlg .body { font-size: 15px; line-height: 1.6; }
.dlg .btns { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.dlg .btns .btn { flex: 1; min-height: 48px; font-size: 16px; padding: 6px 12px; }
.dlg .ex { font-family: var(--font-num); font-size: 22px; text-align: center; padding: 8px; background: var(--cream); border-radius: 12px; margin: 8px 0; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { transform: scale(0.85); opacity: 0; } }

/* ---------- 演出 ---------- */
#fx { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 20; }
#overlay { position: fixed; left: 0; right: 0; top: max(70px, 11vh); pointer-events: none; z-index: 25; display: flex; justify-content: center; }
#overlay .banner { font-family: var(--font-num); font-size: clamp(30px, 9vw, 50px); color: #fff; -webkit-text-stroke: 4px var(--ink); paint-order: stroke fill; text-shadow: 0 5px 0 var(--ink); animation: banner 1.1s cubic-bezier(.2, 1.4, .4, 1) forwards; text-align: center; line-height: 1.1; }
#overlay .banner.pink { color: var(--pink); }
#overlay .banner.gold { color: var(--gold); }
#overlay .banner.blue { color: #7fb0ff; }
#overlay .banner small { display: block; font-size: 0.45em; }
@keyframes banner { 0% { transform: scale(0.2) rotate(-12deg); opacity: 0; } 25% { transform: scale(1.15) rotate(3deg); opacity: 1; } 40% { transform: scale(1) rotate(-2deg); } 80% { opacity: 1; } 100% { transform: scale(1.05); opacity: 0; } }
#toasts { position: fixed; top: max(56px, calc(env(safe-area-inset-top) + 50px)); left: 50%; transform: translateX(-50%); z-index: 50; display: grid; gap: 6px; width: min(92vw, 420px); pointer-events: none; }
.toast { padding: 8px 12px; border-radius: 14px; background: #fff; border: 2.5px solid var(--ink); box-shadow: 0 3px 0 var(--ink); font-size: 14px; text-align: center; animation: toast 2.6s forwards; }
.toast.star { background: #fff4c2; }
.toast.master { background: var(--pink-l); }
@keyframes toast { 0% { transform: translateY(-20px); opacity: 0; } 10%, 85% { transform: none; opacity: 1; } 100% { opacity: 0; transform: translateY(-8px); } }
.finale { position: fixed; inset: 0; z-index: 45; display: grid; place-items: center; background: rgba(255, 255, 255, 0.2); pointer-events: auto; }
.finale .fin-mascot { width: min(80vw, 420px); animation: giant 1.4s cubic-bezier(.2, 1.3, .4, 1) both; }
.finale .fin-score { position: absolute; bottom: 16%; font-family: var(--font-num); font-size: clamp(56px, 18vw, 110px); color: #ff3b7f; -webkit-text-stroke: 5px var(--ink); paint-order: stroke fill; text-shadow: 0 6px 0 var(--ink); animation: banner 2.6s 0.6s cubic-bezier(.2, 1.4, .4, 1) both; }
@keyframes giant { from { transform: translateY(80%) scale(0.3); } }
.shake { animation: shake 0.28s; }
@keyframes shake { 20% { transform: translate(calc(-5px * var(--motion)), calc(2px * var(--motion))); } 40% { transform: translate(calc(4px * var(--motion)), calc(-3px * var(--motion))); } 60% { transform: translate(calc(-3px * var(--motion)), 0); } 80% { transform: translate(calc(2px * var(--motion)), calc(1px * var(--motion))); } }
body.beat .hud-dopa { transform: scale(1.04); }
.reach { position: absolute; left: 50%; top: 4px; transform: translateX(-50%); padding: 2px 12px; border-radius: 999px; background: #ff3b7f; color: #fff; font-size: 13px; border: 2px solid var(--ink); animation: pulse 0.4s infinite alternate; display: none; }
body.reach-on .reach { display: block; }

/* ---------- 低い画面 ---------- */
@media (max-height: 700px) {
  .stage { flex-basis: clamp(70px, 15vh, 110px); }
  .keypad { gap: 5px; padding: 2px 8px 6px; }
  .hud-item b { font-size: 14px; }
  .paper-wrap { padding: 2px 8px 6px; }
  .ptitle { padding-top: 3px; }
  :root { --key-h: max(48px, 7.4vh); }
}
@media (prefers-reduced-motion: reduce) {
  #bg .rays { animation-duration: 600s; }
}
body.still #bg .rays, body.still .crowd svg, body.still .cell.active { animation: none !important; }

.pts { position: fixed; z-index: 30; pointer-events: none; font-family: var(--font-num); font-size: 22px; color: var(--gold); -webkit-text-stroke: 2px var(--ink); paint-order: stroke fill; animation: pts 0.9s ease-out forwards; }
@keyframes pts { from { transform: translateY(0) scale(0.6); opacity: 0; } 20% { transform: translateY(-6px) scale(1.2); opacity: 1; } to { transform: translateY(-34px) scale(1); opacity: 0; } }

/* タブレットの縦横・短い表示領域。ブラウザーの拡大も制限しない。 */
:root { --warning-h: 0px; }
html { padding: 0; }
#app { height: calc(var(--vh) - var(--warning-h)); max-width: 760px; }
#storage-warning { position: relative; z-index: 70; background: #fff2bd; border-bottom: 2px solid #805b00; color: #493300; padding: 8px max(12px, env(safe-area-inset-left)); font-size: 13px; line-height: 1.4; }
.screen { min-height: 0; }
.hud, .subhead, .progress, .keypad { flex-shrink: 0; }
.settings { align-items: center; overscroll-behavior: contain; }
.settings .card { flex-shrink: 0; max-width: 560px; }
.seg button { min-width: 48px; min-height: 48px; }
.set-row { flex-wrap: wrap; }
input[type=range] { min-height: 44px; max-width: 48%; }
.backup-card p { font-size: 14px; line-height: 1.6; margin: 6px 0 12px; }
.backup-card p.small { font-size: 12px; }
.backup-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.backup-actions .btn { flex: 1; min-width: 120px; }
#undo-import { width: 100%; font-size: 15px; }
.dlg { max-height: calc(var(--vh) - 32px); overscroll-behavior: contain; }
.tree-scroll { overscroll-behavior: contain; }
@media (min-width: 760px) and (orientation: landscape) {
  #app { max-width: 1120px; }
  #scr-play.on { display: grid; grid-template-columns: minmax(0, 1fr) minmax(240px, 32%); grid-template-rows: auto 12px minmax(70px, 21%) minmax(0, 1fr); }
  .hud { grid-column: 1 / -1; }
  .progress { grid-column: 1 / -1; }
  .stage { grid-column: 1; grid-row: 3; min-height: 0; }
  .paper-wrap { grid-column: 1; grid-row: 4; min-width: 0; }
  .keypad { grid-column: 2; grid-row: 3 / 5; grid-template-rows: repeat(4, minmax(48px, 1fr)); grid-auto-rows: auto; align-self: stretch; padding: 10px 12px 14px 4px; gap: 10px; }
  .keypad button { font-size: 34px; }
  .ptitle { font-size: 15px; }
  .hud-item b { font-size: 20px; }
  .hud-lbl { font-size: 12px; }
  .hud { padding-top: max(10px, env(safe-area-inset-top)); }
}
@media (max-height: 540px) and (max-width: 759px) {
  #scr-play { overflow-y: auto; }
  .stage { flex-basis: 50px; }
  .paper-wrap { flex: 1 0 160px; }
  .keypad { --key-h: 48px; }
}
@media (min-width: 600px) and (orientation: portrait) {
  .keypad { --key-h: clamp(58px, 8vh, 84px); gap: 10px; padding: 8px 18px 16px; }
  .paper-wrap { padding-left: 18px; padding-right: 18px; }
  .hud-lbl { font-size: 12px; }
  .hud-item b { font-size: 20px; }
}
body.still .progress i, body.still .hud-clock, body.still .reach, body.still #bg { animation: none !important; }
