/* ===================== THEME ===================== */
:root {
  --brown-900: #4a2c1a;
  --brown-700: #6b4226;
  --brown-600: #7b4b2a;
  --brown-500: #9c6239;
  --brown-400: #b7855a;
  --brown-100: #f0e2d4;
  --cream: #fbf4ec;
  --cream-2: #f5e9dc;
  --red: #d6482f;
  --red-soft: #f6d9d2;
  --red-dark: #b53a24;
  --green: #3aa66e;
  --green-soft: #d6f0e2;
  --ink: #3d2b1f;
  --muted: #9c8674;
  --surface: #fff;
  --backdrop: radial-gradient(circle at 30% 10%, #efe3d6, #e4d3c1);
  --card-radius: 26px;
  --brown-grad: linear-gradient(150deg, #7b4b2a 0%, #9c6239 55%, #b7855a 100%);
  --shadow-soft: 0 14px 30px rgba(74, 44, 26, 0.14);
  color-scheme: light dark;
}

/* ===================== DARK THEME (system preference) ===================== */
@media (prefers-color-scheme: dark) {
  :root {
    --brown-900: #f4ece3; /* headings / question text on cards */
    --brown-700: #e7c49e; /* warm accent: fractions, titles, ghost btn */
    --brown-600: #cf9a66;
    --brown-500: #b7855a;
    --brown-400: #9c6239;
    --brown-100: #3a2b22; /* dark tile bg / subtle card borders */
    --cream: #17110d;     /* page background */
    --cream-2: #2c221c;   /* recessed surfaces: tracks, option bg */
    --red: #e2593f;
    --red-soft: #43201a;  /* dark red-tinted bg for pills/wrong option */
    --red-dark: #ff8368;  /* bright red text on dark */
    --green: #4fbf88;
    --green-soft: #163329; /* dark green-tinted bg */
    --ink: #ece1d6;       /* main text */
    --muted: #a9968a;     /* muted text */
    --surface: #241a15;   /* card surfaces */
    --backdrop: radial-gradient(circle at 30% 10%, #211812, #100b08);
    --brown-grad: linear-gradient(150deg, #3d2415 0%, #5a3821 55%, #6d4527 100%);
    --shadow-soft: 0 14px 30px rgba(0, 0, 0, 0.5);
  }

  /* give dark cards a faint edge so they separate from the background */
  .section-card { border-color: rgba(255, 255, 255, 0.06); }
  .mode-switch,
  .mc-card,
  .card-front { box-shadow: 0 14px 30px rgba(0, 0, 0, 0.45); }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  background: var(--backdrop);
  font-family: "Cairo", "Segoe UI", Tahoma, "Noto Sans Arabic", sans-serif;
  color: var(--ink);
  padding: 16px;
}

/* ===================== PHONE FRAME ===================== */
.phone {
  position: relative;
  width: 100%;
  max-width: 420px;
  height: 860px;
  max-height: 94vh;
  background: var(--cream);
  border-radius: 40px;
  box-shadow: 0 30px 70px rgba(74, 44, 26, 0.28);
  overflow: hidden;
}

/* ===================== VIEWS ===================== */
.view {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  animation: viewIn 0.45s ease both;
}
.view.is-active { display: flex; }
@keyframes viewIn {
  from { opacity: 0; transform: translateX(18px); }
  to { opacity: 1; transform: translateX(0); }
}

/* ===================== HEADER ===================== */
.app-header {
  background: var(--brown-grad);
  color: #fff;
  padding: 26px 24px 30px;
  border-radius: 0 0 34px 34px;
  box-shadow: var(--shadow-soft);
}
.header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}
.header-dots { font-size: 17px; opacity: 0.85; letter-spacing: -4px; }
.header-avatar {
  width: 34px; height: 34px;
  display: grid; place-items: center;
  background: rgba(255, 255, 255, 0.22);
  border-radius: 11px;
  font-size: 17px;
}
.header-title { margin: 0; font-size: 30px; font-weight: 900; }
.header-sub { margin: 6px 0 0; font-size: 14px; opacity: 0.85; }

.icon-btn {
  width: 32px; height: 32px;
  border: none; border-radius: 10px;
  background: rgba(255, 255, 255, 0.22);
  color: #fff; font-size: 21px; line-height: 1;
  cursor: pointer;
}
.flag { font-size: 17px; opacity: 0.9; }

/* ===================== SCROLL BODY ===================== */
.body-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 22px 22px 110px;
}
.body-scroll::-webkit-scrollbar { width: 6px; }
.body-scroll::-webkit-scrollbar-thumb {
  background: var(--brown-400);
  border-radius: 8px;
}

/* ===================== STAT TILES ===================== */
.stats-tiles {
  display: flex;
  gap: 14px;
  margin-bottom: 24px;
}
.tile {
  flex: 1;
  border-radius: 20px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.tile-brown { background: var(--brown-100); }
.tile-red { background: var(--red-soft); }
.tile-num { font-size: 30px; font-weight: 900; }
.tile-brown .tile-num { color: var(--brown-700); }
.tile-red .tile-num { color: var(--red-dark); }
.tile-label { font-size: 13px; color: var(--muted); font-weight: 600; }

/* ===================== MODE SWITCH ===================== */
.mode-switch {
  background: var(--surface);
  border-radius: 20px;
  padding: 16px;
  margin-bottom: 22px;
  box-shadow: 0 8px 20px rgba(74, 44, 26, 0.08);
  text-align: center;
}
.mode-switch.pulse { animation: pulseGlow 0.7s ease; }
@keyframes pulseGlow {
  0%, 100% { box-shadow: 0 8px 20px rgba(74, 44, 26, 0.08); transform: scale(1); }
  50% { box-shadow: 0 8px 26px rgba(214, 72, 47, 0.4); transform: scale(1.02); }
}
.mode-label {
  display: block;
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
  margin-bottom: 10px;
}
.seg {
  display: flex;
  gap: 6px;
  background: var(--cream-2);
  border-radius: 14px;
  padding: 5px;
}
.seg-btn {
  flex: 1;
  border: none;
  border-radius: 11px;
  padding: 11px 8px;
  background: transparent;
  color: var(--brown-700);
  font-family: inherit;
  font-size: 15px;
  font-weight: 800;
  cursor: pointer;
  transition: background 0.25s, color 0.25s, box-shadow 0.25s;
}
.seg-btn.is-on {
  background: var(--brown-grad);
  color: #fff;
  box-shadow: 0 6px 14px rgba(123, 75, 42, 0.35);
}
.mode-hint {
  margin: 10px 0 0;
  font-size: 12px;
  color: var(--muted);
  min-height: 16px;
}

/* ===================== SECTION LIST ===================== */
.section-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 14px;
}
.section-head h2 { margin: 0; font-size: 20px; font-weight: 800; }
.section-count { font-size: 13px; color: var(--muted); font-weight: 600; }

.section-list { display: flex; flex-direction: column; gap: 14px; }

.section-card {
  background: var(--surface);
  border-radius: 22px;
  padding: 18px 18px 16px;
  box-shadow: 0 8px 20px rgba(74, 44, 26, 0.08);
  cursor: pointer;
  border: 1.5px solid transparent;
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s;
  animation: cardPop 0.5s ease both;
}
@keyframes cardPop {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: translateY(0); }
}
.section-card:active { transform: scale(0.97); }
.section-card:hover {
  border-color: var(--brown-400);
  box-shadow: 0 12px 26px rgba(74, 44, 26, 0.14);
}
.sc-top { display: flex; align-items: center; gap: 12px; }
.sc-icon {
  width: 46px; height: 46px;
  border-radius: 14px;
  background: var(--cream-2);
  display: grid; place-items: center;
  font-size: 22px;
  flex-shrink: 0;
}
.sc-texts { flex: 1; min-width: 0; }
.sc-title { font-size: 17px; font-weight: 800; margin: 0; }
.sc-desc {
  font-size: 12px; color: var(--muted); margin: 2px 0 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sc-frac { font-size: 17px; font-weight: 900; color: var(--brown-700); }
.sc-progress {
  margin-top: 14px;
  height: 8px;
  background: var(--cream-2);
  border-radius: 8px;
  overflow: hidden;
}
.sc-progress > span {
  display: block; height: 100%;
  background: linear-gradient(90deg, var(--brown-500), var(--brown-400));
  border-radius: 8px;
  width: 0;
  transition: width 0.7s cubic-bezier(0.22, 1, 0.36, 1);
}
.section-card.done .sc-progress > span {
  background: linear-gradient(90deg, var(--green), #58c98d);
}

/* ===================== BOTTOM NAV (review only) ===================== */
.bottom-nav {
  position: absolute;
  left: 18px; right: 18px; bottom: 18px;
  height: 70px;
  background: var(--brown-grad);
  border-radius: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 12px 26px rgba(74, 44, 26, 0.32);
}
/* Circular review button that pops above the bar, with its title below */
.fab-review {
  background: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  transform: translateY(-16px);
}
.fab-circle {
  width: 62px; height: 62px;
  border-radius: 50%;
  border: 5px solid var(--cream);
  background: var(--red);
  color: #fff;
  font-size: 26px;
  display: grid;
  place-items: center;
  box-shadow: 0 8px 18px rgba(214, 72, 47, 0.5);
  transition: transform 0.2s ease;
}
.fab-review:active .fab-circle { transform: scale(0.9) rotate(180deg); }
.fab-label {
  color: #fff;
  font-size: 14px;
  font-weight: 800;
  line-height: 1;
}

/* ===================== STUDY VIEW ===================== */
.study-header { padding-bottom: 24px; }
.progress-wrap {
  margin-top: 18px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.progress-track {
  flex: 1;
  height: 10px;
  background: rgba(255, 255, 255, 0.28);
  border-radius: 10px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  width: 0;
  background: #fff;
  border-radius: 10px;
  transition: width 0.5s cubic-bezier(0.22, 1, 0.36, 1);
}
.progress-text { font-size: 14px; font-weight: 800; white-space: nowrap; }

.study-body {
  padding-top: 18px;
  display: flex;
  flex-direction: column;
}
.mini-stats { display: flex; gap: 10px; justify-content: center; margin-bottom: 10px; }
.pill {
  padding: 6px 16px;
  border-radius: 30px;
  font-weight: 800;
  font-size: 15px;
}
.pill-green { background: var(--green-soft); color: var(--green); }
.pill-red { background: var(--red-soft); color: var(--red-dark); }

/* ===================== MULTIPLE-CHOICE CARD ===================== */
.mc-card {
  background: var(--surface);
  border: 2px solid var(--brown-100);
  border-radius: var(--card-radius);
  padding: 24px 20px;
  box-shadow: var(--shadow-soft);
  margin: 10px auto 4px;
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  animation: dealIn 0.5s ease both;
}
.mc-options {
  margin-top: 20px;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.mc-opt {
  width: 100%;
  padding: 14px 16px;
  border: 2px solid var(--cream-2);
  border-radius: 16px;
  background: var(--cream);
  color: var(--ink);
  font-family: inherit;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.2s, background 0.2s;
  text-align: center;
}
.mc-opt:hover:not(.locked) { border-color: var(--brown-400); }
.mc-opt:active:not(.locked) { transform: scale(0.97); }
.mc-opt.selected {
  border-color: var(--brown-600);
  background: var(--brown-100);
  color: var(--brown-900);
}
.mc-opt.locked { cursor: default; }
.mc-opt.correct {
  border-color: var(--green);
  background: var(--green-soft);
  color: var(--green);
}
.mc-opt.wrong {
  border-color: var(--red);
  background: var(--red-soft);
  color: var(--red-dark);
}

/* ===================== FLASHCARD FLIP ===================== */
.card-scene {
  perspective: 1400px;
  margin: 10px auto 4px;
  width: 100%;
  max-width: 330px;
  min-height: 360px;
  display: flex;
  animation: dealIn 0.5s ease both;
}
.flashcard {
  position: relative;
  width: 100%;
  transform-style: preserve-3d;
  transition: transform 0.7s cubic-bezier(0.4, 0.2, 0.2, 1);
  cursor: pointer;
}
@keyframes dealIn {
  from { opacity: 0; transform: translateY(24px) scale(0.94); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.flashcard.flipped { transform: rotateY(180deg); }
.card-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: var(--card-radius);
  padding: 26px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  box-shadow: var(--shadow-soft);
}
.card-front {
  background: var(--surface);
  border: 2px solid var(--brown-100);
}
.card-index {
  width: 54px; height: 54px;
  border-radius: 16px;
  background: var(--brown-grad);
  color: #fff;
  display: grid; place-items: center;
  font-size: 26px; font-weight: 900;
  margin-bottom: 18px;
}
.card-question {
  font-size: 20px;
  font-weight: 700;
  line-height: 1.7;
  color: var(--brown-900);
  margin: 0;
}
.tap-hint {
  margin-top: 22px;
  font-size: 13px;
  color: var(--muted);
  font-weight: 600;
}
.card-back {
  background: var(--brown-grad);
  color: #fff;
  transform: rotateY(180deg);
}
.back-label {
  font-size: 13px;
  opacity: 0.8;
  letter-spacing: 1px;
  margin-bottom: 10px;
}
.card-answer {
  font-size: 26px;
  font-weight: 900;
  margin: 0 0 16px;
}
.all-options {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
}
.opt-line {
  padding: 8px 14px;
  border-radius: 12px;
  font-size: 14px;
  background: rgba(255, 255, 255, 0.16);
  font-weight: 600;
}
.opt-line.correct {
  background: #fff;
  color: var(--green);
  font-weight: 800;
}

.feedback {
  min-height: 26px;
  text-align: center;
  font-weight: 800;
  margin-top: 12px;
  font-size: 15px;
}

/* ===================== ACTION BARS ===================== */
.reveal-bar, .grade-bar {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  padding: 16px 22px 22px;
  background: linear-gradient(180deg, rgba(251,244,236,0), var(--cream) 40%);
}
.grade-bar { display: none; gap: 12px; }
.grade-bar.show { display: flex; }
.reveal-bar.hide { display: none; }

.reveal-btn {
  width: 100%;
  padding: 16px;
  border: none;
  border-radius: 18px;
  background: var(--red);
  color: #fff;
  font-family: inherit;
  font-size: 18px;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 10px 22px rgba(214, 72, 47, 0.4);
  transition: transform 0.15s ease, background 0.2s;
}
.reveal-btn:active { transform: scale(0.96); }
.reveal-btn:hover:not(:disabled) { background: var(--red-dark); }
.reveal-btn:disabled {
  background: var(--brown-100);
  color: var(--muted);
  cursor: not-allowed;
  box-shadow: none;
}

.grade-btn {
  flex: 1;
  padding: 16px;
  border: none;
  border-radius: 18px;
  font-family: inherit;
  font-size: 17px;
  font-weight: 800;
  cursor: pointer;
  transition: transform 0.15s ease;
  color: #fff;
}
.grade-btn:active { transform: scale(0.95); }
.grade-right { background: var(--green); box-shadow: 0 8px 18px rgba(58,166,110,0.4); }
.grade-wrong { background: var(--red); box-shadow: 0 8px 18px rgba(214,72,47,0.4); }

/* ===================== DONE VIEW ===================== */
.done-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 30px;
  text-align: center;
  background: var(--cream);
}
.done-emoji { font-size: 64px; animation: pop 0.6s ease both; }
@keyframes pop {
  0% { transform: scale(0); }
  70% { transform: scale(1.25); }
  100% { transform: scale(1); }
}
.done-title { font-size: 28px; font-weight: 900; margin: 12px 0 4px; color: var(--brown-700); }
.done-line { font-size: 16px; color: var(--muted); margin: 0 0 22px; }
.done-line b { color: var(--brown-700); }
.done-ring {
  width: 150px; height: 150px;
  border-radius: 50%;
  display: grid; place-items: center;
  font-size: 34px; font-weight: 900;
  color: var(--brown-700);
  background: conic-gradient(var(--green) var(--pct, 0%), var(--cream-2) 0);
  margin-bottom: 28px;
}
.done-ring::before {
  content: "";
  position: absolute;
  width: 116px; height: 116px;
  border-radius: 50%;
  background: var(--cream);
}
.done-ring span { position: relative; }
.done-actions { display: flex; flex-direction: column; gap: 12px; width: 100%; max-width: 300px; }
.ghost-btn {
  width: 100%;
  padding: 14px;
  border: 2px solid var(--brown-400);
  border-radius: 18px;
  background: transparent;
  color: var(--brown-700);
  font-family: inherit;
  font-size: 16px;
  font-weight: 800;
  cursor: pointer;
  transition: background 0.2s;
}
.ghost-btn:active { background: var(--brown-100); }

/* ===================== SHAKE / FLASH FX ===================== */
.shake { animation: shake 0.4s; }
@keyframes shake {
  0%,100% { transform: translateX(0); }
  25% { transform: translateX(-8px); }
  75% { transform: translateX(8px); }
}

/* ===================== RESPONSIVE ===================== */

/* ---------- Phone: fill the screen edge-to-edge ---------- */
@media (max-width: 520px) {
  body { padding: 0; }
  .phone {
    border-radius: 0;
    height: 100vh;
    height: 100dvh;
    max-height: none;
    max-width: none;
  }
}

/* ---------- Tablet (iPad) and up ---------- */
@media (min-width: 700px) {
  .phone { max-width: 720px; height: 92vh; max-height: 980px; }
  .app-header { padding: 30px 40px 32px; }
  .header-title { font-size: 34px; }
  .body-scroll { padding: 26px 40px 120px; }

  /* sections flow into a responsive grid instead of one column */
  .section-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
    gap: 16px;
  }

  /* nav becomes a centered floating bar, not a full-width mobile bar */
  .bottom-nav {
    left: 50%;
    right: auto;
    transform: translateX(-50%);
    width: min(520px, 88%);
  }

  /* study view: give the card room and keep buttons a comfortable width */
  .study-body { padding-top: 28px; }
  .reveal-btn { max-width: 380px; margin-inline: auto; }
  .grade-bar.show { justify-content: center; }
  .grade-btn { max-width: 230px; }
}

/* ---------- Desktop / laptop ---------- */
@media (min-width: 1100px) {
  body { padding: 24px; }
  .phone {
    max-width: 940px;
    height: 88vh;
    max-height: 880px;
    border-radius: 34px;
  }
  .app-header { padding: 34px 54px 36px; }
  .header-title { font-size: 40px; }
  .header-sub { font-size: 16px; }
  .body-scroll { padding: 34px 54px 122px; }

  /* study card sits centered and roomy, not stretched across the width */
  .card-scene, .mc-card { max-width: 480px; }
  .card-scene { min-height: 380px; }
}
