:root {
  --primary-color: #6366f1;
  --primary-hover: #4f46e5;
  --primary-light: #e0e7ff;
  --secondary-color: #ec4899;
  --success-color: #10b981;
  --success-light: #d1fae5;
  --danger-color: #ef4444;
  --danger-light: #fee2e2;
  --warning-color: #f59e0b;
  --bg-gradient: linear-gradient(135deg, #0f172a 0%, #1e1b4b 50%, #31104b 100%);
  --card-bg: rgba(255, 255, 255, 0.95);
  --card-border: rgba(255, 255, 255, 0.2);
  --text-main: #1e293b;
  --text-muted: #64748b;
  --text-light: #f8fafc;
  --shadow-sm: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 20px 25px -5px rgba(0, 0, 0, 0.3), 0 8px 10px -6px rgba(0, 0, 0, 0.3);
  --radius-lg: 24px;
  --radius-md: 16px;
  --radius-sm: 10px;
  --font-family: 'Pretendard', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

body {
  font-family: var(--font-family);
  background: var(--bg-gradient);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow-x: hidden;
  position: relative;
}

/* 배경 장식 블러 오브 */
.bg-shape {
  position: fixed;
  border-radius: 50%;
  filter: blur(80px);
  z-index: 0;
  pointer-events: none;
  opacity: 0.5;
  animation: floatOrb 12s ease-in-out infinite alternate;
}

.shape-1 {
  width: 350px;
  height: 350px;
  background: #6366f1;
  top: -100px;
  left: -100px;
}

.shape-2 {
  width: 400px;
  height: 400px;
  background: #ec4899;
  bottom: -100px;
  right: -100px;
  animation-delay: -6s;
}

.shape-3 {
  width: 250px;
  height: 250px;
  background: #06b6d4;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  opacity: 0.3;
}

@keyframes floatOrb {
  0% { transform: scale(1) translate(0, 0); }
  100% { transform: scale(1.15) translate(30px, 30px); }
}

/* 컨테이너 */
.app-container {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 480px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 16px;
}

@media (min-width: 520px) {
  .app-container {
    min-height: auto;
    padding: 24px;
  }
}

/* 상단 헤더 */
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  padding: 8px 12px;
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(12px);
  border-radius: var(--radius-md);
  border: 1px solid rgba(255, 255, 255, 0.15);
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand-icon {
  font-size: 1.4rem;
}

.brand-title {
  color: #fff;
  font-weight: 800;
  font-size: 1.1rem;
  letter-spacing: -0.5px;
}

.icon-btn {
  background: rgba(255, 255, 255, 0.15);
  border: none;
  border-radius: 50%;
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1.1rem;
  transition: all 0.2s ease;
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.3);
  transform: scale(1.05);
}

.icon-btn:active {
  transform: scale(0.95);
}

/* 화면 전환 */
.screen {
  display: none;
  animation: fadeIn 0.35s cubic-bezier(0.16, 1, 0.3, 1);
  width: 100%;
}

.screen.active {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(12px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

/* 공통 카드 스타일 */
.hero-card, .game-wrapper, .result-card {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  padding: 24px 20px;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--card-border);
  text-align: center;
}

/* 1. 시작 화면 */
.hero-badge {
  display: inline-block;
  background: #ede9fe;
  color: #6d28d9;
  font-weight: 700;
  font-size: 0.85rem;
  padding: 6px 14px;
  border-radius: 20px;
  margin-bottom: 12px;
}

.hero-title {
  font-size: 1.85rem;
  font-weight: 900;
  line-height: 1.3;
  letter-spacing: -0.8px;
  color: var(--text-main);
  margin-bottom: 12px;
}

.hero-title .highlight {
  background: linear-gradient(135deg, #6366f1, #ec4899);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.hero-desc {
  font-size: 0.95rem;
  color: var(--text-muted);
  line-height: 1.5;
  margin-bottom: 20px;
}

/* 난이도 옵션 */
.option-section {
  text-align: left;
  margin-bottom: 20px;
}

.section-label {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-muted);
  margin-bottom: 8px;
  display: block;
}

.difficulty-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.diff-btn {
  background: #f1f5f9;
  border: 2px solid transparent;
  border-radius: var(--radius-sm);
  padding: 10px 8px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  transition: all 0.2s ease;
}

.diff-btn .diff-title {
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--text-main);
}

.diff-btn .diff-sub {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.diff-btn.active {
  background: #eef2ff;
  border-color: var(--primary-color);
}

.diff-btn.active .diff-title {
  color: var(--primary-color);
}

/* 최고 기록 배너 */
.best-score-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: linear-gradient(135deg, #fffbeb, #fef3c7);
  border: 1px solid #fde68a;
  border-radius: var(--radius-md);
  padding: 12px 16px;
  margin-bottom: 20px;
}

.best-icon {
  font-size: 1.8rem;
}

.best-info {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  flex: 1;
  margin-left: 12px;
}

.best-label {
  font-size: 0.75rem;
  font-weight: 700;
  color: #92400e;
}

.best-value {
  font-size: 1.15rem;
  font-weight: 800;
  color: #78350f;
}

.best-tier {
  font-size: 0.8rem;
  font-weight: 800;
  padding: 4px 10px;
  background: #f59e0b;
  color: #fff;
  border-radius: 12px;
}

/* 공통 버튼 */
.btn {
  border: none;
  font-family: inherit;
  font-weight: 800;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: var(--radius-md);
  transition: all 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
  text-decoration: none;
}

.btn-primary {
  background: linear-gradient(135deg, #6366f1 0%, #4f46e5 100%);
  color: #fff;
  box-shadow: 0 8px 16px -4px rgba(99, 102, 241, 0.5);
}

.btn-primary:hover {
  background: linear-gradient(135deg, #4f46e5 0%, #4338ca 100%);
  transform: translateY(-2px);
  box-shadow: 0 12px 20px -4px rgba(99, 102, 241, 0.6);
}

.btn-primary:active {
  transform: translateY(1px);
}

.btn-secondary {
  background: #f1f5f9;
  color: #334155;
}

.btn-secondary:hover {
  background: #e2e8f0;
}

.btn-large {
  width: 100%;
  padding: 16px 24px;
  font-size: 1.15rem;
}

.start-hint {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 12px;
}

/* 2. 게임 화면 */
.game-hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid #f1f5f9;
}

/* 타이머 */
.timer-box {
  position: relative;
  width: 76px;
  height: 76px;
}

.timer-svg {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.timer-circle-bg {
  fill: none;
  stroke: #e2e8f0;
  stroke-width: 8;
}

.timer-circle-progress {
  fill: none;
  stroke: var(--primary-color);
  stroke-width: 8;
  stroke-linecap: round;
  stroke-dasharray: 276.46;
  stroke-dashoffset: 0;
  transition: stroke-dashoffset 0.25s linear, stroke 0.3s ease;
}

.timer-circle-progress.danger {
  stroke: var(--danger-color);
  animation: pulseGauge 0.6s infinite alternate;
}

@keyframes pulseGauge {
  0% { stroke-width: 8; }
  100% { stroke-width: 11; }
}

.timer-text-wrap {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

.timer-number {
  font-size: 1.35rem;
  font-weight: 900;
  line-height: 1;
  color: var(--text-main);
}

.timer-number.danger {
  color: var(--danger-color);
  animation: scalePop 0.5s infinite alternate;
}

@keyframes scalePop {
  0% { transform: scale(1); }
  100% { transform: scale(1.15); }
}

.timer-unit {
  font-size: 0.65rem;
  color: var(--text-muted);
  font-weight: 700;
}

.hud-stats {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: flex-end;
}

.stat-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 800;
}

.correct-pill {
  background: var(--success-light);
  color: #065f46;
}

.combo-pill {
  background: #fef3c7;
  color: #92400e;
  transition: all 0.2s ease;
}

.combo-pill.combo-active {
  background: linear-gradient(135deg, #f59e0b, #ec4899);
  color: #fff;
  transform: scale(1.08);
  box-shadow: 0 4px 10px rgba(236, 72, 153, 0.4);
}

/* 퀴즈 카드 */
.quiz-card {
  position: relative;
  background: #f8fafc;
  border: 2px solid #e2e8f0;
  border-radius: var(--radius-md);
  padding: 24px 16px 16px;
  margin-bottom: 20px;
  transition: all 0.2s ease;
}

.quiz-card.correct-anim {
  background: #ecfdf5;
  border-color: var(--success-color);
  transform: scale(1.02);
}

.quiz-card.wrong-anim {
  background: #fef2f2;
  border-color: var(--danger-color);
  animation: shake 0.35s cubic-bezier(0.36, 0.07, 0.19, 0.97) both;
}

@keyframes shake {
  10%, 90% { transform: translate3d(-3px, 0, 0); }
  20%, 80% { transform: translate3d(5px, 0, 0); }
  30%, 50%, 70% { transform: translate3d(-6px, 0, 0); }
  40%, 60% { transform: translate3d(6px, 0, 0); }
}

.quiz-number-tag {
  position: absolute;
  top: -12px;
  left: 20px;
  background: var(--primary-color);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 800;
  padding: 2px 10px;
  border-radius: 10px;
}

.formula-container {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  font-size: 2.5rem;
  font-weight: 900;
  color: #0f172a;
}

.operator {
  color: var(--primary-color);
  font-size: 2.2rem;
}

.equals {
  color: var(--text-muted);
}

.answer-box {
  display: inline-block;
  width: 100px;
}

#answerInput {
  width: 100%;
  height: 60px;
  font-size: 2.2rem;
  font-weight: 900;
  text-align: center;
  border: 3px solid var(--primary-color);
  border-radius: var(--radius-sm);
  background: #fff;
  color: #1e1b4b;
  outline: none;
  transition: all 0.2s;
  box-shadow: 0 4px 8px rgba(99, 102, 241, 0.15);
}

#answerInput:focus {
  border-color: var(--secondary-color);
  box-shadow: 0 0 0 4px rgba(236, 72, 153, 0.2);
}

.feedback-msg {
  height: 24px;
  margin-top: 10px;
  font-size: 0.95rem;
  font-weight: 800;
  color: transparent;
  transition: all 0.2s;
}

.feedback-msg.correct {
  color: var(--success-color);
}

.feedback-msg.wrong {
  color: var(--danger-color);
}

/* 가상 키패드 */
.virtual-keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 10px;
}

.key-btn {
  background: #fff;
  border: 1px solid #e2e8f0;
  box-shadow: 0 3px 0 #cbd5e1;
  border-radius: var(--radius-sm);
  padding: 14px 0;
  font-size: 1.35rem;
  font-weight: 800;
  font-family: inherit;
  color: #1e293b;
  cursor: pointer;
  transition: all 0.1s ease;
  touch-action: manipulation;
}

.key-btn:active {
  transform: translateY(3px);
  box-shadow: 0 0 0 #cbd5e1;
  background: #f1f5f9;
}

.key-action {
  background: #fee2e2;
  color: #dc2626;
  border-color: #fecaca;
  box-shadow: 0 3px 0 #fca5a5;
}

.key-action:active {
  box-shadow: 0 0 0 #fca5a5;
}

.key-submit {
  background: linear-gradient(135deg, #10b981, #059669);
  color: #fff;
  border-color: #059669;
  box-shadow: 0 3px 0 #047857;
  font-size: 1.1rem;
}

.key-submit:active {
  box-shadow: 0 0 0 #047857;
}

/* 3. 결과 화면 */
.result-trophy {
  font-size: 3.5rem;
  margin-bottom: 6px;
  animation: bounce 1s infinite alternate;
}

@keyframes bounce {
  0% { transform: translateY(0); }
  100% { transform: translateY(-8px); }
}

.tier-tag {
  display: inline-block;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: #fff;
  font-weight: 800;
  font-size: 0.85rem;
  padding: 4px 14px;
  border-radius: 15px;
  margin-bottom: 8px;
}

.result-title {
  font-size: 1.8rem;
  font-weight: 900;
  margin-bottom: 4px;
}

.result-comment {
  font-size: 0.95rem;
  color: var(--text-muted);
  margin-bottom: 16px;
}

.new-record-badge {
  display: none;
  background: linear-gradient(135deg, #f59e0b, #ef4444);
  color: #fff;
  font-weight: 800;
  font-size: 0.9rem;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
  animation: pulse 1s infinite alternate;
}

.new-record-badge.show {
  display: block;
}

@keyframes pulse {
  0% { transform: scale(0.98); }
  100% { transform: scale(1.02); box-shadow: 0 0 15px rgba(245, 158, 11, 0.6); }
}

.result-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 24px;
}

.res-stat-card {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: var(--radius-sm);
  padding: 12px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.res-stat-card.primary {
  grid-column: span 2;
  background: linear-gradient(135deg, #eef2ff, #ede9fe);
  border-color: #c7d2fe;
  padding: 16px;
}

.res-stat-label {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.res-stat-card.primary .res-stat-label {
  color: var(--primary-color);
  font-size: 0.85rem;
}

.res-stat-value {
  font-size: 1.6rem;
  font-weight: 900;
  color: #0f172a;
}

.res-stat-card.primary .res-stat-value {
  font-size: 2.4rem;
  color: var(--primary-color);
}

.res-stat-value small {
  font-size: 0.9rem;
  font-weight: 700;
  margin-left: 2px;
  color: var(--text-muted);
}

.result-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* 오답 노트 모달 */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(15, 23, 42, 0.75);
  backdrop-filter: blur(6px);
  z-index: 99;
  justify-content: center;
  align-items: center;
  padding: 16px;
}

.modal-overlay.active {
  display: flex;
}

.modal-card {
  background: #fff;
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 440px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  animation: popModal 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes popModal {
  from { transform: scale(0.9); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid #f1f5f9;
}

.modal-header h3 {
  font-size: 1.1rem;
  font-weight: 800;
}

.close-modal-btn {
  background: #f1f5f9;
  color: #64748b;
  width: 32px;
  height: 32px;
}

.modal-body {
  padding: 16px 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.review-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: var(--radius-sm);
  padding: 10px 14px;
}

.review-formula {
  font-weight: 800;
  font-size: 1.1rem;
}

.review-answers {
  display: flex;
  gap: 8px;
  align-items: center;
  font-size: 0.9rem;
}

.user-wrong-ans {
  color: var(--danger-color);
  text-decoration: line-through;
  font-weight: 700;
}

.correct-ans-tag {
  background: var(--success-light);
  color: #065f46;
  font-weight: 800;
  padding: 2px 8px;
  border-radius: 6px;
}

.no-wrong-msg {
  text-align: center;
  color: var(--text-muted);
  padding: 30px 0;
  font-weight: 700;
}

/* 캔버스 (폭죽) */
#confettiCanvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  z-index: 100;
}
