:root {
  --bg: #e6f6ff;
  --paper: #ffffff;
  --ink: #2c3440;
  --sub: #6b7a8a;
  --accent: #ff8c42;
  --accent-dark: #c75a16;
  --blue: #3fa9f5;
  --blue-dark: #1b6fae;
  --green: #5fd068;
  --green-dark: #2f8a3a;
  --line: #c9dbe6;
  --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; }
.range-tabs { display: flex; gap: 6px; background: rgba(255,255,255,.7); border-radius: 999px; padding: 5px; }
.range-tab { padding: 8px 20px; border-radius: 999px; font-size: 22px; font-weight: 900; background: transparent; color: var(--sub); }
.range-tab.active { background: var(--blue); color: #fff; box-shadow: 0 3px 0 var(--blue-dark); }
.mode-list {
  flex: 1; min-height: 0; display: flex; gap: 22px; padding: 12px 24px;
  align-items: stretch; justify-content: center;
}
.mode-card {
  flex: 1; max-width: 460px; min-height: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  border-radius: 28px; background: var(--paper); box-shadow: 0 8px 0 rgba(0,0,0,.1);
  padding: 16px;
}
.mode-card:active { transform: translateY(4px); box-shadow: 0 4px 0 rgba(0,0,0,.1); }
.mode-art { width: 100%; max-width: 320px; flex: 1; min-height: 0; display: flex; align-items: center; }
.mode-art svg { width: 100%; max-height: 100%; }
.mode-name { font-size: clamp(26px, 4vw, 38px); font-weight: 900; color: var(--accent-dark); }
.mode-card.compare .mode-name { color: var(--blue-dark); }
.home-foot { display: flex; gap: 16px; justify-content: center; padding: 10px 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; font-size: clamp(26px, 4.4vw, 40px); font-weight: 900; }
.field { flex: 1; min-height: 0; display: flex; gap: 16px; padding: 4px 20px; }
.mode-compare .field { padding-bottom: 18px; }
.pane {
  flex: 1; min-width: 0; min-height: 0; width: 100%; height: 100%;
  background: var(--paper); border-radius: 26px; box-shadow: var(--shadow);
  border: 5px solid transparent; transition: border-color .15s;
}
.mode-compare .pane { cursor: pointer; }
.mode-compare .pane:active { transform: scale(.985); }
.pane.right { border-color: var(--green); background: #f0fff1; }
.pane.wrong { animation: shake .4s; }
.item-inner { transform-box: fill-box; transform-origin: center; }
.item { cursor: pointer; }
.item-inner.bump { animation: bump .35s ease-out; }
@keyframes bump { 50% { transform: scale(1.18); } }
/* ヒント中、しばらくタップが無いときに 次に数える絵をゆらす */
.item-inner.nudge { animation: nudge 1.1s ease-in-out infinite; }
@keyframes nudge { 0%, 60%, 100% { transform: rotate(0) scale(1); } 15% { transform: rotate(-10deg) scale(1.1); } 30% { transform: rotate(10deg) scale(1.1); } 45% { transform: rotate(-6deg) scale(1.05); } }
.badge circle { fill: var(--accent); stroke: #fff; stroke-width: 3; }
.badge text { fill: #fff; font-weight: 900; text-anchor: middle; dominant-baseline: central; font-family: inherit; }
.badge { pointer-events: none; animation: pop .3s cubic-bezier(.2, 1.5, .4, 1); transform-box: fill-box; transform-origin: center; }

.choices { display: flex; justify-content: center; gap: clamp(14px, 3vw, 30px); padding: 12px 20px 18px; }
.mode-compare .choices { display: none; }
.choice {
  min-width: clamp(96px, 16vw, 150px); height: clamp(84px, 14vh, 120px); padding: 6px 14px;
  border-radius: 26px; background: var(--paper); box-shadow: 0 7px 0 rgba(0,0,0,.12);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
}
.choice:active { transform: translateY(4px); box-shadow: 0 3px 0 rgba(0,0,0,.12); }
.choice-num { font-size: clamp(44px, 8vh, 64px); font-weight: 900; line-height: 1; color: var(--blue-dark); }
/* てん: 5 こで折り返し、真ん中にそろえる */
.choice-dots { display: flex; flex-wrap: wrap; justify-content: center; gap: 3px; max-width: 67px; }
.choice-dots i { width: 11px; height: 11px; border-radius: 50%; background: var(--accent); }
.choice.right { background: var(--green); box-shadow: 0 7px 0 var(--green-dark); }
.choice.right .choice-num { color: #fff; }
.choice.wrong { animation: shake .4s; }
.choice[disabled] { opacity: .35; }
@keyframes shake { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-7px); } 75% { transform: translateX(7px); } }

/* 縦長画面: 比べるときは上下に並べる */
@media (orientation: portrait) {
  .field { flex-direction: column; }
}

/* キラキラ粒子 */
.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(20, 40, 60, .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: #eef5fa; 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 (max-width: 700px) {
  /* タイトルと ⚙ を 1 行目、はんいタブを 2 行目に */
  .home-head { flex-wrap: wrap; }
  .home-head h1 { font-size: 26px; }
  .range-tabs { order: 3; width: 100%; justify-content: center; }
  .range-tab { flex: 1; padding: 6px 14px; font-size: 20px; }
  .mode-list { flex-direction: column; gap: 14px; padding: 8px 16px; }
  .mode-card { max-width: none; padding: 10px 16px; gap: 4px; }
  .field { padding: 4px 12px; gap: 10px; }
  .book-grid { grid-template-columns: repeat(5, 1fr); }
  .big-btn { min-width: 0; font-size: 22px; padding: 12px 22px; }
}
