@import url('https://fonts.googleapis.com/css2?family=M+PLUS+Rounded+1c:wght@400;700;900&display=swap');

:root {
  --color-bg: #FFF8F0;
  --color-pink: #FFB3C7;
  --color-sky: #A8D8EA;
  --color-green: #B5EAD7;
  --color-orange: #FFB088;
  --color-yellow: #FFF1A6;
  --color-text: #5A4A3F;
  --color-text-soft: #8A7A6F;
  --color-white: #FFFFFF;
  --shadow-soft: 0 4px 12px rgba(255, 179, 199, 0.3);
  --shadow-btn: 0 6px 0 rgba(0, 0, 0, 0.1);
  --radius-md: 16px;
  --radius-lg: 24px;
  --radius-round: 50%;
  --font: 'M PLUS Rounded 1c', sans-serif;
}

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

body {
  font-family: var(--font);
  background: var(--color-bg);
  color: var(--color-text);
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

.screen {
  max-width: 500px;
  margin: 0 auto;
  padding: 20px 16px;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.screen[hidden] { display: none !important; }

.app-title { font-size: 2em; font-weight: 900; margin: 20px 0 10px; text-align: center; }
.app-subtitle { font-size: 1em; color: var(--color-text-soft); margin-bottom: 30px; }
.mascot { width: 120px; height: 120px; margin: 10px 0 20px; }

.op-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; width: 100%; max-width: 320px; margin-bottom: 24px; }

.op-btn {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 20px; border: none; border-radius: var(--radius-lg); font-family: var(--font);
  font-size: 1.8em; font-weight: 900; color: var(--color-text); cursor: pointer;
  box-shadow: var(--shadow-btn); transition: transform 0.1s, box-shadow 0.1s; min-height: 100px;
}
.op-btn:active { transform: translateY(3px); box-shadow: 0 2px 0 rgba(0, 0, 0, 0.1); }
.op-btn.add { background: var(--color-pink); }
.op-btn.sub { background: var(--color-sky); }
.op-btn.mul { background: var(--color-green); }
.op-btn.div { background: var(--color-orange); }
.op-label { font-size: 0.4em; font-weight: 700; margin-top: 4px; }

.sticker-book-btn {
  display: flex; align-items: center; gap: 8px; padding: 14px 28px;
  border: 3px solid var(--color-pink); border-radius: var(--radius-lg);
  background: var(--color-white); font-family: var(--font); font-size: 1.1em;
  font-weight: 700; color: var(--color-text); cursor: pointer; box-shadow: var(--shadow-soft);
}

.level-title { font-size: 1.4em; font-weight: 700; margin: 20px 0; }

.auto-level-btn {
  width: 100%; max-width: 320px; padding: 18px; border: none; border-radius: var(--radius-lg);
  background: linear-gradient(135deg, #FFD700, #FFA500); font-family: var(--font);
  font-size: 1.3em; font-weight: 900; color: var(--color-white); cursor: pointer;
  box-shadow: var(--shadow-btn); margin-bottom: 16px; transition: transform 0.1s;
}
.auto-level-btn:active { transform: translateY(3px); }

.level-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; width: 100%; max-width: 320px; }

.level-btn {
  padding: 14px; border: 2px solid var(--color-text-soft); border-radius: var(--radius-md);
  background: var(--color-white); font-family: var(--font); font-size: 1.1em; font-weight: 700;
  color: var(--color-text); cursor: pointer; transition: transform 0.1s;
}
.level-btn:active { transform: translateY(2px); }
.level-desc { font-size: 0.65em; font-weight: 400; color: var(--color-text-soft); display: block; margin-top: 4px; }

.back-btn {
  margin-top: 20px; padding: 10px 24px; border: none; border-radius: var(--radius-md);
  background: var(--color-text-soft); color: var(--color-white); font-family: var(--font);
  font-size: 1em; font-weight: 700; cursor: pointer;
}

.timer-bar-container { width: 100%; max-width: 400px; height: 16px; background: #eee; border-radius: 8px; overflow: hidden; margin: 16px 0; }
.timer-bar { height: 100%; background: #4CAF50; border-radius: 8px; transition: width 0.1s linear, background 0.3s; width: 100%; }
.timer-bar.warning { background: #FFC107; }
.timer-bar.danger { background: #F44336; }

.progress-text { font-size: 1em; color: var(--color-text-soft); margin-bottom: 8px; }

.problem-display {
  font-size: 2.8em; font-weight: 900; margin: 20px 0; letter-spacing: 4px;
  min-height: 80px; display: flex; align-items: center; justify-content: center;
}

.answer-display {
  font-size: 2.2em; font-weight: 900; min-height: 60px; min-width: 120px;
  border-bottom: 4px solid var(--color-text); text-align: center; margin-bottom: 16px;
  display: flex; align-items: center; justify-content: center;
}

.numpad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; width: 100%; max-width: 280px; margin-bottom: 12px; }

.num-btn {
  width: 100%; aspect-ratio: 1; max-width: 80px; max-height: 80px; min-width: 60px; min-height: 60px;
  border: none; border-radius: var(--radius-md); background: var(--color-white); font-family: var(--font);
  font-size: 1.8em; font-weight: 700; color: var(--color-text); cursor: pointer;
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.08); transition: transform 0.05s; justify-self: center;
}
.num-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(0, 0, 0, 0.08); }

.action-row { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; width: 100%; max-width: 280px; }

.action-btn {
  padding: 14px; min-height: 60px; border: none; border-radius: var(--radius-md);
  font-family: var(--font); font-size: 1.1em; font-weight: 700; cursor: pointer; transition: transform 0.05s;
}
.action-btn:active { transform: translateY(2px); }
.btn-zero { background: var(--color-white); color: var(--color-text); box-shadow: 0 3px 0 rgba(0, 0, 0, 0.08); font-size: 1.8em; }
.btn-delete { background: var(--color-text-soft); color: var(--color-white); }
.btn-ok { background: #4CAF50; color: var(--color-white); font-size: 1.3em; }

.feedback-overlay {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: rgba(255, 248, 240, 0.95); z-index: 100; animation: fadeIn 0.2s;
}
.feedback-overlay[hidden] { display: none !important; }
.feedback-text { font-size: 1.8em; font-weight: 900; margin: 16px 0; }
.feedback-correct { color: #4CAF50; }
.feedback-wrong { color: var(--color-orange); }
.feedback-sticker { margin: 10px 0; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes popIn { from { transform: scale(0); } to { transform: scale(1); } }
.sticker-pop { animation: popIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1); }

.result-score { font-size: 2.5em; font-weight: 900; margin: 20px 0; }
.result-stickers { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin: 16px 0; max-width: 350px; }

.result-btn {
  width: 100%; max-width: 300px; padding: 16px; margin: 6px 0; border: none;
  border-radius: var(--radius-lg); font-family: var(--font); font-size: 1.2em; font-weight: 700;
  cursor: pointer; box-shadow: var(--shadow-btn); transition: transform 0.1s;
}
.result-btn:active { transform: translateY(3px); }
.result-btn-sticker { background: var(--color-pink); color: var(--color-white); }
.result-btn-retry { background: var(--color-white); color: var(--color-text); border: 2px solid var(--color-text-soft); }
.result-btn-home { background: var(--color-text-soft); color: var(--color-white); }

.sticker-book-header { display: flex; align-items: center; justify-content: space-between; width: 100%; max-width: 400px; margin-bottom: 12px; }
.sticker-book-title { font-size: 1.3em; font-weight: 700; }
.page-nav { display: flex; align-items: center; gap: 8px; }
.page-btn {
  width: 36px; height: 36px; border: 2px solid var(--color-text-soft); border-radius: var(--radius-round);
  background: var(--color-white); font-family: var(--font); font-size: 1em; font-weight: 700; cursor: pointer;
}

.canvas-area {
  width: 100%; max-width: 400px; aspect-ratio: 3 / 4; background: var(--color-white);
  border: 3px dashed var(--color-pink); border-radius: var(--radius-lg);
  position: relative; overflow: hidden; touch-action: none;
}

.sticker-tray {
  width: 100%; max-width: 400px; margin-top: 12px; padding: 12px;
  background: var(--color-white); border-radius: var(--radius-lg); border: 2px solid #eee;
}
.tray-title { font-size: 0.9em; font-weight: 700; color: var(--color-text-soft); margin-bottom: 8px; }
.tray-items { display: flex; flex-wrap: wrap; gap: 6px; max-height: 120px; overflow-y: auto; }
.tray-sticker { cursor: grab; touch-action: none; }
.placed-sticker { position: absolute; cursor: grab; touch-action: none; }

.reset-btn {
  margin-top: 16px; padding: 8px 16px; border: 1px solid #ccc; border-radius: 8px;
  background: #f5f5f5; font-family: var(--font); font-size: 0.85em; color: var(--color-text-soft); cursor: pointer;
}

.sparkle-layer { position: fixed; top: 0; left: 0; right: 0; bottom: 0; pointer-events: none; z-index: 200; }
.sparkle { position: absolute; font-size: 24px; animation: sparkleAnim 0.8s ease-out forwards; }
@keyframes sparkleAnim {
  0% { opacity: 1; transform: scale(0) rotate(0deg); }
  50% { opacity: 1; transform: scale(1.2) rotate(180deg); }
  100% { opacity: 0; transform: scale(0.5) rotate(360deg) translateY(-40px); }
}
