:root {
  --bg: #fff3d6;
  --paper: #ffffff;
  --ink: #2c3440;
  --sub: #6b7a8a;
  --accent: #ff8c42;
  --accent-dark: #c75a16;
  --blue: #3fa9f5;
  --blue-dark: #1b6fae;
  --green: #5fd068;
  --green-dark: #2f8a3a;
  --line: #ecd9a8;
  --shadow: 0 6px 0 rgba(0, 0, 0, 0.10);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body {
  font-family: "Zen Maru Gothic", "Hiragino Maru Gothic ProN", "Rounded Mplus 1c", sans-serif;
  font-weight: 700;
  color: var(--ink);
  background: var(--bg);
  background-image:
    radial-gradient(circle at 12% 18%, rgba(255, 255, 255, 0.8) 0 20px, transparent 21px),
    radial-gradient(circle at 88% 72%, rgba(255, 255, 255, 0.7) 0 28px, transparent 29px),
    radial-gradient(circle at 72% 12%, rgba(255, 255, 255, 0.6) 0 12px, transparent 13px);
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

.screen {
  position: fixed; inset: 0;
  display: flex; flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
[hidden] { display: none !important; }

/* ---------- ボタン共通 ---------- */
button { font: inherit; color: inherit; cursor: pointer; border: 0; }
.icon-btn {
  width: 56px; height: 56px; border-radius: 50%; flex: none;
  background: var(--paper); box-shadow: var(--shadow);
  font-size: 26px; line-height: 1;
}
.icon-btn:active { transform: translateY(3px); box-shadow: 0 3px 0 rgba(0,0,0,.1); }
.big-btn {
  min-width: 200px; padding: 14px 30px;
  border-radius: 999px; font-size: 26px; font-weight: 900;
  color: #fff; background: var(--accent); box-shadow: 0 6px 0 var(--accent-dark);
}
.big-btn.secondary { color: var(--ink); background: #fff; box-shadow: var(--shadow); }
.big-btn:active { transform: translateY(4px); box-shadow: 0 2px 0 var(--accent-dark); }
.big-btn.secondary:active { box-shadow: 0 2px 0 rgba(0,0,0,.1); }
.danger-btn {
  padding: 12px 20px; border-radius: 12px; background: #ffe1e1; color: #a12020;
  position: relative; overflow: hidden;
}
.danger-btn.holding::after {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 0;
  background: rgba(161, 32, 32, .25); animation: hold 2s linear forwards;
}
@keyframes hold { to { width: 100%; } }

/* ---------- ホーム ---------- */
.home-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 14px 20px 6px;
}
.home-head h1 { margin: 0; font-size: 34px; font-weight: 900; letter-spacing: .04em; }
/* なかまのカード: 横長は 5 列、縦長は 3 列。画面に収め、なかまが増えたら縦に流す */
.group-list {
  flex: 1; min-height: 0; overflow-y: auto;
  display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); grid-auto-rows: minmax(120px, 1fr);
  gap: 16px; padding: 10px 24px 14px;
}
.group-card {
  min-height: 0; min-width: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  border-radius: 26px; background: var(--paper); box-shadow: 0 8px 0 rgba(0,0,0,.1);
  padding: 10px;
}
.group-card:active { transform: translateY(4px); box-shadow: 0 4px 0 rgba(0,0,0,.1); }
.group-art { flex: 1; min-height: 0; width: 100%; display: flex; align-items: center; justify-content: center; }
.group-art img { max-width: 100%; max-height: 100%; min-height: 0; object-fit: contain; pointer-events: none; }
/* 「ぜんぶ」は 4 枚を 2×2 に並べる */
.group-card.all .group-art { display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; gap: 2px; }
.group-card.all .group-art img { width: 100%; height: 100%; }
.group-name { font-size: clamp(15px, 2.1vw, 26px); font-weight: 900; color: var(--accent-dark); line-height: 1.2; word-break: keep-all; }
.group-card.all .group-name { color: var(--blue-dark); }
.home-foot { display: flex; gap: 16px; justify-content: center; padding: 6px 20px 18px; }

/* ---------- もんだい画面 ---------- */
.play-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 20px 0; }
.progress { display: flex; gap: 10px; }
.progress .dot { width: 22px; height: 22px; border-radius: 50%; background: #fff; border: 3px solid var(--line); }
.progress .dot.now { border-color: var(--accent); }
.progress .dot.done { background: var(--accent); border-color: var(--accent); }
.question {
  margin: 6px 0 4px; text-align: center; line-height: 1.25;
  font-size: clamp(30px, 5.4vh, 46px); font-weight: 900;
}
/* 答えが出たら 名前を大きく */
.revealed .question { color: var(--accent-dark); font-size: clamp(20px, min(8vh, calc(84vw / var(--len, 6))), 72px); letter-spacing: .08em; white-space: nowrap; animation: pop .4s cubic-bezier(.2, 1.5, .4, 1); }
.card {
  flex: 1; min-height: 0; margin: 4px 20px; padding: 14px;
  display: flex; align-items: center; justify-content: center;
  background: var(--paper); border-radius: 30px; box-shadow: var(--shadow);
  border: 5px solid transparent; transition: border-color .15s;
}
.revealed .card { border-color: var(--green); }
.card.bump { animation: bump .35s ease-out; }
@keyframes bump { 50% { transform: scale(1.04); } }
.picture { width: 100%; height: 100%; min-height: 0; object-fit: contain; pointer-events: none; opacity: 0; }
.picture.show { opacity: 1; animation: appear .5s cubic-bezier(.2, 1.4, .4, 1); }
@keyframes appear { from { transform: scale(.5) rotate(-8deg); opacity: 0; } }
.play-foot { display: flex; justify-content: center; padding: 12px 20px 18px; }
/* 「つぎ」は答えが出るまで隠す（場所は取っておき、絵の大きさが変わらないように） */
.next-btn { visibility: hidden; min-width: 240px; font-size: 30px; }
.revealed .next-btn { visibility: visible; }
.next-btn:disabled { opacity: .5; }

/* キラキラ粒子 */
.particle {
  position: fixed; z-index: 60; pointer-events: none; width: 14px; height: 14px; border-radius: 50%;
  background: var(--c, #ffd54a);
  animation: burst var(--d, 900ms) ease-out forwards;
}
.particle.star {
  border-radius: 0;
  clip-path: polygon(50% 0, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%);
}
@keyframes burst {
  0%   { transform: translate(0, 0) scale(.4) rotate(0deg); opacity: 1; }
  100% { transform: translate(var(--dx), var(--dy)) scale(1.1) rotate(220deg); opacity: 0; }
}

/* ---------- オーバーレイ ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 20;
  background: rgba(60, 40, 20, .45);
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
}
.done-card, .book-card, .settings-card {
  background: var(--paper); border-radius: 28px; box-shadow: 0 16px 40px rgba(0,0,0,.25);
  padding: 20px 28px; max-width: 92vw; max-height: 92vh; overflow: auto;
  animation: pop .45s cubic-bezier(.2, 1.4, .4, 1);
}
@keyframes pop { from { transform: scale(.6); opacity: 0; } }
.done-card { text-align: center; }
.done-title { margin: 0 0 4px; font-size: 48px; font-weight: 900; color: var(--accent); }
.done-label { margin: 4px 0 16px; font-size: 24px; }
.tray-list { display: flex; flex-wrap: wrap; justify-content: center; gap: 16px; }

/* シール（図柄は nazori/js/stickers.js） */
.sticker { position: relative; display: inline-block; width: 120px; height: 120px; padding: 0; background: none; }
.sticker svg { width: 100%; height: 100%; filter: drop-shadow(0 4px 6px rgba(0,0,0,.2)); }
.tray-item { width: clamp(72px, 11vw, 104px); height: clamp(72px, 11vw, 104px); border-radius: 50%; animation: float 2.4s ease-in-out infinite; }
.tray-item:nth-child(2n) { animation-delay: -1.2s; }
.tray-item:active { transform: scale(1.15); }
@keyframes float { 0%, 100% { transform: translateY(0) rotate(-3deg); } 50% { transform: translateY(-6px) rotate(3deg); } }

/* シールちょう */
.book-card { width: min(92vw, 900px); display: flex; flex-direction: column; gap: 12px; }
.book-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.book-head h2 { margin: 0; font-size: 28px; font-weight: 900; }
.book-grid { display: grid; grid-template-columns: repeat(10, 1fr); gap: 8px; }
.slot {
  aspect-ratio: 1; border-radius: 16px; background: #fff8e6; border: 3px dashed var(--line);
  display: flex; align-items: center; justify-content: center;
}
.slot.filled { border-style: solid; background: #fff; }
.slot .sticker { width: 82%; height: 82%; transform: rotate(var(--rot, 0deg)); }
.slot .sticker svg { filter: none; }
.slot .sticker.pasted { animation: paste .55s cubic-bezier(.2, 1.5, .4, 1); }
@keyframes paste { 0% { transform: scale(2) rotate(var(--rot, 0deg)); opacity: .5; } 100% { transform: scale(1) rotate(var(--rot, 0deg)); } }
.book-foot { display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; }

/* せってい */
.settings-card { width: min(92vw, 640px); }
.setting { border: 0; padding: 0; margin: 0 0 18px; }
.setting legend { font-size: 18px; font-weight: 900; margin-bottom: 6px; }
.setting label { display: block; padding: 8px 4px; font-size: 17px; }
.setting input { transform: scale(1.4); margin-right: 12px; }
.note { font-size: 14px; color: var(--sub); margin: 4px 0 0; }
.settings-card a { color: #1f6fd1; }

/* おとなのせってい: ながおし中は輪がたまる */
.gate { position: relative; }
.gate-btn { position: relative; }
.gate-btn::after {
  content: ""; position: absolute; inset: -5px; border-radius: 50%; pointer-events: none;
  background: conic-gradient(var(--accent) var(--p, 0%), transparent 0);
  -webkit-mask: radial-gradient(circle, transparent 60%, #000 61%); mask: radial-gradient(circle, transparent 60%, #000 61%);
  opacity: 0;
}
.gate-btn.holding::after { opacity: 1; animation: gatefill 1.2s linear forwards; }
@property --p { syntax: '<percentage>'; inherits: false; initial-value: 0%; }
@keyframes gatefill { to { --p: 100%; } }
.gate-hint {
  position: absolute; right: 0; top: 64px; z-index: 10; margin: 0; white-space: nowrap;
  padding: 8px 14px; border-radius: 12px; background: #fff; box-shadow: 0 6px 14px rgba(0,0,0,.15);
  font-size: 14px; color: var(--sub);
}

/* スマホなど狭い幅・縦長 */
@media (orientation: portrait) {
  .group-list { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .group-name { font-size: clamp(14px, 3.6vw, 26px); }
}
@media (max-width: 700px) {
  .home-head h1 { font-size: 26px; }
  .group-list { gap: 12px; padding: 8px 14px 10px; grid-auto-rows: minmax(104px, 1fr); }
  .card { margin: 4px 12px; }
  .book-grid { grid-template-columns: repeat(5, 1fr); }
  .big-btn { min-width: 0; font-size: 22px; padding: 12px 22px; }
  .next-btn { min-width: 200px; font-size: 26px; }
}
