/* כל הזכויות שמורות לאושרת רון – הקשר המונטסורי
   מעבדת האלגברה – עיצוב משותף ללוח, למקלדת ולשלושת השלבים.
   זהה ל־tools/algebra-lab-ui.css באתר הלמידה של ים. כל עמוד מגדיר את משתני הצבע:
   --acc --card --card2 --line --ink --soft --gold --ok --okbg --bad --badbg --note */

/* ---- כתיבה מתמטית (תמיד משמאל לימין) ---- */
.ax { direction: ltr; unicode-bidi: isolate; font-weight: 700; white-space: nowrap; }
bdi.ax { display: inline-block; vertical-align: middle; }
.ax .ax-t { font-weight: 700; display: inline-block; font-style: normal; }
.ax sup { font-size: .58em; line-height: 0; vertical-align: .72em; font-weight: 800; margin-inline-start: .04em; }
.ax .ax-op, .ax .ax-par, .ax .ax-pp, .ax .ax-rel { font-style: normal; display: inline-block; }
.ax .ax-pm { margin: 0 .2em; }
.ax .ax-dot { margin: 0 .1em; }
.ax .ax-par, .ax .ax-pp { font-weight: 500; }
.ax .ax-rel { margin: 0 .32em; }
.ax .ax-g { display: inline-block; white-space: nowrap; }
.ax .ax-side { display: inline-block; }
.ax .ax-f { display: inline-flex; flex-direction: column; align-items: center; vertical-align: middle; margin: 0 .12em; }
.ax .ax-fn, .ax .ax-fd { display: block; padding: 0 .14em; line-height: 1.15; white-space: nowrap; }
.ax .ax-bar { display: block; align-self: stretch; height: .07em; min-height: 2px; background: currentColor; border-radius: 1em; margin: .05em 0; }

/* ---- לוח התרגיל ---- */
.ab { --h: 215; display: grid; gap: 12px; grid-template-columns: minmax(300px, 390px) minmax(0, 1fr); grid-template-areas: "panel stage"; height: var(--abh, 560px); min-height: 330px; }
.ab-stage { grid-area: stage; position: relative; border-radius: 24px; background: linear-gradient(160deg, hsl(var(--h) 58% 46%), hsl(var(--h) 64% 34%)); color: #fff; display: flex; flex-direction: column; overflow: hidden; min-height: 0; }
.ab.done .ab-stage { box-shadow: 0 0 0 4px #ffd95a inset; }
.ab-goal { font-size: 15px; opacity: .92; padding: 8px 14px 0; text-align: center; }
.ab-wrap { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; padding: 4px 6px 10px; }
.ab-expr { display: inline-block; text-align: center; touch-action: none; user-select: none; -webkit-user-select: none; line-height: 1.3; text-shadow: 0 .03em 0 rgba(0, 0, 0, .2); }
.ab-expr .ax-t, .ab-expr .ax-op, .ab-expr .ax-par, .ab-expr .ax-rel { cursor: pointer; border-radius: .16em; padding: 0 .06em; transition: background .15s, transform .15s; }
.ab-expr .ax-t:hover, .ab-expr .ax-op:hover, .ab-expr .ax-par:hover, .ab-expr .ax-rel:hover { background: rgba(255, 255, 255, .16); }
.ab-expr [role=button]:focus-visible { outline: .05em solid #fff; outline-offset: .04em; }
.ab-expr .sel { background: rgba(255, 255, 255, .3); box-shadow: 0 0 0 .04em #fff; }
.ab-expr .hi { background: rgba(255, 217, 90, .38); box-shadow: 0 0 0 .05em #ffd95a; animation: axhi 1s ease-in-out infinite; }
.ab-expr .over { background: rgba(255, 255, 255, .42); transform: scale(1.1); }
.ab-expr .dragging { opacity: .3; }
.ab-expr .ax-bar { cursor: pointer; position: relative; }
.ab-expr .ax-bar::before { content: ""; position: absolute; inset: -.2em 0; }
.ab-expr .ax-bar.hi { background: #ffd95a; }
.ab-expr.pop { animation: axpop .45s ease-out; }
.ab-stage.shake { animation: axshake .35s; }
.ab-ghost { position: fixed; z-index: 60; pointer-events: none; transform: translate(-50%, -120%); color: #fff; background: rgba(20, 30, 60, .88); border-radius: .22em; padding: .02em .2em; box-shadow: 0 8px 22px rgba(0, 0, 0, .35); }
.ab-burst { position: absolute; inset: 0; pointer-events: none; }
.ab-burst i { position: absolute; left: 50%; top: 50%; width: 11px; height: 11px; border-radius: 50%; background: #ffe27a; opacity: 0; }
.ab-burst.go i { animation: axburst .95s ease-out forwards; }
@keyframes axburst { 0% { opacity: 1; transform: rotate(var(--a)) translateX(0) scale(1); } 100% { opacity: 0; transform: rotate(var(--a)) translateX(calc(var(--d) * 2.6)) scale(.3); } }
@keyframes axhi { 50% { box-shadow: 0 0 0 .12em rgba(255, 217, 90, .55); } }
@keyframes axpop { 0% { transform: scale(.93); opacity: .55; } 60% { transform: scale(1.04); } 100% { transform: none; opacity: 1; } }
@keyframes axshake { 25% { transform: translateX(-7px); } 50% { transform: translateX(7px); } 75% { transform: translateX(-4px); } }

.ab-panel { grid-area: panel; display: flex; flex-direction: column; gap: 10px; min-height: 0; overflow: auto; padding: 1px; }
.ab-tip { background: var(--card, #fff); border: 2px solid var(--line, #ddd); border-radius: 16px; padding: 10px 12px; font-size: 17px; min-height: 60px; line-height: 1.45; }
.ab-tip.ok { background: var(--okbg, #e8f5ec); border-color: var(--ok, #15803d); }
.ab-tip.no { background: var(--badbg, #fdecea); border-color: var(--bad, #be123c); }
.ab-tip.hint { background: var(--note, #fff4d6); border-color: var(--gold, #d99a00); }
.ab-act { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; gap: 8px; }
.ab-bar { display: flex; gap: 6px; flex-wrap: wrap; }
.abtn { border: 2px solid var(--line, #ddd); background: var(--card, #fff); color: var(--ink, #222); border-radius: 12px; padding: 7px 12px; font-weight: 700; min-height: 44px; cursor: pointer; font-size: 16px; font-family: inherit; line-height: 1.3; }
.abtn:hover { border-color: var(--acc, #555); }
.abtn.go { background: var(--acc, #2e6b45); border-color: var(--acc, #2e6b45); color: var(--onacc, #fff); }
.abtn.big { font-size: 19px; padding: 9px 16px; min-height: 52px; }
.abtn:disabled { opacity: .55; cursor: default; }
.abtn.ok { background: var(--okbg, #e8f5ec); border-color: var(--ok, #15803d); opacity: 1; }
.abtn.no { background: var(--badbg, #fdecea); border-color: var(--bad, #be123c); }
.ab-q { font-weight: 700; font-size: 18px; line-height: 1.4; }
.ab-pick { background: var(--card, #fff); border: 2px solid var(--line, #ddd); border-radius: 16px; padding: 10px 12px; }
.ab-moves { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.ab-note { background: var(--note, #fff4d6); border-radius: 12px; padding: 8px 10px; margin-top: 6px; font-size: 16px; }
.ab-small { font-size: 14.5px; color: var(--soft, #666); margin-top: 6px; }
.ab-pad, .ao { background: var(--card, #fff); border: 2px solid var(--line, #ddd); border-radius: 16px; padding: 10px 12px; display: grid; gap: 8px; }
.ab-typed { display: flex; align-items: center; gap: 8px; direction: ltr; justify-content: center; background: var(--card2, #f3f3f3); border-radius: 12px; min-height: 64px; padding: 6px 10px; font-size: 27px; flex-wrap: wrap; }
.ab-old { opacity: .8; }
.ab-prev { min-width: 64px; text-align: center; border-bottom: 3px dashed var(--acc, #555); padding: 0 6px; min-height: 1.3em; }
.ab-ph { color: var(--soft, #777); font-weight: 400; }
.ab-raw { font-weight: 500; }
.ab-keys { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 5px; }
.k { border: 2px solid var(--line, #ddd); background: var(--card, #fff); border-radius: 10px; min-height: 44px; font-size: 20px; font-weight: 700; cursor: pointer; color: var(--ink, #222); padding: 0; font-family: inherit; }
.k:active { transform: scale(.95); }
.k-v { color: var(--acc, #2e6b45); font-style: italic; }
.k-o, .k-r, .k-b { background: var(--card2, #f3f3f3); }
.ab-padbtn { display: flex; gap: 6px; flex-wrap: wrap; }
.ab-padmsg { min-height: 1.5em; font-size: 16px; line-height: 1.4; }
.ab-padmsg.no { color: var(--bad, #be123c); font-weight: 600; }
.ab-padmsg.hint { color: var(--ink, #222); }
.ab-done { font-size: 22px; text-align: center; background: var(--okbg, #e8f5ec); border: 2px solid var(--ok, #15803d); border-radius: 16px; padding: 10px; }

/* ---- מעטפת היישומון ---- */
.al-lead { margin: 0 0 10px; max-width: 75ch; }
.al-grid { display: grid; gap: 12px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.al-ch { --h: 215; border: none; border-radius: 22px; padding: 16px 14px; min-height: 148px; color: #fff; background: linear-gradient(160deg, hsl(var(--h) 58% 46%), hsl(var(--h) 64% 34%)); display: grid; gap: 6px; justify-items: start; align-content: space-between; text-align: start; cursor: pointer; font-size: inherit; font-family: inherit; }
.al-ch:hover, .al-ch:focus-visible { outline: 4px solid hsl(var(--h) 70% 70%); outline-offset: 2px; }
.al-ch b { font-size: clamp(19px, 2vw, 25px); line-height: 1.2; }
.al-e { font-size: 42px; line-height: 1; }
.al-prog { display: flex; gap: 5px; flex-wrap: wrap; font-size: 14px; }
.al-prog span { background: rgba(255, 255, 255, .22); border-radius: 999px; padding: 2px 9px; white-space: nowrap; }
.al-head { display: flex; align-items: center; gap: 8px 12px; flex-wrap: wrap; margin-bottom: 8px; }
.al-head h2 { margin: 0; font-size: clamp(20px, 2.4vw, 28px); color: hsl(var(--h) 62% 36%); }
.al-back { border: 2px solid var(--line, #ddd); background: var(--card, #fff); color: var(--ink, #222); border-radius: 999px; padding: 5px 14px; min-height: 40px; cursor: pointer; font-size: 15px; font-family: inherit; }
.al-tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-inline-start: auto; }
.al-tab { border: 2px solid var(--line, #ddd); background: var(--card, #fff); color: var(--ink, #222); border-radius: 999px; padding: 6px 14px; font-weight: 700; min-height: 44px; cursor: pointer; font-size: 16px; font-family: inherit; }
.al-tab[aria-selected=true] { background: hsl(var(--h) 62% 36%); border-color: hsl(var(--h) 62% 36%); color: #fff; }
.al-light { display: inline-flex; align-items: center; gap: 4px; background: #2a2d33; border-radius: 999px; padding: 4px 6px 4px 12px; color: #fff; font-size: 14px; font-weight: 700; direction: ltr; }
.al-light span { direction: rtl; margin-inline-start: 4px; }
.lamp { width: 14px; height: 14px; border-radius: 50%; background: #5b5f66; display: inline-block; }
.lamp.l1.on { background: #ef4444; box-shadow: 0 0 6px #ef4444; }
.lamp.l2.on { background: #facc15; box-shadow: 0 0 6px #facc15; }
.lamp.l3.on { background: #22c55e; box-shadow: 0 0 6px #22c55e; }
.al-chips, .al-kinds { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; align-items: center; }
.al-chap .chip { border: 2px solid var(--line, #ddd); background: var(--card, #fff); color: var(--ink, #222); border-radius: 999px; padding: 5px 13px; font-weight: 700; min-height: 40px; cursor: pointer; font-size: 15.5px; font-family: inherit; }
.al-chap .chip.on { background: hsl(var(--h) 62% 36%); border-color: hsl(var(--h) 62% 36%); color: #fff; }
.al-chap .chip.done:not(.on) { border-color: var(--ok, #15803d); background: var(--okbg, #e8f5ec); }
.al-chap .chip.k { border-radius: 12px; }
.al-chap .seg { display: inline-flex; border: 2px solid var(--line, #ddd); border-radius: 999px; overflow: hidden; margin-inline-start: auto; }
.al-chap .seg button { border: none; background: var(--card, #fff); color: var(--ink, #222); padding: 5px 13px; font-weight: 700; min-height: 40px; cursor: pointer; font-size: 15.5px; font-family: inherit; }
.al-chap .seg button.on { background: var(--acc, #2e6b45); color: var(--onacc, #fff); }
.al-run { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 6px; min-height: 38px; }
.al-chips .al-run { margin: 0; margin-inline-start: auto; }
.al-runtxt { font-size: 15px; color: var(--soft, #666); }
.lanterns { display: inline-flex; gap: 2px; direction: ltr; align-items: center; flex-wrap: wrap; }
.lanterns .al-runtxt { direction: rtl; margin-inline-start: 8px; }
.lantern { width: 26px; height: 34px; }
.lantern .glass { fill: #e9e2d6; transition: fill .4s; }
.lantern.lit .glass { fill: #e9b44c; }
.lantern .glow { opacity: 0; transition: opacity .4s; }
.lantern.lit .glow { opacity: 1; }
.lantern.cur .glass { stroke: var(--acc, #2e6b45); stroke-width: 1.5; stroke-dasharray: 2 2; }
.stars { display: inline-flex; gap: 5px; direction: ltr; flex-wrap: wrap; }
.star { width: 32px; height: 32px; border-radius: 50%; border: 3px solid var(--line, #ddd); display: grid; place-items: center; font-size: 15px; background: var(--card2, #f3f3f3); font-weight: 700; }
.star.y { background: #fff1cf; border-color: #e9b44c; }
.star.cur { border-color: var(--acc, #2e6b45); border-style: dashed; }
.ts-label { display: inline-block; font-size: 13px; font-weight: 700; background: var(--card2, #f3f3f3); border-radius: 999px; padding: 2px 10px; color: var(--soft, #666); justify-self: start; }
.al-lesson h3 { margin: 2px 0; font-size: 22px; }
.al-intro { margin: 0 0 8px; max-width: 80ch; }
.al-teach { margin: 0 0 8px; background: var(--note, #fff4d6); border-radius: 12px; padding: 6px 10px; font-size: 15.5px; }
.al-rule { background: var(--note, #fff4d6); border-inline-start: 5px solid var(--gold, #d99a00); border-radius: 12px; padding: 8px 10px; font-size: 17px; line-height: 1.6; }
.al-ident { background: var(--card, #fff); border: 2px solid var(--line, #ddd); border-radius: 16px; padding: 10px; display: grid; gap: 8px; }
.al-two { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.al-fb { border-radius: 12px; padding: 8px 10px; display: none; line-height: 1.45; }
.al-fb.ok { display: block; background: var(--okbg, #e8f5ec); }
.al-fb.no { display: block; background: var(--badbg, #fdecea); }
.al-after, .al-row { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.al-sl { display: grid; gap: .12em; justify-items: center; font-size: clamp(44px, 7.5vw, 104px); color: #fff; line-height: 1.2; }
.al-arc { width: 62%; height: .32em; border: .045em solid rgba(255, 255, 255, .75); border-bottom: none; border-radius: 999px 999px 0 0; }
.al-slx { font-size: .62em; white-space: normal; text-align: center; }
.al-range { display: grid; gap: 6px; font-weight: 700; background: var(--card, #fff); border: 2px solid var(--line, #ddd); border-radius: 16px; padding: 10px 12px; }
.al-range input { width: 100%; accent-color: var(--acc, #2e6b45); height: 36px; direction: ltr; }
.as { max-width: 1250px; margin: 0 auto; display: grid; gap: 10px; text-align: center; grid-template-columns: minmax(0, 1fr); justify-items: center; }
.as > * { width: 100%; max-width: 760px; }
.as > .ts-label { width: auto; justify-self: center; }
.as-count { color: var(--soft, #666); font-size: 15px; }
.as-card { --h: 215; border-radius: 22px; color: #fff; background: linear-gradient(160deg, hsl(var(--h) 58% 46%), hsl(var(--h) 64% 34%)); padding: 20px 12px; display: grid; gap: 4px; justify-items: center; font-size: clamp(28px, 5vw, 56px); }
.as-line { white-space: normal; }
.as-arrow { font-size: .55em; opacity: .9; }
.as-bins { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.abtn.yes { border-color: var(--ok, #15803d); }
.abtn.trap { border-color: var(--gold, #d99a00); }
.as-medal, .al-medal { font-size: 62px; line-height: 1.1; }
.as-end { justify-items: center; }
.ao { max-width: 820px; margin: 0 auto; }
.ao-ex { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; font-size: 15px; color: var(--soft, #666); }
.al-gold { display: grid; place-items: center; padding: 6px 0; }
.al-gcard { max-width: 660px; background: var(--card, #fff); border: 2px solid #e3b341; border-radius: 22px; padding: 18px; text-align: center; display: grid; gap: 8px; justify-items: center; }
.al-gcard h3 { margin: 0; font-size: 24px; }
.al-gcard p { margin: 0; }
.al-best { color: var(--gold, #b07a12); font-weight: 700; }
.al-adult { font-size: 15px; color: var(--soft, #666); }
.al-adult[open] { flex-basis: 100%; }
.al-adult summary { cursor: pointer; display: inline-block; border: 1px solid var(--line, #ddd); border-radius: 999px; padding: 3px 12px; }
.al-adult p { margin: 6px 0 0; max-width: 80ch; }

/* ---- מחשב רחב: יותר בשורה ---- */
@media (min-width: 768px) { .al-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (min-width: 1100px) {
  .al-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
  .al-ch { min-height: var(--chh, 190px); padding: 22px 20px; }
  .al-e { font-size: 58px; }
  .al-ch b { font-size: 28px; }
  .al-prog { font-size: 16px; }
  .as { grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr); grid-template-areas: "lab lab" "card count" "card q" "card bins" "card fb" "card next"; align-items: center; column-gap: 20px; }
  .as > * { max-width: none; }
  .as > .ts-label { grid-area: lab; } .as-count { grid-area: count; } .as-card { grid-area: card; min-height: 320px; align-content: center; } .as > .ab-q { grid-area: q; } .as-bins { grid-area: bins; } .as > .al-fb { grid-area: fb; } .as-next { grid-area: next; }
  .as.as-end { grid-template-columns: minmax(0, 1fr); grid-template-areas: none; }
  .as.as-end > * { grid-area: auto; max-width: 760px; }
}
/* ---- אייפד לאורך: הלוח למעלה, ומתחתיו שתי עמודות ---- */
@media (min-width: 768px) and (max-width: 1099px) {
  .ab { grid-template-columns: minmax(0, 1fr); grid-template-areas: "stage" "panel"; height: auto; min-height: 0; }
  .ab-stage { height: var(--sth, clamp(280px, 40vh, 520px)); }
  .al-ch { min-height: var(--chh, 170px); }
  .ab-panel { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr); grid-template-areas: "tip act" "bar act"; align-items: start; overflow: visible; grid-template-rows: auto 1fr; }
  .ab-tip { grid-area: tip; } .ab-act { grid-area: act; } .ab-bar { grid-area: bar; }
}
/* ---- טלפון: עמודה אחת ---- */
@media (max-width: 767px) {
  .ab { grid-template-columns: minmax(0, 1fr); grid-template-areas: "stage" "panel"; height: auto; min-height: 0; gap: 8px; }
  .ab-stage { height: clamp(190px, 32vh, 290px); border-radius: 18px; }
  .ab-panel { overflow: visible; gap: 8px; }
  .ab-tip { font-size: 16px; min-height: 52px; padding: 8px 10px; }
  .abtn { font-size: 15px; padding: 6px 10px; }
  .ab-typed { font-size: 23px; min-height: 54px; }
  .al-ch { min-height: 132px; padding: 12px 10px; border-radius: 18px; }
  .al-e { font-size: 34px; }
  .al-tabs { width: 100%; margin-inline-start: 0; order: 5; }
  .al-head { gap: 5px 8px; margin-bottom: 6px; }
  .al-head h2 { font-size: 19px; }
  .al-back { padding: 3px 10px; min-height: 36px; font-size: 14px; }
  .al-chap .lg { display: none; }
  .al-chips, .al-kinds { gap: 4px; margin-bottom: 6px; }
  .al-chap .seg button { padding: 4px 9px; font-size: 14px; min-height: 36px; }
  .al-chap .chip { min-height: 36px; }
  .al-intro { font-size: 15.5px; }
  .al-lesson h3 { font-size: 19px; }
  .al-tab { flex: 1 1 auto; padding: 4px 8px; font-size: 14px; }
  .al-head h2 { flex: 1 1 auto; }
  .al-chap .seg { margin-inline-start: 0; }
  .al-chap .chip { font-size: 14.5px; padding: 4px 10px; }
  .lantern { width: 22px; height: 29px; }
}
@media (prefers-reduced-motion: reduce) { .ab-expr .hi, .ab-expr.pop, .ab-stage.shake, .ab-burst.go i { animation: none !important; } }
@media print { .ab-bar, .al-adult { display: none; } }
