:root {
  --purple: #7c3aed;
  --purple-light: #ede9fe;
  --teal: #0d9488;
  --teal-light: #ccfbf1;
  --pink: #db2777;
  --pink-light: #fce7f3;
  --orange: #ea580c;
  --orange-light: #ffedd5;
  --yellow: #ca8a04;
  --yellow-light: #fef9c3;
  --green: #16a34a;
  --green-light: #dcfce7;
  --red: #dc2626;
  --red-light: #fee2e2;
  --bg: #faf5ff;
  --card-radius: 18px;
  --shadow: 0 4px 20px rgba(124,58,237,0.12);
}

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

body {
  font-family: 'Segoe UI', 'Arial', sans-serif;
  background: var(--bg);
  color: #1e1b4b;
  min-height: 100vh;
  direction: rtl;
}

/* ===== SCREEN SYSTEM ===== */
.screen { display: none; min-height: 100vh; }
.screen.active { display: flex; flex-direction: column; }

/* ===== HEADER ===== */
.app-header {
  background: var(--purple);
  color: white;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
  position: sticky; top: 0; z-index: 10;
}
.app-header h1 { flex: 1; font-size: 1.15rem; font-weight: 700; text-align: center; }
.btn-back {
  background: rgba(255,255,255,0.2);
  border: 2px solid rgba(255,255,255,0.5);
  color: white; font-size: 0.9rem; font-weight: 700;
  border-radius: 10px; padding: 7px 12px; cursor: pointer;
  white-space: nowrap;
}
.btn-back:hover { background: rgba(255,255,255,0.35); }
.btn-summary {
  background: white; color: var(--purple);
  border: none; border-radius: 10px; padding: 6px 12px;
  font-weight: 700; cursor: pointer; font-size: 0.9rem;
}
.header-left { display: flex; gap: 8px; align-items: center; font-size: 0.9rem; }
.hdr-stars { background: rgba(255,255,255,0.2); border-radius: 8px; padding: 3px 8px; }
.hdr-streak { background: rgba(255,165,0,0.3); border-radius: 8px; padding: 3px 8px; }
.practice-meta { font-size: 0.85rem; display: flex; gap: 6px; align-items: center; }

/* ===== SECTION LIST ===== */
.section-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  padding: 18px 14px;
  max-width: 600px;
  margin: 0 auto;
  width: 100%;
}
.section-card {
  background: white;
  border-radius: var(--card-radius);
  box-shadow: var(--shadow);
  padding: 20px 14px 16px;
  cursor: pointer;
  text-align: center;
  border: 3px solid transparent;
  transition: transform 0.1s, border-color 0.2s;
  user-select: none;
}
.section-card:active { transform: scale(0.96); }
.section-card .sec-emoji { font-size: 2.5rem; display: block; margin-bottom: 8px; }
.section-card .sec-name { font-weight: 700; font-size: 1rem; display: block; margin-bottom: 6px; }
.section-card .sec-stars { font-size: 0.85rem; color: var(--yellow); }
.section-card .sec-bar { height: 6px; border-radius: 3px; background: #e5e7eb; margin-top: 8px; overflow: hidden; }
.section-card .sec-bar-fill { height: 100%; border-radius: 3px; transition: width 0.4s; }
.section-card.mastered { border-color: gold; }

/* ===== SKILL LIST ===== */
.skill-list { padding: 14px; max-width: 600px; margin: 0 auto; width: 100%; display: flex; flex-direction: column; gap: 10px; }
.skill-card {
  background: white; border-radius: var(--card-radius);
  box-shadow: var(--shadow); padding: 16px 18px;
  display: flex; align-items: center; gap: 12px;
  cursor: pointer; border: 2px solid transparent;
  transition: transform 0.1s;
}
.skill-card:active { transform: scale(0.97); }
.skill-card .sk-label { flex: 1; font-weight: 600; font-size: 1rem; }
.skill-card .sk-level { font-size: 0.82rem; color: #6b7280; }
.skill-card .sk-stars { color: var(--yellow); font-size: 0.85rem; }
.skill-card.mastered { border-color: gold; }
.skill-card .sk-badge { font-size: 1rem; }

/* ===== PRACTICE ===== */
.problem-area {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; padding: 20px 16px;
  max-width: 600px; margin: 0 auto; width: 100%; gap: 16px;
}
.problem-render { width: 100%; text-align: center; }
.problem-prompt {
  font-size: 1.35rem; font-weight: 700; text-align: center;
  line-height: 1.5; padding: 10px;
}
.problem-input { width: 100%; }

/* Keypad */
.keypad-display {
  background: white; border: 3px solid var(--purple); border-radius: 14px;
  font-size: 2rem; font-weight: 700; text-align: center;
  padding: 14px; margin-bottom: 10px; min-height: 64px;
  color: var(--purple); direction: ltr;
}
.keypad-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px;
}
.keypad-btn {
  background: white; border: 2px solid #e5e7eb; border-radius: 12px;
  font-size: 1.4rem; font-weight: 700; padding: 14px 8px;
  cursor: pointer; color: #1e1b4b; transition: background 0.1s;
}
.keypad-btn:active, .keypad-btn:hover { background: var(--purple-light); border-color: var(--purple); }
.keypad-btn.key-ok { background: var(--green); color: white; border-color: var(--green); }
.keypad-btn.key-ok:hover { background: #15803d; }
.keypad-btn.key-del { background: var(--red-light); border-color: var(--red); }

/* Fraction input */
.frac-input-widget {
  display: inline-flex; flex-direction: column;
  align-items: center; gap: 6px;
}
.frac-input-widget input {
  width: 80px; text-align: center; font-size: 1.5rem; font-weight: 700;
  border: 3px solid var(--purple); border-radius: 10px; padding: 8px;
  outline: none;
}
.frac-input-widget .frac-bar { width: 80px; height: 4px; background: #1e1b4b; border-radius: 2px; }

/* Choices */
.choices-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; width: 100%; }
.choice-btn {
  background: white; border: 3px solid #e5e7eb; border-radius: 14px;
  font-size: 1.15rem; font-weight: 700; padding: 18px 10px;
  cursor: pointer; text-align: center; transition: all 0.1s;
}
.choice-btn:active { transform: scale(0.96); }
.choice-btn:hover { border-color: var(--purple); background: var(--purple-light); }
.choice-btn.correct { background: var(--green-light); border-color: var(--green); }
.choice-btn.wrong { background: var(--red-light); border-color: var(--red); }

/* Number line */
.numberline-container { width: 100%; overflow-x: auto; }
.numberline-svg { display: block; margin: 0 auto; }

/* Fraction display */
.frac-display {
  display: inline-flex; flex-direction: column; align-items: center;
  vertical-align: middle; font-size: 1.2rem; font-weight: 700; line-height: 1.1;
}
.frac-display .frac-top { border-bottom: 2px solid currentColor; padding-bottom: 2px; }

/* Shape SVG */
.shape-svg { display: block; margin: 0 auto; }

/* Feedback */
.feedback-area {
  width: 100%; border-radius: 16px; padding: 16px 20px;
  text-align: center; font-size: 1.2rem; font-weight: 700;
  animation: popIn 0.2s ease-out;
}
.feedback-area.correct { background: var(--green-light); color: var(--green); }
.feedback-area.wrong { background: var(--red-light); color: var(--red); }
.explanation-area {
  background: #fff7ed; border: 2px solid var(--orange);
  border-radius: 14px; padding: 14px 18px;
  font-size: 0.95rem; line-height: 1.6; width: 100%;
}
.explanation-area .explanation-title { font-weight: 700; margin-bottom: 6px; }
.explanation-body { margin-top: 6px; text-align: right; direction: rtl; }
.btn-continue {
  display: block; width: 100%; margin-top: 14px;
  background: var(--purple); color: white;
  border: none; border-radius: 12px; padding: 14px;
  font-size: 1.1rem; font-weight: 700; cursor: pointer;
  direction: rtl;
}
.btn-continue:active { opacity: 0.85; }

@keyframes popIn {
  from { transform: scale(0.8); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

/* ===== SUMMARY ===== */
.summary-content { padding: 14px; max-width: 600px; margin: 0 auto; width: 100%; }
.summary-section-card {
  background: white; border-radius: var(--card-radius);
  box-shadow: var(--shadow); padding: 16px 18px; margin-bottom: 12px;
}
.sum-sec-header { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.sum-sec-emoji { font-size: 1.6rem; }
.sum-sec-name { font-weight: 700; font-size: 1.05rem; flex: 1; }
.sum-sec-stars { color: var(--yellow); font-weight: 700; }
.sum-skill-row { display: flex; align-items: center; gap: 8px; padding: 4px 0; font-size: 0.9rem; }
.sum-skill-row .sum-sk-label { flex: 1; }
.sum-skill-row .sum-sk-acc { color: #6b7280; }
.sum-skill-row .sum-sk-gold { color: gold; }
.focus-hint { background: var(--yellow-light); border: 2px solid var(--yellow); border-radius: 10px; padding: 10px 14px; margin-top: 8px; font-size: 0.9rem; }
.badge-shelf { display: flex; flex-wrap: wrap; gap: 8px; padding: 14px; }
.badge { background: white; border-radius: 12px; box-shadow: var(--shadow); padding: 10px 14px; display: flex; align-items: center; gap: 8px; font-size: 0.9rem; font-weight: 600; }
.badge-emoji { font-size: 1.4rem; }
.summary-actions { padding: 10px 14px 24px; max-width: 600px; margin: 0 auto; }
.btn-danger {
  background: var(--red-light); color: var(--red); border: 2px solid var(--red);
  border-radius: 12px; padding: 12px 20px; font-size: 1rem; font-weight: 700;
  cursor: pointer; width: 100%;
}

/* ===== PIN SCREEN ===== */
.pin-card {
  background: white; border-radius: 24px; box-shadow: 0 8px 40px rgba(124,58,237,0.18);
  padding: 36px 28px; max-width: 360px; margin: 60px auto; text-align: center;
}
.pin-card h2 { margin: 12px 0 20px; font-size: 1.3rem; color: #1e1b4b; }
.big-emoji { font-size: 3rem; }
.pin-dots { display: flex; justify-content: center; gap: 14px; margin-bottom: 16px; }
.pin-dots span {
  width: 18px; height: 18px; border-radius: 50%;
  border: 3px solid var(--purple); background: transparent; display: block;
}
.pin-dots span.filled { background: var(--purple); }
.pin-error { color: var(--red); font-weight: 700; margin-bottom: 10px; font-size: 0.95rem; }

/* ===== TOAST ===== */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: #1e1b4b; color: white; border-radius: 14px;
  padding: 12px 24px; font-weight: 700; font-size: 1rem;
  z-index: 100; box-shadow: 0 4px 20px rgba(0,0,0,0.25);
  animation: slideUp 0.3s ease-out;
}
@keyframes slideUp {
  from { transform: translateX(-50%) translateY(30px); opacity: 0; }
  to { transform: translateX(-50%) translateY(0); opacity: 1; }
}

/* ===== LEVEL-UP ===== */
.levelup-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.4);
  display: flex; align-items: center; justify-content: center; z-index: 200;
}
.levelup-box {
  background: white; border-radius: 24px; padding: 40px 50px; text-align: center;
  animation: popIn 0.3s ease-out;
}
.levelup-emoji { font-size: 4rem; }
.levelup-text { font-size: 1.8rem; font-weight: 800; color: var(--purple); margin-top: 10px; }

/* ===== OFFLINE BANNER ===== */
.offline-banner {
  background: var(--orange-light); border-top: 2px solid var(--orange);
  text-align: center; padding: 10px; font-size: 0.9rem; font-weight: 600;
}

/* ===== SELFTEST ===== */
.selftest-panel {
  padding: 20px; font-family: monospace; max-height: 80vh;
  overflow-y: auto; background: #1e1b4b; color: #a3e635; border-radius: 12px; margin: 16px;
}

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

/* Responsive */
@media (max-width: 400px) {
  .section-list { grid-template-columns: 1fr; }
  .choices-grid { grid-template-columns: 1fr; }
  .keypad-btn { padding: 12px 6px; font-size: 1.2rem; }
}
