/* ぴょこり 見た目
 * 動きは CSS の animation だけで書く（transition は一時停止で止められないので使わない。design §6.6）。
 * 遊びの層（#stage）に .paused が付くと、その中の animation を全部止める。重ねる画面は #stage の外。
 */
:root {
  --sat: env(safe-area-inset-top, 0px);
  --sar: env(safe-area-inset-right, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --band: calc(24px + var(--sab));
  --ink: #4a3329;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

html, body {
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  background: #aee3ff;
}
body {
  font-family: system-ui, -apple-system, "Hiragino Maru Gothic ProN", "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", sans-serif;
  color: var(--ink);
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; touch-action: none; }
button:focus { outline: none; }
svg { display: block; }

#app { position: relative; width: 100%; height: 100vh; height: 100dvh; overflow: hidden; }
#stage, .scr { position: absolute; top: 0; left: 0; right: 0; bottom: 0; }
.scr { overflow: hidden; }
.scr.enter { z-index: 2; animation: fade-in .3s ease-out both; }
#stage.paused, #stage.paused * { animation-play-state: paused !important; }
#probe {
  position: absolute; left: 0; top: 0; width: 0; height: 0; visibility: hidden; pointer-events: none;
  padding: var(--sat) var(--sar) var(--sab) var(--sal);
}

/* ---------- はじめ ---------- */
#scr-start {
  background: linear-gradient(#aee3ff, #e3f6ff);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3vmin;
  padding: calc(var(--sat) + 64px) 16px calc(var(--band) + 24px);
}
[data-orient="land"] #scr-start { flex-direction: row; gap: 8vmin; }
.start-mascot { width: min(40vmin, 230px); height: min(48vmin, 276px); animation: hop 1.6s ease-in-out infinite; }
.start-mascot svg, .mascot-in svg, .tile-art svg, .sleep-scene svg { width: 100%; height: 100%; }
.play { width: max(120px, 40vmin); height: max(120px, 40vmin); animation: pulse 1.8s ease-in-out infinite; }
.play-in {
  width: 100%; height: 100%; border-radius: 50%;
  background: #ff7a8a; box-shadow: 0 8px 0 #d65a6b, 0 12px 24px rgba(214, 90, 107, .25);
  display: flex; align-items: center; justify-content: center;
}
.play-in svg { width: 56%; height: 56%; }
#scr-start.pressed .play-in { transform: translateY(6px) scale(.94); box-shadow: 0 2px 0 #d65a6b; }
/* 折り返すのは空きの所だけ（「ひら／きます」のように語の途中で切らない）。pretty で最後の行に 1 語だけ残さない
   （「せっていが ひらきます」を 2 行目にそろえる。対応していない端末でも空きの所では折り返す。ux R1 m5） */
.adult-note {
  position: absolute; left: 16px; right: 16px; bottom: calc(var(--sab) + 8px);
  font-size: 13px; line-height: 1.4; text-align: center; color: #33607c; word-break: keep-all; text-wrap: pretty;
}

/* ---------- ホーム ---------- */
#scr-home { background: linear-gradient(#bfe9ff 0%, #e9f8ff 45%, #fff6e6 100%); }
.home-mascot { position: absolute; }
.mascot-in { width: 100%; height: 100%; }
.home-tiles { position: absolute; display: grid; gap: 16px; }
.tile { width: var(--tile); animation: float 3.2s ease-in-out infinite; }
.tile:nth-child(2n) { animation-delay: -1.6s; }
.tile-art { width: var(--tile); height: var(--tile); filter: drop-shadow(0 6px 0 rgba(0, 0, 0, .08)); }
.tile-name { height: 28px; line-height: 28px; font-size: 15px; font-weight: 700; text-align: center; color: #5a4a40; white-space: nowrap; }
.home-tiles.nolabel .tile-name { display: none; }

/* ---------- 遊びの共通 ---------- */
.game-root { position: absolute; top: 0; left: 0; right: 0; bottom: 0; overflow: hidden; }

/* G1 あわあわ */
.awa { background: linear-gradient(180deg, #e2f8ff 0%, #b5e8fb 55%, #86d2f1 100%); }
.awa canvas { position: absolute; top: 0; left: 0; width: 100%; height: 100%; }

/* G2 いないいないばあ */
.inai { background: linear-gradient(#fff4dc, #ffe3ec); }
.inai-grid { position: absolute; display: grid; }
.cell { position: relative; }
.stack { position: absolute; left: calc(50% - var(--B) / 2); bottom: 2%; width: var(--B); height: calc(var(--B) * 1.48); }
.box-pack { position: absolute; left: 0; bottom: 0; width: var(--B); height: calc(var(--B) * .8); z-index: 2; }
.box, .lid, .animal, .animal-in { position: absolute; }
.box { left: 0; top: 0; width: 100%; height: 100%; }
.lid { left: -5%; top: -23.75%; width: 110%; height: 43.75%; z-index: 3; }
.animal { left: 10%; bottom: calc(var(--B) * .68); width: calc(var(--B) * .8); height: calc(var(--B) * .8); z-index: 1; opacity: 0; transform: translateY(45%) scale(.3); }
.animal-in { left: 0; top: 0; width: 100%; height: 100%; }
.box svg, .lid svg, .animal-in svg { width: 100%; height: 100%; }
.cell.shaking .box-pack { animation: shake .28s ease-in-out infinite; }
.cell.shaking.more .box-pack { animation: shake-more .2s ease-in-out infinite; }
.cell.open .lid { animation: lid-fly .55s ease-out forwards; }
.cell.open .animal { animation: pop-up .45s cubic-bezier(.3, 1.6, .5, 1) forwards; }
.cell.closing .lid { animation: lid-back .5s ease-out both; }
.cell.closing .animal { animation: sink .4s ease-in forwards; }
.talk .p-mouth-open { display: inline; }
.talk .p-mouth-closed { display: none; }

/* 一度きりの動き（a/b を入れ替えて最初から動かし直す） */
.wig-a { animation: wig1 .35s ease-in-out; }
.wig-b { animation: wig2 .35s ease-in-out; }
.jmp-a { animation: jmp1 .42s ease-out; }
.jmp-b { animation: jmp2 .42s ease-out; }
.bmp-a { animation: bmp1 .35s ease-out; }
.bmp-b { animation: bmp2 .35s ease-out; }

/* ---------- 重ねる部品（Shell の層） ---------- */
#fx { position: absolute; top: 0; left: 0; width: 100%; height: 100%; z-index: 15; pointer-events: none; }

.lp-btn { position: absolute; z-index: 20; }
.lp-btn .btn-vis { position: absolute; display: flex; align-items: center; justify-content: center; border-radius: 50%; }
.ring { position: absolute; transform: rotate(-90deg); pointer-events: none; overflow: visible; }
.ring circle { fill: none; stroke-dasharray: 100; stroke-dashoffset: 100; visibility: hidden; }
.lp-on .ring circle { visibility: visible; animation: ring-fill var(--hold, 1s) linear forwards; }

/* 幅 88px は js/core.js の UI.HOME_HIT と同じ値（遊びの配置がこの幅を避ける） */
#btn-home { display: none; left: calc(var(--sal) + 4px); top: calc(var(--sat) + 4px); width: 88px; height: 88px; }
#app[data-screen="game"] #btn-home { display: block; }
#app[data-sleep] #btn-home { display: none; }
#btn-home .btn-vis { left: 8px; top: 8px; width: 72px; height: 72px; background: #ffffff; box-shadow: 0 4px 0 rgba(0, 0, 0, .12); }
#btn-home .btn-vis svg { width: 46px; height: 46px; }
#btn-home .ring { left: 4px; top: 4px; width: 80px; height: 80px; }
#btn-home .ring circle { stroke: #ffb800; stroke-width: 8; }

#btn-gear { right: calc(var(--sar) + 4px); top: calc(var(--sat) + 4px); width: 56px; height: 56px; z-index: 30; }
#app[data-ov] #btn-gear { display: none; }
#btn-gear .btn-vis { left: 14px; top: 14px; width: 28px; height: 28px; opacity: .4; }
#btn-gear .btn-vis svg { width: 28px; height: 28px; }
#btn-gear .ring { left: 10px; top: 10px; width: 36px; height: 36px; }
#btn-gear .ring circle { stroke: rgba(80, 90, 110, .45); stroke-width: 6; }
/* G3 の夜空の上では薄い青灰にする（夜空の上で 3:1 以上。ux R1 m1）。おやすみの色はこのあとの規則が勝つ */
#app[data-game="kira"] #btn-gear .btn-vis { opacity: .55; }
#app[data-game="kira"] #btn-gear .btn-vis svg g { fill: #b8c4e0; }
#app[data-game="kira"] #btn-gear .btn-vis svg circle { stroke: #b8c4e0; }
#app[data-game="kira"] #btn-gear .ring circle { stroke: rgba(184, 196, 224, .6); }
#app[data-sleep] #btn-gear .btn-vis { opacity: .3; }
#app[data-sleep] #btn-gear .btn-vis svg g, #app[data-sleep] #btn-gear .btn-vis svg circle { fill: #c7cde6; stroke: #c7cde6; }
#app[data-sleep] #btn-gear .btn-vis svg circle { fill: none; }

/* おやすみ */
#sleep { position: absolute; top: 0; left: 0; right: 0; bottom: 0; z-index: 10; }
.sleep-dim { position: absolute; top: 0; left: 0; right: 0; bottom: 0; background: #151b46; opacity: .72; animation: dim 3s ease-in-out both; }
.sleep-sky { position: absolute; top: 0; left: 0; right: 0; bottom: 0; animation: fade-in 3s ease-in both; }
.sleep-hill {
  position: absolute; left: -15%; right: -15%; bottom: 0; height: calc(var(--band) + 20%);
  background: #262e6b; border-radius: 50% 50% 0 0 / 80px 80px 0 0;
}
.moon { position: absolute; left: calc(var(--sal) + 10%); top: calc(var(--sat) + 8%); width: min(18vmin, 110px); height: min(18vmin, 110px); }
.sleep-scene {
  position: absolute; left: 0; right: 0; bottom: calc(var(--band) + 6%);
  display: flex; align-items: flex-end; justify-content: center; gap: 2vmin;
  animation: fade-in 3s ease-in both;
}
.sleep-scene .s-mascot { width: min(34vmin, 200px); height: min(40.8vmin, 240px); animation: breathe 3.6s ease-in-out infinite; }
.sleep-scene .s-animal { width: min(22vmin, 130px); height: min(22vmin, 130px); animation: breathe 4.2s ease-in-out infinite; }

/* 大人向けの重ね画面 */
.ov {
  position: absolute; top: 0; left: 0; right: 0; bottom: 0; z-index: 40;
  background: rgba(28, 36, 66, .55);
  display: flex; align-items: center; justify-content: center;
  padding: calc(var(--sat) + 12px) calc(var(--sar) + 12px) calc(var(--sab) + 12px) calc(var(--sal) + 12px);
  color: #2e2a33;
}
.panel { position: relative; background: #ffffff; border-radius: 20px; width: 100%; max-width: 540px; max-height: 100%; display: flex; flex-direction: column; overflow: hidden; box-shadow: 0 10px 40px rgba(0, 0, 0, .25); }
.panel h2 { font-size: 20px; }
.btn-x { position: absolute; right: 6px; top: 6px; width: 48px; height: 48px; font-size: 28px; line-height: 48px; color: #6b6f80; }

.quiz { padding: 20px 20px 18px; align-items: center; max-width: 380px; container-type: inline-size; }
.quiz-for { font-size: 13px; line-height: 20px; color: #6b6f80; }
/* 問題文（全角 19 字＋空き 2 つ）を幅いっぱいで 1 行に収める。文字の大きさは幅 ÷ 21 字（20px まで）。
   幅いっぱいに使うので、右上の ×（下端 54px）より下から始める（20＋20＋18 = 58px。横持ちも上の余白は 20px のまま）。
   収まらない字形の端末でも、折り返すのは空きの所だけ（app R1 m1） */
.quiz-q { margin-top: 18px; font-size: 16px; font-size: min(20px, 100cqi / 21); font-weight: 700; text-align: center; line-height: 1.5; word-break: keep-all; }
.quiz-slots { display: flex; gap: 10px; margin: 12px 0; }
.quiz-slots span { width: 44px; height: 52px; border-radius: 10px; background: #f0f2f7; font-size: 28px; font-weight: 700; line-height: 52px; text-align: center; }
.keypad { position: relative; display: grid; grid-template-columns: repeat(3, 72px); gap: 10px; }
/* 間違えたときの知らせ。テンキーを覆って、押せないことも見せる（ux R1 M2） */
.quiz-wrong {
  position: absolute; top: -4px; left: -4px; right: -4px; bottom: -4px; border-radius: 14px; background: #ffffff;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  font-size: 16px; font-weight: 700; line-height: 1.5; text-align: center; word-break: keep-all; color: #2e2a33;
}
.quiz-wrong .qw-h { font-size: 20px; color: #b3261e; }
.keypad button { height: 56px; border-radius: 14px; background: #eef1f8; font-size: 24px; font-weight: 700; box-shadow: 0 3px 0 #d5dae6; }
.keypad button:active { background: #dfe5f2; }
.keypad .k0 { grid-column: 2; }
@media (max-height: 480px) {
  .quiz { padding: 20px 12px 12px; }
  .quiz-slots { margin: 6px 0; }
  .quiz-slots span { height: 40px; line-height: 40px; font-size: 22px; }
  .keypad { grid-template-columns: repeat(5, 60px); gap: 8px; }
  .keypad button { height: 44px; }
  .keypad .k0 { grid-column: auto; }
}

.menu .panel-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 14px 10px 20px; border-bottom: 1px solid #eceef3; }
/* 白い文字のボタンの地は、白に対して 4.5:1 以上（青 5.1・緑 5.3・橙 5.3。ux R1 M3） */
.btn-close { min-height: 44px; padding: 10px 18px; border-radius: 999px; background: #1f6fc0; color: #ffffff; font-weight: 700; font-size: 16px; }
.scroll { overflow-y: auto; touch-action: pan-y; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; padding: 4px 20px 24px; }
/* touch-action はスクロールする箱の中で祖先と重ねて効くので、ボタンの上から指を動かしてもスクロールできるようにする（m7） */
.scroll button { touch-action: pan-y; }
.menu section { padding: 14px 0; border-bottom: 1px solid #f0f1f5; }
.menu h3 { font-size: 15px; margin-bottom: 8px; }
.menu .row { display: flex; align-items: center; justify-content: space-between; padding: 4px 0; font-size: 16px; }
.tog { min-width: 76px; min-height: 44px; padding: 8px 14px; border-radius: 999px; background: #dfe3ec; color: #555b6e; font-weight: 700; }
.tog[aria-pressed="true"] { background: #2b7a3b; color: #ffffff; }
.choices { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.choices button { min-height: 44px; padding: 0 8px; border-radius: 12px; background: #eef1f8; font-weight: 700; }
.choices button[aria-pressed="true"] { background: #a85500; color: #ffffff; }
.note { font-size: 13px; line-height: 1.6; color: #555b6e; margin-top: 6px; }
.note.warn { color: #c0392b; }
.step-h { font-size: 14px; font-weight: 700; margin-top: 8px; }
.menu ol { padding-left: 1.4em; font-size: 13px; line-height: 1.6; color: #555b6e; }
.credit p { font-size: 12px; color: #6b6f80; }
/* 続きがあるとき（menuMore）は下端に「▼ つづき」（ux R1 m8）。
   中身に重ねるとボタンが白く抜けて欠けて見えるので、スクロールの下に 24px の帯を取っておいて、そこに出す（ux R2 n2）。
   帯は続きがないときも取っておく（出し入れで見える高さが変わると、いちばん下で中身が 24px 跳ねるため） */
.menu::after {
  content: ''; flex: 0 0 24px; border-top: 1px solid transparent; padding-top: 3px;
  font-size: 13px; font-weight: 700; line-height: 20px; text-align: center; color: #555b6e; pointer-events: none;
}
.menu.more::after { content: '▼ つづき'; border-top-color: #eceef3; }

.wake { padding: 28px 20px 22px; align-items: center; gap: 14px; max-width: 360px; }
.wake .big { width: 100%; padding: 16px; border-radius: 16px; font-size: 18px; font-weight: 700; background: #1f6fc0; color: #ffffff; }
.wake .big + .big { background: #eef1f8; color: #2e2a33; }

/* ---------- 動き ---------- */
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes hop { 0%, 100% { transform: translateY(0); } 45% { transform: translateY(-7%); } 60% { transform: translateY(0) scaleY(.96); } }
@keyframes pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.06); } }
@keyframes float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-6px); } }
@keyframes breathe { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.03, .98); } }
@keyframes dim { from { opacity: 0; } to { opacity: .72; } }
@keyframes ring-fill { from { stroke-dashoffset: 100; } to { stroke-dashoffset: 0; } }
@keyframes wig1 { 0%, 100% { transform: rotate(0); } 25% { transform: rotate(-6deg); } 75% { transform: rotate(6deg); } }
@keyframes wig2 { 0%, 100% { transform: rotate(0); } 25% { transform: rotate(-6deg); } 75% { transform: rotate(6deg); } }
@keyframes jmp1 { 0%, 100% { transform: translateY(0); } 40% { transform: translateY(-18%) scale(1.05); } 70% { transform: translateY(0) scale(1.04, .95); } }
@keyframes jmp2 { 0%, 100% { transform: translateY(0); } 40% { transform: translateY(-18%) scale(1.05); } 70% { transform: translateY(0) scale(1.04, .95); } }
@keyframes bmp1 { 0%, 100% { transform: scale(1); } 40% { transform: scale(1.1); } 70% { transform: scale(.97); } }
@keyframes bmp2 { 0%, 100% { transform: scale(1); } 40% { transform: scale(1.1); } 70% { transform: scale(.97); } }
@keyframes shake { 0%, 100% { transform: rotate(0); } 25% { transform: rotate(-4deg); } 75% { transform: rotate(4deg); } }
@keyframes shake-more { 0%, 100% { transform: rotate(0) scale(1.03); } 25% { transform: rotate(-8deg) scale(1.03); } 75% { transform: rotate(8deg) scale(1.03); } }
@keyframes lid-fly { 0% { transform: none; opacity: 1; } 100% { transform: translate(40%, -170%) rotate(28deg); opacity: 0; } }
@keyframes lid-back { 0% { transform: translate(40%, -170%) rotate(28deg); opacity: 0; } 100% { transform: none; opacity: 1; } }
@keyframes pop-up { 0% { opacity: 0; transform: translateY(45%) scale(.3); } 100% { opacity: 1; transform: none; } }
@keyframes sink { 0% { opacity: 1; transform: none; } 100% { opacity: 0; transform: translateY(45%) scale(.3); } }
