/* ============================================================
   ماث لينجو — Duolingo-style design system (orange theme, RTL)
   ============================================================ */
:root {
  --primary: #ff9600;
  --primary-shade: #e07d00;
  --primary-light: #ffe3bd;
  --primary-text: #cc7000;
  --green: #58cc02;
  --green-shade: #46a302;
  --green-light: #d7ffb8;
  --green-text: #58a700;
  --blue: #1cb0f6;
  --blue-shade: #1899d6;
  --blue-light: #ddf4ff;
  --blue-border: #84d8ff;
  --red: #ff4b4b;
  --red-shade: #ea2b2b;
  --red-light: #ffdfe0;
  --yellow: #ffc800;
  --yellow-shade: #e6a800;
  --gray-border: #e5e5e5;
  --gray-shade: #cfcfcf;
  --text: #4b4b4b;
  --text-soft: #777777;
  --bg: #ffffff;
  --purple: #ce82ff;
  /* correct/wrong quiz feedback — intentionally teal/wine, not Duolingo's green/red */
  --correct: #0d9488;
  --correct-shade: #0f766e;
  --correct-light: #ccfbf1;
  --correct-text: #0f766e;
  --wrong: #9d174d;
  --wrong-shade: #831843;
  --wrong-light: #fde2ec;
  --wrong-text: #9d174d;
  --navy: #1e2a4a;
  --navy-shade: #141c33;
  --navy-light: #e8ebf3;
  --font: 'Baloo Bhaijaan 2', 'Nunito', 'Segoe UI', system-ui, sans-serif;
  --hand: 'Patrick Hand', 'Baloo Bhaijaan 2', 'Comic Sans MS', cursive;
}

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

html, body { height: 100%; }

body {
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  overflow: hidden;
  font-weight: 700;
}

#app { height: 100%; max-width: 640px; margin: 0 auto; position: relative; }
#app-main { position: relative; height: 100%; }

/* ============ screens ============ */
.screen {
  position: absolute; inset: 0;
  display: none;
  flex-direction: column;
  animation: screenIn .35s ease both;
}
.screen.active { display: flex; }
@keyframes screenIn {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ============ buttons (Duolingo 3D style) ============ */
.btn {
  font-family: var(--font);
  font-weight: 800;
  font-size: 16px;
  color: #fff;
  background: var(--primary);
  border: none;
  border-radius: 16px;
  padding: 13px 24px;
  cursor: pointer;
  box-shadow: 0 4px 0 var(--primary-shade);
  transition: filter .15s, transform .05s, box-shadow .05s;
  user-select: none;
  touch-action: manipulation;
}
.btn:hover { filter: brightness(1.06); }
.btn:active { transform: translateY(4px); box-shadow: 0 0 0 var(--primary-shade); }
.btn:disabled {
  background: var(--gray-border); color: #afafaf;
  box-shadow: 0 4px 0 var(--gray-border); cursor: default; filter: none;
}
.btn:disabled:active { transform: none; }

.btn-primary { background: var(--primary); box-shadow: 0 4px 0 var(--primary-shade); }
.btn-blue { background: var(--blue); box-shadow: 0 4px 0 var(--blue-shade); }
.btn-red { background: var(--red); box-shadow: 0 4px 0 var(--red-shade); }

.btn-ghost {
  background: #fff; color: var(--blue);
  border: 2px solid var(--gray-border);
  box-shadow: 0 4px 0 var(--gray-border);
}
.btn-ghost:active { box-shadow: 0 0 0 var(--gray-border); }

.btn-danger-outline {
  background: #fff; color: var(--red);
  border: 2px solid var(--gray-border);
  box-shadow: 0 4px 0 var(--gray-border);
}
.btn-danger-outline:active { box-shadow: 0 0 0 var(--gray-border); }

.btn-wide { width: 100%; max-width: 340px; }

.icon-btn {
  background: none; border: none; font-size: 22px; cursor: pointer;
  color: #afafaf; padding: 6px 10px; border-radius: 10px;
  transition: background .15s;
  font-family: var(--font);
}
.icon-btn:hover { background: #f1f1f1; }

/* ============ HOME ============ */
#screen-home { justify-content: center; align-items: center; padding: 24px; }
.home-inner {
  display: flex; flex-direction: column; align-items: center; gap: 14px;
  width: 100%;
}
.logo-title {
  font-size: 46px; font-weight: 800; color: var(--primary);
  margin-top: 8px;
}
.logo-title span { color: var(--text); }
.tagline {
  font-size: 18px; color: var(--text-soft); text-align: center;
  max-width: 320px; margin-bottom: 18px; font-weight: 700;
}

/* ============ mascot ============ */
.mascot-slot svg { display: block; width: 100%; height: 100%; }
.mascot-big { width: 170px; height: 170px; animation: bob 2.6s ease-in-out infinite; }
.mascot-teach { width: 96px; height: 96px; flex: 0 0 96px; animation: bob 2.6s ease-in-out infinite; }
@keyframes bob {
  0%,100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}
.mascot-party { animation: party .55s ease-in-out infinite alternate; }
@keyframes party {
  from { transform: rotate(-6deg) translateY(0); }
  to   { transform: rotate(6deg) translateY(-10px); }
}

/* blink + talk (classes toggled from JS on svg parts) */
.mascot-slot .eye-lid {
  transform-box: fill-box; transform-origin: center;
  transform: scaleY(0);
  animation: blink 4.2s infinite;
}
@keyframes blink {
  0%, 94%, 100% { transform: scaleY(0); }
  96%, 98% { transform: scaleY(1); }
}
.mascot-slot .mouth-open { opacity: 0; }
.mascot-slot.talking .mouth-open { animation: talk .28s steps(1) infinite; }
.mascot-slot.talking .mouth-closed { animation: talkC .28s steps(1) infinite; }
@keyframes talk  { 0%,100% { opacity: 0; } 50% { opacity: 1; } }
@keyframes talkC { 0%,100% { opacity: 1; } 50% { opacity: 0; } }

/* ============ PATH ============ */
#screen-path { background: #fff; }
.path-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 18px; border-bottom: 2px solid #f1f1f1;
}
.stat { font-size: 17px; font-weight: 800; }
.stat-streak { color: #ff9600; }
.stat-xp { color: var(--yellow-shade); }

.unit-banner {
  margin: 0 16px 4px;
  background: var(--primary);
  border-radius: 16px;
  box-shadow: 0 4px 0 var(--primary-shade);
  color: #fff;
  padding: 14px 20px;
  display: flex; justify-content: space-between; align-items: center;
}
.unit-eyebrow { font-size: 13px; font-weight: 800; opacity: .9; }
.unit-title { font-size: 22px; font-weight: 800; }
.unit-book { font-size: 30px; }
.unit-progress { font-size: 12px; font-weight: 800; opacity: .85; margin-top: 2px; }

/* ============ desktop sidebar (hidden below 1080px) ============ */
.app-sidebar {
  display: none; flex-direction: column;
  width: 240px; flex: 0 0 240px;
  background: var(--navy); color: #fff;
  padding: 26px 18px 20px; gap: 6px;
}
.sidebar-logo { font-size: 25px; font-weight: 800; color: #fff; margin-bottom: 22px; padding: 0 8px; }
.sidebar-logo span { color: var(--primary); }
.sidebar-nav { display: flex; flex-direction: column; gap: 4px; margin-bottom: auto; }
.sidebar-link {
  display: flex; align-items: center; gap: 12px;
  background: none; border: none; color: #c7cee3;
  font-family: var(--font); font-weight: 700; font-size: 15px;
  padding: 12px 14px; border-radius: 12px; cursor: pointer; text-align: start;
  transition: background .15s, color .15s;
}
.sidebar-link:hover { background: rgba(255,255,255,.07); color: #fff; }
.sidebar-link.active { background: var(--primary); color: #fff; }
.sidebar-link-icon { font-size: 19px; }
.sidebar-stats {
  display: flex; gap: 16px; padding: 14px 10px; margin-top: 14px;
  border-top: 1px solid rgba(255,255,255,.12); border-bottom: 1px solid rgba(255,255,255,.12);
}
.sidebar-stat { color: #fff; font-weight: 800; font-size: 14px; }
.sidebar-settings { margin-top: 12px; }

/* ============ mobile bottom nav (hidden at desktop, toggled via JS) ============ */
.bottom-nav {
  display: none; position: absolute; left: 0; right: 0; bottom: 0;
  background: #fff; border-top: 2px solid var(--gray-border);
  justify-content: space-around; align-items: center;
  padding: 8px 0 max(8px, env(safe-area-inset-bottom));
  z-index: 60;
}
.bottom-nav.show { display: flex; }
.bottom-nav-link {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  background: none; border: none; font-family: var(--font); font-weight: 700; font-size: 11px;
  color: var(--text-soft); cursor: pointer; padding: 4px 20px; border-radius: 10px;
}
.bottom-nav-icon { font-size: 21px; }
.bottom-nav-link.active { color: var(--primary); }
:root[data-theme="dark"] .bottom-nav { background: #17181c; border-color: #2a2b31; }

.path-scroll { flex: 1; overflow-y: auto; position: relative; padding-bottom: 84px; }
.path-groups { padding-top: 18px; max-width: 640px; margin: 0 auto; width: 100%; }
.path-unit-group { margin-bottom: 26px; padding: 0 16px; }

/* ===== Winding journey map: starts at the BOTTOM and climbs upward =====
   column-reverse makes DOM order [1,2,3] render as 1 at the bottom, so the
   learner literally climbs the page as they progress. */
.path-groups { display: flex; flex-direction: column-reverse; }
.path-unit-group { display: flex; flex-direction: column-reverse; }
.path-nodes {
  display: flex; flex-direction: column-reverse;
  align-items: center; gap: 20px; padding: 18px 0 24px;
  position: relative;
}

.lesson-node {
  position: relative;
  display: flex; flex-direction: column; align-items: center; gap: 7px;
  cursor: pointer; width: 132px;
  transition: transform .08s;
}
.lesson-node:active { transform: translateY(3px); }
/* zigzag: alternate sides so the path snakes up the screen */
.lesson-node:nth-child(4n+1) { transform: translateX(0); }
.lesson-node:nth-child(4n+2) { transform: translateX(66px); }
.lesson-node:nth-child(4n+3) { transform: translateX(0); }
.lesson-node:nth-child(4n+4) { transform: translateX(-66px); }
.lesson-node:nth-child(4n+2):active { transform: translateX(66px) translateY(3px); }
.lesson-node:nth-child(4n+4):active { transform: translateX(-66px) translateY(3px); }

/* dotted trail linking each node to the one below it */
.lesson-node::after {
  content: ''; position: absolute; bottom: -22px; left: 50%;
  width: 4px; height: 20px; margin-left: -2px;
  background-image: radial-gradient(circle, var(--gray-shade) 1.6px, transparent 1.7px);
  background-size: 4px 7px; background-repeat: repeat-y;
  pointer-events: none;
}
.path-nodes .lesson-node:first-child::after { display: none; }

.node-circle {
  width: 72px; height: 72px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 29px; position: relative;
  background: var(--gray-border); color: #9a9a9a;
  box-shadow: 0 6px 0 var(--gray-shade);
  transition: box-shadow .08s;
}
.lesson-node:active .node-circle { box-shadow: 0 3px 0 var(--gray-shade); }

.lesson-node.done .node-circle {
  background: var(--yellow); color: #fff; box-shadow: 0 6px 0 var(--yellow-shade);
}
.lesson-node.active-lesson .node-circle {
  background: var(--primary); color: #fff; box-shadow: 0 6px 0 var(--primary-shade);
  animation: nodePulse 1.8s ease-in-out infinite;
}
@keyframes nodePulse {
  0%, 100% { box-shadow: 0 6px 0 var(--primary-shade), 0 0 0 0 rgba(255,150,0,.45); }
  50%      { box-shadow: 0 6px 0 var(--primary-shade), 0 0 0 14px rgba(255,150,0,0); }
}
.lesson-node.locked { cursor: default; opacity: .75; }
.lesson-node.locked:active { transform: none; }
.lesson-node:nth-child(4n+2).locked:active { transform: translateX(66px); }
.lesson-node:nth-child(4n+4).locked:active { transform: translateX(-66px); }

.node-title {
  font-size: 12.5px; font-weight: 800; text-align: center;
  color: var(--text-soft); line-height: 1.35;
}
.lesson-node.active-lesson .node-title { color: var(--primary-text); }
.lesson-node.done .node-title { color: var(--text); }

/* منير stands on the node you're currently at */
.node-mascot {
  position: absolute; top: -14px; left: -54px;
  width: 62px; height: 62px; pointer-events: none;
  animation: bob 2.6s ease-in-out infinite;
  z-index: 3;
}
.node-mascot svg { width: 100%; height: 100%; }
.node-flag {
  position: absolute; top: -30px; left: 50%; transform: translateX(-50%);
  background: var(--primary); color: #fff; font-size: 11px; font-weight: 800;
  padding: 3px 12px; border-radius: 10px; white-space: nowrap; z-index: 4;
}
.node-flag::after {
  content: ''; position: absolute; bottom: -4px; left: 50%; margin-left: -4px;
  border-left: 4px solid transparent; border-right: 4px solid transparent;
  border-top: 5px solid var(--primary);
}

/* trophy sits at the very top — the summit of the climb */
.trophy-node .node-circle {
  width: 82px; height: 82px; font-size: 36px;
}
.trophy-node.done .node-circle {
  background: var(--yellow); color: #fff; box-shadow: 0 6px 0 var(--yellow-shade);
}

:root[data-theme="dark"] .node-circle { background: #2a2b31; color: #6d6d73; }

/* ============ topbar ============ */
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px;
}
.lesson-title { flex: 1; text-align: center; font-weight: 800; font-size: 17px; color: var(--text-soft); }
.close-btn { font-size: 20px; font-weight: 900; }

.progress-track {
  flex: 1; height: 16px; background: var(--gray-border); border-radius: 10px;
  overflow: hidden;
}
.progress-fill {
  height: 100%; width: 0%; background: var(--primary); border-radius: 10px;
  transition: width .45s cubic-bezier(.3,1.4,.5,1);
  position: relative;
}
.progress-fill::after {
  content: ''; position: absolute; top: 4px; left: 8px; right: 8px; height: 4px;
  background: rgba(255,255,255,.35); border-radius: 4px;
}
.hearts { color: var(--red); font-weight: 800; font-size: 16px; white-space: nowrap; }

/* ============ LESSON ============ */
#screen-lesson { background: #fff; }
.lesson-body { flex: 1; overflow-y: auto; padding: 10px 18px 20px; }

.teach-row { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 16px; }

.speech-bubble {
  position: relative; flex: 1;
  border: 2px solid var(--gray-border); border-radius: 16px;
  padding: 12px 16px; font-size: 17px; font-weight: 700; line-height: 1.55;
  min-height: 58px; background: #fff;
}
/* arrow points toward the mascot (on the right in RTL) */
.speech-bubble::before {
  content: ''; position: absolute; right: -9px; top: 34px;
  width: 14px; height: 14px; background: #fff;
  border-right: 2px solid var(--gray-border); border-top: 2px solid var(--gray-border);
  transform: rotate(45deg);
}
.bubble-caret { display: inline-block; width: 2px; background: var(--primary); animation: caret .8s steps(1) infinite; }
@keyframes caret { 50% { opacity: 0; } }

/* notebook card where the exam is "written" */
.notebook-card {
  border: 2px solid var(--gray-border); border-radius: 16px;
  background:
    repeating-linear-gradient(#fff, #fff 33px, #fff3e0 33px, #fff3e0 35px);
  padding: 14px 34px 18px 18px;
  position: relative;
  min-height: 140px;
  box-shadow: 0 4px 0 var(--gray-border);
}
.notebook-card::before {
  content: ''; position: absolute; top: 0; bottom: 0; right: 20px;
  width: 2px; background: #ffb3b3; opacity: .7;
}
.notebook-title {
  font-family: var(--hand); font-size: 19px; color: var(--primary-text);
  margin-bottom: 6px; text-decoration: underline;
}
.notebook-steps { display: flex; flex-direction: column; }
.note-step {
  font-family: var(--hand); font-size: 21px; line-height: 35px;
  color: #2d3a4a; opacity: 0; transform: translateY(6px);
  transition: opacity .4s, transform .4s;
  white-space: pre-wrap;
  unicode-bidi: plaintext;
}
.note-step.show { opacity: 1; transform: none; }
.note-step .hl { color: var(--red-shade); }
.note-step .hl2 { color: var(--green-text); }

/* charts (function graphs with tangent lines) */
.chart-box {
  display: flex; justify-content: center;
  margin: 8px 0 12px;
}
.chart-box svg {
  width: 100%; max-width: 320px; height: auto;
  background: #fff; border: 2px solid var(--gray-border); border-radius: 14px;
}
.chart-caption {
  text-align: center; font-size: 14px; color: var(--text-soft);
  margin-top: -6px; margin-bottom: 10px;
}

.lesson-footer {
  display: flex; gap: 12px; padding: 14px 18px 18px;
  border-top: 2px solid #f1f1f1;
}
.lesson-footer .btn { flex: 1; font-size: 15px; padding: 13px 8px; }

/* ============ QUIZ ============ */
#screen-quiz { background: #fff; }
.quiz-topbar { padding-top: 16px; }
.quiz-body { flex: 1; overflow-y: auto; padding: 8px 20px 20px; position: relative; }

.quiz-prompt { font-size: 21px; font-weight: 800; margin: 10px 0 6px; line-height: 1.5; }
.quiz-math {
  font-family: var(--hand); font-size: 32px; color: #2d3a4a;
  margin: 12px 0 18px; text-align: center;
  min-height: 10px;
}
.quiz-math:empty { margin: 0; }

.choices { display: flex; flex-direction: column; gap: 12px; }
.choice {
  border: 2px solid var(--gray-border); border-radius: 14px;
  background: #fff; box-shadow: 0 4px 0 var(--gray-border);
  padding: 13px 16px; font-size: 18px; font-weight: 700;
  font-family: var(--font); color: var(--text);
  cursor: pointer; text-align: start;
  display: flex; align-items: center; gap: 14px;
  transition: transform .05s, box-shadow .05s, background .15s, border-color .15s;
}
.choice .choice-key {
  width: 30px; height: 30px; flex: 0 0 30px;
  border: 2px solid var(--gray-border); border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; color: #afafaf; font-weight: 800;
}
.choice:active { transform: translateY(4px); box-shadow: 0 0 0 var(--gray-border); }
.choice.selected {
  border-color: var(--blue-border); background: var(--blue-light);
  box-shadow: 0 4px 0 var(--blue-border); color: var(--blue-shade);
}
.choice.selected .choice-key { border-color: var(--blue-border); color: var(--blue-shade); }
.choice.correct {
  border-color: var(--correct); background: var(--correct-light);
  box-shadow: 0 4px 0 var(--correct); color: var(--correct-text);
  animation: correctPop .3s ease;
}
.choice.wrong {
  border-color: var(--wrong); background: var(--wrong-light);
  box-shadow: 0 4px 0 var(--wrong); color: var(--wrong-text);
  animation: wrongPulse .35s ease;
}
.choice.dim { opacity: .5; }
.choice:disabled { cursor: default; }
@keyframes correctPop {
  0% { transform: scale(1); }
  50% { transform: scale(1.03); }
  100% { transform: scale(1); }
}
@keyframes wrongPulse {
  0% { transform: scale(1); }
  40% { transform: scale(.96); }
  100% { transform: scale(1); }
}

/* writing area — ruled notebook paper */
.write-wrap { margin-top: 6px; }
.write-hint { font-size: 15px; color: var(--text-soft); margin-bottom: 10px; }
.notebook-input {
  width: 100%;
  border: 2px solid var(--gray-border); border-radius: 16px;
  box-shadow: 0 4px 0 var(--gray-border);
  background:
    repeating-linear-gradient(#fff, #fff 36px, #fff3e0 36px, #fff3e0 38px);
  font-family: var(--hand); font-size: 26px; line-height: 38px;
  color: #2d3a4a;
  padding: 8px 16px 8px 38px;
  outline: none; resize: none;
  background-attachment: local;
  text-align: left;
}
.notebook-input:focus { border-color: var(--blue-border); box-shadow: 0 4px 0 var(--blue-border); }

/* keyboard FAB — absolute bottom right corner of quiz area */
.kbd-fab {
  position: absolute;
  right: 14px; bottom: 92px;
  width: 58px; height: 58px; border-radius: 50%;
  background: var(--blue); color: #fff; border: none;
  box-shadow: 0 4px 0 var(--blue-shade), 0 6px 14px rgba(0,0,0,.18);
  cursor: pointer; z-index: 30;
  display: flex; align-items: center; justify-content: center;
  transition: transform .05s, box-shadow .05s, filter .15s;
}
.kbd-fab:hover { filter: brightness(1.08); }
.kbd-fab:active { transform: translateY(4px); box-shadow: 0 0 0 var(--blue-shade); }
.kbd-fab.on { background: var(--purple); box-shadow: 0 4px 0 #a855e8, 0 6px 14px rgba(0,0,0,.18); }

/* custom math keyboard */
.math-keyboard {
  position: absolute; left: 0; right: 0; bottom: 0;
  background: #f7f7f7; border-top: 2px solid var(--gray-border);
  border-radius: 20px 20px 0 0;
  padding: 8px 10px 14px;
  transform: translateY(110%);
  transition: transform .28s cubic-bezier(.3,1.2,.5,1);
  z-index: 40;
  box-shadow: 0 -8px 24px rgba(0,0,0,.10);
}
.math-keyboard.open { transform: translateY(0); }
.kbd-drag-handle {
  width: 44px; height: 5px; border-radius: 4px; background: var(--gray-shade);
  margin: 2px auto 8px;
}
.kbd-rows { display: flex; flex-direction: column; gap: 6px; }
.kbd-row { display: flex; gap: 6px; justify-content: center; }
.kbd-key {
  flex: 1; max-width: 64px; min-width: 0;
  padding: 9px 0; font-size: 17px; font-weight: 800;
  font-family: var(--font); color: var(--text);
  background: #fff; border: 2px solid var(--gray-border); border-radius: 10px;
  box-shadow: 0 3px 0 var(--gray-border); cursor: pointer;
  transition: transform .04s, box-shadow .04s;
  white-space: nowrap;
}
.kbd-key:active { transform: translateY(3px); box-shadow: 0 0 0 var(--gray-border); }
.kbd-key.op { color: var(--blue-shade); background: var(--blue-light); border-color: var(--blue-border); box-shadow: 0 3px 0 var(--blue-border); }
.kbd-key.fn { color: var(--primary-text); background: var(--primary-light); border-color: #ffcd80; box-shadow: 0 3px 0 #ffcd80; font-size: 14px; }
.kbd-key.act { color: var(--red-shade); background: var(--red-light); border-color: #ffb3b6; box-shadow: 0 3px 0 #ffb3b6; }

/* quiz footer + feedback */
.quiz-footer {
  display: flex; justify-content: space-between; gap: 12px;
  padding: 14px 18px 18px; border-top: 2px solid #f1f1f1;
  background: #fff;
}
.quiz-footer .btn { min-width: 130px; }

.feedback {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding: 18px 20px 22px;
  transform: translateY(110%);
  transition: transform .3s cubic-bezier(.3,1.2,.5,1);
  z-index: 50;
  display: flex; flex-direction: column; gap: 14px;
  border-radius: 20px 20px 0 0;
}
.feedback.show { transform: translateY(0); }
.feedback.good { background: var(--correct-light); }
.feedback.bad  { background: var(--wrong-light); }
.feedback-inner { display: flex; gap: 14px; align-items: flex-start; }
.feedback-icon {
  width: 54px; height: 54px; flex: 0 0 54px; border-radius: 50%;
  background: #fff; display: flex; align-items: center; justify-content: center;
  font-size: 28px; font-weight: 900;
}
.feedback.good .feedback-icon { color: var(--correct); }
.feedback.bad  .feedback-icon { color: var(--wrong); }
.feedback-title { font-size: 20px; font-weight: 800; unicode-bidi: plaintext; }
.feedback.good .feedback-title, .feedback.good .feedback-detail { color: var(--correct-text); }
.feedback.bad  .feedback-title, .feedback.bad  .feedback-detail { color: var(--wrong-text); }
.feedback-detail { font-size: 15.5px; font-weight: 700; line-height: 1.5; margin-top: 3px; unicode-bidi: plaintext; }
.feedback .btn { width: 100%; }
.feedback.good .btn { background: var(--correct); box-shadow: 0 4px 0 var(--correct-shade); }
.feedback.bad  .btn { background: var(--wrong); box-shadow: 0 4px 0 var(--wrong-shade); }

/* ============ CONGRATS ============ */
#screen-congrats { justify-content: center; align-items: center; background: #fff; }
#confetti-canvas { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.congrats-inner {
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  padding: 24px; z-index: 2; width: 100%;
}
.congrats-title {
  font-size: 34px; font-weight: 800; color: var(--primary);
  animation: popIn .5s cubic-bezier(.3,1.6,.5,1) both;
}
.congrats-sub { color: var(--text-soft); font-size: 17px; margin-bottom: 8px; }
@keyframes popIn { from { transform: scale(.4); opacity: 0; } to { transform: scale(1); opacity: 1; } }

.result-cards { display: flex; gap: 14px; margin: 10px 0 22px; }
.result-card {
  border-radius: 16px; padding: 3px; min-width: 130px;
}
.result-xp  { background: var(--yellow); }
.result-acc { background: var(--green); }
.result-label {
  text-align: center; font-size: 13px; font-weight: 800;
  color: #fff; padding: 5px 0 6px;
}
.result-value {
  background: #fff; border-radius: 13px; text-align: center;
  font-size: 22px; font-weight: 800; padding: 12px 10px;
}
.result-xp .result-value { color: var(--yellow-shade); }
.result-acc .result-value { color: var(--green-text); }

/* ============ settings modal ============ */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.45);
  display: none; align-items: center; justify-content: center;
  z-index: 100; padding: 18px;
}
.modal-overlay.open { display: flex; }
.modal {
  background: #fff; border-radius: 20px; padding: 24px;
  width: 100%; max-width: 420px; max-height: 90vh; overflow-y: auto;
  animation: popIn .3s cubic-bezier(.3,1.4,.5,1) both;
}
.modal-title { font-size: 22px; font-weight: 800; margin-bottom: 16px; }
.field-label { display: block; font-size: 14px; font-weight: 800; margin: 12px 0 6px; }
.field-note { color: #afafaf; font-weight: 700; font-size: 12px; }
.field-input {
  width: 100%; padding: 12px 14px; font-family: var(--font); font-weight: 700;
  font-size: 15px; border: 2px solid var(--gray-border); border-radius: 12px;
  outline: none; color: var(--text); background: #f7f7f7;
}
.field-input:focus { border-color: var(--blue-border); background: #fff; }
.field-range {
  width: 100%; height: 8px; border-radius: 8px;
  background: var(--gray-border); outline: none; -webkit-appearance: none;
  direction: ltr;
}
.field-range::-webkit-slider-thumb {
  -webkit-appearance: none; width: 22px; height: 22px; border-radius: 50%;
  background: var(--primary); border: 3px solid #fff; box-shadow: 0 0 0 2px var(--primary);
  cursor: pointer;
}
.field-range::-moz-range-thumb {
  width: 22px; height: 22px; border-radius: 50%; border: 3px solid #fff;
  background: var(--primary); box-shadow: 0 0 0 2px var(--primary); cursor: pointer;
}
.toggle-row {
  display: flex; align-items: center; justify-content: space-between;
  margin-top: 16px; font-size: 15px; font-weight: 800; cursor: pointer;
}
.toggle-row input { display: none; }
.toggle-pill {
  width: 50px; height: 28px; border-radius: 20px; background: var(--gray-border);
  position: relative; transition: background .2s;
}
.toggle-pill::after {
  content: ''; position: absolute; top: 3px; left: 3px;
  width: 22px; height: 22px; border-radius: 50%; background: #fff;
  transition: left .2s;
  box-shadow: 0 1px 3px rgba(0,0,0,.25);
}
.toggle-row input:checked + .toggle-pill { background: var(--primary); }
.toggle-row input:checked + .toggle-pill::after { left: 25px; }
.modal-hint { font-size: 13px; color: #afafaf; margin-top: 16px; line-height: 1.5; }
.modal-actions { display: flex; gap: 12px; margin-top: 20px; }
.modal-actions .btn { flex: 1; }

/* thinking dots while AI re-explains */
.thinking-dots::after {
  content: '';
  animation: dots 1.2s steps(4) infinite;
}
@keyframes dots {
  0% { content: ''; } 25% { content: '.'; } 50% { content: '..'; } 75% { content: '...'; }
}

/* ============ responsive ============ */
@media (max-width: 380px) {
  .quiz-prompt { font-size: 18px; }
  .quiz-math { font-size: 26px; }
  .lesson-footer .btn { font-size: 13px; }
  .kbd-key { font-size: 15px; padding: 8px 0; }
  .kbd-key.fn { font-size: 12px; }
  .mascot-teach { width: 76px; height: 76px; flex-basis: 76px; }
}

/* ============ subject switcher (path screen) ============ */
.subject-switch {
  display: flex; gap: 8px; padding: 10px 16px 0;
}
.subject-tab {
  flex: 1; padding: 10px 8px; border-radius: 12px;
  border: 2px solid var(--gray-border); background: #fff;
  font-family: var(--font); font-weight: 800; font-size: 14px;
  color: var(--text-soft); cursor: pointer;
  transition: background .15s, border-color .15s, color .15s;
}
.subject-tab.active {
  background: var(--primary-light); border-color: var(--primary);
  color: var(--primary-text);
}

/* school-level chips (0-5) under the subject tabs */
.level-chips {
  display: flex; gap: 8px; padding: 10px 16px 4px;
  overflow-x: auto; scrollbar-width: none;
}
.level-chips::-webkit-scrollbar { display: none; }
.level-chip {
  flex: 0 0 auto; padding: 8px 14px; border-radius: 20px;
  border: 2px solid var(--gray-border); background: #fff;
  font-family: var(--font); font-weight: 800; font-size: 12.5px;
  color: var(--text-soft); cursor: pointer; white-space: nowrap;
  transition: background .15s, border-color .15s, color .15s;
}
.level-chip.mine { border-color: var(--yellow-shade); }
.level-chip.active {
  background: var(--primary); border-color: var(--primary-shade); color: #fff;
}
.path-level-head {
  padding: 8px 16px 0; font-size: 14px; color: var(--text-soft); font-weight: 700;
}
.path-level-head b { color: var(--text); }
:root[data-theme="dark"] .level-chip { background: #212227; }
:root[data-theme="dark"] .level-chip.active { background: var(--primary); color: #fff; }

.book-chapter-stage { font-size: 12px; color: var(--text-soft); font-weight: 700; }
.book-unit-head {
  font-size: 13.5px; font-weight: 800; color: var(--primary-text);
  margin: 10px 0 2px; padding-right: 4px;
}
.school-level-badge {
  font-size: 13px; font-weight: 800; color: var(--primary-text);
  background: var(--primary-light); padding: 5px 14px; border-radius: 12px;
}
.school-level-badge:empty { display: none; }
.school-level-badge span { color: var(--text-soft); font-weight: 700; }

/* ============ auth screens (login / signup / forgot password) ============ */
.auth-body {
  flex: 1; overflow-y: auto; padding: 8px 24px 24px;
  display: flex; flex-direction: column; align-items: stretch; gap: 12px;
}
.mascot-auth { width: 84px; height: 84px; align-self: center; margin-bottom: 4px; animation: bob 2.6s ease-in-out infinite; }
.google-btn-slot { display: flex; justify-content: center; min-height: 44px; }
.auth-divider {
  display: flex; align-items: center; gap: 10px;
  color: #afafaf; font-weight: 800; font-size: 13px; margin: 2px 0;
}
.auth-divider::before, .auth-divider::after { content: ''; flex: 1; height: 2px; background: var(--gray-border); }
.auth-body .field-input { margin: 0; }
.auth-error {
  color: var(--red-shade); font-size: 14px; font-weight: 700; min-height: 0;
  display: none;
}
.auth-error.show { display: block; }
.auth-hint { color: var(--text-soft); font-size: 14px; font-weight: 700; line-height: 1.5; margin-bottom: 2px; }
.btn-link {
  background: none; border: none; color: var(--blue-shade);
  font-family: var(--font); font-weight: 800; font-size: 14px;
  cursor: pointer; padding: 6px; text-align: center;
}

/* ============ profile screen ============ */
.profile-body {
  flex: 1; overflow-y: auto; padding: 8px 24px 84px;
  display: flex; flex-direction: column; align-items: center; gap: 10px;
}
.profile-name { font-size: 22px; font-weight: 800; margin-top: 4px; }
.premium-badge {
  background: linear-gradient(90deg, var(--navy), var(--navy-shade));
  color: var(--yellow); font-weight: 800; font-size: 13px;
  padding: 6px 16px; border-radius: 20px;
}
.profile-stats {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px;
  width: 100%; margin: 14px 0;
}
.profile-stat-card {
  border: 2px solid var(--gray-border); border-radius: 16px;
  padding: 16px 10px; text-align: center;
}
.profile-stat-value { font-size: 26px; font-weight: 800; color: var(--primary-text); }
.profile-stat-label { font-size: 13px; color: var(--text-soft); font-weight: 700; margin-top: 4px; }

/* ============ paywall screen ============ */
.screen-paywall { background: var(--navy); }
.screen-paywall .topbar .icon-btn { color: #fff; }
.paywall-body {
  flex: 1; overflow-y: auto; padding: 8px 28px 28px;
  display: flex; flex-direction: column; align-items: center; text-align: center;
}
.paywall-title { color: #fff; font-size: 30px; font-weight: 800; margin-top: 6px; }
.paywall-sub { color: #b9c2da; font-size: 16px; margin: 6px 0 22px; }
.perk-list { width: 100%; display: flex; flex-direction: column; gap: 12px; margin-bottom: 26px; }
.perk-row {
  display: flex; align-items: center; gap: 12px;
  background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.12);
  border-radius: 14px; padding: 14px 16px; font-size: 15px;
  color: #fff; font-weight: 700; text-align: start;
}
.btn-premium {
  background: var(--yellow); color: var(--navy-shade);
  box-shadow: 0 4px 0 var(--yellow-shade);
}
.paywall-note { color: #8b93ac; font-size: 12px; margin-top: 12px; }

/* ============ subject selection screen ============ */
.subjects-body { flex: 1; overflow-y: auto; padding: 12px 20px 24px; }
.subjects-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 14px;
}
.subject-card {
  border: 2px solid var(--gray-border); border-radius: 18px;
  background: #fff; box-shadow: 0 4px 0 var(--gray-border);
  padding: 18px 12px; text-align: center; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  transition: transform .05s, box-shadow .05s, border-color .15s;
}
.subject-card:active { transform: translateY(4px); box-shadow: 0 0 0 var(--gray-border); }
.subject-card .subject-icon { font-size: 40px; }
.subject-card .subject-name { font-size: 16px; font-weight: 800; }
.subject-card .subject-level { font-size: 12px; color: var(--text-soft); font-weight: 700; }
.subject-card.math { border-color: var(--primary); }
.subject-card.math:active { box-shadow: 0 0 0 var(--primary-shade); }
.subject-card.english { border-color: var(--blue-border); }
.subject-card.english:active { box-shadow: 0 0 0 var(--blue-shade); }
.subject-card.disabled {
  cursor: default; opacity: .6; filter: grayscale(.5);
  box-shadow: 0 4px 0 var(--gray-border);
}
.subject-card.disabled:active { transform: none; box-shadow: 0 4px 0 var(--gray-border); }
.soon-badge {
  background: var(--gray-border); color: var(--text-soft);
  font-size: 11px; font-weight: 800; padding: 3px 10px; border-radius: 10px;
}

/* ============ profile: per-subject progress ============ */
.subject-progress-list { width: 100%; display: flex; flex-direction: column; gap: 12px; margin: 4px 0 20px; }
.subject-progress-card {
  border: 2px solid var(--gray-border); border-radius: 16px; padding: 14px 16px;
}
.subject-progress-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.subject-progress-name { font-weight: 800; font-size: 15px; }
.level-badge {
  background: var(--primary-light); color: var(--primary-text);
  font-size: 12px; font-weight: 800; padding: 3px 12px; border-radius: 10px;
}
.xp-bar-track { height: 10px; border-radius: 6px; background: var(--gray-border); overflow: hidden; margin-bottom: 8px; }
.xp-bar-fill { height: 100%; background: var(--primary); border-radius: 6px; transition: width .4s; }
.unit-breakdown { display: flex; flex-direction: column; gap: 4px; }
.unit-breakdown-row { display: flex; justify-content: space-between; font-size: 13px; color: var(--text-soft); font-weight: 700; }
.unit-breakdown-row span:last-child { color: var(--text); }

/* ============ settings sections ============ */
.settings-section { margin-top: 18px; padding-top: 14px; border-top: 2px solid #f1f1f1; }
.settings-section:first-of-type { margin-top: 8px; padding-top: 0; border-top: none; }
.settings-section-title { font-size: 15px; font-weight: 800; margin-bottom: 10px; }
.settings-account-row { display: flex; justify-content: space-between; align-items: center; font-weight: 700; }
.settings-advanced {
  margin-top: 18px; padding-top: 14px; border-top: 2px solid #f1f1f1;
}
.settings-advanced summary {
  font-size: 15px; font-weight: 800; cursor: pointer; list-style: none;
}
.settings-advanced summary::-webkit-details-marker { display: none; }
.settings-advanced summary::before { content: '▸ '; }
.settings-advanced[open] summary::before { content: '▾ '; }
.settings-danger { border-top: 2px solid var(--red-light); }

/* ============ dark mode ============ */
:root[data-theme="dark"] {
  --bg: #17181c;
  --text: #eaeaea;
  --text-soft: #a3a3a3;
  --gray-border: #33343a;
  --gray-shade: #45464d;
}
:root[data-theme="dark"] body { background: var(--bg); }
/* every screen gets the dark background — one rule so new screens never get missed
   (screen-paywall keeps its own intentional navy background in both themes) */
:root[data-theme="dark"] .screen:not(.screen-paywall) { background: var(--bg); }
:root[data-theme="dark"] .speech-bubble,
:root[data-theme="dark"] .choice,
:root[data-theme="dark"] .subject-card,
:root[data-theme="dark"] .subject-progress-card,
:root[data-theme="dark"] .profile-stat-card,
:root[data-theme="dark"] .btn-ghost,
:root[data-theme="dark"] .btn-danger-outline,
:root[data-theme="dark"] .field-input,
:root[data-theme="dark"] .kbd-key,
:root[data-theme="dark"] .modal,
:root[data-theme="dark"] .math-keyboard {
  background: #212227; color: var(--text);
}
:root[data-theme="dark"] .notebook-card,
:root[data-theme="dark"] .notebook-input {
  background: repeating-linear-gradient(#212227, #212227 33px, #2a2410 33px, #2a2410 35px);
  color: #eaeaea;
}
:root[data-theme="dark"] .note-step { color: #d8d8d8; }
:root[data-theme="dark"] .choice { color: var(--text); }
:root[data-theme="dark"] .icon-btn { color: #ccc; }
:root[data-theme="dark"] .icon-btn:hover { background: #2a2b31; }
:root[data-theme="dark"] .path-header,
:root[data-theme="dark"] .lesson-footer,
:root[data-theme="dark"] .quiz-footer { border-color: #2a2b31; }

/* ============ responsive: tablet / laptop / big screens ============ */
@media (min-width: 720px) {
  body { background: #f2f2f2; }
  :root[data-theme="dark"] body { background: #0c0c0e; }
  #app {
    max-width: 760px; margin: 16px auto; min-height: calc(100vh - 32px); height: calc(100vh - 32px);
    border-radius: 24px; overflow: hidden; box-shadow: 0 8px 40px rgba(0,0,0,.12);
    border: none;
  }
  .subjects-grid { grid-template-columns: repeat(3, 1fr); }
  .profile-stats { grid-template-columns: repeat(2, 1fr); max-width: 420px; margin-left: auto; margin-right: auto; }
}

/* Desktop / laptop: a persistent sidebar replaces the mobile bottom nav,
   and the app becomes a wide sidebar+content layout instead of a scaled-up phone. */
@media (min-width: 1080px) {
  #app { max-width: 1140px; display: flex; align-items: stretch; }
  .app-sidebar { display: flex; }
  #app-main { flex: 1; min-width: 0; }
  .bottom-nav { display: none !important; }
  .subjects-grid { grid-template-columns: repeat(4, 1fr); }
  .lesson-body, .quiz-body, .auth-body, .profile-body, .paywall-body, .subjects-body { max-width: 640px; margin: 0 auto; width: 100%; }
}

/* ============ library ============ */
.library-body { flex: 1; overflow-y: auto; padding: 12px 20px 84px; }
.library-search-wrap { margin-bottom: 14px; }
.library-search-input {
  width: 100%; padding: 13px 16px; font-family: var(--font); font-weight: 700;
  font-size: 15px; border: 2px solid var(--gray-border); border-radius: 14px;
  outline: none; color: var(--text); background: #f7f7f7;
}
.library-search-input:focus { border-color: var(--blue-border); background: #fff; }
.library-hint { color: var(--text-soft); font-size: 14px; font-weight: 700; margin: 4px 0 16px; line-height: 1.5; }

.library-search-results { display: flex; flex-direction: column; gap: 10px; }
.search-result-row {
  display: flex; align-items: center; gap: 12px;
  border: 2px solid var(--gray-border); border-radius: 14px; padding: 12px 14px;
  cursor: pointer; text-align: start; background: #fff;
  transition: border-color .15s, transform .05s;
}
.search-result-row:active { transform: scale(.99); }
.search-result-row:hover { border-color: var(--blue-border); }
.search-result-icon { font-size: 24px; flex: 0 0 auto; }
.search-result-title { font-weight: 800; font-size: 15px; }
.search-result-meta { font-size: 12px; color: var(--text-soft); font-weight: 700; margin-top: 2px; }
.search-no-results { color: var(--text-soft); font-weight: 700; text-align: center; padding: 30px 10px; }

.library-books { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.book-card {
  border: 2px solid var(--gray-border); border-radius: 20px;
  background: #fff; box-shadow: 0 4px 0 var(--gray-border);
  padding: 14px; text-align: center; cursor: pointer;
  transition: transform .05s, box-shadow .05s;
}
.book-card:active { transform: translateY(4px); box-shadow: 0 0 0 var(--gray-border); }
.book-cover-img { width: 100%; aspect-ratio: 3/4; object-fit: contain; margin-bottom: 8px; }
.book-card-title { font-weight: 800; font-size: 15px; }
.book-card-sub { font-size: 12px; color: var(--text-soft); font-weight: 700; margin-top: 2px; }

/* ============ book table of contents ============ */
.book-body { flex: 1; overflow-y: auto; padding: 12px 20px 84px; }
.book-chapter { margin-bottom: 22px; }
.book-chapter-head {
  display: flex; align-items: center; gap: 10px;
  font-weight: 800; font-size: 16px; margin-bottom: 10px;
  padding-bottom: 8px; border-bottom: 2px solid var(--gray-border);
}
.book-chapter-icon { font-size: 22px; }
.book-lesson-row {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 6px; cursor: pointer; border-radius: 12px;
  transition: background .15s;
}
.book-lesson-row:hover { background: #f7f7f7; }
.book-lesson-row .lesson-icon {
  width: 38px; height: 38px; border-radius: 50%; background: var(--primary-light);
  color: var(--primary-text); display: flex; align-items: center; justify-content: center;
  font-size: 16px; font-weight: 800; flex: 0 0 38px;
}
.book-lesson-row.done .lesson-icon { background: var(--correct-light); color: var(--correct-text); }
.book-lesson-row .lesson-row-title { font-weight: 700; font-size: 15px; flex: 1; }
.book-lesson-row .lesson-row-check { font-size: 15px; }
.book-lesson-row .lesson-row-arrow { color: #c8c8c8; font-size: 14px; }

/* ============ book lesson reading page ============ */
.book-lesson-body { flex: 1; overflow-y: auto; padding: 14px 22px 90px; }
.reading-summary {
  border: 2px solid var(--gray-border); border-radius: 16px;
  padding: 16px 18px; margin-bottom: 18px; font-size: 15.5px; font-weight: 700;
  line-height: 1.6; background: var(--primary-light); color: var(--primary-text);
}
.reading-section-title { font-size: 15px; font-weight: 800; margin: 4px 0 10px; color: var(--text-soft); }
.reading-steps {
  border: 2px solid var(--gray-border); border-radius: 16px;
  background: repeating-linear-gradient(#fff, #fff 33px, #fff3e0 33px, #fff3e0 35px);
  padding: 16px 20px; margin-bottom: 18px;
}
.reading-step {
  font-family: var(--hand); font-size: 20px; line-height: 34px;
  color: #2d3a4a; unicode-bidi: plaintext;
}
.reading-step .hl { color: var(--red-shade); }
.reading-step .hl2 { color: var(--correct-text); }
.reading-cta { margin-top: 6px; }
.variant-details { margin-top: 4px; margin-bottom: 20px; }
.variant-details summary {
  font-weight: 800; font-size: 14.5px; cursor: pointer; color: var(--blue-shade);
  list-style: none; padding: 6px 0;
}
.variant-details summary::-webkit-details-marker { display: none; }
.variant-details summary::before { content: '▸ '; }
.variant-details[open] summary::before { content: '▾ '; }
.variant-block { margin: 14px 0; }
.variant-block-title { font-weight: 800; font-size: 13.5px; color: var(--text-soft); margin-bottom: 6px; }

:root[data-theme="dark"] .reading-steps { background: repeating-linear-gradient(#212227, #212227 33px, #2a2410 33px, #2a2410 35px); }
:root[data-theme="dark"] .reading-step { color: #d8d8d8; }
:root[data-theme="dark"] .book-card, :root[data-theme="dark"] .search-result-row { background: #212227; }
:root[data-theme="dark"] .book-lesson-row:hover { background: #212227; }

@media (min-width: 720px) {
  .library-books { max-width: 500px; margin: 0 auto; }
}
@media (min-width: 1080px) {
  .library-body, .book-body, .book-lesson-body { max-width: 640px; margin: 0 auto; width: 100%; }
  .library-books { grid-template-columns: repeat(2, 1fr); max-width: 460px; }
}

/* ============ home screen: library watermark button ============ */
.library-watermark-btn {
  position: relative; overflow: hidden;
  width: 100%; max-width: 340px;
  display: flex; align-items: center; gap: 14px;
  border: 2px solid var(--navy); border-radius: 16px;
  background: linear-gradient(120deg, var(--navy), var(--navy-shade));
  padding: 14px 18px;
  cursor: pointer; text-align: start;
  box-shadow: 0 4px 0 var(--navy-shade);
  transition: transform .05s, box-shadow .05s, filter .15s;
  font-family: var(--font);
}
.library-watermark-btn:hover { filter: brightness(1.08); }
.library-watermark-btn:active { transform: translateY(4px); box-shadow: 0 0 0 var(--navy-shade); }
.library-watermark-btn::after {
  content: '📚';
  position: absolute; left: -14px; bottom: -22px;
  font-size: 88px; line-height: 1; opacity: .14;
  transform: rotate(-12deg);
  pointer-events: none;
}
.library-watermark-icon {
  font-size: 30px; flex: 0 0 auto; z-index: 1;
  background: rgba(255,255,255,.12); width: 46px; height: 46px;
  border-radius: 12px; display: flex; align-items: center; justify-content: center;
}
.library-watermark-text { flex: 1; z-index: 1; }
.library-watermark-title { color: #fff; font-weight: 800; font-size: 16px; }
.library-watermark-sub { color: var(--yellow); font-weight: 700; font-size: 12.5px; margin-top: 2px; }
.library-watermark-arrow { color: rgba(255,255,255,.5); font-size: 20px; z-index: 1; }

/* ============ onboarding ============ */
.onboarding-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px;
}
.onboarding-dots { display: flex; gap: 7px; }
.onboarding-dot {
  width: 8px; height: 8px; border-radius: 50%; background: var(--gray-border);
  transition: background .2s, transform .2s;
}
.onboarding-dot.done { background: var(--primary-light); }
.onboarding-dot.active { background: var(--primary); transform: scale(1.35); }

.onboarding-body { flex: 1; overflow-y: auto; padding: 6px 24px 24px; display: flex; flex-direction: column; }
.onboarding-question { font-size: 21px; font-weight: 800; text-align: center; line-height: 1.4; margin: 8px 0 4px; }
.onboarding-subtext { text-align: center; color: var(--text-soft); font-size: 14px; font-weight: 700; margin-bottom: 20px; }

.onboarding-options { display: flex; flex-direction: column; gap: 12px; }
.onboarding-options.layout-chips { flex-direction: row; flex-wrap: wrap; justify-content: center; }

.option-card {
  display: flex; align-items: center; gap: 14px;
  border: 2px solid var(--gray-border); border-radius: 16px; padding: 10px 16px;
  cursor: pointer; background: #fff; text-align: start;
  transition: border-color .15s, background .15s, transform .05s;
}
.option-card:active { transform: scale(.99); }
.option-card img { width: 64px; height: 64px; object-fit: contain; flex: 0 0 64px; }
.option-card .option-label { font-weight: 800; font-size: 16px; }
.option-card.selected { border-color: var(--primary); background: var(--primary-light); box-shadow: 0 3px 0 var(--primary); }

.option-chip {
  border: 2px solid var(--gray-border); border-radius: 14px; padding: 14px 20px;
  font-weight: 800; font-size: 15px; cursor: pointer; background: #fff;
  font-family: var(--font); color: var(--text);
  transition: border-color .15s, background .15s, transform .05s;
}
.option-chip:active { transform: scale(.98); }
.option-chip.selected { border-color: var(--primary); background: var(--primary-light); color: var(--primary-text); }

.onboarding-select {
  width: 100%; padding: 14px 16px; font-family: var(--font); font-weight: 700; font-size: 16px;
  border: 2px solid var(--gray-border); border-radius: 14px; background: #f7f7f7; color: var(--text);
  outline: none;
}
.onboarding-select:focus { border-color: var(--blue-border); background: #fff; }

.onboarding-footer { padding: 14px 24px 22px; }

:root[data-theme="dark"] .option-card,
:root[data-theme="dark"] .option-chip { background: #212227; }
:root[data-theme="dark"] .onboarding-select { background: #212227; color: var(--text); }

/* ============ performance report ============ */
.report-body { flex: 1; overflow-y: auto; padding: 12px 18px 90px; }

.report-kpis {
  display: flex; align-items: center; gap: 16px;
  border: 2px solid var(--gray-border); border-radius: 18px;
  padding: 16px; margin-bottom: 14px;
}
.donut-wrap { text-align: center; flex: 0 0 auto; }
.donut { width: 92px; height: 92px; }
.donut-label { font-size: 12px; font-weight: 800; color: var(--text-soft); margin-top: 2px; }
.kpi-stack { flex: 1; display: grid; grid-template-columns: 1fr 1fr; gap: 8px 10px; }
.kpi { display: flex; flex-direction: column; }
.kpi-v { font-size: 19px; font-weight: 800; color: var(--primary-text); line-height: 1.1; }
.kpi-l { font-size: 11px; font-weight: 700; color: var(--text-soft); }

.report-card {
  border: 2px solid var(--gray-border); border-radius: 18px;
  padding: 14px 16px; margin-bottom: 14px;
}
.report-card-title { font-size: 15px; font-weight: 800; margin-bottom: 4px; }
.report-hint { font-size: 12px; color: var(--text-soft); font-weight: 700; margin-bottom: 10px; line-height: 1.5; }
.report-empty { font-size: 13px; color: var(--text-soft); font-weight: 700; padding: 14px 4px; text-align: center; }
.chart-svg { width: 100%; display: block; overflow: visible; }

.hbar-list { display: flex; flex-direction: column; gap: 9px; }
.hbar-row { display: flex; align-items: center; gap: 10px; }
.hbar-label {
  flex: 0 0 40%; font-size: 12.5px; font-weight: 700;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.hbar-track { flex: 1; height: 12px; border-radius: 8px; background: var(--gray-border); overflow: hidden; }
.hbar-fill { height: 100%; border-radius: 8px; transition: width .5s ease; }
.hbar-value { flex: 0 0 38px; text-align: end; font-size: 12px; font-weight: 800; color: var(--text-soft); }

.miss-row {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 10px 0; border-bottom: 1px solid var(--gray-border);
}
.miss-row:last-child { border-bottom: none; }
.miss-count {
  flex: 0 0 auto; background: var(--wrong-light); color: var(--wrong-text);
  font-size: 12px; font-weight: 800; padding: 3px 9px; border-radius: 8px;
}
.miss-q { font-size: 13.5px; font-weight: 700; line-height: 1.45; }
.miss-meta { font-size: 11.5px; color: var(--text-soft); font-weight: 700; margin-top: 3px; }

.report-empty-state { text-align: center; padding: 50px 24px; }
.report-empty-icon { font-size: 54px; margin-bottom: 10px; }
.report-empty-state h3 { font-size: 19px; font-weight: 800; margin-bottom: 8px; }
.report-empty-state p { font-size: 14px; color: var(--text-soft); font-weight: 700; line-height: 1.6; }
.report-privacy { text-align: center; font-size: 11.5px; color: var(--text-soft); font-weight: 700; padding: 4px 0 10px; }

@media (min-width: 1080px) {
  .report-body { max-width: 640px; margin: 0 auto; width: 100%; }
}

/* ============================================================
   Auth gate · level lock · avatars · dictionary · activity chart
   ============================================================ */

/* ---- signed-out chrome ---- */
.app-sidebar.hidden { display: none !important; }

.home-gate-note {
  font-size: 12.5px; font-weight: 700; color: var(--text-soft);
  text-align: center; line-height: 1.6; max-width: 320px; margin: 4px auto 0;
}
.google-note {
  font-size: 12px; font-weight: 700; color: var(--text-soft);
  text-align: center; line-height: 1.55; margin: 2px 0 4px; display: none;
}
.dev-code-note {
  font-size: 13px; font-weight: 800; color: var(--primary-text);
  background: var(--primary-light); border-radius: 12px;
  padding: 10px 12px; margin-bottom: 10px; text-align: center; line-height: 1.5;
}
:root[data-theme="dark"] .dev-code-note { background: #3a2a10; color: #ffbe5c; }

/* ---- transient toast ---- */
.app-toast {
  position: fixed; left: 50%; bottom: 92px; transform: translate(-50%, 20px);
  background: var(--navy); color: #fff; font-family: var(--font);
  font-size: 13.5px; font-weight: 800; line-height: 1.5;
  padding: 12px 18px; border-radius: 14px; max-width: min(440px, 88vw);
  text-align: center; z-index: 400; pointer-events: none;
  opacity: 0; transition: opacity .22s ease, transform .22s ease;
  box-shadow: 0 10px 28px rgba(0,0,0,.24);
}
.app-toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---- locked levels ---- */
.level-chip.locked {
  opacity: .55; border-style: dashed; background: transparent; cursor: not-allowed;
}
.level-chip.locked:hover { opacity: .72; }

.node-unlocked, .node-nextlock {
  font-size: 11.5px; font-weight: 800; line-height: 1.5;
  margin-top: 6px; padding: 5px 10px; border-radius: 10px; max-width: 220px;
}
.node-unlocked { background: var(--correct-light); color: var(--correct-text); }
.node-nextlock { background: var(--gray-border); color: var(--text-soft); }
:root[data-theme="dark"] .node-nextlock { background: #2a2b31; }

/* ---- 7-day activity chart ----
   Flex bars instead of an SVG: the old viewBox with
   preserveAspectRatio="none" scaled x and y by different factors, which
   smeared the day labels sideways across the card. */
.vbar-chart {
  display: flex; align-items: flex-end; gap: 6px;
  height: var(--vbar-h, 130px); padding-top: 4px;
}
.vbar-col {
  flex: 1 1 0; min-width: 0; height: 100%;
  display: flex; flex-direction: column; align-items: center;
}
.vbar-value {
  font-size: 11px; font-weight: 800; color: var(--text-soft);
  height: 15px; line-height: 15px;
}
.vbar-track {
  flex: 1; width: 100%; max-width: 34px;
  display: flex; align-items: flex-end;
  background: var(--gray-border); border-radius: 8px; overflow: hidden;
}
.vbar-fill { width: 100%; border-radius: 8px; transition: height .5s ease; }
.vbar-col.empty .vbar-track { opacity: .5; }
.vbar-label {
  font-size: 10.5px; font-weight: 800; color: var(--text-soft);
  margin-top: 6px; height: 16px; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; max-width: 100%;
}

/* ---- profile avatar + name ---- */
.avatar-slot {
  position: relative; width: 116px; height: 116px; padding: 0;
  border: none; background: none; cursor: pointer; display: block;
  margin: 4px auto 10px;
}
.avatar-slot:active { transform: scale(.96); }
.avatar-art, .avatar-art .avatar-svg { display: block; width: 100%; height: 100%; }
.avatar-edit-badge {
  position: absolute; inset-inline-end: -2px; bottom: 2px;
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--primary); color: #fff; border: 3px solid var(--bg);
  font-size: 15px; font-weight: 800;
  display: flex; align-items: center; justify-content: center;
}
.profile-name-row { display: flex; align-items: center; justify-content: center; gap: 8px; }
.name-edit-btn {
  border: 2px solid var(--gray-border); background: none; color: var(--text-soft);
  width: 30px; height: 30px; border-radius: 50%; cursor: pointer;
  font-size: 14px; font-weight: 800; flex: 0 0 auto;
}
.name-edit-btn:hover { border-color: var(--primary); color: var(--primary); }
.profile-email {
  font-size: 12.5px; font-weight: 700; color: var(--text-soft);
  text-align: center; margin-top: 2px; direction: ltr;
}

.avatar-choices {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(96px, 1fr));
  gap: 10px; margin: 6px 0 4px;
}
.avatar-choice {
  border: 3px solid var(--gray-border); border-radius: 16px; background: none;
  padding: 10px 6px 8px; cursor: pointer; display: flex;
  flex-direction: column; align-items: center; gap: 6px; transition: .15s;
}
.avatar-choice.selected { border-color: var(--primary); background: var(--primary-light); }
:root[data-theme="dark"] .avatar-choice.selected { background: #3a2a10; }
.avatar-choice-art { width: 62px; height: 62px; display: block; }
.avatar-choice-art .avatar-svg { width: 100%; height: 100%; display: block; }
.avatar-choice-name { font-size: 11px; font-weight: 800; text-align: center; line-height: 1.35; }

.field-select {
  width: 100%; border: 2px solid var(--gray-border); border-radius: 14px;
  padding: 12px 14px; font-family: var(--font); font-size: 15px; font-weight: 700;
  color: var(--text); background: var(--bg); cursor: pointer;
}
.field-select:focus { outline: none; border-color: var(--primary); }
:root[data-theme="dark"] .field-select { background: #212227; }

/* ---- dictionary promo card in the library ---- */
.dict-promo {
  width: 100%; margin-top: 16px; border: none; cursor: pointer;
  display: flex; align-items: center; gap: 14px; text-align: start;
  padding: 16px 18px; border-radius: 22px;
  background: linear-gradient(135deg, #5e35b1, #9a4dff);
  color: #fff; box-shadow: 0 6px 0 #43248a; transition: .12s;
}
.dict-promo:active { transform: translateY(3px); box-shadow: 0 3px 0 #43248a; }
.dict-promo-art {
  position: relative; flex: 0 0 auto; width: 58px; height: 58px;
  border-radius: 18px; background: rgba(255,255,255,.18);
  display: flex; align-items: center; justify-content: center;
}
.dict-promo-glyph { font-size: 30px; }
.dict-promo-spark {
  position: absolute; font-size: 12px; font-weight: 900;
  background: #fff; color: #5e35b1; border-radius: 6px; padding: 1px 4px;
}
.dict-promo-spark.s1 { top: -6px; inset-inline-start: -6px; }
.dict-promo-spark.s2 { bottom: -6px; inset-inline-start: -4px; }
.dict-promo-spark.s3 { top: -4px; inset-inline-end: -8px; }
.dict-promo-text { flex: 1; min-width: 0; }
.dict-promo-title { display: block; font-size: 17px; font-weight: 800; }
.dict-promo-sub { display: block; font-size: 12px; font-weight: 700; opacity: .88; margin-top: 3px; line-height: 1.5; }
.dict-promo-arrow { font-size: 26px; font-weight: 800; opacity: .8; }

/* ---- dictionary screen ---- */
.dict-body { flex: 1; overflow-y: auto; padding: 14px 16px 100px; }
.dict-search-wrap { margin-bottom: 12px; }
.dict-cats {
  display: flex; gap: 8px; overflow-x: auto; padding-bottom: 10px;
  scrollbar-width: none; margin-bottom: 4px;
}
.dict-cats::-webkit-scrollbar { display: none; }
.dict-cat {
  flex: 0 0 auto; cursor: pointer; white-space: nowrap;
  border: 2px solid var(--gray-border); background: var(--bg); color: var(--text);
  border-radius: 999px; padding: 8px 13px;
  font-family: var(--font); font-size: 12.5px; font-weight: 800;
}
.dict-cat.active {
  color: #fff; border-color: transparent;
  background: linear-gradient(135deg, var(--cat-c1), var(--cat-c2));
}
.dict-cat-n { opacity: .65; font-size: 11px; }
.dict-count { font-size: 12px; font-weight: 800; color: var(--text-soft); margin: 4px 2px 10px; }

.dict-grid {
  display: grid; gap: 10px;
  grid-template-columns: repeat(auto-fill, minmax(148px, 1fr));
}
.dict-card {
  border: 2px solid var(--gray-border); border-radius: 18px; background: var(--bg);
  cursor: pointer; overflow: hidden; text-align: center;
  display: flex; flex-direction: column; transition: .14s;
}
.dict-card:hover { transform: translateY(-3px); border-color: var(--cat-c1); }
.dict-card-art {
  display: block; padding: 16px 8px;
  background: linear-gradient(135deg, var(--cat-c1), var(--cat-c2));
}
.dict-card-glyph { font-size: 40px; line-height: 1; filter: drop-shadow(0 3px 5px rgba(0,0,0,.22)); }
.dict-card-body { display: block; padding: 9px 8px 11px; }
.dict-card-w { display: block; font-size: 15px; font-weight: 800; }
.dict-card-ar { display: block; font-size: 12.5px; font-weight: 700; color: var(--text-soft); margin-top: 2px; }

/* ---- word detail sheet ---- */
.word-modal { padding: 0 !important; overflow: hidden; max-width: 420px; }
.word-hero {
  position: relative; padding: 30px 16px 26px; text-align: center;
  background: linear-gradient(135deg, var(--cat-c1), var(--cat-c2));
}
.word-hero-glyph { font-size: 78px; line-height: 1; filter: drop-shadow(0 5px 9px rgba(0,0,0,.25)); }
.word-close {
  position: absolute; top: 12px; inset-inline-end: 12px;
  width: 34px; height: 34px; border-radius: 50%; border: none; cursor: pointer;
  background: rgba(255,255,255,.28); color: #fff; font-size: 16px; font-weight: 800;
}
.word-main { padding: 18px 20px 20px; }
.word-en { font-size: 30px; font-weight: 800; text-align: center; line-height: 1.2; }
.word-ipa { font-size: 13.5px; font-weight: 700; color: var(--text-soft); text-align: center; margin-top: 3px; }
.word-pos {
  display: inline-block; margin-inline-start: 6px; padding: 1px 8px;
  border-radius: 8px; background: var(--gray-border); font-size: 11px;
}
.word-ar {
  font-size: 22px; font-weight: 800; text-align: center;
  color: var(--primary-text); margin: 10px 0 14px;
}
.word-listen { margin-bottom: 14px; }
.word-example { border: 2px solid var(--gray-border); border-radius: 16px; padding: 13px 14px; }
.word-example-label { font-size: 11.5px; font-weight: 800; color: var(--text-soft); margin-bottom: 6px; }
.word-example-en { font-size: 15.5px; font-weight: 700; line-height: 1.55; }
.word-example-ar { font-size: 14px; font-weight: 700; color: var(--text-soft); margin-top: 4px; line-height: 1.6; }
.word-example .btn { margin-top: 10px; }
.word-cat-tag { margin-top: 12px; text-align: center; font-size: 12px; font-weight: 800; color: var(--text-soft); }

:root[data-theme="dark"] .dict-cat,
:root[data-theme="dark"] .dict-card { background: #212227; }
:root[data-theme="dark"] .word-pos { background: #33343a; }

@media (min-width: 1080px) {
  .dict-body { max-width: 900px; margin: 0 auto; width: 100%; }
  .dict-grid { grid-template-columns: repeat(auto-fill, minmax(168px, 1fr)); }
}
