/* ===== Reset & Base ===== */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --blue: #1a73e8;
  --blue-dark: #0d47a1;
  --blue-light: #bbdefb;
  --orange: #ff8f00;
  --orange-light: #fff3e0;
  --yellow: #ffd600;
  --green: #43a047;
  --red: #e53935;
  --bg: #e8f0fe;
  --card: #ffffff;
  --text: #1a202c;
  --text-light: #64748b;
  --shadow: 0 4px 20px rgba(0,0,0,0.1);
  --shadow-lg: 0 8px 40px rgba(0,0,0,0.15);
  --radius: 20px;
  --radius-sm: 12px;
  --font: 'Noto Sans SC', system-ui, -apple-system, sans-serif;
  --transition: 300ms cubic-bezier(0.16, 1, 0.3, 1);
}

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: var(--font);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

/* ===== Train Background ===== */
.bg-scene {
  position: fixed;
  inset: 0;
  background: linear-gradient(180deg, #87ceeb 0%, #b8e1f5 30%, #d4eaf7 45%, #e8f0fe 50%, #d4eaf7 52%, #c8d6e5 55%, #b0bec5 56%);
  z-index: 0;
  overflow: hidden;
}

/* Buildings skyline */
.city-skyline {
  position: absolute;
  bottom: calc(12% + 80px);
  left: 0;
  right: 0;
  height: 140px;
  display: flex;
  align-items: flex-end;
  gap: 4px;
  padding: 0 20px;
  opacity: 0.25;
}

.building {
  flex: 1;
  background: linear-gradient(180deg, #90a4ae, #b0bec5);
  border-radius: 3px 3px 0 0;
  height: 60%;
}
.building:nth-child(2n) { height: 85%; background: linear-gradient(180deg, #78909c, #90a4ae); }
.building:nth-child(3n) { height: 45%; background: linear-gradient(180deg, #b0bec5, #cfd8dc); }
.building:nth-child(5n) { height: 100%; background: linear-gradient(180deg, #607d8b, #78909c); }

/* Railway track */
.track {
  position: absolute;
  bottom: 12%;
  left: 0;
  right: 0;
  height: 32px;
  background: repeating-linear-gradient(
    90deg,
    #5d4037 0px, #5d4037 24px,
    #795548 24px, #795548 48px
  );
  z-index: 1;
}

.track::before {
  content: '';
  position: absolute;
  top: 14px;
  left: 0;
  right: 0;
  height: 3px;
  background: repeating-linear-gradient(
    90deg,
    #bdbdbd 0px, #bdbdbd 14px,
    transparent 14px, transparent 24px
  );
}

.track::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 6px;
  background: #8d6e63;
  border-radius: 2px 2px 0 0;
}

/* Animated train */
.train-wrapper {
  position: absolute;
  bottom: calc(12% + 2px);
  z-index: 2;
  animation: train-move 8s linear infinite;
}

@keyframes train-move {
  0% { transform: translateX(-220px); }
  100% { transform: translateX(calc(100vw + 220px)); }
}

.train {
  display: flex;
  align-items: flex-end;
  gap: 2px;
}

.train-head {
  width: 100px;
  height: 52px;
  background: linear-gradient(135deg, #e53935, #c62828);
  border-radius: 12px 6px 4px 4px;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.train-head::before {
  content: '';
  position: absolute;
  top: 8px;
  left: 10px;
  width: 18px;
  height: 18px;
  background: #ffeb3b;
  border-radius: 50%;
  box-shadow: 0 0 8px rgba(255,235,59,0.6);
}

.train-head::after {
  content: '';
  position: absolute;
  top: 8px;
  right: 10px;
  width: 14px;
  height: 14px;
  background: #fff;
  border-radius: 50%;
}

.train-car {
  width: 80px;
  height: 44px;
  background: linear-gradient(180deg, #ef5350, #c62828);
  border-radius: 4px 4px 4px 4px;
  position: relative;
}

.train-car::after {
  content: '';
  position: absolute;
  top: 8px;
  left: 12px;
  right: 12px;
  height: 20px;
  background: rgba(255,255,255,0.25);
  border-radius: 3px;
}

.train-wheels {
  position: absolute;
  bottom: -10px;
  left: 8px;
  right: 8px;
  display: flex;
  justify-content: space-between;
}

.train-wheel {
  width: 14px;
  height: 14px;
  background: #37474f;
  border-radius: 50%;
  border: 2px solid #546e7a;
}

.train-wheel::after {
  content: '';
  display: block;
  width: 4px;
  height: 4px;
  background: #78909c;
  border-radius: 50%;
  margin: 3px auto;
}

.train-wheel:nth-child(2) { animation: wheel-spin 0.6s linear infinite; }
.train-wheel:nth-child(3) { animation: wheel-spin 0.6s linear infinite; }

@keyframes wheel-spin {
  to { transform: rotate(360deg); }
}

/* Subway/station decoration */
.station-sign {
  position: fixed;
  top: 16px;
  right: 56px;
  background: var(--blue-dark);
  color: #fff;
  padding: 6px 14px 6px 10px;
  border-radius: 8px;
  font-size: 0.75rem;
  font-weight: 600;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 6px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.25);
  letter-spacing: 0.02em;
}

.metro-logo {
  flex-shrink: 0;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.2));
}

.running-dot {
  width: 7px;
  height: 7px;
  background: #4caf50;
  border-radius: 50%;
  animation: blink 1.5s ease-in-out infinite;
}

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

/* Music Button */
.music-btn {
  position: fixed;
  top: 16px;
  right: 16px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.3);
  background: rgba(13,71,161,0.85);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
  transition: all 0.3s ease;
  backdrop-filter: blur(4px);
}

.music-btn:hover {
  background: var(--blue-dark);
  border-color: rgba(255,255,255,0.6);
  transform: scale(1.08);
}

.music-btn.playing {
  border-color: #4caf50;
  animation: music-pulse 2s ease-in-out infinite;
}

@keyframes music-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(76,175,80,0.4); }
  50% { box-shadow: 0 0 0 8px rgba(76,175,80,0); }
}

.music-btn svg { transition: transform 0.3s ease; }
.music-btn.playing svg { transform: rotate(360deg); animation: spin-record 4s linear infinite; }

@keyframes spin-record {
  to { transform: rotate(360deg); }
}

/* ===== Station Clock ===== */
.station-clock {
  position: fixed;
  top: 16px;
  left: 16px;
  z-index: 20;
  background: #1a1a2e;
  border: 3px solid #4a4a6a;
  border-radius: 12px;
  padding: 2px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.35), inset 0 0 8px rgba(0,0,0,0.3);
}

.clock-face {
  background: #0d0d1a;
  border-radius: 9px;
  padding: 6px 14px;
  text-align: center;
  border: 1px solid #3a3a5a;
}

.clock-label {
  font-size: 0.55rem;
  font-weight: 600;
  color: #8888aa;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  margin-bottom: 2px;
}

.clock-time {
  font-family: 'Courier New', Courier, monospace;
  font-size: 1.4rem;
  font-weight: 700;
  color: #ff4444;
  text-shadow: 0 0 10px rgba(255,68,68,0.6), 0 0 20px rgba(255,68,68,0.3);
  letter-spacing: 2px;
  line-height: 1.1;
}

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

/* ===== App Container ===== */
.app {
  position: relative;
  z-index: 5;
  min-height: 100dvh;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 80px 20px 30vh;
}

.screen {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 80px 20px 32vh;
  transition: opacity 0.4s cubic-bezier(0.16, 1, 0.3, 1),
              transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

.screen.hidden {
  opacity: 0;
  pointer-events: none;
  transform: translateY(20px) scale(0.97);
}

.screen:not(.hidden) {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0) scale(1);
}

/* ===== Card Base ===== */
.card {
  background: rgba(255,255,255,0.88);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 2.5rem;
  max-width: 520px;
  width: 100%;
  position: relative;
  overflow: hidden;
  max-height: calc(100dvh - 220px);
  overflow-y: auto;
}

.card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: linear-gradient(90deg, var(--blue), var(--orange), var(--yellow));
}

/* ===== Welcome Screen ===== */
.welcome-card {
  text-align: center;
}

.welcome-emoji {
  font-size: 4rem;
  line-height: 1;
  margin-bottom: 0.5rem;
  animation: bounce 2s ease-in-out infinite;
}

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

.welcome-title {
  font-size: 1.75rem;
  font-weight: 800;
  color: var(--blue-dark);
  margin-bottom: 0.5rem;
  letter-spacing: -0.02em;
}

.welcome-subtitle {
  font-size: 1rem;
  color: var(--text-light);
  margin-bottom: 1.5rem;
  line-height: 1.6;
}

.welcome-stats {
  display: flex;
  justify-content: center;
  gap: 1.5rem;
  margin-bottom: 1.5rem;
}

.stat-item {
  text-align: center;
}

.stat-number {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--blue);
  display: block;
}

.stat-label {
  font-size: 0.75rem;
  color: var(--text-light);
}

.history-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--orange-light);
  color: var(--orange);
  padding: 6px 14px;
  border-radius: 99px;
  font-size: 0.8rem;
  font-weight: 600;
  margin-bottom: 1.5rem;
}

/* ===== Form ===== */
.student-form {
  width: 100%;
}

.form-row {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.form-group {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
  text-align: left;
}

.form-group label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-light);
}

.form-input {
  width: 100%;
  padding: 10px 14px;
  border: 2px solid #e2e8f0;
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 0.9rem;
  outline: none;
  transition: border-color var(--transition);
}

.form-input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(26,115,232,0.12);
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 32px;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 1.05rem;
  font-weight: 700;
  cursor: pointer;
  transition: all var(--transition);
  text-decoration: none;
}

.btn:active {
  transform: scale(0.96);
}

.btn-blue {
  background: linear-gradient(135deg, var(--blue), var(--blue-dark));
  color: #fff;
  box-shadow: 0 4px 12px rgba(26,115,232,0.35);
}

.btn-blue:hover {
  box-shadow: 0 6px 20px rgba(26,115,232,0.45);
  transform: translateY(-2px);
}

.btn-orange {
  background: linear-gradient(135deg, var(--orange), #e65100);
  color: #fff;
  box-shadow: 0 4px 12px rgba(255,143,0,0.35);
}

.btn-orange:hover {
  box-shadow: 0 6px 20px rgba(255,143,0,0.45);
  transform: translateY(-2px);
}

.btn-green {
  background: linear-gradient(135deg, var(--green), #2e7d32);
  color: #fff;
  box-shadow: 0 4px 12px rgba(67,160,71,0.35);
}

.btn-green:hover {
  box-shadow: 0 6px 20px rgba(67,160,71,0.45);
  transform: translateY(-2px);
}

.btn-outline {
  background: transparent;
  color: var(--blue);
  border: 2px solid var(--blue);
}

.btn-outline:hover {
  background: var(--blue);
  color: #fff;
}

.btn-full { width: 100%; }
.btn-lg { padding: 16px 40px; font-size: 1.1rem; border-radius: var(--radius-sm); }

/* ===== Quiz Screen ===== */
.quiz-card {
  max-width: 600px;
  padding: 2rem;
}

.quiz-top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
}

.quiz-student-badge {
  font-size: 0.8rem;
  color: var(--text-light);
  font-weight: 600;
}

/* Subway line progress */
.progress-container {
  margin-bottom: 1.5rem;
}

.progress-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: relative;
  padding: 0 6px;
}

.progress-line::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 12px;
  right: 12px;
  height: 4px;
  background: #e2e8f0;
  border-radius: 2px;
  transform: translateY(-50%);
  z-index: 0;
}

.progress-line-fill {
  position: absolute;
  top: 50%;
  left: 12px;
  height: 4px;
  background: linear-gradient(90deg, var(--blue), #42a5f5);
  border-radius: 2px;
  transform: translateY(-50%);
  transition: width 0.5s cubic-bezier(0.16, 1, 0.3, 1);
  z-index: 1;
}

.progress-stop {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #e2e8f0;
  border: 3px solid #e2e8f0;
  position: relative;
  z-index: 2;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.55rem;
  font-weight: 700;
  color: transparent;
}

.progress-stop.active {
  background: var(--blue);
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(26,115,232,0.2);
  transform: scale(1.15);
}

.progress-stop.done {
  background: var(--green);
  border-color: var(--green);
  color: #fff;
  font-size: 0.65rem;
}

.progress-stop.wrong {
  background: var(--red);
  border-color: var(--red);
  color: #fff;
  font-size: 0.65rem;
}

.progress-counter {
  text-align: center;
  margin-top: 0.75rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-light);
}

.progress-counter span {
  color: var(--blue);
  font-size: 1.1rem;
}

/* ===== Vertical Multiplication Display ===== */
.multiplication-box {
  background: #fafafa;
  border: 2px solid #e8e8e8;
  border-radius: var(--radius-sm);
  padding: 1.5rem 2rem;
  margin-bottom: 1.5rem;
  display: inline-block;
  width: 100%;
  text-align: center;
  position: relative;
}

.multiplication-box::before {
  content: '列竖式计算';
  position: absolute;
  top: -10px;
  left: 20px;
  background: var(--card);
  padding: 0 8px;
  font-size: 0.75rem;
  color: var(--text-light);
  font-weight: 600;
}

.math-vertical {
  display: inline-block;
  text-align: right;
  font-family: 'Courier New', Courier, monospace;
  font-size: 2rem;
  font-weight: 700;
  line-height: 1.3;
  letter-spacing: 4px;
  color: var(--text);
}

.math-vertical .top-num {
  display: block;
  padding-right: 28px;
}

.math-vertical .bottom-row {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
}

.math-vertical .multiply-sign {
  font-size: 1.5rem;
  font-weight: 600;
}

.math-vertical .bottom-num {
  display: block;
  padding-right: 28px;
}

.math-vertical .divider {
  display: block;
  width: 100%;
  height: 3px;
  background: var(--text);
  border-radius: 2px;
  margin: 4px 0 8px;
}

/* Answer input */
.answer-area {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-bottom: 1.5rem;
}

.answer-area label {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
}

.answer-input {
  width: 120px;
  padding: 12px 16px;
  border: 3px solid #e2e8f0;
  border-radius: var(--radius-sm);
  font-family: 'Courier New', Courier, monospace;
  font-size: 1.5rem;
  font-weight: 700;
  text-align: center;
  outline: none;
  transition: border-color var(--transition);
}

.answer-input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 4px rgba(26,115,232,0.12);
}

.answer-input.correct {
  border-color: var(--green);
  background: #e8f5e9;
}

.answer-input.wrong {
  border-color: var(--red);
  background: #ffebee;
  animation: shake 0.4s ease-out;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-8px); }
  40% { transform: translateX(8px); }
  60% { transform: translateX(-6px); }
  80% { transform: translateX(6px); }
}

/* Feedback toast */
.feedback {
  text-align: center;
  font-size: 1rem;
  font-weight: 700;
  padding: 8px;
  border-radius: var(--radius-sm);
  margin-bottom: 1rem;
  min-height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: all var(--transition);
}

.feedback.correct {
  color: var(--green);
  background: #e8f5e9;
}

.feedback.wrong {
  color: var(--red);
  background: #ffebee;
}

.feedback.empty {
  opacity: 0;
}

/* Quiz actions */
.quiz-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.quiz-actions .btn {
  flex: none;
}

.btn-nav {
  padding: 10px 8px !important;
  font-size: 0.85rem !important;
  border-radius: 10px !important;
}

/* Pause Overlay */
.pause-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  border-radius: var(--radius);
}

.pause-card {
  background: #fff;
  border-radius: var(--radius);
  padding: 2.5rem;
  text-align: center;
  box-shadow: var(--shadow-lg);
  max-width: 300px;
  width: 90%;
}

.pause-emoji {
  font-size: 3rem;
  margin-bottom: 0.5rem;
}

.pause-title {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--blue-dark);
  margin-bottom: 0.5rem;
}

.pause-subtitle {
  font-size: 0.9rem;
  color: var(--text-light);
  margin-bottom: 1.5rem;
}

/* ===== Result Screen ===== */
.result-card {
  max-width: 600px;
  text-align: center;
}

.result-trophy {
  font-size: 4rem;
  line-height: 1;
  margin-bottom: 0.5rem;
  animation: bounce 2s ease-in-out infinite;
}

.result-title {
  font-size: 1.75rem;
  font-weight: 800;
  color: var(--blue-dark);
  margin-bottom: 0.25rem;
}

.result-subtitle {
  color: var(--text-light);
  margin-bottom: 1.5rem;
  font-size: 0.95rem;
}

/* Score circle */
.score-circle {
  width: 140px;
  height: 140px;
  border-radius: 50%;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  margin-bottom: 1.5rem;
  position: relative;
}

.score-circle.big-score {
  background: conic-gradient(var(--blue) var(--score-deg, 0deg), #e2e8f0 0deg);
}

.score-circle::before {
  content: '';
  position: absolute;
  inset: 6px;
  border-radius: 50%;
  background: var(--card);
}

.score-number {
  position: relative;
  z-index: 1;
  font-size: 2.5rem;
  font-weight: 800;
  color: var(--blue);
  line-height: 1;
}

.score-label {
  position: relative;
  z-index: 1;
  font-size: 0.75rem;
  color: var(--text-light);
}

.score-details {
  display: flex;
  justify-content: center;
  gap: 2rem;
  margin-bottom: 1rem;
}

.score-detail {
  text-align: center;
}

.score-detail-num {
  font-size: 1.2rem;
  font-weight: 800;
}

.score-detail-num.green { color: var(--green); }
.score-detail-num.red { color: var(--red); }

.score-detail-label {
  font-size: 0.75rem;
  color: var(--text-light);
}

.time-spent {
  font-size: 0.85rem;
  color: var(--text-light);
  margin-bottom: 1.5rem;
}

/* Review list */
.review-section {
  text-align: left;
  margin-bottom: 1.5rem;
  border-top: 1px solid #e8e8e8;
  padding-top: 1.5rem;
}

.review-title {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 1rem;
  color: var(--text);
}

.review-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 200px;
  overflow-y: auto;
}

.review-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: #fafafa;
  border-radius: 8px;
  font-size: 0.9rem;
}

.review-item .review-problem {
  font-family: 'Courier New', monospace;
  font-weight: 600;
}

.review-item .review-status {
  font-size: 0.8rem;
  font-weight: 700;
}

.review-status.correct { color: var(--green); }
.review-status.wrong { color: var(--red); }

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

/* ===== Scrollbar ===== */
::-webkit-scrollbar {
  width: 4px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: #ccc;
  border-radius: 99px;
}

/* ===== Responsive ===== */
@media (max-width: 520px) {
  .card { padding: 1.5rem; border-radius: 16px; max-height: calc(100dvh - 100px); }
  .quiz-card { padding: 1.5rem; }
  .form-row { flex-direction: column; }
  .welcome-title { font-size: 1.4rem; }
  .math-vertical { font-size: 1.5rem; }
  .answer-input { width: 100px; font-size: 1.25rem; }
  .score-circle { width: 110px; height: 110px; }
  .score-number { font-size: 2rem; }
  .quiz-top-bar { flex-direction: column; gap: 8px; align-items: flex-start; }
  .progress-stop { width: 18px; height: 18px; font-size: 0.45rem; }
  .app { padding: 60px 12px 25vh; }
  .screen { padding: 60px 12px 28vh; }
  .clock-time { font-size: 1.1rem; }
  .station-clock { top: 10px; left: 10px; }
  .btn-nav { font-size: 0.75rem !important; padding: 8px 4px !important; }
}

@media (min-width: 768px) {
  .card { padding: 3rem; }
  .math-vertical { font-size: 2.5rem; }
}

/* ===== Reduced Motion ===== */
@media (prefers-reduced-motion: reduce) {
  .train-wrapper,
  .train-wheel:nth-child(2),
  .train-wheel:nth-child(3),
  .welcome-emoji,
  .result-trophy,
  .music-btn.playing svg,
  .running-dot {
    animation: none !important;
  }
  .train-wrapper { display: none; }
  .music-btn.playing { animation: none !important; }
}
