:root {
  --bg: #ffffff;
  --ink: #0066ff;   /* כחול בהיר — הצבע הראשי של האתר */
  --muted: #555555;
  --line: #0066ff;
  --soft: #f2f2f2;
  --green: #1f9d3a;
  --pink: #ffc4dd;
  --gray: #dddddd;
  --red: #e02424;
  --navy: #0b2a6b;
  --math: #000000;  /* התרגיל ושורת התשובה בשחור */
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Calibri, Carlito, "Segoe UI", Arial, sans-serif;
}

body { min-height: 100vh; }

[hidden] { display: none !important; }

/* זכויות יוצרים — קבוע בתחתית כל העמודים */
body { padding-bottom: 40px; }
.copyright {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 2;
  padding: 8px 16px;
  text-align: center;
  font-size: .9rem;
  color: var(--muted);
  background: var(--bg);
}

button {
  font: inherit;
  background: var(--ink);
  color: var(--bg);
  border: 2px solid var(--ink);
  border-radius: 10px;
  padding: 12px 22px;
  font-size: 1.15rem;
  cursor: pointer;
  transition: transform .08s ease, opacity .15s ease;
}
button:hover { opacity: .85; }
button:active { transform: scale(.97); }
button:focus-visible, input:focus-visible { outline: 3px solid var(--ink); outline-offset: 3px; }

.ltr { direction: ltr; unicode-bidi: isolate; display: inline-block; }

/* ---------- top bar ---------- */
/* השם מימין, ומיד משמאלו הכפתור "לכל הנושאים" (הציטוט באמצע, מחוץ לזרימה) */
.topbar {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  padding: 14px 20px;
  border-bottom: 2px solid var(--line);
}
.brand {
  background: none;
  color: var(--ink);
  border: none;
  padding: 0;
  font-size: 1.4rem;
  font-weight: 700;
}
.topbar { position: relative; gap: 20px; }
.quote {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  margin: 0;
  font-size: 1.1rem;
  font-style: italic;
  white-space: nowrap;
}
.quote-by { font-style: normal; font-size: .9em; margin-right: 6px; }
.topbar .back { font-size: 1rem; padding: 8px 16px; }
/* "לכל הנושאים" מתחיל בדיוק מעל הקו של עמודת הרמות (רוחב העמודה 210px) + רווח קטן */
#screen-practice .topbar .back { position: absolute; right: calc(210px + 14px); top: 50%; transform: translateY(-50%); }

/* ---------- home ---------- */
.home {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px 16px;
}
/* כל העמודים מעל שכבת הסמלים */
#screen-home, #screen-subjects, #screen-practice { position: relative; z-index: 1; }

/* סמלי מתמטיקה מרחפים ברקע של כל העמודים */
.math-bg { position: fixed; inset: 0; overflow: hidden; z-index: 0; pointer-events: none; user-select: none; }
.math-bg span {
  position: absolute;
  left: var(--x);
  top: var(--y);
  font-size: var(--s);
  font-weight: 700;
  font-style: italic;
  color: var(--ink);
  opacity: .12;
  line-height: 1;
  transform: translate(-50%, -50%) rotate(var(--r));
  animation: float 7s ease-in-out var(--d) infinite;
}
@keyframes float {
  0%, 100% { transform: translate(-50%, -50%) rotate(var(--r)); }
  50%      { transform: translate(-50%, calc(-50% - 14px)) rotate(calc(var(--r) + 6deg)); }
}
/* בעמוד פתרון התרגילים הסמלים לא זזים, כדי לא להפריע לריכוז */
body[data-screen="practice"] .math-bg span { animation: none; }
@media (prefers-reduced-motion: reduce) {
  .math-bg span { animation: none; }
}

/* קו "מחברת" דק מתחת לשם האתר */
.home h1::after {
  content: "";
  display: block;
  width: 60%;
  height: 4px;
  margin: 14px auto 0;
  background: var(--ink);
  border-radius: 2px;
}

.home h1 {
  font-size: clamp(3rem, 11vw, 6.5rem);
  margin: 0 0 12px;
  line-height: 1.05;
  /* עיצוב "בלוני": מילוי לבן עם מסגרת כחולה עבה */
  color: var(--bg);
  -webkit-text-stroke: .1em var(--ink);
  paint-order: stroke fill;
  letter-spacing: .02em;
  text-shadow: 0 .06em 0 rgba(0, 102, 255, .25);
}
.home .tagline {
  font-size: clamp(1.2rem, 4vw, 1.8rem);
  margin: 0 0 48px;
}
.big-btn {
  font-size: clamp(1.4rem, 5vw, 2rem);
  padding: 20px 56px;
  border-radius: 14px;
}

.start-row { display: flex; align-items: center; justify-content: center; gap: 18px; }
.nerd { font-size: clamp(2.6rem, 8vw, 3.6rem); line-height: 1; }

/* קוד כניסה */
.code-form { margin-top: 32px; font-size: 1.2rem; }
.code-form label { display: block; margin-bottom: 10px; }
.code-row { display: flex; gap: 10px; justify-content: center; }
.code-row input {
  font: inherit;
  width: 7em;
  text-align: center;
  letter-spacing: .3em;
  direction: ltr;
  padding: 8px 10px;
  border: 2px solid var(--ink);
  border-radius: 10px;
  background: var(--bg);
  color: var(--math);
}
.code-row button { padding: 8px 22px; }
.code-error { color: var(--red); min-height: 1.4em; margin: 10px 0 0; font-size: 1.05rem; }
.beta-note { color: var(--muted); font-size: .95rem; margin: 6px 0 0; }

/* ---------- subjects ---------- */
.subjects {
  max-width: 820px;
  margin: 0 auto;
  padding: 40px 16px;
}
.subjects h2 { font-size: 2rem; margin: 0 0 24px; }
.subject-list { display: grid; gap: 16px; }
.subject-btn {
  width: 100%;
  text-align: right;
  padding: 22px 26px;
  font-size: 1.35rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}
.subject-btn.soon {
  background: var(--bg);
  color: var(--ink);
  border-style: dashed;
  cursor: default;
}
.subject-btn.soon:hover { opacity: 1; }
.subject-btn small { font-size: .95rem; opacity: .8; white-space: nowrap; }

/* ---------- practice ---------- */
.practice {
  display: flex;
  gap: 0;
  min-height: calc(100vh - 66px);
}
.levels {
  width: 210px;
  flex-shrink: 0;
  border-left: 2px solid var(--line);
  padding: 20px 14px;
}
.levels h3 { margin: 0 0 12px; font-size: 1.15rem; }
.level-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.level-btn {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 9px 14px;
  font-size: 1.05rem;
  border-radius: 8px;
}
.level-btn .meta { font-size: .85rem; opacity: .85; }
/* לשונית ההסבר: נפתחת שמאלה כשמניחים את העכבר על רמה */
.level-list li { position: relative; }
.level-tip {
  position: absolute;
  right: calc(100% + 14px);
  top: 50%;
  transform: translate(8px, -50%);
  background: var(--pink);
  color: var(--math);
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 1rem;
  white-space: nowrap;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .12);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  z-index: 5;
  transition: opacity .15s ease, transform .15s ease, visibility .15s;
}
.level-tip::after {
  content: "";
  position: absolute;
  left: 100%;
  top: 50%;
  transform: translateY(-50%);
  border: 7px solid transparent;
  border-left-color: var(--pink);
}
.level-list li:hover .level-tip,
.level-list li:focus-within .level-tip {
  opacity: 1;
  visibility: visible;
  transform: translate(0, -50%);
}

.level-btn.current { outline: 3px solid var(--ink); outline-offset: 2px; }
.level-btn.locked {
  background: var(--bg);
  color: var(--muted);
  border-color: #bbbbbb;
  cursor: not-allowed;
}
.level-btn.locked:hover { opacity: 1; }

/* דף תרגול מעורב — מתחת לרשימת הרמות */
.mix-box { margin-top: 18px; padding-top: 14px; border-top: 2px solid var(--line); }
.mix-btn { width: 100%; background: var(--navy); border-color: var(--navy); font-size: 1rem; padding: 10px 8px; }
.mix-hint { margin: 6px 0 0; font-size: .85rem; color: var(--muted); }
.mix-last { margin: 6px 0 0; font-size: .85rem; color: var(--math); }
.mix-fields { display: grid; gap: 6px; margin-bottom: 18px; font-size: 1.05rem; color: var(--math); }
.mix-fields input, .mix-fields select {
  font: inherit;
  padding: 8px 10px;
  border: 2px solid var(--ink);
  border-radius: 8px;
  background: var(--bg);
  color: var(--math);
  margin-bottom: 8px;
}

/* סמיילי — המשבצת הראשונה ברשימת התרגילים */
.intro-btn { display: flex; align-items: center; justify-content: center; padding: 4px 0; }
.intro-btn svg { width: 30px; height: 30px; display: block; }

/* צד שמאל: מספרי התרגילים של הרמה */
.questions {
  width: 150px;
  flex-shrink: 0;
  border-right: 2px solid var(--line);
  padding: 20px 14px;
}
.questions h3 { margin: 0 0 12px; font-size: 1.15rem; }

/* i קטנה ליד "תרגילים" — הסבר כשהעכבר עליה */
.info-tip {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.15em;
  height: 1.15em;
  margin-right: 6px;
  border: 1.5px solid currentColor;
  border-radius: 50%;
  font-family: Georgia, "Times New Roman", serif;
  font-style: italic;
  font-size: .8em;
  font-weight: 700;
  line-height: 1;
  vertical-align: middle;
  cursor: help;
}
.info-tip-text {
  position: absolute;
  top: calc(100% + 10px);
  left: -12px;
  width: 240px;
  padding: 10px 14px;
  border-radius: 8px;
  background: var(--pink);
  color: var(--math);
  font-family: Calibri, Carlito, "Segoe UI", Arial, sans-serif;
  font-style: normal;
  font-weight: 400;
  font-size: .95rem;
  line-height: 1.45;
  text-align: right;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .12);
  opacity: 0;
  visibility: hidden;
  z-index: 20;
  transition: opacity .15s ease, visibility .15s;
}
/* בסרגל הרמות (בצד ימין של המסך) — ההסבר נפתח שמאלה */
.info-tip--right .info-tip-text { left: auto; right: -12px; }
/* מופיע רק כשהעכבר על ה-i (לחיצה לא "מקפיאה" אותו). focus-visible = רק לניווט במקלדת (Tab) */
.info-tip:hover .info-tip-text,
.info-tip:focus-visible .info-tip-text { opacity: 1; visibility: visible; }
.question-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}
.question-btn {
  width: 100%;
  padding: 8px 0;
  font-size: 1.1rem;
  border-radius: 8px;
  background: var(--gray);
  border-color: var(--gray);
  color: #444444;
}
.question-btn.solved {
  background: var(--green);
  border-color: var(--green);
  color: #ffffff;
}
.delete-all-btn {
  width: 100%;
  margin-top: 16px;
  padding: 10px 8px;
  font-size: .95rem;
  background: var(--red);
  border-color: var(--red);
}

/* תפריט מקש ימני */
.context-menu {
  position: fixed;
  z-index: 50;
  background: var(--bg);
  border: 2px solid var(--ink);
  border-radius: 10px;
  padding: 6px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .15);
}
.context-menu button {
  display: block;
  width: 100%;
  background: var(--bg);
  border: none;
  color: var(--red);
  font-size: 1rem;
  padding: 8px 16px;
  text-align: right;
  white-space: nowrap;
  border-radius: 6px;
}
.context-menu button:hover { background: #fdecec; opacity: 1; }
/* "צור קובץ word" — ריבוע כחול כהה */
.context-menu .ctx-word {
  background: var(--navy);
  color: #ffffff;
  border-radius: 6px;
  padding: 10px 18px;
}
.context-menu .ctx-word:hover { background: var(--navy); opacity: .88; }
.context-menu .ctx-word:disabled { background: var(--gray); color: var(--muted); opacity: 1; }
.context-menu button:disabled { color: var(--muted); cursor: default; background: var(--bg); }

/* חלון אישור להורדת Word */
.word-dialog {
  border: 2px solid var(--ink);
  border-radius: 14px;
  padding: 24px 26px;
  max-width: min(460px, calc(100vw - 32px));
  color: var(--ink);
  background: var(--bg);
  font-family: inherit;
}
.word-dialog::backdrop { background: rgba(0, 0, 0, .35); }
.word-dialog h3 { margin: 0 0 18px; font-size: 1.3rem; }
.check {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 14px;
  font-size: 1.05rem;
  color: var(--math);
  cursor: pointer;
}
.check input { width: 20px; height: 20px; margin: 2px 0 0; flex-shrink: 0; accent-color: var(--ink); cursor: pointer; }
.dialog-actions { display: flex; gap: 10px; margin-top: 22px; }
.word-dialog .ctx-word { background: var(--navy); border-color: var(--navy); }
.word-dialog button:disabled { opacity: .4; cursor: not-allowed; }
/* "לאפס תשובות - כל הרמות": בפס העליון, מעל עמודת "תרגילים" (רוחבה 150px) */
.reset-btn {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 126px;
  padding: 5px 8px;
  font-size: .9rem;
  line-height: 1.25;
  border-radius: 8px;
  background: var(--red);
  border-color: var(--red);
}
.nowrap { white-space: nowrap; }
.reset-question { margin: 0; font-size: 1.15rem; color: var(--math); line-height: 1.5; }
.word-dialog .danger { background: var(--red); border-color: var(--red); min-width: 80px; }
.word-dialog .secondary { background: var(--bg); color: var(--ink); }

/* התרגיל הנוכחי: מסגרת שחורה */
.question-btn.current,
.question-btn.current:focus-visible,
.question-btn:focus-visible { outline: 3px solid #000000; outline-offset: 2px; }

.workspace {
  flex: 1;
  padding: 40px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}
.instruction {
  margin: 0 0 22px;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--math);
  max-width: 640px;
}
.equation.ratio-question { direction: rtl; font-size: clamp(1.3rem, 3.6vw, 1.9rem); font-weight: 600; line-height: 1.5; max-width: 680px; }
#ratio-row input { width: 3.2em; }
/* תזכורת "היחס אליו הגעתי וצריך לצמצם עוד" — מימין לתיבות, בלי להזיז אותן מהמרכז */
#ratio-row { position: relative; }
.prev-ratio {
  position: absolute;
  left: calc(100% + 18px);
  top: 50%;
  transform: translateY(-50%);
  width: 210px;
  direction: rtl;
  unicode-bidi: plaintext;
  text-align: right;
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.4;
  color: var(--ink);
}
.picture { margin: 0 0 18px; }
.dots-picture { width: min(320px, 80vw); height: auto; border: 2px solid var(--gray); border-radius: 10px; display: block; }

.choice-row { direction: rtl; text-align: right; margin: 0 auto 16px; font-size: 1.2rem; color: var(--math); }
.choice-title { margin: 0 0 10px; font-weight: 700; }
.choice-list { display: grid; gap: 10px; }
.choice {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 1.6rem;
  font-weight: 700;
  cursor: pointer;
}
.choice input { width: 22px; height: 22px; margin: 0; accent-color: var(--ink); cursor: pointer; }

.ratio-hint { margin: 0 0 22px; font-size: .95rem; color: var(--green); }
.subject-title { margin: 0 0 6px; font-size: 1.3rem; }
.progress-label { margin: 0 0 36px; color: var(--muted); font-size: 1.05rem; }

.equation {
  color: var(--math);
  font-size: clamp(2rem, 6vw, 3.4rem);
  font-weight: 700;
  margin: 0 0 36px;
}

/* שורת התרגיל: כפתור "הראה דרך פתרון" מימין לתרגיל, במרחק נוח */
#question-view { width: 100%; display: flex; flex-direction: column; align-items: center; }

/* שלוש עמודות: [כפתור] [התרגיל] [ריק] — כך התרגיל תמיד באמצע בדיוק,
   גם כשיש כפתור "הראה דרך פתרון" מימין לו */
.equation-row {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  column-gap: 24px;
  width: 100%;
  margin: 0 0 36px;
}
.equation-row .equation { margin: 0; grid-column: 2; grid-row: 1; }
.equation-row .steps-btn { grid-column: 1; grid-row: 1; justify-self: center; }
.steps-btn {
  background: var(--pink);
  border-color: var(--pink);
  color: var(--math);
  font-size: 1rem;
  padding: 10px 18px;
}

/* דרך הפתרון */
.steps {
  display: grid;
  justify-items: start;
  gap: 10px;
  width: fit-content;
  margin: -16px auto 32px;
  padding: 16px 24px;
  border-right: 4px solid var(--pink);
  color: var(--math);
  font-size: clamp(1.3rem, 4vw, 1.8rem);
}
/* שורת הסבר בתוך דרך הפתרון — עברית, מימין לשמאל */
.step-text {
  direction: rtl;
  justify-self: stretch;
  text-align: right;
  margin: 0;
  max-width: 620px;
  font-size: .62em;
  line-height: 1.6;
}
.step-text strong { color: var(--ink); }
.steps .underline { color: var(--math); text-decoration: underline; text-underline-offset: 3px; }
/* הנקודתיים שאחרי מילה עם קו תחתון (למשל "זוכרים:") — מודגשות ושחורות, בלי קו */
.steps .underline + strong { color: var(--math); }
/* צבעים בדרך הפתרון: {blue|...} {green|...} {red|...} */
.steps .c-blue { color: var(--ink); }
.steps .c-green { color: var(--green); }
.steps .c-red { color: var(--red); }
.steps .c-black { color: var(--math); }
.step { display: flex; align-items: baseline; gap: .45em; }
.step-op { color: var(--ink); font-weight: 700; font-size: .85em; white-space: nowrap; }
/* שבר בודד בדרך הפתרון: גדול יותר, והפעולה ליד המונה וליד המכנה */
.step-frac { font-size: 1.45em; align-items: center; }
.frac-op .frac { font-size: .94em; margin: 0; }
.steps .frac-op .frac .den { border-top-color: transparent; } /* בלי קו שבר בעמודת הפעולה */
.step-note { direction: rtl; font-weight: 400; font-size: .7em; }

/* שבר אמיתי: מונה מעל הקו, מכנה מתחתיו */
.frac {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  vertical-align: middle;
  font-size: .8em;
  line-height: 1.1;
  margin: 0 .12em;
}
.frac .num { padding: 0 .15em .05em; }
.frac .den {
  padding: .05em .15em 0;
  border-top: .09em solid currentColor;
  align-self: stretch;
  text-align: center;
}

.answer-row {
  color: var(--math);
  font-size: clamp(1.6rem, 5vw, 2.4rem);
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 10px;
  margin-bottom: 14px;
}
.answer-row input {
  font: inherit;
  width: 5.5em;
  border: none;
  border-bottom: 3px solid var(--math);
  background: transparent;
  color: var(--math);
  text-align: center;
  padding: 2px 4px;
  border-radius: 0;
}
.hint { color: var(--muted); font-size: .95rem; margin: 0 0 22px; min-height: 1.2em; }

.result {
  font-size: clamp(1.4rem, 4.5vw, 2rem);
  font-weight: 700;
  min-height: 1.5em;
  margin: 0 0 22px;
  display: flex;
  gap: 18px;
  align-items: baseline;
  justify-content: center;
  flex-wrap: wrap;
}

.reveal-note {
  flex-basis: 100%;
  margin: 6px 0 0;
  font-size: .95rem;
  font-weight: 400;
  color: var(--muted);
}

.actions { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }

#delete-btn {
  background: var(--red);
  border-color: var(--red);
}

#retry-btn {
  background: var(--green);
  border-color: var(--green);
}

#notice-view { display: flex; flex-direction: column; align-items: center; }
.notice-title { margin: 0 0 10px; font-size: 1.3rem; color: var(--ink); }
.notice {
  border: 2px solid var(--ink);
  border-radius: 12px;
  padding: 18px 22px;
  max-width: 520px;
  font-size: 1.15rem;
  margin-bottom: 18px;
}

/* ---------- phones ---------- */
@media (max-width: 720px) {
  /* בטלפון: הכפתור בפס העליון, בתור הרגיל (בלי מיקום קבוע) */
  .reset-btn { position: static; transform: none; width: auto; }
  /* בטלפון אין מקום מימין — התזכורת מתחת לתיבות */
  #ratio-row { flex-wrap: wrap; }
  .prev-ratio { position: static; transform: none; width: 100%; text-align: center; }
  /* בטלפון עמודת הרמות למעלה ברוחב מלא — הכפתור חוזר להיות ליד השם */
  #screen-practice .topbar .back { position: static; transform: none; }
  /* בטלפון: הכפתור מעל התרגיל */
  .equation-row { grid-template-columns: 1fr; row-gap: 16px; }
  .equation-row .equation { grid-column: 1; grid-row: 2; }
  .equation-row .steps-btn { grid-column: 1; grid-row: 1; }
  .topbar { flex-wrap: wrap; }
  .quote {
    position: static;
    transform: none;
    order: 3;
    width: 100%;
    text-align: center;
    white-space: normal;
    font-size: 1rem;
  }
  .practice { flex-direction: column; }
  .levels {
    width: 100%;
    border-left: none;
    border-bottom: 2px solid var(--line);
    padding: 12px 16px;
  }
  .level-list {
    display: flex;
    overflow-x: auto;
    padding: 4px 2px 8px;
  }
  .level-list li { flex-shrink: 0; }
  .level-btn { white-space: nowrap; gap: 8px; }
  .level-tip { display: none; }
  .workspace { padding: 28px 16px; order: 2; }
  .questions {
    order: 1;
    width: 100%;
    border-right: none;
    border-bottom: 2px solid var(--line);
    padding: 12px 16px;
  }
  .question-list { grid-template-columns: repeat(10, minmax(32px, 1fr)); gap: 6px; }
  .question-btn { padding: 6px 0; font-size: 1rem; }
}
