/* さんすうどうぶつえん — スタイル */
:root {
  --bg: #FDF6E3;
  --card: #FFFFFF;
  --ink: #4A3B2A;
  --primary: #4CAF7D;
  --primary-dark: #388E5C;
  --accent: #FFB300;
  --blue: #4FA3D9;
  --pink: #FF8FA3;
  --soft: #F0E6CE;
  --radius: 22px;
  --shadow: 0 4px 12px rgba(90, 70, 30, 0.15);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  height: 100%;
  overscroll-behavior: none;
}

body {
  font-family: "Hiragino Maru Gothic ProN", "Hiragino Kaku Gothic ProN", "BIZ UDGothic", sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

.hidden { display: none !important; }
.accent { color: var(--primary); }

/* ---------- ヘッダー ---------- */
#topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: calc(8px + env(safe-area-inset-top)) 16px 8px;
  min-height: 60px;
}
#topbar-title { font-size: 22px; font-weight: bold; flex: 1; text-align: center; }
#coin-counter {
  background: var(--card);
  border-radius: 999px;
  padding: 10px 18px;
  font-size: 20px;
  font-weight: bold;
  box-shadow: var(--shadow);
  min-width: 96px;
  text-align: center;
}
#coin-counter.pulse { animation: pulse 0.5s ease; }
@keyframes pulse { 50% { transform: scale(1.25); } }

.chip {
  border: none;
  background: var(--card);
  border-radius: 999px;
  padding: 12px 20px;
  font-size: 18px;
  font-family: inherit;
  color: var(--ink);
  box-shadow: var(--shadow);
  min-height: 48px;
}

/* ---------- 画面共通 ---------- */
#app { flex: 1; display: flex; flex-direction: column; overflow-y: auto; }
.screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 12px 20px calc(20px + env(safe-area-inset-bottom));
  max-width: 1100px;
  width: 100%;
  margin: 0 auto;
}

button { cursor: pointer; font-family: inherit; color: var(--ink); }
button:active { transform: scale(0.96); }

.btn-big {
  border: none;
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: var(--shadow);
  font-size: 26px;
  font-weight: bold;
  min-height: 84px;
  padding: 16px 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-amber { background: var(--accent); color: #fff; }
.btn-blue { background: var(--blue); color: #fff; }
.btn-pink { background: var(--pink); color: #fff; }
.btn-big .big-emoji { font-size: 34px; }
.btn-big:disabled { opacity: 0.5; }

/* ---------- ホーム ---------- */
.home-mascots {
  display: flex;
  justify-content: center;
  gap: 10px;
  font-size: 44px;
  min-height: 64px;
  margin: 4px 0 10px;
}
.home-mascots span { animation: bob 2.4s ease-in-out infinite; }
.home-mascots span:nth-child(2n) { animation-delay: 0.4s; }
.home-mascots span:nth-child(3n) { animation-delay: 0.8s; }
@keyframes bob { 50% { transform: translateY(-10px); } }

.home-menu { display: flex; flex-direction: column; gap: 16px; margin-bottom: 16px; }

.mission-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 20px;
  font-size: 19px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.mission-card .bar {
  flex: 1;
  height: 16px;
  background: var(--soft);
  border-radius: 999px;
  overflow: hidden;
}
.mission-card .bar > div { height: 100%; background: var(--accent); border-radius: 999px; transition: width 0.4s; }

.stamp-row { display: flex; gap: 8px; justify-content: center; font-size: 26px; margin-top: 8px; }
.stamp-row .day { opacity: 0.25; }
.stamp-row .day.on { opacity: 1; }

.home-footer {
  margin-top: auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 16px;
}
.link-plain {
  border: none;
  background: none;
  font-size: 15px;
  color: #96865f;
  text-decoration: underline;
  min-height: 44px;
}

/* ---------- 単元えらび ---------- */
.topic-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
}
@media (orientation: landscape) { .topic-grid { grid-template-columns: repeat(4, 1fr); } }
.topic-card {
  border: none;
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: var(--shadow);
  min-height: 120px;
  font-size: 21px;
  font-weight: bold;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px;
}
.topic-card .t-emoji { font-size: 36px; }
.topic-card .t-stars { font-size: 16px; color: var(--accent); letter-spacing: 2px; }
.topic-card.mix { background: linear-gradient(135deg, #FFF3D6, #E1F5E9); }

/* ---------- クイズ ---------- */
#screen-quiz { gap: 10px; }
.quiz-head { display: flex; align-items: center; gap: 14px; font-size: 20px; }
.quiz-dots { flex: 1; display: flex; gap: 8px; font-size: 22px; letter-spacing: 2px; }
.quiz-streak { font-size: 19px; }

.quiz-body { flex: 1; display: flex; flex-direction: column; gap: 12px; min-height: 0; }
@media (orientation: landscape) {
  .quiz-body { flex-direction: row; align-items: stretch; }
  .quiz-body > .q-area { flex: 1.2; }
  .quiz-body > .a-area { flex: 1; }
}

.q-area {
  position: relative;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 200px;
}
.q-prompt { font-size: 22px; text-align: center; }
.q-expr { font-size: 44px; font-weight: bold; letter-spacing: 2px; text-align: center; }
.ans-box {
  display: inline-block;
  min-width: 100px;
  border-bottom: 5px solid var(--primary);
  color: var(--primary-dark);
  text-align: center;
}
.q-area.wobble { animation: wobble 0.5s ease; }
@keyframes wobble {
  20% { transform: translateX(-10px) rotate(-1.5deg); }
  40% { transform: translateX(9px) rotate(1.2deg); }
  60% { transform: translateX(-6px); }
  80% { transform: translateX(5px); }
}

.q-feedback {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 34px;
  font-weight: bold;
  border-radius: var(--radius);
  pointer-events: none;
  opacity: 0;
}
.q-feedback.show-ok {
  opacity: 1;
  background: rgba(76, 175, 125, 0.92);
  color: #fff;
  animation: popfb 0.3s ease;
}
.q-feedback.show-retry {
  opacity: 1;
  background: rgba(255, 179, 0, 0.92);
  color: #fff;
  animation: popfb 0.3s ease;
}
.q-feedback .fb-big { font-size: 76px; }
@keyframes popfb { 0% { transform: scale(0.6); opacity: 0; } }

.reveal-box {
  background: #FFF6DF;
  border: 3px dashed var(--accent);
  border-radius: 16px;
  padding: 12px 18px;
  font-size: 20px;
  text-align: center;
}
.reveal-box .rv-ans { font-size: 40px; font-weight: bold; color: var(--primary-dark); }

/* 筆算 */
.hissan {
  font-variant-numeric: tabular-nums;
  font-size: 46px;
  font-weight: bold;
  display: inline-grid;
  gap: 2px 6px;
  text-align: right;
}
.hissan .row { display: contents; }
.hissan .cell { min-width: 38px; text-align: center; }
.hissan .op { color: var(--blue); }
.hissan .line { grid-column: 1 / -1; border-bottom: 5px solid var(--ink); margin: 4px 0; }
.hissan .ans .cell { color: var(--primary-dark); }
.hissan .ans .empty { border-bottom: 4px solid #cbbf9f; min-width: 38px; }

/* とけい SVG */
.clock-wrap svg { width: min(46vw, 240px); height: auto; display: block; }

/* かたち */
.shape-single svg { width: 140px; height: 140px; }

/* ---------- 入力エリア ---------- */
.a-area { display: flex; flex-direction: column; gap: 10px; justify-content: flex-end; }

.numpad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.numpad button {
  border: none;
  border-radius: 18px;
  background: var(--card);
  box-shadow: var(--shadow);
  font-size: 34px;
  font-weight: bold;
  min-height: 72px;
}
.numpad .key-ok { background: var(--primary); color: #fff; }
.numpad .key-del { background: var(--soft); font-size: 26px; }

.choices { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.choices.two { grid-template-columns: 1fr 1fr; }
.choices.three { grid-template-columns: repeat(3, 1fr); }
.choice-btn {
  border: none;
  border-radius: 18px;
  background: var(--card);
  box-shadow: var(--shadow);
  font-size: 26px;
  font-weight: bold;
  min-height: 84px;
  padding: 10px;
}
.choice-btn svg { width: 90px; height: 90px; }
.choice-btn.shape-choice { min-height: 110px; }

/* タイムアタックの太陽バー */
.sunbar { height: 14px; background: var(--soft); border-radius: 999px; overflow: hidden; }
.sunbar > div {
  height: 100%;
  background: linear-gradient(90deg, #FFD54F, #FFB300);
  border-radius: 999px;
}

/* ---------- けっか ---------- */
.result-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 26px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
}
.result-stars { font-size: 52px; letter-spacing: 6px; }
.result-score { font-size: 28px; font-weight: bold; }
.coin-lines { font-size: 19px; text-align: left; display: inline-block; }
.coin-lines div { display: flex; justify-content: space-between; gap: 30px; }
.coin-total { font-size: 26px; font-weight: bold; color: var(--primary-dark); border-top: 3px solid var(--soft); margin-top: 6px; padding-top: 6px; }
.result-actions { display: flex; flex-direction: column; gap: 12px; margin-top: 14px; width: 100%; max-width: 460px; align-self: center; }
.glow { animation: glow 1.2s ease-in-out infinite; }
@keyframes glow { 50% { box-shadow: 0 0 24px rgba(255, 179, 0, 0.8); } }

/* ---------- ガチャ ---------- */
.gacha-stage {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 24px;
  position: relative;
  overflow: hidden;
}
.gacha-egg { font-size: 110px; }
.gacha-egg.shake { animation: eggshake 1.2s ease; }
@keyframes eggshake {
  0%, 100% { transform: rotate(0); }
  15% { transform: rotate(-14deg); }
  30% { transform: rotate(12deg); }
  45% { transform: rotate(-10deg); }
  60% { transform: rotate(8deg) translateY(-6px); }
  75% { transform: rotate(-6deg); }
}
.gacha-reveal { display: flex; flex-direction: column; align-items: center; gap: 8px; animation: popfb 0.45s ease; }
.gacha-reveal .rv-emoji { font-size: 120px; }
.gacha-reveal .rv-name { font-size: 30px; font-weight: bold; }
.rarity-badge { border-radius: 999px; padding: 6px 18px; font-size: 18px; font-weight: bold; color: #fff; }
.rarity-normal { background: #8BC34A; }
.rarity-rare { background: var(--blue); }
.rarity-sr { background: #AB47BC; }
.rarity-secret { background: linear-gradient(90deg, #f66, #fa3, #4caf7d, #49f, #a4f); }
.rays {
  position: absolute; inset: -50%;
  background: repeating-conic-gradient(rgba(255, 213, 79, 0.35) 0 12deg, transparent 12deg 24deg);
  animation: spin 7s linear infinite;
  pointer-events: none;
}
.rainbow-bg {
  position: absolute; inset: -50%;
  background: repeating-conic-gradient(rgba(255,102,102,.2) 0 20deg, rgba(255,179,0,.2) 20deg 40deg, rgba(76,175,125,.2) 40deg 60deg, rgba(79,163,217,.2) 60deg 80deg, rgba(170,68,255,.2) 80deg 100deg);
  animation: spin 9s linear infinite;
  pointer-events: none;
}
@keyframes spin { to { transform: rotate(360deg); } }
.pity-dots { font-size: 15px; color: #96865f; letter-spacing: 3px; }

/* ---------- ずかん ---------- */
.zukan-head { display: flex; align-items: center; gap: 14px; font-size: 20px; font-weight: bold; margin-bottom: 10px; flex-wrap: wrap; }
.zukan-bar { flex: 1; min-width: 140px; height: 14px; background: var(--soft); border-radius: 999px; overflow: hidden; }
.zukan-bar > div { height: 100%; background: var(--primary); }
.zukan-tabs { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.zukan-tabs .chip { min-height: 44px; padding: 8px 14px; font-size: 15px; }
.zukan-tabs .chip.on { background: var(--primary); color: #fff; }
.zukan-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(88px, 1fr));
  gap: 10px;
}
.zukan-tile {
  border: none;
  background: var(--card);
  border-radius: 16px;
  box-shadow: var(--shadow);
  min-height: 104px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  font-size: 13px;
  padding: 6px;
}
.zukan-tile .z-emoji { font-size: 40px; }
.zukan-tile.locked .z-emoji { filter: brightness(0); opacity: 0.3; }
.zukan-tile.locked { color: #b3a583; }
.zukan-tile.secret-locked { border: 2px dashed #d5b3f5; }
.zukan-tile.fav3 { outline: 3px solid var(--accent); }
.z-hearts { font-size: 11px; }

/* ---------- モーダル・トースト ---------- */
#modal-root {
  position: fixed;
  inset: 0;
  background: rgba(74, 59, 42, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 50;
}
.modal-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 28px;
  max-width: 480px;
  width: 100%;
  max-height: 85dvh;
  overflow-y: auto;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 14px;
  align-items: center;
  box-shadow: var(--shadow);
  animation: popfb 0.3s ease;
  font-size: 20px;
}
.modal-card .m-emoji { font-size: 76px; }
.modal-actions { display: flex; gap: 12px; width: 100%; }
.modal-actions .btn-big { flex: 1; font-size: 21px; min-height: 64px; }

#toast {
  position: fixed;
  bottom: calc(24px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  border-radius: 999px;
  padding: 12px 24px;
  font-size: 17px;
  z-index: 60;
}

/* ---------- 紙吹雪 ---------- */
#confetti-layer { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 55; }
.confetti {
  position: absolute;
  top: -20px;
  width: 12px;
  height: 12px;
  border-radius: 3px;
  animation: fall 1.4s ease-in forwards;
}
@keyframes fall {
  to { transform: translateY(105vh) rotate(720deg); opacity: 0.6; }
}

/* コイン獲得表示 */
.coin-float {
  position: fixed;
  font-size: 26px;
  font-weight: bold;
  color: var(--accent);
  text-shadow: 0 1px 0 #fff;
  pointer-events: none;
  z-index: 56;
  animation: rise 1s ease-out forwards;
}
@keyframes rise { to { transform: translateY(-70px); opacity: 0; } }

/* ---------- おうちのひと ---------- */
.parent-wrap { display: flex; flex-direction: column; gap: 18px; font-size: 17px; max-width: 720px; margin: 0 auto; width: 100%; }
.parent-card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.parent-card h3 { font-size: 19px; margin-bottom: 12px; }
.pbar-chart { display: flex; align-items: flex-end; gap: 6px; height: 120px; }
.pbar { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 10px; color: #96865f; }
.pbar > div { width: 100%; background: var(--primary); border-radius: 6px 6px 0 0; min-height: 2px; }
table.ptable { width: 100%; border-collapse: collapse; font-size: 16px; }
table.ptable th, table.ptable td { padding: 8px 6px; border-bottom: 1px solid var(--soft); text-align: center; }
table.ptable th:first-child, table.ptable td:first-child { text-align: left; }
.weak-list { display: flex; flex-wrap: wrap; gap: 8px; }
.weak-chip { background: #FFF0F2; border: 2px solid var(--pink); border-radius: 999px; padding: 8px 16px; font-size: 17px; font-weight: bold; }
.parent-textarea {
  width: 100%;
  min-height: 110px;
  font-size: 12px;
  font-family: monospace;
  border-radius: 12px;
  border: 2px solid var(--soft);
  padding: 10px;
  -webkit-user-select: text;
  user-select: text;
}
.danger { background: #E57373; color: #fff; }

/* ---------- 設定 ---------- */
.settings-list { display: flex; flex-direction: column; gap: 14px; max-width: 520px; margin: 0 auto; width: 100%; }
.setting-row {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 22px;
  font-size: 21px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
}
.toggle {
  border: none;
  border-radius: 999px;
  min-width: 96px;
  min-height: 52px;
  font-size: 19px;
  font-weight: bold;
  background: var(--soft);
}
.toggle.on { background: var(--primary); color: #fff; }

/* 画面切替アニメ */
.screen { animation: screenin 0.25s ease; }
@keyframes screenin { from { opacity: 0; transform: translateY(8px); } }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
