:root {
  --bg: #fef9ef;
  --bg2: #fff4df;
  --card: #ffffff;
  --ink: #4a3b2a;
  --ink-soft: #8a7a64;
  --teal: #2f8f9d;
  --teal-dark: #237582;
  --teal-soft: #e3f3f2;
  --brown: #bb9a6a;
  --line: #ece3d3;
  --ok: #3fae6e;
  --ok-soft: #e4f6ec;
  --ng: #e0654f;
  --ng-soft: #fbe7e2;
  --warn: #f0a832;
  --shadow: 0 6px 18px rgba(90, 70, 40, .12);
  --radius: 18px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Kaku Gothic ProN",
    "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", Meiryo, sans-serif;
  -webkit-font-smoothing: antialiased;
}

body { overscroll-behavior-y: none; }

#app {
  max-width: 520px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  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; }

/* ===== Topbar ===== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  background: linear-gradient(180deg, var(--bg2), var(--bg));
  border-bottom: 1px solid var(--line);
}
.logo {
  margin: 0;
  font-size: 1.18rem;
  font-weight: 800;
  letter-spacing: .02em;
  display: flex;
  align-items: center;
  gap: 6px;
}
.paw { font-size: 1.1rem; }
.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  background: var(--teal-soft);
  color: var(--teal-dark);
  font-size: 1.1rem;
  font-weight: 800;
  cursor: pointer;
}
.icon-btn:active { transform: scale(.92); }

/* ===== View ===== */
.view {
  flex: 1;
  padding: 16px 18px 28px;
  animation: fade .25s ease;
}
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ===== Cat banner ===== */
.cat-banner {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--teal-soft);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 16px;
}
.cat-mark {
  width: 52px;
  height: 52px;
  flex: 0 0 52px;
  background: url("../images/icon_chimeiquiz-512.png") center/contain no-repeat;
  filter: drop-shadow(0 2px 3px rgba(0,0,0,.12));
}
.speech {
  background: #fff;
  border-radius: 14px;
  padding: 9px 12px;
  font-size: .9rem;
  font-weight: 600;
  color: var(--teal-dark);
  position: relative;
  line-height: 1.4;
}
.speech::before {
  content: "";
  position: absolute;
  left: -7px;
  top: 16px;
  border: 7px solid transparent;
  border-right-color: #fff;
}

/* ===== Stats board ===== */
.stats-board {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 22px;
}
.stat {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 6px;
  text-align: center;
  box-shadow: var(--shadow);
}
.stat-num {
  display: block;
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--teal);
  line-height: 1.1;
}
.stat-label {
  display: block;
  margin-top: 3px;
  font-size: .68rem;
  color: var(--ink-soft);
}

/* ===== Setup ===== */
.section-title {
  font-size: .95rem;
  font-weight: 800;
  margin: 18px 0 10px;
  color: var(--ink);
}
.chip-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.chip {
  border: 1.5px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 999px;
  padding: 9px 14px;
  font-size: .85rem;
  font-weight: 700;
  cursor: pointer;
  transition: all .12s ease;
}
.chip:active { transform: scale(.95); }
.chip.active {
  background: var(--teal);
  border-color: var(--teal);
  color: #fff;
  box-shadow: 0 3px 10px rgba(47,143,157,.35);
}
.pool-info {
  margin: 14px 2px 0;
  font-size: .8rem;
  color: var(--ink-soft);
}

.start-btn {
  margin: 22px 0 8px;
  width: 100%;
  border: none;
  border-radius: 16px;
  padding: 17px;
  font-size: 1.1rem;
  font-weight: 800;
  color: #fff;
  background: linear-gradient(180deg, var(--teal), var(--teal-dark));
  box-shadow: 0 8px 18px rgba(47,143,157,.4);
  cursor: pointer;
}
.start-btn:active { transform: translateY(2px); box-shadow: 0 4px 10px rgba(47,143,157,.4); }
.start-btn:disabled { opacity: .5; box-shadow: none; }

/* ===== Quiz ===== */
.quiz-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.back-btn {
  border: none;
  background: none;
  color: var(--ink-soft);
  font-size: .95rem;
  font-weight: 700;
  cursor: pointer;
  padding: 4px 2px;
}
.streak-chip {
  background: #fff3e0;
  color: #e07c2a;
  border-radius: 999px;
  padding: 6px 13px;
  font-weight: 800;
  font-size: .9rem;
}
.streak-chip.glow { animation: pop .35s ease; }
@keyframes pop { 0%{transform:scale(1)} 40%{transform:scale(1.25)} 100%{transform:scale(1)} }

.progress-wrap { margin-bottom: 18px; }
.progress-bar {
  height: 8px;
  background: var(--line);
  border-radius: 999px;
  overflow: hidden;
}
.progress-bar span {
  display: block;
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--teal), #58c3c0);
  border-radius: 999px;
  transition: width .3s ease;
}
.progress-text {
  margin-top: 6px;
  text-align: right;
  font-size: .78rem;
  color: var(--ink-soft);
  font-weight: 700;
}

.question-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px 18px 24px;
  text-align: center;
  margin-bottom: 18px;
}
.q-tags {
  display: flex;
  gap: 6px;
  justify-content: center;
  margin-bottom: 14px;
}
.tag {
  font-size: .72rem;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 999px;
}
.tag-region { background: var(--teal-soft); color: var(--teal-dark); }
.tag-genre { background: #f3ecdd; color: #9a7b3e; }
.q-label {
  font-size: .82rem;
  color: var(--ink-soft);
  margin-bottom: 8px;
}
.q-place {
  font-size: clamp(2.6rem, 14vw, 3.6rem);
  font-weight: 800;
  letter-spacing: .04em;
  line-height: 1.1;
  color: var(--ink);
}
.q-pref {
  margin-top: 12px;
  font-size: .82rem;
  color: var(--ink-soft);
  min-height: 1em;
}

.choices {
  display: grid;
  gap: 10px;
}
.choice {
  width: 100%;
  border: 1.5px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 14px;
  padding: 16px;
  font-size: 1.15rem;
  font-weight: 700;
  cursor: pointer;
  transition: all .12s ease;
  text-align: center;
}
.choice:active { transform: scale(.98); }
.choice:disabled { cursor: default; }
.choice.correct {
  background: var(--ok-soft);
  border-color: var(--ok);
  color: var(--ok);
}
.choice.wrong {
  background: var(--ng-soft);
  border-color: var(--ng);
  color: var(--ng);
}
.choice.dim { opacity: .5; }

/* ===== Feedback ===== */
.feedback {
  margin-top: 18px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  text-align: center;
  animation: fade .2s ease;
}
.fb-result {
  font-size: 1.3rem;
  font-weight: 800;
}
.fb-result.ok { color: var(--ok); }
.fb-result.ng { color: var(--ng); }
.fb-answer {
  margin-top: 6px;
  font-size: 1rem;
  font-weight: 700;
  color: var(--ink);
}
.fb-trivia {
  margin: 12px 0 0;
  font-size: .85rem;
  color: var(--ink-soft);
  line-height: 1.6;
  text-align: left;
}
.next-btn {
  margin-top: 16px;
  width: 100%;
  border: none;
  border-radius: 14px;
  padding: 15px;
  font-size: 1.05rem;
  font-weight: 800;
  color: #fff;
  background: linear-gradient(180deg, var(--teal), var(--teal-dark));
  cursor: pointer;
}
.next-btn:active { transform: translateY(2px); }

/* ===== Result ===== */
.result-hero {
  text-align: center;
  padding: 14px 0 4px;
}
.result-cat {
  width: 92px;
  height: 92px;
  margin: 0 auto 10px;
  background: url("../images/icon_chimeiquiz-512.png") center/contain no-repeat;
  filter: drop-shadow(0 4px 6px rgba(0,0,0,.12));
}
.result-title {
  margin: 0;
  font-size: 1.4rem;
  font-weight: 800;
}
.result-speech {
  margin-top: 8px;
  font-size: .95rem;
  font-weight: 700;
  color: var(--teal-dark);
}
.result-stats {
  margin: 22px 0 12px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.rs-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 15px 18px;
  border-bottom: 1px solid var(--line);
  font-size: .92rem;
}
.rs-row:last-child { border-bottom: none; }
.rs-row b { font-size: 1.15rem; color: var(--teal); }
.new-record {
  text-align: center;
  font-weight: 800;
  color: var(--warn);
  background: #fff7e6;
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 16px;
  animation: pop .4s ease;
}
.result-actions { display: grid; gap: 10px; margin-top: 6px; }

.btn {
  width: 100%;
  border: 1.5px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 14px;
  padding: 15px;
  font-size: 1rem;
  font-weight: 800;
  cursor: pointer;
}
.btn:active { transform: scale(.98); }
.btn-primary {
  border: none;
  color: #fff;
  background: linear-gradient(180deg, var(--teal), var(--teal-dark));
  box-shadow: 0 6px 14px rgba(47,143,157,.35);
}

/* ===== Modal ===== */
.modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(40,30,20,.45);
}
.modal-card {
  position: relative;
  width: 100%;
  max-width: 520px;
  background: var(--card);
  border-radius: 22px 22px 0 0;
  padding: 22px 20px calc(24px + env(safe-area-inset-bottom));
  box-shadow: 0 -8px 24px rgba(0,0,0,.18);
  animation: slideUp .25s ease;
}
@keyframes slideUp { from { transform: translateY(100%); } to { transform: none; } }
.modal-card h2 { margin: 0 0 12px; font-size: 1.1rem; }
.howto {
  margin: 0 0 16px;
  padding-left: 20px;
  font-size: .88rem;
  line-height: 1.8;
  color: var(--ink);
}
.howto li { margin-bottom: 4px; }

/* ===== Toast ===== */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(28px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: rgba(45,35,25,.92);
  color: #fff;
  padding: 11px 18px;
  border-radius: 999px;
  font-size: .85rem;
  font-weight: 700;
  z-index: 80;
  animation: fade .2s ease;
}
