:root {
  --pink: #FF4FA3; --gold: #FFD23F; --sofa: #7FB7C9; --ink: #2B2320; --paper: #FFFDF4;
  --sat: env(safe-area-inset-top, 0px); --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px); --sar: env(safe-area-inset-right, 0px);
  --font: "Hiragino Maru Gothic ProN", "Hiragino Sans", "BIZ UDPGothic", "Yu Gothic UI", "Meiryo", system-ui, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body, body * { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; -webkit-user-drag: none; touch-action: none; }
input[type="range"] { touch-action: none; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #7FB7C9; font-family: var(--font); color: var(--ink); overscroll-behavior: none; }
body { position: fixed; inset: 0; touch-action: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
#app { position: fixed; inset: 0; overflow: hidden; }
#scene, #fx { position: absolute; left: 0; top: 0; width: 100%; height: 100%; display: block; }
#fx { pointer-events: none; }
#danger { position: absolute; inset: 0; pointer-events: none; opacity: 0; box-shadow: inset 0 0 min(16vmin, 100px) min(4vmin, 26px) rgba(255, 40, 40, 0.7); }
#glow { position: absolute; inset: 0; pointer-events: none; opacity: 0; box-shadow: inset 0 0 min(14vmin, 90px) min(3vmin, 20px) rgba(255, 79, 163, 0.75); transition: opacity 0.25s; }
.hidden { display: none !important; }

button { font-family: var(--font); cursor: pointer; }
.btn {
  border: none; border-radius: 999px; font-weight: 900; white-space: nowrap; overflow: hidden; text-overflow: clip;
  color: #fff; background: var(--pink); box-shadow: 0 0.35em 0 #C92E7A, 0 0.5em 1em rgba(0,0,0,0.12);
  padding: 0.5em 1.2em; transition: transform 0.12s cubic-bezier(.3,1.6,.5,1), box-shadow 0.12s; font-size: clamp(14px, 4.4vmin, 22px); line-height: 1.2;
}
.btn:active { transform: translateY(0.25em) scale(0.97); box-shadow: 0 0.1em 0 #C92E7A; }
.btn.main { font-size: clamp(18px, 6.4vmin, 32px); padding: 0.45em 1.6em; background: linear-gradient(#FF6DB6, #FF4FA3); }
.btn.sub { background: #fff; color: var(--ink); box-shadow: 0 0.3em 0 #9DBFCB, 0 0.4em 0.8em rgba(0,0,0,0.1); font-size: clamp(12px, 3.8vmin, 18px); padding: 0.45em 1em; }
.btn.sub:active { box-shadow: 0 0.08em 0 #9DBFCB; }
.row { display: flex; gap: clamp(6px, 2vmin, 12px); justify-content: center; flex-wrap: nowrap; }

.screen { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; }

/* タイトル */
#title { justify-content: space-between; padding: calc(var(--sat) + 3vh) calc(var(--sar) + 12px) calc(var(--sab) + 2.5vh) calc(var(--sal) + 12px); pointer-events: none; }
#title > * { pointer-events: auto; }
.logoWrap { position: relative; margin-top: 1vh; max-width: 100%; }
.logo {
  margin: 0; font-weight: 900; letter-spacing: 0.02em; white-space: nowrap;
  font-size: min(12.5vw, 11vh, 72px); color: var(--pink);
  -webkit-text-stroke: 0.14em #fff; paint-order: stroke fill;
  text-shadow: 0 0.07em 0 #C92E7A, 0 0.14em 0.2em rgba(0,0,0,0.18);
  transform: rotate(-3deg);
}
.kira { position: absolute; width: 0.9em; height: 0.9em; font-size: min(7vw, 6vh, 38px); background: var(--gold);
  clip-path: polygon(50% 0, 60% 40%, 100% 50%, 60% 60%, 50% 100%, 40% 60%, 0 50%, 40% 40%); animation: kira 1.6s ease-in-out infinite; }
.kira.k1 { right: -0.3em; top: -0.4em; }
.kira.k2 { left: -0.2em; bottom: -0.1em; animation-delay: 0.5s; font-size: min(4.5vw, 4vh, 24px); }
.kira.k3 { right: 30%; top: -0.7em; animation-delay: 1s; font-size: min(3.5vw, 3vh, 18px); }
@keyframes kira { 0%,100% { transform: scale(0.5) rotate(0); opacity: 0.6; } 50% { transform: scale(1.1) rotate(20deg); opacity: 1; } }
.bests { font-size: clamp(11px, 3.2vmin, 15px); font-weight: 700; color: #fff; text-shadow: 0 1px 2px rgba(0,0,0,0.35); white-space: nowrap; text-align: center; }
.menu { display: flex; flex-direction: column; align-items: center; gap: clamp(4px, 1.2vh, 10px); max-width: 100%; }
.diffLabel { font-size: clamp(11px, 3.2vmin, 15px); font-weight: 900; color: #fff; text-shadow: 0 1px 2px rgba(0,0,0,0.35); }
.seg { display: flex; gap: 6px; background: rgba(255,255,255,0.55); padding: 4px; border-radius: 999px; }
.seg1 { background: transparent; color: var(--ink); box-shadow: none; font-size: clamp(12px, 3.9vmin, 18px); padding: 0.4em 0.9em; }
.seg1.on { background: var(--gold); box-shadow: 0 0.2em 0 #D9A400; }
.seg1:active { transform: scale(0.96); box-shadow: none; }
.diffDesc { font-size: clamp(11px, 3.3vmin, 15px); font-weight: 700; color: var(--ink); background: rgba(255,255,255,0.75); padding: 0.25em 0.9em; border-radius: 0.6em; white-space: nowrap; max-width: 100%; }

/* 遊び方・音量・一時停止 */
#howto, #volume, #pause { justify-content: center; background: rgba(127,183,201,0.55); padding: calc(var(--sat) + 10px) calc(var(--sar) + 10px) calc(var(--sab) + 10px) calc(var(--sal) + 10px); }
.card { background: var(--paper); border-radius: 22px; padding: clamp(10px, 3vmin, 22px) clamp(12px, 4vmin, 26px); box-shadow: 0 10px 30px rgba(0,0,0,0.2); width: min(94vw, 520px); max-height: 100%; overflow: hidden; display: flex; flex-direction: column; gap: clamp(4px, 1.4vh, 10px); align-items: stretch; }
.card.small { width: min(90vw, 360px); align-items: center; }
.card h2 { margin: 0; text-align: center; font-size: clamp(18px, 5.5vmin, 28px); color: var(--pink); }
.step { display: flex; align-items: center; gap: 10px; }
.step canvas { width: clamp(52px, 17vmin, 96px); height: auto; aspect-ratio: 120/96; flex: none; border-radius: 12px; background: #FDE7D6; }
.step p { margin: 0; font-size: clamp(12px, 3.8vmin, 17px); font-weight: 700; line-height: 1.35; }
.joy { margin: 0; text-align: center; font-weight: 900; color: var(--pink); font-size: clamp(14px, 4.6vmin, 22px); }
.tapclose { margin: 0; text-align: center; font-size: clamp(11px, 3vmin, 14px); color: #8A7A75; }
.vol { display: flex; align-items: center; gap: 10px; width: 100%; font-weight: 700; font-size: clamp(13px, 3.8vmin, 17px); }
.vol span { width: 4.2em; flex: none; white-space: nowrap; }
.vol input { flex: 1; min-width: 0; accent-color: var(--pink); height: 28px; }

/* プレイ中 */
#hud { position: absolute; inset: 0; pointer-events: none; }
#hudTop { position: absolute; left: 50%; top: calc(var(--sat) + 6px); transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 0; white-space: nowrap; line-height: 1.2;
  font-weight: 900; font-size: clamp(13px, 4.2vmin, 20px); color: #fff; text-shadow: 0 1px 0 rgba(0,0,0,0.35), 0 0 6px rgba(40,80,100,0.6); }
#hudClock { font-size: 1.25em; letter-spacing: 0.03em; }
.hudRow { display: flex; gap: 0.7em; align-items: baseline; }
#hudRoll { font-size: 0.78em; color: #FFF3B0; }
#hudRoll.soon { color: #FF8A8A; animation: glowtxt 0.8s ease-in-out infinite; }
@keyframes glowtxt { 50% { text-shadow: 0 0 10px #FFD23F, 0 1px 0 rgba(0,0,0,0.35); } }
body.land #hudTop { left: calc(var(--sal) + 12px); top: 22%; transform: none; align-items: flex-start; gap: 0.25em; }
body.land .hudRow { flex-direction: column; gap: 0.25em; }
#hudNear { position: absolute; left: 0; top: 0; text-align: center; white-space: nowrap; font-weight: 900; will-change: transform; }
#hudDopa { font-size: clamp(11px, 3.2vmin, 14px); color: #fff; text-shadow: 0 1px 2px rgba(0,0,0,0.5); }
#hudChain { font-size: clamp(18px, 6vmin, 28px); color: var(--pink); -webkit-text-stroke: 0.16em #fff; paint-order: stroke fill; line-height: 1; min-height: 1em; }
#hudChain.bump { animation: bump 0.25s ease-out; }
@keyframes bump { 0% { transform: scale(1.3); } 100% { transform: scale(1); } }
.iconbtn { position: absolute; top: calc(var(--sat) + 6px); right: calc(var(--sar) + 8px); width: 44px; height: 44px; border-radius: 50%; border: none; background: rgba(255,255,255,0.7); pointer-events: auto; display: flex; gap: 6px; align-items: center; justify-content: center; box-shadow: 0 2px 6px rgba(0,0,0,0.15); }
.iconbtn span { width: 5px; height: 16px; background: var(--ink); border-radius: 2px; }

#pops { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.pop { position: absolute; left: 0; top: 0; white-space: nowrap; font-weight: 900; pointer-events: none; will-change: transform, opacity; }
.pop.gain { color: var(--pink); -webkit-text-stroke: 0.18em #fff; paint-order: stroke fill; font-size: clamp(16px, 5vmin, 24px); }
.pop.gain.big { color: var(--gold); -webkit-text-stroke: 0.18em #C92E7A; }
.pop.hint { font-size: clamp(11px, 3.4vmin, 15px); color: var(--ink); background: rgba(255,255,255,0.88); padding: 0.15em 0.6em; border-radius: 0.8em; }
.pop.voice { font-size: clamp(14px, 4.5vmin, 20px); color: #4F79A8; -webkit-text-stroke: 0.15em #fff; paint-order: stroke fill; }
.pop.shout { font-size: clamp(22px, 7vmin, 34px); color: var(--pink); -webkit-text-stroke: 0.16em #fff; paint-order: stroke fill; }

/* 区切り */
#result { justify-content: space-between; padding: calc(var(--sat) + 10px) calc(var(--sar) + 10px) calc(var(--sab) + 12px) calc(var(--sal) + 10px); gap: 6px; }
.resHead { font-weight: 900; font-size: clamp(22px, 7.5vmin, 40px); color: var(--pink); -webkit-text-stroke: 0.2em #fff; paint-order: stroke fill; white-space: nowrap; text-shadow: 0 3px 0 rgba(0,0,0,0.12); animation: pophead 0.5s cubic-bezier(.3,1.6,.5,1); }
.resHead.fail { color: #E0507A; }
@keyframes pophead { from { transform: scale(0.4); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.sheetWrap { flex: 1; min-height: 0; width: 100%; display: flex; align-items: center; justify-content: center; }
#resSheet { max-width: 100%; max-height: 100%; width: auto; height: auto; border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,0.22); transform: translateY(110vh); transition: transform 0.7s cubic-bezier(.2,1.1,.3,1); aspect-ratio: 720 / 900; }
#resSheet.in { transform: translateY(0); }
.resStats { font-weight: 900; font-size: clamp(11px, 3.5vmin, 17px); color: #fff; text-shadow: 0 1px 2px rgba(0,0,0,0.45); white-space: nowrap; text-align: center; line-height: 1.35; }
.resBtns { display: flex; flex-direction: column; align-items: center; gap: 10px; }
body.land #result { display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: auto 1fr auto; column-gap: 12px; }
body.land #result .sheetWrap { grid-column: 1; grid-row: 1 / span 3; height: 100%; }
body.land #result .resHead { grid-column: 2; grid-row: 1; justify-self: center; }
body.land #result .resStats { grid-column: 2; grid-row: 2; align-self: center; justify-self: center; white-space: normal; text-align: center; }
body.land #result .resBtns { grid-column: 2; grid-row: 3; }
#toast { position: absolute; left: 50%; bottom: calc(var(--sab) + 18px); transform: translateX(-50%); background: rgba(43,35,32,0.85); color: #fff; padding: 0.4em 1em; border-radius: 999px; font-weight: 700; font-size: clamp(12px, 3.6vmin, 16px); white-space: nowrap; pointer-events: none; }

/* 横向き：タイトルは左に題字、右にボタン */
body.land #title { display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: 1fr auto; align-items: center; justify-items: center; }
body.land #title .logoWrap { grid-column: 1; grid-row: 1 / span 2; }
body.land #title .menu { grid-column: 2; grid-row: 1 / span 2; }
body.land .logo { font-size: min(7.5vw, 13vh, 64px); }

/* ---- 追加依頼2：スマホ縦の上の帯・押せボタン・大演出の文字 ---- */
.btn, .seg1, .iconbtn { min-height: 44px; }
.btn.sub { min-width: 44px; }
body:not(.land) #hudTop { left: calc(var(--sal) + 8px); top: calc(var(--sat) + 4px); transform: none; align-items: flex-start; font-size: clamp(11px, 3.3vmin, 15px); max-width: calc(var(--lcdL) - 12px); overflow: hidden; }
body:not(.land) .hudRow { flex-direction: column; gap: 0; }
body:not(.land) #hudClock { font-size: 1.3em; }
#btnOse { white-space: nowrap; position: absolute; left: 50%; bottom: calc(var(--sab) + 22%); transform: translateX(-50%); width: clamp(96px, 30vmin, 140px); height: clamp(96px, 30vmin, 140px); border-radius: 50%; border: 6px solid #fff;
  background: radial-gradient(circle at 35% 30%, #FFF3A6, #FFC61A 45%, #E08A00); color: #7A2E00; font-family: var(--font); font-weight: 900; font-size: clamp(20px, 6.5vmin, 30px); padding: 0;
  box-shadow: 0 8px 0 #A85C00, 0 0 30px rgba(255,210,63,0.9); animation: ose 0.7s ease-in-out infinite; z-index: 5; }
#btnOse:active { transform: translateX(-50%) translateY(6px); box-shadow: 0 2px 0 #A85C00; }
@keyframes ose { 50% { box-shadow: 0 8px 0 #A85C00, 0 0 50px rgba(255,120,200,1); } }
#showText { position: absolute; left: 0; right: 0; bottom: calc(var(--sab) + 9%); text-align: center; pointer-events: none; font-weight: 900; color: #fff; }
#showCount { font-size: clamp(22px, 8vmin, 42px); -webkit-text-stroke: 0.14em #2B0B2E; paint-order: stroke fill; }
#showSub { font-size: clamp(12px, 3.6vmin, 18px); -webkit-text-stroke: 0.14em #2B0B2E; paint-order: stroke fill; }
#showSkip { font-size: clamp(12px, 3.4vmin, 15px); margin-top: 6px; -webkit-text-stroke: 0.14em #2B0B2E; paint-order: stroke fill; }

/* ---- 追加依頼4：左下「うごかす」パッド・右下「つまむ」ボタン ---- */
#ctrl { position: absolute; left: 0; right: 0; top: var(--ctrlTop, 70%); height: var(--ctrlH, 24%); display: flex; pointer-events: none; }
#ctrl .zone { flex: 1; position: relative; pointer-events: auto; touch-action: none; display: flex; align-items: center; justify-content: center; }
body:not(.land) #ctrl { background: linear-gradient(#5E9DB3, #3E768E); border-top: 3px solid rgba(255,255,255,0.55); box-shadow: 0 -6px 12px rgba(20,50,70,0.18); }
body.land #ctrl { top: 50%; height: 50%; }
body.land #ctrl .zone { flex: none; position: absolute; top: 0; bottom: 0; width: var(--ctrlMargin, 25%); }
body.land #padL { left: 0; } body.land #btnR { right: 0; }
.padVis, .btnVis { position: relative; width: var(--ctrlD, 130px); height: var(--ctrlD, 130px); border-radius: 50%; pointer-events: none; }
.padVis svg { width: 100%; height: 100%; }
.padVis .ring { fill: rgba(255,255,255,0.22); stroke: rgba(255,255,255,0.85); stroke-width: 3; }
.padVis .arw { fill: rgba(255,255,255,0.9); }
.padVis .knob { fill: rgba(255,255,255,0.55); }
#padL.active .padVis .ring { fill: rgba(255,255,255,0.38); }
.btnVis { background: radial-gradient(circle at 35% 30%, #FFE7F3, #FF6DB6 55%, #D93A8A); box-shadow: 0 6px 0 #A8286A, 0 8px 16px rgba(0,0,0,0.2); border: 4px solid #fff; }
#btnR.active .btnVis { transform: translateY(4px); box-shadow: 0 2px 0 #A8286A; }
#btnCv { position: absolute; inset: 0; width: 100%; height: 100%; }
.ctrlLabel { position: absolute; left: 50%; bottom: -2px; transform: translate(-50%, 100%); font-weight: 900; font-size: clamp(11px, 3.2vmin, 14px); color: #fff; text-shadow: 0 1px 2px rgba(0,0,0,0.45); white-space: nowrap; }
body:not(.land) .ctrlLabel { bottom: auto; top: 50%; writing-mode: vertical-rl; letter-spacing: 0.1em; }
body:not(.land) #padL .ctrlLabel { left: calc((var(--ctrlD) - 50vw) / 2 + 4px); transform: translate(0, -50%); }
body:not(.land) #btnR .ctrlLabel { left: auto; right: calc((var(--ctrlD) - 50vw) / 2 + 4px); transform: translate(0, -50%); }
#btnOse.onctrl { left: var(--oseX); top: var(--oseY); bottom: auto; transform: translate(-50%, -50%); }
#btnOse.onctrl:active { transform: translate(-50%, -46%); }
body.land .ctrlLabel { bottom: auto; top: -2px; transform: translate(-50%, -100%); }

/* ---- 追加依頼6：導入（お話） ---- */
.tagline { margin: 0.3em 0 0; text-align: center; font-weight: 900; font-size: clamp(11px, 3.4vmin, 16px); color: #fff; text-shadow: 0 1px 3px rgba(0,0,0,0.4); white-space: nowrap; }
#story { position: absolute; inset: 0; z-index: 6; }
#storyCap { position: absolute; left: 50%; bottom: calc(var(--sab) + var(--capB, 24%)); transform: translateX(-50%); max-width: calc(100% - 24px); padding: 0.35em 0.9em; border-radius: 0.6em; background: rgba(20,20,30,0.62); color: #fff; font-weight: 900; font-size: clamp(13px, 4.2vmin, 20px); white-space: nowrap; text-align: center; }
#btnSkip { position: absolute; top: calc(var(--sat) + 8px); right: calc(var(--sar) + 8px); }
