/**
 * 萌宠口算大冒险 (Bunny Math) - 样式表
 * 融入 Duolingo 3D 卡通拟物风格，极度可爱、明快护眼
 * 针对手机、iPad 与 Android 横竖屏全自适应
 */

:root {
  --primary: #58cc02;
  --primary-shadow: #46a302;
  --primary-light: #d7ffb8;
  
  --secondary: #1cb0f6;
  --secondary-shadow: #1899d6;
  --secondary-light: #ddf4ff;

  --accent-orange: #ff9600;
  --accent-orange-shadow: #e08400;

  --danger: #ff4b4b;
  --danger-shadow: #ea2b2b;
  --danger-light: #ffdfe0;

  --neutral-dark: #3c3c3c;
  --neutral-gray: #afafaf;
  --neutral-light: #e5e5e5;
  --card-bg: #ffffff;
  --bg-page: #f7f9fa;

  --font-family: "Nunito", -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --radius-lg: 20px;
  --radius-md: 14px;
}

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

body {
  font-family: var(--font-family);
  background-color: var(--bg-page);
  color: var(--neutral-dark);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

/* 顶部导航与进度条 */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: #ffffff;
  border-bottom: 2px solid var(--neutral-light);
  position: sticky;
  top: 0;
  z-index: 50;
  gap: 12px;
}

.top-btn {
  background: #ffffff;
  border: 2px solid var(--neutral-light);
  border-bottom: 4px solid var(--neutral-light);
  border-radius: var(--radius-md);
  padding: 8px 12px;
  font-size: 14px;
  font-weight: 700;
  color: #777;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: all 0.1s ease;
  outline: none;
}

.top-btn:active {
  transform: translateY(2px);
  border-bottom-width: 2px;
}

/* Duolingo 经典兔子进度条 */
.progress-container {
  flex: 1;
  max-width: 500px;
  height: 16px;
  background: #e5e5e5;
  border-radius: 20px;
  position: relative;
  overflow: visible;
  margin: 0 8px;
}

.progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #58cc02, #2ecc71);
  border-radius: 20px;
  transition: width 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  position: relative;
}

.progress-bunny {
  position: absolute;
  right: -14px;
  top: -12px;
  font-size: 24px;
  line-height: 1;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.15));
  animation: bunnyHop 1s infinite alternate ease-in-out;
}

@keyframes bunnyHop {
  0% { transform: translateY(0); }
  100% { transform: translateY(-4px) scale(1.08); }
}

.hearts-display {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 16px;
  font-weight: 800;
  color: var(--danger);
  padding: 4px 8px;
  background: var(--danger-light);
  border-radius: 20px;
}

/* 主容器 */
.math-main-container {
  flex: 1;
  width: 100%;
  max-width: 960px;
  margin: 0 auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
}

/* 欢迎/模式选择页 */
.setup-view {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px 16px;
  max-width: 560px;
  margin: 0 auto;
  width: 100%;
}

.mascot-hero {
  font-size: 68px;
  margin-bottom: 8px;
  animation: floatMascot 2.5s infinite ease-in-out;
}

@keyframes floatMascot {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}

.setup-title {
  font-size: 28px;
  font-weight: 900;
  color: #3c3c3c;
  margin-bottom: 6px;
}

.setup-subtitle {
  font-size: 14px;
  color: #777;
  margin-bottom: 24px;
}

.config-card {
  background: #ffffff;
  border: 2px solid var(--neutral-light);
  border-bottom: 5px solid var(--neutral-light);
  border-radius: var(--radius-lg);
  padding: 20px;
  width: 100%;
  margin-bottom: 20px;
  text-align: left;
}

.config-section-title {
  font-size: 14px;
  font-weight: 800;
  color: #777;
  text-transform: uppercase;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.pill-group {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 18px;
}

.pill-choice {
  flex: 1 1 calc(50% - 10px);
  min-width: 110px;
  padding: 12px 10px;
  background: #f7f9fa;
  border: 2px solid var(--neutral-light);
  border-bottom: 4px solid var(--neutral-light);
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 700;
  color: #555;
  text-align: center;
  cursor: pointer;
  transition: all 0.15s;
}

.pill-choice:active {
  transform: translateY(2px);
  border-bottom-width: 2px;
}

.pill-choice.active {
  background: var(--secondary-light);
  border-color: var(--secondary);
  border-bottom-color: var(--secondary-shadow);
  color: var(--secondary-shadow);
}

/* 经典 3D 大按钮 (Duolingo 风格) */
.btn-duo {
  width: 100%;
  padding: 15px 20px;
  font-size: 17px;
  font-weight: 800;
  border-radius: var(--radius-lg);
  cursor: pointer;
  text-align: center;
  outline: none;
  transition: all 0.1s ease;
  border: none;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.btn-duo-green {
  background: var(--primary);
  color: #ffffff;
  border-bottom: 5px solid var(--primary-shadow);
}

.btn-duo-green:active {
  transform: translateY(3px);
  border-bottom-width: 2px;
}

.btn-duo-blue {
  background: var(--secondary);
  color: #ffffff;
  border-bottom: 5px solid var(--secondary-shadow);
}

.btn-duo-blue:active {
  transform: translateY(3px);
  border-bottom-width: 2px;
}

.btn-duo-white {
  background: #ffffff;
  color: #4b4b4b;
  border: 2px solid var(--neutral-light);
  border-bottom: 5px solid var(--neutral-light);
}

.btn-duo-white:active {
  transform: translateY(3px);
  border-bottom-width: 2px;
}

/* 测验视图 (Quiz View) */
.quiz-view {
  display: flex;
  flex-direction: column;
  flex: 1;
  width: 100%;
}

.quiz-layout-wrap {
  display: flex;
  flex-direction: column;
  flex: 1;
  justify-content: space-between;
}

/* 题目大卡片 */
.question-card {
  background: #ffffff;
  border: 2px solid var(--neutral-light);
  border-bottom: 6px solid var(--neutral-light);
  border-radius: 24px;
  padding: 30px 20px;
  margin: 12px 0 20px 0;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  box-shadow: 0 8px 24px rgba(0,0,0,0.03);
}

.question-badge {
  position: absolute;
  top: 14px;
  left: 18px;
  font-size: 12px;
  font-weight: 800;
  background: #f1f3f4;
  color: #888;
  padding: 4px 10px;
  border-radius: 20px;
}

.formula-display {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  font-size: 46px;
  font-weight: 900;
  color: #2b2b2b;
  margin: 16px 0;
  flex-wrap: wrap;
}

.formula-op {
  color: var(--secondary);
}

/* 答案输入槽 */
.answer-slot {
  min-width: 100px;
  height: 68px;
  padding: 0 14px;
  border-radius: var(--radius-md);
  border: 3px dashed var(--secondary);
  background: var(--secondary-light);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--secondary-shadow);
  font-size: 44px;
  font-weight: 900;
  position: relative;
}

.answer-slot.filled {
  border-style: solid;
  border-color: var(--secondary-shadow);
  background: #ffffff;
}

.cursor-blink {
  display: inline-block;
  width: 3px;
  height: 38px;
  background: var(--secondary);
  margin-left: 2px;
  animation: blink 1s infinite;
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

/* 虚拟数字大键盘 (适合手指大面积触控，防误触) */
.keypad-container {
  width: 100%;
  max-width: 440px;
  margin: 0 auto 10px auto;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.keypad-btn {
  height: 60px;
  background: #ffffff;
  border: 2px solid var(--neutral-light);
  border-bottom: 5px solid var(--neutral-light);
  border-radius: 16px;
  font-size: 26px;
  font-weight: 800;
  color: #3c3c3c;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  outline: none;
  transition: all 0.08s ease;
}

.keypad-btn:active {
  transform: translateY(3px);
  border-bottom-width: 2px;
  background: #fafafa;
}

.keypad-btn.action-btn {
  background: #f7f9fa;
  color: #666;
  font-size: 20px;
}

.keypad-btn.submit-btn {
  background: var(--primary);
  border-color: var(--primary-shadow);
  border-bottom: 5px solid var(--primary-shadow);
  color: #ffffff;
  font-size: 22px;
}

.keypad-btn.submit-btn:active {
  transform: translateY(3px);
  border-bottom-width: 2px;
}

/* 底部滑出抽屉 (Duolingo 风格即时反馈) */
.feedback-drawer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: #ffffff;
  border-top: 2px solid var(--neutral-light);
  padding: 18px 24px 24px 24px;
  display: none;
  flex-direction: column;
  z-index: 100;
  animation: slideUp 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  box-shadow: 0 -8px 30px rgba(0,0,0,0.12);
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.feedback-drawer.correct {
  background: #d7ffb8;
  border-top-color: #58cc02;
}

.feedback-drawer.wrong {
  background: #ffdfe0;
  border-top-color: #ff4b4b;
}

.feedback-content-wrap {
  max-width: 680px;
  width: 100%;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.feedback-info {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.feedback-icon {
  font-size: 34px;
  line-height: 1;
}

.feedback-title {
  font-size: 20px;
  font-weight: 900;
  margin-bottom: 4px;
}

.feedback-drawer.correct .feedback-title {
  color: #2b7400;
}

.feedback-drawer.wrong .feedback-title {
  color: #ea2b2b;
}

.feedback-desc {
  font-size: 14px;
  color: #555;
  font-weight: 600;
}

/* 极简思路拆解卡片 (不冗长，一目了然) */
.hint-card {
  background: #ffffff;
  border: 1.5px solid rgba(0,0,0,0.08);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  margin-top: 10px;
  width: 100%;
  max-width: 680px;
  margin-left: auto;
  margin-right: auto;
}

.hint-title {
  font-size: 13px;
  font-weight: 800;
  color: #ff9600;
  margin-bottom: 4px;
}

.hint-step {
  font-size: 13px;
  color: #444;
  line-height: 1.5;
  font-family: monospace, sans-serif;
  font-weight: 600;
}

/* 测验结束结算页 (Results View) */
.results-view {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px 16px;
  max-width: 580px;
  margin: 0 auto;
  width: 100%;
}

.stars-celebration {
  display: flex;
  gap: 12px;
  margin: 16px 0;
}

.star-item {
  font-size: 48px;
  opacity: 0.2;
  transform: scale(0.8);
  transition: all 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.star-item.active {
  opacity: 1;
  transform: scale(1.15);
  animation: starBounce 0.6s ease;
}

@keyframes starBounce {
  0% { transform: scale(0.5); }
  50% { transform: scale(1.3); }
  100% { transform: scale(1.15); }
}

.results-stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  width: 100%;
  margin: 20px 0;
}

.stat-box {
  background: #ffffff;
  border: 2px solid var(--neutral-light);
  border-bottom: 4px solid var(--neutral-light);
  border-radius: var(--radius-md);
  padding: 14px 10px;
  text-align: center;
}

.stat-box-val {
  font-size: 22px;
  font-weight: 900;
  color: var(--secondary-shadow);
  margin-bottom: 4px;
}

.stat-box-label {
  font-size: 12px;
  font-weight: 700;
  color: #888;
}

/* 错题汇总表 */
.wrong-list-card {
  background: #ffffff;
  border: 2px solid var(--neutral-light);
  border-radius: var(--radius-lg);
  padding: 16px;
  width: 100%;
  text-align: left;
  margin-bottom: 20px;
}

.wrong-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px dashed var(--neutral-light);
  font-size: 15px;
  font-weight: 700;
}

.wrong-item:last-child {
  border-bottom: none;
}

/* 打印预览排版视图 (Print View) */
.print-view {
  width: 100%;
  max-width: 800px;
  margin: 0 auto;
  background: #ffffff;
  padding: 24px;
  border-radius: 12px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.06);
}

.print-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 2px dashed #ddd;
  flex-wrap: wrap;
  gap: 12px;
}

.worksheet-header {
  text-align: center;
  margin-bottom: 24px;
}

.worksheet-title {
  font-size: 24px;
  font-weight: 900;
  margin-bottom: 12px;
  color: #111;
}

.worksheet-meta {
  display: flex;
  justify-content: space-around;
  font-size: 14px;
  font-weight: 600;
  color: #444;
  border-bottom: 1.5px solid #222;
  padding-bottom: 10px;
  margin-bottom: 24px;
}

.worksheet-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px 24px;
}

.worksheet-item {
  font-size: 18px;
  font-weight: 700;
  font-family: Arial, "PingFang SC", sans-serif;
  color: #000;
  padding: 10px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid #ddd;
}

.worksheet-item .q-exp {
  letter-spacing: 1px;
}

.worksheet-item .q-ans-line {
  display: inline-block;
  min-width: 60px;
  height: 24px;
  border-bottom: 1.5px solid #000;
  text-align: center;
  font-weight: 900;
  color: #333;
}

.worksheet-answers-section {
  margin-top: 40px;
  padding-top: 20px;
  border-top: 2px dashed #999;
}

/* ========================================================
   横屏平板 (iPad / Android 平板) 与大屏横屏适配
   自动转换为左侧算式、右侧矩阵键盘，舒适双手握持
   ======================================================== */
@media (orientation: landscape) and (min-width: 640px) {
  .quiz-layout-wrap {
    flex-direction: row;
    align-items: center;
    gap: 30px;
    padding: 10px 20px;
  }

  .question-card {
    flex: 1.2;
    min-height: 280px;
    margin: 0;
  }

  .keypad-container {
    flex: 1;
    max-width: 360px;
    margin: 0;
  }

  .keypad-btn {
    height: 56px;
    font-size: 24px;
  }

  .formula-display {
    font-size: 54px;
  }

  .answer-slot {
    height: 76px;
    min-width: 120px;
    font-size: 50px;
  }
}

/* ========================================================
   打印专属样式 (@media print)
   去除一切背景、按钮、导航栏，纯净黑白 A4 排版
   ======================================================== */
@media print {
  body {
    background: #ffffff !important;
    color: #000000 !important;
    padding: 0 !important;
  }

  .top-bar,
  .print-toolbar,
  .btn-duo,
  .no-print {
    display: none !important;
  }

  .math-main-container {
    max-width: 100% !important;
    padding: 0 !important;
    margin: 0 !important;
  }

  .print-view {
    box-shadow: none !important;
    padding: 0 !important;
    border: none !important;
    width: 100% !important;
  }

  .worksheet-grid {
    grid-template-columns: repeat(3, 1fr) !important;
    gap: 16px 20px !important;
  }

  .worksheet-item {
    font-size: 16pt !important;
    border-bottom: 1px solid #aaa !important;
    page-break-inside: avoid;
  }

  .worksheet-answers-section {
    page-break-before: always;
  }
}

/* ========================================================
   可爱卡通模态弹窗 (Cute Modal) - 彻底替代丑陋的系统 confirm
   ======================================================== */
.cute-modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fadeIn 0.2s ease-out;
}

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

.cute-modal-card {
  background: #ffffff;
  border: 3px solid #e5e5e5;
  border-bottom: 6px solid #d5d5d5;
  border-radius: 28px;
  padding: 28px 22px;
  width: 100%;
  max-width: 360px;
  text-align: center;
  box-shadow: 0 16px 36px rgba(0,0,0,0.18);
  animation: popCard 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes popCard {
  from { transform: scale(0.85); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.cute-modal-emoji {
  font-size: 54px;
  line-height: 1;
  margin-bottom: 12px;
}

.cute-modal-title {
  font-size: 19px;
  font-weight: 900;
  color: #333;
  margin-bottom: 8px;
}

.cute-modal-desc {
  font-size: 13.5px;
  color: #666;
  line-height: 1.5;
  margin-bottom: 22px;
}

.cute-modal-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* 打印工具栏自适应微调 */
.print-actions-group {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

@media (max-width: 600px) {
  .print-toolbar {
    flex-direction: column;
    align-items: stretch;
  }
  .print-actions-group {
    width: 100%;
    justify-content: space-between;
  }
}
