:root {
  --cream: #F4EAD5; --lamp: #F2A541; --night: #1F2A44; --red: #D9483B; --green: #6BA368; --blue: #4A86C5;
  --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);
  --fs: clamp(12px, min(2.2vw, 3.6vh), 18px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: #0d1220; overflow: hidden; overscroll-behavior: none; }
body { font-family: "Hiragino Maru Gothic ProN", "Yu Gothic", "Noto Sans JP", sans-serif; color: var(--cream); user-select: none; -webkit-user-select: none; touch-action: none; }
#app { position: fixed; inset: 0; overflow: hidden; }
#c { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
#vignette { position: absolute; inset: 0; pointer-events: none; background: radial-gradient(ellipse at 45% 42%, rgba(0,0,0,0) 52%, rgba(5,6,14,0.55) 100%); }
#ribbons { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; overflow: hidden; }
.hidden { display: none !important; }

button { font-family: inherit; color: inherit; cursor: pointer; white-space: nowrap; touch-action: manipulation; }
button.big { font-size: calc(var(--fs) * 1.15); padding: 0.5em 1.3em; border-radius: 999px; border: 2px solid rgba(244,234,213,0.8); background: rgba(217,72,59,0.92); color: #fffaf0; box-shadow: 0 3px 0 rgba(0,0,0,0.3); min-height: 44px; }
button.big:active { transform: translateY(2px); box-shadow: none; }
button.small { font-size: var(--fs); padding: 0.35em 0.9em; border-radius: 999px; border: 1.5px solid rgba(244,234,213,0.6); background: rgba(31,42,68,0.75); min-height: 40px; }
.iconbtn { position: absolute; width: 44px; height: 44px; border-radius: 50%; border: 1.5px solid rgba(244,234,213,0.5); background: rgba(31,42,68,0.55); padding: 10px; }
.iconbtn svg { width: 100%; height: 100%; fill: var(--cream); }
#pauseBtn { top: calc(8px + var(--sat)); right: calc(10px + var(--sar)); }

/* HUD：状態は文字の色と光で */
#hud { position: absolute; top: calc(6px + var(--sat)); left: 50%; transform: translateX(-50%); display: flex; gap: 1.1em; align-items: center; font-size: var(--fs); white-space: nowrap; pointer-events: none; text-shadow: 0 1px 3px rgba(0,0,0,0.8), 0 0 8px rgba(0,0,0,0.5); }
#hMig { color: #f7d58a; }
#hMig.flash { color: #fff6d0; text-shadow: 0 0 10px #F2A541, 0 0 3px #F2A541; }
#hShiori { display: inline-flex; gap: 3px; align-items: center; }
#hShiori i { display: inline-block; width: 6px; height: 1.2em; background: var(--red); clip-path: polygon(0 0,100% 0,100% 100%,50% 82%,0 100%); transition: opacity .3s, transform .3s; }
#hShiori i.off { opacity: 0.18; transform: scaleY(0.7); }
#hShiori.glow i { filter: drop-shadow(0 0 4px #ffd27a); }

#meter { position: absolute; width: 80px; height: 48px; pointer-events: none; left: 0; top: 0; }
#floats { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.float { position: absolute; font-size: calc(var(--fs) * 1.05); color: #fff5d6; text-shadow: 0 0 8px #F2A541, 0 1px 2px rgba(0,0,0,0.6); transform: translate(-50%, -50%); white-space: nowrap; animation: floatUp 1.4s ease-out forwards; }
@keyframes floatUp { 0% { opacity: 0; transform: translate(-50%, -30%) scale(0.7); } 15% { opacity: 1; transform: translate(-50%, -60%) scale(1.08); } 100% { opacity: 0; transform: translate(-50%, -140%) scale(1); } }
#note { position: absolute; left: 50%; top: 40%; transform: translate(-50%, -50%); font-size: calc(var(--fs) * 1.6); color: #fff1d2; text-shadow: 0 0 12px rgba(242,165,65,0.8), 0 2px 4px rgba(0,0,0,0.7); pointer-events: none; white-space: nowrap; }

#tabHit { position: absolute; width: 64px; height: 64px; border: none; background: transparent; border-radius: 12px; transform: translate(-50%, -50%); }
#tabHit.ready::after { content: ""; position: absolute; inset: 14px; border-radius: 8px; box-shadow: 0 0 0 2px rgba(255,241,210,0.55); animation: tabPulse 1.6s ease-in-out infinite; }
@keyframes tabPulse { 50% { box-shadow: 0 0 0 4px rgba(255,241,210,0.15); } }

#finger, .finger { position: absolute; width: 44px; height: 66px; pointer-events: none; transform: translate(-50%, -50%); }
#finger svg, .finger svg { width: 100%; height: 100%; }
.finger { width: 40px; height: 60px; pointer-events: none; transform: translate(-50%, -20%); }

/* タイトル */
#title { position: absolute; inset: 0; pointer-events: none; }
#title button { pointer-events: auto; }
#titleTop { position: absolute; top: calc(8px + var(--sat)); right: calc(10px + var(--sar)); display: flex; gap: 6px; }
#titleBar { position: absolute; left: calc(8px + var(--sal)); right: calc(8px + var(--sar)); bottom: calc(10px + var(--sab)); display: flex; align-items: flex-end; justify-content: center; gap: clamp(8px, 2.5vw, 28px); flex-wrap: wrap; }
#bookDesc { position: absolute; left: 50%; transform: translateX(-50%); bottom: calc(env(safe-area-inset-bottom) + clamp(62px, 13vh, 96px)); width: min(92vw, 640px); text-align: center; font-size: clamp(11px, 1.8vw, 15px); color: #fff6e2; background: rgba(20,18,24,0.72); padding: 0.35em 0.9em; border-radius: 4px; width: auto; max-width: min(92vw, 640px); pointer-events: none; }
#ribbonRow { display: flex; gap: clamp(4px, 1.6vw, 18px); }
.ribbon { position: relative; font-size: var(--fs); padding: 0.45em 0.8em; min-height: 44px; border-radius: 8px 8px 14px 14px; border: none; background: rgba(20,24,40,0.7); color: var(--cream); transition: transform .25s, box-shadow .25s; }
.ribbon span { position: relative; }
.ribbon.sel { transform: translateY(6px); box-shadow: 0 0 0 2px rgba(255,236,190,0.9), 0 0 16px rgba(242,165,65,0.7); }
#bookBest { position: absolute; left: 50%; transform: translateX(-50%); bottom: calc(66px + var(--sab) + var(--fs) * 2); font-size: calc(var(--fs) * 0.9); color: #f7d58a; white-space: nowrap; text-shadow: 0 1px 3px rgba(0,0,0,0.8); }

/* パネル */
.panel { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(92vw, 520px); max-height: calc(100% - 20px); overflow: auto; background: rgba(244,234,213,0.96); color: #3a2a22; border-radius: 16px; padding: clamp(10px, 2.5vh, 22px) clamp(12px, 3vw, 26px); box-shadow: 0 10px 40px rgba(0,0,0,0.5); font-size: var(--fs); }
.panel h2 { margin: 0 0 0.5em; font-size: calc(var(--fs) * 1.35); color: #7a2f2a; text-align: center; }
.panel ol { margin: 0 0 0.6em; padding-left: 1.4em; line-height: 1.55; }
.panel p { margin: 0.3em 0; line-height: 1.5; }
.panel p.sub, .panel .pc-only { font-size: calc(var(--fs) * 0.85); color: #6a5446; }
.panel label { display: flex; align-items: center; justify-content: space-between; gap: 1em; margin: 0.5em 0; white-space: nowrap; }
.panel input[type=range] { flex: 1; min-width: 80px; accent-color: #D9483B; }
.panel .row { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 0.7em; }
.panel .closeBtn { display: block; margin: 0.6em auto 0; }
.panel button.small { background: #1F2A44; color: var(--cream); }
#rBook { text-align: center; color: #6a5446; margin-bottom: 0.3em; }
#rStars { text-align: center; font-size: calc(var(--fs) * 2); letter-spacing: 0.1em; color: #e0a92e; line-height: 1.1; }
#rStars .off { color: rgba(90,70,50,0.25); }
#rStars .moon { color: #9aa6ba; font-size: 0.8em; margin-left: 0.3em; }
#rStats { display: grid; grid-template-columns: auto auto; gap: 0.15em 1.2em; justify-content: center; margin: 0.5em 0; white-space: nowrap; }
#rStats .best { color: #b0472f; }
body.touch .pc-only { display: none; }

#result { left: auto; right: calc(12px + var(--sar)); transform: translateY(-50%); width: min(44vw, 420px); }
#result .row button { flex: 1 1 auto; }
@media (max-aspect-ratio: 1/1) {
  #result { left: 50%; right: auto; top: auto; bottom: calc(10px + var(--sab)); transform: translateX(-50%); width: min(94vw, 460px); max-height: 58%; }
}
@media (max-height: 460px) {
  .panel { padding: 8px 12px; }
  .panel h2 { margin-bottom: 0.2em; font-size: calc(var(--fs) * 1.15); }
  #rStars { font-size: calc(var(--fs) * 1.4); }
  #rStats { margin: 0.2em 0; line-height: 1.25; }
  .panel .row { margin-top: 0.35em; gap: 6px; }
  .panel button.big, .panel button.small { min-height: 36px; padding: 0.3em 0.9em; }
  #result { width: min(56vw, 440px); }
}
@media (max-aspect-ratio: 1/1) {
  #result { max-height: 72%; }
}
@media (max-aspect-ratio: 1/1) and (max-height: 600px) {
  #result { padding: 8px 12px; }
  #result h2 { margin-bottom: 0.1em; }
  #rStars { font-size: calc(var(--fs) * 1.5); }
  #rStats { line-height: 1.25; margin: 0.2em 0; }
  #result .row { margin-top: 0.3em; gap: 6px; }
  #result button.big, #result button.small { min-height: 38px; padding: 0.3em 0.8em; }
}

/* 結果：結末と仲間 */
#rEnding { display: flex; align-items: center; justify-content: center; gap: 0.4em; margin: 0.2em 0; white-space: nowrap; }
#rEnding .moonIcon svg { width: 2em; height: 2em; display: block; }
#rFriends { display: flex; flex-wrap: wrap; justify-content: center; gap: 0.2em 0.7em; font-size: calc(var(--fs) * 0.9); }
#rFriends .fr { display: inline-flex; align-items: center; gap: 0.15em; white-space: nowrap; }
#rFriends svg { width: 1.6em; height: 1.6em; }
#rFriends .alone { color: #6a5446; }
#result .first { color: #b0472f; font-size: 0.75em; margin-left: 0.2em; }
#rStory { font-family: "Yu Mincho", "Hiragino Mincho ProN", serif; color: #4a3528; text-align: center; font-size: calc(var(--fs) * 0.85); margin: 0.3em 0; line-height: 1.45; }
/* 目次 */
#toc { width: min(94vw, 640px); }
#tocBody { display: flex; gap: 0; align-items: stretch; }
.tocPage { flex: 1; min-width: 0; }
.tocFold { width: 2px; margin: 0 10px; background: linear-gradient(rgba(90,70,50,0), rgba(90,70,50,0.35), rgba(90,70,50,0)); }
.tocPage h3 { margin: 0 0 0.3em; font-size: var(--fs); color: #7a2f2a; text-align: center; font-family: "Yu Mincho", "Hiragino Mincho ProN", serif; }
.tocPage ul { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(72px, 1fr)); gap: 4px; }
.tocPage li { display: flex; flex-direction: column; align-items: center; font-size: calc(var(--fs) * 0.8); white-space: nowrap; }
.tocPage li svg { width: 40px; height: 40px; }
.tocPage li.unseen span { color: rgba(90,70,50,0.45); }
@media (max-height: 460px) {
  #rStory { display: none; }
  .tocPage li svg { width: 30px; height: 30px; }
  .tocPage ul { grid-template-columns: repeat(auto-fill, minmax(62px, 1fr)); }
}
@media (max-aspect-ratio: 1/1) and (max-height: 600px) { #rStory { display: none; } }

/* 縦画面：本が小さいので、本の下に刷った紙の帯で文章を見せる */
#storyStrip { position: absolute; left: 50%; transform: translateX(-50%); width: min(94vw, 460px); padding: 0.45em 0.8em; background: rgba(244,234,213,0.94); color: #4a3528; border-radius: 6px; box-shadow: 0 2px 10px rgba(0,0,0,0.35); font-family: "Yu Mincho", "YuMincho", "Hiragino Mincho ProN", serif; font-weight: 600; font-size: clamp(12px, 3.6vw, 16px); line-height: 1.55; text-align: center; pointer-events: none; transition: opacity .4s, filter .4s; }
#storyStrip.bleed { opacity: 0.2; filter: blur(3px); }
/* 桃太郎：結果と場面の目次 */
#rEnding .fr { margin-left: 0.4em; color: #6a5446; }
#rFriends .miniStar { color: #e0a92e; margin-left: 0.15em; letter-spacing: -0.05em; }
.sceneToc { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; }
.sceneToc li { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: calc(var(--fs) * 0.85); white-space: nowrap; font-family: "Yu Mincho", "Hiragino Mincho ProN", serif; }
.sceneToc li .no { color: #C8553D; font-size: 0.8em; }
.sceneToc li svg { width: 48px; height: 48px; }
.sceneToc li .st { color: #e0a92e; font-size: 0.8em; letter-spacing: -0.08em; }
.sceneToc li .st .off, .sceneToc li.unseen .nm { color: rgba(90,70,50,0.35); }
@media (max-width: 420px) { .sceneToc { grid-template-columns: repeat(3, minmax(0, 1fr)); } .sceneToc li svg { width: 38px; height: 38px; } }
@media (max-height: 460px) { .sceneToc li svg { width: 34px; height: 34px; } }
