:root {
  color-scheme: light dark;
  --bg: #eef3ff;
  --ink: #2b2433;
  --sub: #55607a;
  --card: #ffffff;
  --card-sh: #c4d0ec;
  --gold: #ffc53d;
  --focus: #2f7cf6;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c2130;
    --ink: #eef2fa;
    --sub: #aab4c8;
    --card: #2c3346;
    --card-sh: #0e111a;
    --focus: #ffc53d;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; background: var(--bg); color: var(--ink); }
body {
  font-family: "Hiragino Maru Gothic ProN", "Hiragino Maru Gothic Pro", "BIZ UDPGothic", "Yu Gothic UI", Meiryo, system-ui, sans-serif;
  -webkit-user-select: none; user-select: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  touch-action: manipulation;
  overscroll-behavior: none;
  overflow: hidden;
}
button { font: inherit; color: inherit; border: 0; background: none; padding: 0; margin: 0; cursor: pointer; touch-action: manipulation; }
button:focus-visible { outline: 4px solid var(--focus); outline-offset: 3px; }
svg { display: block; width: 100%; height: 100%; overflow: visible; }

/* 画面の下 15% には押すものを置かない(手首が当たる) */
#app {
  position: fixed; inset: 0; display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr) auto; gap: 10px;
  padding: calc(env(safe-area-inset-top) + 10px) calc(env(safe-area-inset-right) + 12px) 15vh calc(env(safe-area-inset-left) + 12px);
}
.top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.logo { display: flex; align-items: center; gap: 8px; margin: 0; font-size: clamp(20px, 6vw, 28px); font-weight: 900; letter-spacing: .02em; white-space: nowrap; }
.logo img { width: 1.5em; height: 1.5em; }
.night { width: 56px; height: 56px; padding: 8px; border-radius: 16px; background: var(--card); box-shadow: 0 4px 0 var(--card-sh); flex-shrink: 0; }
.night:disabled { opacity: .4; }
.btns { display: flex; gap: 8px; flex-shrink: 0; }
/* せかいを かえる ボタン: ステージの みぎうえ(おやすみ から はなす)。つぎの せかいの そらの いろと なかま + やじるし */
.world { position: absolute; right: 3cqw; top: 3cqh; z-index: 5; width: clamp(56px, min(17cqw, 24cqh), 96px); aspect-ratio: 1; border-radius: 50%; background: var(--card); box-shadow: 0 4px 0 rgba(0, 0, 0, .25); padding: 4px; }
.world:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0, 0, 0, .25); }
.wb { display: block; width: 100%; height: 100%; padding: 12%; border-radius: 50%; border: 3px solid #2b2433; }
.world .arrow { position: absolute; right: -6%; bottom: -6%; width: 42%; height: 42%; border-radius: 50%; background: #ffc53d; border: 3px solid #2b2433; padding: 8%; }
.night:active:not(:disabled), .token:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--card-sh); }

/* よるの ステージ(こわくない: あおい そら・わらう おつきさま・まるい おか) */
.scene {
  position: relative; container-type: size; border-radius: 22px; overflow: hidden;
  background:
    radial-gradient(circle at 18% 22%, #fff 0 1.5px, transparent 2.5px),
    radial-gradient(circle at 72% 14%, #fff 0 1.5px, transparent 2.5px),
    radial-gradient(circle at 88% 34%, #fff 0 1px, transparent 2px),
    radial-gradient(circle at 46% 9%, #fff 0 1px, transparent 2px),
    radial-gradient(circle at 60% 28%, #fff 0 1px, transparent 2px),
    linear-gradient(#203466, #3c5ba0 75%, #5776b8);
  box-shadow: 0 5px 0 var(--card-sh);
}
.scene::before { content: ''; position: absolute; left: -10%; right: -10%; bottom: -14%; height: 40%; border-radius: 50%; background: #4f9c7d; box-shadow: inset 0 8px 0 #63b391; }
.moon { position: absolute; left: 5cqw; top: 5cqh; width: min(15cqw, 22cqh); aspect-ratio: 1; transform-origin: 50% 90%; z-index: 3; cursor: pointer; }
.moon svg { animation: bob 3.2s ease-in-out infinite; transform-origin: 50% 90%; }
@keyframes bob { 0%, 100% { transform: rotate(-5deg); } 50% { transform: rotate(5deg); } }
.scene { cursor: pointer; } /* touch-action は manipulation のまま(紹介ページの iframe で ステージに ゆびを おいても スクロール できる) */

/* せかい: おまつり(ゆうやけ・ちょうちん)・うみ(みずの なか・すな)・おもちゃ(ピンクの へや) */
[data-world="matsuri"] .scene {
  background:
    radial-gradient(circle at 80% 30%, #fff 0 1px, transparent 2px),
    radial-gradient(circle at 60% 20%, #fff 0 1px, transparent 2px),
    linear-gradient(#3a2a6b, #8d4f86 55%, #e0866a 85%, #f3a95f);
}
[data-world="matsuri"] .scene::before { background: #a8744f; box-shadow: inset 0 8px 0 #c08a5f; }
[data-world="umi"] .scene {
  background:
    radial-gradient(circle at 30% 30%, transparent 0 5px, rgba(255, 255, 255, .5) 5px 6.5px, transparent 7px),
    radial-gradient(circle at 75% 45%, transparent 0 3px, rgba(255, 255, 255, .5) 3px 4.5px, transparent 5px),
    radial-gradient(circle at 62% 18%, transparent 0 4px, rgba(255, 255, 255, .45) 4px 5.5px, transparent 6px),
    linear-gradient(100deg, transparent 30%, rgba(255, 255, 255, .12) 34% 40%, transparent 44% 60%, rgba(255, 255, 255, .1) 63% 68%, transparent 72%),
    linear-gradient(#1b6f9c, #2fa7c9 65%, #6fd0de);
}
[data-world="umi"] .scene::before { background: #e9cf96; box-shadow: inset 0 8px 0 #f5dfae; }
[data-world="toy"] .scene {
  background:
    radial-gradient(circle at 20% 25%, #fff 0 3px, transparent 4px),
    radial-gradient(circle at 78% 18%, #fff 0 3px, transparent 4px),
    radial-gradient(circle at 55% 32%, #ffd93d 0 3px, transparent 4px),
    radial-gradient(circle at 90% 40%, #7fe6dc 0 3px, transparent 4px),
    linear-gradient(#ff9ec4, #ffc2d9 60%, #ffe0a8);
}
[data-world="toy"] .scene::before { background: #8fd0ff; box-shadow: inset 0 8px 0 #b3e0ff; }
.deco { position: absolute; inset: 0; pointer-events: none; }
.deco svg { position: absolute; width: auto; }
.garland { left: 24%; right: 2%; top: 1cqh; width: 74% !important; height: auto !important; }
.weed { bottom: 4cqh; height: 34cqh; }
.weed.l { left: 1cqw; } .weed.r { right: 1cqw; }
.block { bottom: 3cqh; height: 16cqh; }
.block.l { left: 2cqw; } .block.r { right: 2cqw; }

/* そらを さわった ところが きらっ(Web Animations で transform と opacity だけ) */
.sparks { position: absolute; inset: 0; pointer-events: none; z-index: 4; }
.sparks b { position: absolute; width: 96px; height: 96px; opacity: 0; transform: translate(-50%, -50%); background: radial-gradient(circle, #fff 0 18%, transparent 20%), conic-gradient(from 0deg, transparent 0 10%, #ffe28a 10% 15%, transparent 15% 35%, #ffe28a 35% 40%, transparent 40% 60%, #ffe28a 60% 65%, transparent 65% 85%, #ffe28a 85% 90%, transparent 90%); border-radius: 50%; box-shadow: 0 0 0 3px rgba(255, 255, 255, .6); }
.flash { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; z-index: 6; }
/* てびき: ゆびが とんとん */
.hand { position: fixed; z-index: 20; width: 48px; height: 58px; pointer-events: none; opacity: 0; transition: opacity .2s, left .3s, top .3s; filter: drop-shadow(0 3px 0 rgba(0, 0, 0, .25)); }
.hand.show { opacity: 1; animation: poke .52s ease-in-out infinite; }
@keyframes poke { 0%, 100% { transform: translate(6px, 10px); } 50% { transform: translate(0, 0) scale(.92); } }

/* ごほうび(5にん そろって なかまが うたう あいだ): ほし・はなび・あわ・かみふぶき */
.fx { position: absolute; inset: 0; pointer-events: none; overflow: hidden; z-index: 3; }
.fx i { display: none; position: absolute; top: -10%; width: 14px; height: 14px; }
.party .fx i, .cheer .fx i { display: block; animation: fall 2.4s linear infinite; }
.fx i:nth-child(1) { left: 6%; animation-delay: 0s; } .fx i:nth-child(2) { left: 14%; animation-delay: -1.1s; }
.fx i:nth-child(3) { left: 23%; animation-delay: -.5s; } .fx i:nth-child(4) { left: 31%; animation-delay: -1.8s; }
.fx i:nth-child(5) { left: 40%; animation-delay: -.2s; } .fx i:nth-child(6) { left: 48%; animation-delay: -1.4s; }
.fx i:nth-child(7) { left: 57%; animation-delay: -.8s; } .fx i:nth-child(8) { left: 65%; animation-delay: -2s; }
.fx i:nth-child(9) { left: 73%; animation-delay: -.4s; } .fx i:nth-child(10) { left: 81%; animation-delay: -1.6s; }
.fx i:nth-child(11) { left: 89%; animation-delay: -1s; } .fx i:nth-child(12) { left: 95%; animation-delay: -2.2s; }
.fx i { width: 26px; height: 26px; }
[data-world="yoru"] .fx i { background: #ffe28a; clip-path: polygon(50% 0, 62% 38%, 100% 38%, 69% 60%, 80% 100%, 50% 75%, 20% 100%, 31% 60%, 0 38%, 38% 38%); }
[data-world="matsuri"] .fx i { top: 20%; width: 72px; height: 72px; border-radius: 50%; background: radial-gradient(circle, transparent 0 40%, #ffd36b 42% 50%, transparent 52% 62%, #ff7a5c 64% 70%, transparent 72%); animation-name: burst; animation-duration: 1.6s; }
[data-world="matsuri"] .fx i:nth-child(even) { top: 35%; }
[data-world="umi"] .fx i { top: auto; bottom: -10%; border-radius: 50%; border: 2.5px solid rgba(255, 255, 255, .85); animation-name: rise; }
[data-world="toy"] .fx i { width: 14px; height: 22px; background: #ff8a7a; }
[data-world="umi"] .fx i { width: 24px; height: 24px; }
[data-world="toy"] .fx i:nth-child(3n) { background: #7fb6ff; } [data-world="toy"] .fx i:nth-child(3n+1) { background: #a9e07a; }
@keyframes fall { from { transform: translateY(0) rotate(0deg); } to { transform: translateY(125cqh) rotate(360deg); } }
@keyframes rise { from { transform: translateY(0) scale(.6); } to { transform: translateY(-125cqh) scale(1.2); } }
@keyframes burst { 0% { transform: scale(.1); opacity: 1; } 80% { opacity: 1; } 100% { transform: scale(2.4); opacity: 0; } }
.spots { position: absolute; inset: 0; }
.spot { position: absolute; width: min(18cqw, 40cqh); aspect-ratio: 108 / 126; transform: translate(-50%, -50%); }
.spot::after { content: ''; position: absolute; left: 14%; right: 14%; bottom: -4%; height: 11%; border-radius: 50%; background: rgba(255, 255, 255, .22); z-index: -1; }
.spot:nth-child(1) { left: 14%; top: 64%; }
.spot:nth-child(2) { left: 32%; top: 52%; }
.spot:nth-child(3) { left: 50%; top: 46%; }
.spot:nth-child(4) { left: 68%; top: 52%; }
.spot:nth-child(5) { left: 86%; top: 64%; }
/* たてながの ステージ: まえに 3にん・うしろに 2にん で おおきく */
@container (max-aspect-ratio: 1 / 1) {
  .spot { width: min(27cqw, 30cqh); }
  .spot:nth-child(1) { left: 20%; top: 70%; z-index: 2; }
  .spot:nth-child(2) { left: 31%; top: 40%; z-index: 1; }
  .spot:nth-child(3) { left: 50%; top: 72%; z-index: 2; }
  .spot:nth-child(4) { left: 69%; top: 40%; z-index: 1; }
  .spot:nth-child(5) { left: 80%; top: 70%; z-index: 2; }
}
.spot:empty::before { content: ''; position: absolute; inset: 10% 8% 2%; opacity: .32; background: center / contain no-repeat url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'%3E%3Cpath d='M50 4C26 4 14 24 14 48V88Q21 98 29 88Q36 98 43 88Q50 97 57 88Q64 98 71 88Q79 98 86 88V48C86 24 74 4 50 4Z' fill='rgba(255,255,255,.25)' stroke='white' stroke-width='3' stroke-dasharray='8 7'/%3E%3C/svg%3E"); }
.ghost { position: absolute; inset: 0; transform-origin: 50% 100%; will-change: transform; }
.ghost-btn { display: block; width: 100%; height: 100%; }
.mouth { transform-box: fill-box; transform-origin: 50% 30%; }
.eyes-x, .eyes-h { display: none; }
.poked .eyes, .giggle .eyes, .party .ghost .eyes, .cheer .ghost .eyes { display: none; }
.poked .eyes-x { display: inline; }
.giggle .eyes-h, .party .ghost:not(.poked) .eyes-h, .cheer .ghost .eyes-h { display: inline; }
.giggle .eyes-x { display: none; }
.ghost .eyes { transform-box: fill-box; transform-origin: 50% 50%; animation: blink 4.6s infinite; }
.spot:nth-child(2) .eyes { animation-delay: -1.7s; } .spot:nth-child(3) .eyes { animation-delay: -3.1s; }
.spot:nth-child(4) .eyes { animation-delay: -0.6s; } .spot:nth-child(5) .eyes { animation-delay: -2.4s; }
@keyframes blink { 0%, 95%, 100% { transform: none; } 97.5% { transform: scaleY(.12); } }
/* ぴたっ: みんな めを まるく して とまる */
.freeze .ghost .eyes { animation: none; transform: scale(1.15); }

/* よぶ ボタン(10にん。5こずつ 2れつ) */
.tray { display: flex; justify-content: center; }
.tokens { display: grid; grid-template-columns: repeat(5, var(--tk)); gap: 6px; --tk: clamp(52px, min(calc((100vw - 48px) / 5), 13vh), 112px); }
.token { width: var(--tk); height: var(--tk); padding: 6px 8px 4px; border-radius: 18px; background: var(--card); box-shadow: 0 4px 0 var(--card-sh); }
.token[aria-pressed="true"] { box-shadow: 0 0 0 4px var(--gold), 0 4px 0 var(--card-sh); }
/* まだ だれも いない ときは、ボタンが ゆっくり ゆれて「さわってね」 */
.idle .token { animation: wig 2.6s ease-in-out infinite; }
.idle .token:nth-child(2n) { animation-delay: .4s; }
.idle .token:nth-child(3n) { animation-delay: .9s; }
@keyframes wig { 0%, 70%, 100% { transform: none; } 78% { transform: rotate(-6deg); } 86% { transform: rotate(6deg); } }

/* スマホを よこに した とき: ステージは ひだり、よぶ ボタンは みぎ */
@media (orientation: landscape) and (max-height: 600px) {
  #app { grid-template-columns: minmax(0, 1fr) auto; grid-template-rows: auto minmax(0, 1fr); padding-top: calc(env(safe-area-inset-top) + 6px); gap: 6px 12px; }
  .top { grid-column: 1 / -1; }
  .tray { align-items: center; }
  .tokens { --tk: 56px; gap: 6px; }
  .night { width: 50px; height: 50px; }
  .logo { font-size: 20px; }
}
@media (orientation: landscape) and (max-height: 360px) {
  #app { grid-template-columns: auto minmax(0, 1fr) auto; grid-template-rows: minmax(0, 1fr); }
  .top { grid-column: 1; flex-direction: column; justify-content: flex-start; }
  .btns { flex-direction: column; }
  .logo { display: none; }
  .tray { align-items: flex-start; }
  .tokens { --tk: 52px; }
}

/* いちばん 小さい スマホ: 題を 小さく して ボタン 3つを おさめる */
@media (max-width: 359px) {
  .logo img { display: none; }
  .logo { font-size: 19px; }
  .night { width: 52px; height: 52px; padding: 7px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; animation-delay: 0s !important; transition-duration: .01ms !important; }
}
