:root {
  --bg: #faf5e8;
  --dot: #e8ddc5;
  --text: #3d2e1f;
  --text-soft: #7a6a55;
  --card-shadow: 0 4px 0 rgba(0,0,0,0.06), 0 6px 16px rgba(0,0,0,0.05);
  --accent: #f5c63a;
  --accent-dark: #7a5b10;
  --correct: #4a9f4a;
  --correct-bg: #d8eed4;
  --wrong: #d96a5a;
  --wrong-bg: #f6d9d2;
}

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

body {
  font-family: "M PLUS Rounded 1c", -apple-system, BlinkMacSystemFont, sans-serif;
  background-color: var(--bg);
  background-image: radial-gradient(var(--dot) 1.2px, transparent 1.2px);
  background-size: 18px 18px;
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-weight: 500;
}

.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.1rem 1.6rem;
}

.top-bar a, .top-bar .title {
  color: var(--text);
  text-decoration: none;
  font-size: 1rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.top-bar a:hover { opacity: 0.7; }

.top-bar .title { font-size: 1.05rem; }

.avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid #d9ccac;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #7a6a55;
  font-size: 1.15rem;
}

main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0.5rem 1rem 2rem;
  position: relative;
}

.deco {
  position: absolute;
  font-size: 2.6rem;
  opacity: 0.2;
  pointer-events: none;
  user-select: none;
}
.deco-1 { top: 5%; left: 4%; }
.deco-2 { top: 40%; right: 4%; opacity: 0.15; }
.deco-3 { bottom: 8%; right: 5%; }

/* Progress */
.progress-wrap {
  width: 100%;
  max-width: 560px;
  margin-top: 0.5rem;
}

.progress-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  color: var(--text-soft);
  margin-bottom: 0.5rem;
  font-weight: 700;
}

.progress-dots {
  display: flex;
  justify-content: space-between;
  gap: 4px;
  position: relative;
}

.dot {
  flex: 1;
  height: 12px;
  border-radius: 999px;
  background: #e0d8c4;
  transition: background 0.3s;
}

.dot.done { background: var(--correct); }
.dot.wrong-done { background: var(--wrong); }

.dot.current {
  background: var(--accent);
  position: relative;
  box-shadow: 0 0 0 3px #fff;
}

.dot.current::after {
  content: "😊";
  position: absolute;
  top: -16px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 1.1rem;
  background: var(--accent);
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid #fff;
}

/* Question */
.question-area {
  margin-top: 3rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.question-text {
  font-size: clamp(2.2rem, 6vw, 3.4rem);
  font-weight: 800;
  letter-spacing: 0.05em;
  color: #1c1410;
}

.answer-box {
  min-width: 110px;
  height: 110px;
  padding: 0 1rem;
  background: #fff;
  border: 3px solid var(--accent);
  border-radius: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 3rem;
  font-weight: 800;
  color: #1c1410;
  box-shadow: var(--card-shadow);
  position: relative;
}

.answer-box .caret {
  display: inline-block;
  width: 4px;
  height: 48px;
  background: var(--accent);
  animation: blink 1s steps(2) infinite;
  margin-left: 2px;
}

.answer-box.empty .caret { display: inline-block; }

@keyframes blink { 50% { opacity: 0; } }

.answer-box .pencil-deco {
  position: absolute;
  top: -14px;
  right: -8px;
  font-size: 1.5rem;
  transform: rotate(25deg);
}

/* Submit */
.submit-btn {
  margin-top: 2.2rem;
  padding: 0.95rem 2.8rem;
  background: var(--accent);
  color: var(--accent-dark);
  border: none;
  border-radius: 999px;
  font-size: 1.15rem;
  font-weight: 800;
  font-family: inherit;
  cursor: pointer;
  box-shadow: 0 4px 0 rgba(0,0,0,0.1);
  transition: transform 0.1s, box-shadow 0.1s, opacity 0.2s;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.submit-btn:hover { transform: translateY(-2px); box-shadow: 0 6px 0 rgba(0,0,0,0.1); }
.submit-btn:active { transform: translateY(2px); box-shadow: 0 2px 0 rgba(0,0,0,0.1); }
.submit-btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; box-shadow: 0 4px 0 rgba(0,0,0,0.1); }

/* Numpad */
.numpad {
  margin-top: auto;
  margin-bottom: 1rem;
  padding: 1.1rem 1rem 1.2rem;
  background: #f3ebd5;
  border: 2px solid var(--accent);
  border-radius: 22px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.6rem;
  max-width: 360px;
  width: 100%;
}

.key {
  background: #fff;
  border: none;
  border-radius: 999px;
  padding: 0.9rem 0;
  font-size: 1.45rem;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  box-shadow: 0 3px 0 rgba(0,0,0,0.08);
  transition: transform 0.08s, box-shadow 0.08s;
  color: var(--text);
}

.key:hover { transform: translateY(-1px); }
.key:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(0,0,0,0.08); }
.key.back { background: #8cc7e6; color: #154a66; }
.key.placeholder { visibility: hidden; pointer-events: none; }

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(250, 245, 232, 0.85);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 100;
}

.modal-backdrop.show { display: flex; animation: fadeIn 0.2s ease; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: linear-gradient(180deg, #fffdf6 0%, #faf5e8 100%);
  border-radius: 26px;
  padding: 2rem 2.2rem 1.7rem;
  text-align: center;
  max-width: 340px;
  width: 100%;
  box-shadow: 0 8px 32px rgba(0,0,0,0.12);
  animation: popIn 0.3s cubic-bezier(0.2, 1.2, 0.4, 1);
}

@keyframes popIn {
  from { transform: scale(0.7); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.modal h2 {
  font-size: 1.9rem;
  font-weight: 800;
  margin-bottom: 1rem;
}

.modal.correct h2 { color: #2a6b2a; }
.modal.wrong h2 { color: #8a2418; }

.modal .badge {
  width: 110px;
  height: 110px;
  margin: 0 auto 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 3.8rem;
  background: #eef6e8;
  border-radius: 24px;
  transform: rotate(-5deg);
}

.modal.wrong .badge { background: #fbeae5; }

.modal p {
  color: var(--text-soft);
  margin-bottom: 1.4rem;
  font-size: 1rem;
  font-weight: 700;
}

.modal .next-btn {
  width: 100%;
  background: #2e7a3a;
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: 0.95rem;
  font-size: 1.05rem;
  font-weight: 800;
  font-family: inherit;
  cursor: pointer;
  box-shadow: 0 4px 0 rgba(0,0,0,0.15);
  transition: transform 0.1s, box-shadow 0.1s;
}

.modal.wrong .next-btn { background: #c94a3a; }

.modal .next-btn:hover { transform: translateY(-2px); box-shadow: 0 6px 0 rgba(0,0,0,0.15); }
.modal .next-btn:active { transform: translateY(2px); box-shadow: 0 2px 0 rgba(0,0,0,0.15); }

.modal .points {
  display: inline-block;
  margin-top: 1rem;
  padding: 0.4rem 1rem;
  background: var(--correct-bg);
  color: #2a6b2a;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 700;
}

/* Final Result */
.result-card {
  background: #fff;
  border-radius: 28px;
  padding: 2rem 1.8rem;
  max-width: 480px;
  width: 100%;
  margin: 0 auto;
  box-shadow: 0 8px 32px rgba(0,0,0,0.08);
  text-align: center;
}

.result-tag {
  display: inline-block;
  background: var(--correct-bg);
  color: #2a6b2a;
  padding: 0.35rem 1rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 700;
  margin-bottom: 0.7rem;
}

.result-title {
  font-size: 1.7rem;
  font-weight: 800;
  margin-bottom: 1.2rem;
}
.result-title .hi { color: #c94a3a; }

.result-banner {
  background: #fbf1d4;
  border: 2px dashed var(--accent);
  border-radius: 18px;
  padding: 1.5rem 1rem;
  margin-bottom: 1.3rem;
}

.result-banner .trophy { font-size: 3.5rem; margin-bottom: 0.5rem; }
.result-banner h3 { font-size: 1.5rem; font-weight: 800; color: var(--accent-dark); margin-bottom: 0.3rem; }
.result-banner p { color: var(--text-soft); font-weight: 700; font-size: 0.9rem; }
.result-banner .confetti { font-size: 1.3rem; margin-top: 0.6rem; letter-spacing: 0.3rem; }

.metrics {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.6rem;
  margin-bottom: 1.3rem;
}

.metric {
  background: #f7f1e0;
  border-radius: 14px;
  padding: 0.7rem 0.3rem;
}

.metric .m-label { font-size: 0.7rem; color: var(--text-soft); font-weight: 700; margin-bottom: 0.2rem; }
.metric .m-value { font-size: 1.1rem; font-weight: 800; color: var(--text); }

.result-actions {
  display: flex;
  gap: 0.7rem;
  flex-wrap: wrap;
}

.result-actions button {
  flex: 1;
  min-width: 140px;
  border: none;
  border-radius: 999px;
  padding: 0.95rem 1rem;
  font-size: 1rem;
  font-weight: 800;
  font-family: inherit;
  cursor: pointer;
  box-shadow: 0 4px 0 rgba(0,0,0,0.1);
  transition: transform 0.1s, box-shadow 0.1s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
}

.result-actions .retry {
  background: #d4b371;
  color: #3d2e1f;
}

.result-actions .choose {
  background: #8cc7e6;
  color: #154a66;
}

.result-actions button:hover { transform: translateY(-2px); box-shadow: 0 6px 0 rgba(0,0,0,0.1); }
.result-actions button:active { transform: translateY(2px); box-shadow: 0 2px 0 rgba(0,0,0,0.1); }

.mascot {
  margin-top: 1.4rem;
  font-size: 3rem;
}

/* Theme overrides */
body.theme-g1 { --accent: #f5c63a; --accent-dark: #7a5b10; }
body.theme-g2 { --accent: #8cc7e6; --accent-dark: #154a66; }
body.theme-g3 { --accent: #a4db9b; --accent-dark: #1e5a24; }
body.theme-g4 { --accent: #f0a89c; --accent-dark: #8a2418; }
body.theme-g5 { --accent: #dcc488; --accent-dark: #6b5520; }
body.theme-g6 { --accent: #9bc7e0; --accent-dark: #144966; }

/* Hidden */
.hidden { display: none !important; }

@media (max-width: 520px) {
  .question-area { gap: 0.5rem; margin-top: 1.5rem; }
  .answer-box { min-width: 80px; height: 80px; font-size: 2.2rem; border-radius: 16px; }
  .submit-btn { margin-top: 1.5rem; padding: 0.8rem 2rem; font-size: 1rem; }
  .numpad { padding: 0.8rem; gap: 0.5rem; }
  .key { font-size: 1.2rem; padding: 0.75rem 0; }
  .deco { display: none; }
}
