/* =========================================================
   구구단 알깨기 - style.css
   초등 2학년 대상, 태블릿 터치 친화적 UI
   ========================================================= */

:root {
  --bg-top: #bfe3ff;
  --bg-bot: #ffe9f6;
  --card: #ffffff;
  --card-soft: #fbfbff;
  --ink: #3a3350;
  --ink-soft: #746c8c;
  --primary: #6c8cff;
  --primary-dark: #4a63d6;
  --accent: #ff8fb3;
  --accent-dark: #f2678f;
  --good: #3fbf8f;
  --good-dark: #229a6d;
  --warn: #ffb648;
  --bad: #ff7b6b;
  --gold: #ffcf4d;
  --shadow: 0 8px 20px rgba(90, 70, 140, 0.18);
  --shadow-sm: 0 4px 10px rgba(90, 70, 140, 0.14);
  --radius-lg: 28px;
  --radius-md: 20px;
  --radius-sm: 14px;
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  min-height: 100%;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: "Gowun Dodum", "Nanum Gothic", -apple-system, sans-serif;
  color: var(--ink);
  background: linear-gradient(160deg, var(--bg-top) 0%, var(--bg-bot) 100%);
  background-attachment: fixed;
  min-height: 100vh;
  user-select: none;
}

h1, h2, h3, .jua { font-family: "Jua", "Gowun Dodum", sans-serif; }

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  outline: none;
  background: none;
  -webkit-tap-highlight-color: transparent;
}
button:active { transform: scale(0.96); }
button:disabled { opacity: 0.45; cursor: not-allowed; }
button:disabled:active { transform: none; }

img, svg { display: block; }

#app {
  max-width: 720px;
  margin: 0 auto;
  min-height: 100vh;
  padding: 0 0 28px;
  position: relative;
}

.screen { animation: fadeSlideIn 0.28s ease; }
@keyframes fadeSlideIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- Topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(255,255,255,0.72);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid rgba(120,110,170,0.12);
}
.topbar .stat {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--card);
  border-radius: 999px;
  padding: 6px 12px;
  box-shadow: var(--shadow-sm);
  font-weight: bold;
  font-size: 14px;
  white-space: nowrap;
}
.topbar .stat .emoji { font-size: 16px; }
.topbar .spacer { flex: 1; }
.topbar .icon-btn {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: var(--card);
  box-shadow: var(--shadow-sm);
  font-size: 18px;
  display: flex; align-items: center; justify-content: center;
}
.topbar .icon-btn.locked { opacity: 0.4; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 22px;
  min-height: 52px;
  border-radius: var(--radius-md);
  font-size: 17px;
  font-weight: bold;
  box-shadow: var(--shadow-sm);
  transition: transform 0.12s ease;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:not(:disabled):hover { background: var(--primary-dark); }
.btn-accent { background: var(--accent); color: #fff; }
.btn-good { background: var(--good); color: #fff; }
.btn-ghost { background: var(--card); color: var(--ink); }
.btn-gold { background: linear-gradient(135deg,#ffe28a,#ffc23c); color: #6b4700; }
.btn-block { width: 100%; }
.btn-lg { min-height: 64px; font-size: 20px; border-radius: var(--radius-lg); }

/* ---------- Cards / generic ---------- */
.card {
  background: var(--card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 20px;
}
.section-title {
  font-size: 20px;
  margin: 18px 14px 10px;
  color: var(--ink);
}
.muted { color: var(--ink-soft); font-size: 14px; }
.center { text-align: center; }
.hstack { display: flex; gap: 10px; align-items: center; }
.wrap { flex-wrap: wrap; }
.gap8 { gap: 8px; } .gap12 { gap: 12px; } .gap16 { gap: 16px; }

/* ---------- Login screen ---------- */
.login-wrap {
  min-height: calc(100vh - 0px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px 20px;
  gap: 18px;
  text-align: center;
}
.login-title { font-size: 30px; margin: 0; }
.login-egg { font-size: 90px; animation: idleFloat 2.6s ease-in-out infinite; }
@keyframes idleFloat {
  0%,100% { transform: translateY(0) rotate(-2deg); }
  50% { transform: translateY(-10px) rotate(2deg); }
}
.login-card { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 12px; }
.field { text-align: left; }
.field label { font-size: 14px; color: var(--ink-soft); display: block; margin-bottom: 6px; }
.field input {
  width: 100%;
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  border: 2px solid #e3ddf5;
  font-size: 18px;
  font-family: inherit;
  background: var(--card-soft);
}
.field input:focus { border-color: var(--primary); }
.code-box {
  background: #fff7de;
  border: 2px dashed var(--gold);
  border-radius: var(--radius-sm);
  padding: 12px;
  font-size: 15px;
}
.code-box b { font-size: 22px; letter-spacing: 2px; color: var(--accent-dark); }
.tab-toggle { display: flex; gap: 8px; background: #eee7fb; padding: 5px; border-radius: 999px; }
.tab-toggle button { flex: 1; padding: 10px; border-radius: 999px; font-weight: bold; color: var(--ink-soft); }
.tab-toggle button.active { background: var(--card); color: var(--primary-dark); box-shadow: var(--shadow-sm); }

/* ---------- Home screen ---------- */
.stage-hero {
  margin: 10px 14px 6px;
  border-radius: var(--radius-lg);
  padding: 18px 14px 8px;
  position: relative;
  overflow: hidden;
  min-height: 300px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  box-shadow: var(--shadow);
}
.pet-nametag {
  position: absolute;
  top: 14px; left: 50%;
  transform: translateX(-50%);
  background: rgba(255,255,255,0.85);
  padding: 6px 16px;
  border-radius: 999px;
  font-weight: bold;
  font-size: 15px;
  box-shadow: var(--shadow-sm);
  z-index: 3;
  white-space: nowrap;
}
.char-stage-wrap {
  position: relative;
  width: 100%;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 210px;
}
.char-svg-holder { width: 220px; height: 220px; position: relative; z-index: 2; }
.char-svg-holder svg { width: 100%; height: 100%; overflow: visible; }

.gauge-row { width: 100%; max-width: 320px; margin: 10px auto 6px; z-index: 3; }
.gauge-label { display:flex; justify-content: space-between; font-size: 13px; color: var(--ink-soft); margin-bottom: 4px; font-weight: bold;}
.gauge-track {
  height: 16px;
  background: rgba(255,255,255,0.55);
  border-radius: 999px;
  overflow: hidden;
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.08);
}
.gauge-fill {
  height: 100%;
  background: linear-gradient(90deg, #9be15d, #3fbf8f);
  border-radius: 999px;
  transition: width 0.5s cubic-bezier(.2,.9,.3,1.2);
}

.evolve-hint {
  margin: 4px 14px 0;
  text-align: center;
  font-size: 14px;
  color: var(--ink-soft);
  background: rgba(255,255,255,0.6);
  border-radius: 999px;
  padding: 6px 12px;
}

.table-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  padding: 4px 14px 4px;
}
.table-card {
  background: var(--card);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  padding: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  position: relative;
  border: 3px solid transparent;
}
.table-card .dan { font-size: 26px; font-weight: bold; color: var(--primary-dark); }
.table-card .status { font-size: 13px; color: var(--ink-soft); }
.table-card.cleared { border-color: var(--good); }
.table-card.cleared .dan { color: var(--good-dark); }
.table-card .medal { position: absolute; top: -10px; right: -6px; font-size: 22px; }

.mix-card {
  margin: 6px 14px 4px;
  background: linear-gradient(135deg,#7b6cff,#a56cff);
  color: #fff;
  border-radius: var(--radius-md);
  padding: 16px 18px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 12px;
}
.mix-card .txt { flex: 1; }
.mix-card .txt b { font-size: 17px; display:block; }
.mix-card .txt span { font-size: 13px; opacity: 0.9; }

.bottom-actions {
  margin: 18px 14px 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ---------- Quiz screen ---------- */
.quiz-wrap { padding: 6px 14px 20px; display: flex; flex-direction: column; gap: 14px; }
.quiz-top { display: flex; align-items: center; gap: 10px; }
.progress-dots { display: flex; gap: 6px; flex: 1; flex-wrap: wrap; }
.progress-dots .dot {
  width: 14px; height: 14px; border-radius: 50%;
  background: #e3ddf5;
}
.progress-dots .dot.done { background: var(--good); }
.progress-dots .dot.wrong { background: var(--bad); }
.progress-dots .dot.current { background: var(--primary); box-shadow: 0 0 0 4px rgba(108,140,255,0.25); }
.streak-badge {
  font-weight: bold; font-size: 14px; color: var(--accent-dark);
  background: #ffe6f0; padding: 6px 12px; border-radius: 999px; white-space: nowrap;
}

.speed-bar-track { height: 10px; background: #eee5ff; border-radius: 999px; overflow: hidden; }
.speed-bar-fill { height: 100%; background: linear-gradient(90deg,#ffd23f,#ff8fb3); width: 100%; transform-origin: left; }

.quiz-char-row { display: flex; justify-content: center; }
.quiz-char-row .char-svg-holder { width: 140px; height: 140px; }

.question-card {
  text-align: center;
  padding: 26px 16px;
}
.question-card .expr { font-size: 44px; font-weight: bold; color: var(--ink); }
.question-card .expr .op { color: var(--primary); margin: 0 6px; }

.choices-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.choice-btn {
  background: var(--card);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  padding: 20px 10px;
  font-size: 26px;
  font-weight: bold;
  color: var(--ink);
  border: 3px solid transparent;
}
.choice-btn.correct { border-color: var(--good); background: #eafff3; color: var(--good-dark); }
.choice-btn.wrong { border-color: var(--bad); background: #fff0ee; color: #c94c3c; }

.keypad-wrap { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.keypad-display {
  min-width: 160px;
  min-height: 56px;
  background: var(--card-soft);
  border: 2px solid #e3ddf5;
  border-radius: var(--radius-sm);
  font-size: 30px;
  font-weight: bold;
  display: flex; align-items: center; justify-content: center;
  padding: 0 14px;
}
.keypad-grid { display: grid; grid-template-columns: repeat(3, 64px); gap: 10px; }
.keypad-grid button {
  width: 64px; height: 58px;
  background: var(--card);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
  font-size: 22px;
  font-weight: bold;
}
.keypad-grid button.wide { grid-column: span 1; }

.input-mode-toggle {
  align-self: center;
  font-size: 13px;
  color: var(--primary-dark);
  background: #eef0ff;
  padding: 6px 14px;
  border-radius: 999px;
  font-weight: bold;
}

.feedback-banner {
  text-align: center;
  font-size: 18px;
  font-weight: bold;
  border-radius: var(--radius-sm);
  padding: 12px;
  min-height: 24px;
}
.feedback-banner.ok { background: #e4ffef; color: var(--good-dark); }
.feedback-banner.no { background: #ffece9; color: #c94c3c; }

/* ---------- Result screen ---------- */
.result-wrap { padding: 16px; display: flex; flex-direction: column; align-items: center; gap: 14px; text-align: center; }
.result-emoji { font-size: 70px; }
.result-stats { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }
.result-stat {
  background: var(--card); border-radius: var(--radius-md); box-shadow: var(--shadow-sm);
  padding: 14px 18px; min-width: 100px;
}
.result-stat .num { font-size: 24px; font-weight: bold; color: var(--primary-dark); }
.result-stat .lbl { font-size: 13px; color: var(--ink-soft); }
.badge-earned {
  background: linear-gradient(135deg,#ffe28a,#ffc23c);
  color: #6b4700; padding: 10px 18px; border-radius: 999px; font-weight: bold;
}

/* ---------- Shop screen ---------- */
.shop-tabs { display: flex; gap: 8px; padding: 4px 14px; overflow-x: auto; }
.shop-tabs button {
  background: var(--card); border-radius: 999px; padding: 10px 16px;
  font-weight: bold; box-shadow: var(--shadow-sm); white-space: nowrap; color: var(--ink-soft);
}
.shop-tabs button.active { background: var(--primary); color: #fff; }
.shop-preview {
  margin: 8px 14px; border-radius: var(--radius-lg); padding: 14px;
  display: flex; align-items: center; justify-content: center; min-height: 200px;
  box-shadow: var(--shadow); position: relative; overflow: hidden;
}
.shop-preview .char-svg-holder { width: 170px; height: 170px; }
.shop-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; padding: 6px 14px 20px; }
.item-card {
  background: var(--card); border-radius: var(--radius-md); box-shadow: var(--shadow-sm);
  padding: 14px; display: flex; flex-direction: column; align-items: center; gap: 6px;
  border: 3px solid transparent; position: relative;
}
.item-card .icon { font-size: 34px; }
.item-card .name { font-size: 14px; font-weight: bold; text-align: center; }
.item-card .price { font-size: 13px; color: var(--ink-soft); }
.item-card.owned { border-color: var(--good); }
.item-card.equipped { border-color: var(--primary); background: #eef1ff; }
.item-card.locked { opacity: 0.55; }
.item-card .lock-req { font-size: 11px; color: var(--accent-dark); text-align: center; }
.item-card button { width: 100%; padding: 8px; border-radius: 999px; font-size: 13px; font-weight: bold; }

/* ---------- Gallery screen ---------- */
.gallery-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; padding: 10px 14px 24px; }
.gallery-card {
  background: var(--card); border-radius: var(--radius-md); box-shadow: var(--shadow-sm);
  padding: 12px; display: flex; flex-direction: column; align-items: center; gap: 4px;
}
.gallery-card .char-svg-holder { width: 100px; height: 100px; }
.gallery-card .gname { font-weight: bold; font-size: 14px; }
.gallery-card .gsub { font-size: 12px; color: var(--ink-soft); }
@media (min-width: 560px) {
  .gallery-grid { grid-template-columns: repeat(3, 1fr); }
}

/* ---------- New egg screen ---------- */
.element-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; padding: 10px 14px; }
.element-card {
  background: var(--card); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm);
  padding: 18px; display: flex; flex-direction: column; align-items: center; gap: 8px;
  border: 3px solid transparent;
}
.element-card.selected { border-color: var(--primary); background: #eef1ff; }
.element-card .icon { font-size: 46px; }

/* ---------- Toasts ---------- */
#toast-layer {
  position: fixed; top: 14px; left: 50%; transform: translateX(-50%);
  z-index: 999; display: flex; flex-direction: column; gap: 8px; align-items: center;
  pointer-events: none;
}
.toast {
  background: rgba(50,40,70,0.92); color: #fff; padding: 10px 18px; border-radius: 999px;
  font-weight: bold; font-size: 14px; box-shadow: var(--shadow);
  animation: toastIn 0.25s ease, toastOut 0.3s ease 2.4s forwards;
}
@keyframes toastIn { from { opacity:0; transform: translateY(-10px);} to {opacity:1; transform:translateY(0);} }
@keyframes toastOut { to { opacity:0; transform: translateY(-8px);} }

/* ---------- Character animation classes ---------- */
.char-idle { animation: idleBob 2.4s ease-in-out infinite; }
@keyframes idleBob { 0%,100%{transform:translateY(0)} 50%{transform:translateY(-6px)} }

.char-shake { animation: shakeX 0.4s ease; }
@keyframes shakeX {
  0%,100% { transform: translateX(0) rotate(0); }
  20% { transform: translateX(-8px) rotate(-4deg); }
  40% { transform: translateX(7px) rotate(3deg); }
  60% { transform: translateX(-5px) rotate(-2deg); }
  80% { transform: translateX(4px) rotate(1deg); }
}

.char-happy { animation: happyBounce 0.55s ease; }
@keyframes happyBounce {
  0% { transform: translateY(0) scale(1); }
  30% { transform: translateY(-18px) scale(1.05,0.95); }
  55% { transform: translateY(0) scale(0.97,1.03); }
  100% { transform: translateY(0) scale(1); }
}

.char-jump { animation: bigJump 0.7s ease; }
@keyframes bigJump {
  0% { transform: translateY(0) rotate(0); }
  35% { transform: translateY(-34px) rotate(-6deg); }
  60% { transform: translateY(-6px) rotate(4deg); }
  100% { transform: translateY(0) rotate(0); }
}

.char-sad { animation: sadWobble 0.6s ease; }
@keyframes sadWobble {
  0%,100% { transform: translateY(0) rotate(0); }
  30% { transform: translateY(4px) rotate(-3deg); }
  60% { transform: translateY(4px) rotate(3deg); }
}

.char-hatch { animation: hatchPop 0.9s cubic-bezier(.3,1.6,.4,1); }
@keyframes hatchPop {
  0% { transform: scale(0.6) rotate(0); opacity: 0.4; }
  60% { transform: scale(1.15) rotate(6deg); opacity: 1; }
  100% { transform: scale(1) rotate(0); }
}

.wing-flap { animation: wingFlap 1.8s ease-in-out infinite; transform-origin: 50% 70%; }
@keyframes wingFlap { 0%,100%{transform:rotate(0deg)} 50%{transform:rotate(8deg)} }

.blink { animation: blinkEye 4.5s infinite; }
@keyframes blinkEye { 0%,94%,100% { transform: scaleY(1);} 96% { transform: scaleY(0.1);} }

.sparkle-particle { animation: floatUp 2.2s ease-in infinite; }
@keyframes floatUp {
  0% { transform: translateY(6px) scale(0.7); opacity: 0; }
  20% { opacity: 1; }
  100% { transform: translateY(-40px) scale(1.1); opacity: 0; }
}

.crack-in { animation: crackAppear 0.3s ease; }
@keyframes crackAppear { from{opacity:0} to{opacity:1} }

/* scrollbar tidy */
::-webkit-scrollbar { width: 0; height: 0; }
