/* The lesson viewer. Class prefix ls-. Uses only variables from tokens.css. */

.ls-root, .ls-root * { box-sizing: border-box; }
.ls-root [hidden] { display: none !important; }

.ls-root {
  position: absolute; inset: 0; z-index: 50;
  display: grid; place-items: center;
  padding: clamp(8px, 2vh, 26px) clamp(10px, 2.4vw, 36px);
  overflow: hidden;
  font-family: var(--font-ui, "IBM Plex Sans Arabic", system-ui, sans-serif); font-size: var(--size-body); color: var(--ink);
  direction: rtl; text-align: right;
  touch-action: manipulation;
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent;
}
.ls-backdrop {
  position: absolute; inset: 0;
  background: rgba(42, 27, 94, 0.45);
  background: color-mix(in srgb, var(--night) 45%, transparent);
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
  animation: ls-fade 0.3s ease-out both;
}
.ls-card {
  position: relative; width: min(1180px, 100%); height: min(100%, 800px);
  display: flex; flex-direction: column; gap: clamp(8px, 1.4vh, 16px);
  padding: clamp(10px, 1.8vh, 22px) clamp(14px, 2vw, 30px);
  background: var(--cream); border: var(--outline); border-radius: var(--radius-l);
  box-shadow: var(--shadow-sticker), var(--shadow-soft);
  animation: ls-rise 0.5s var(--pop) both;
  overflow: hidden;
}

/* header: leave room for the shell's pause button, as the puzzle does */
.ls-head { flex: 0 0 auto; display: flex; align-items: center; gap: 14px; padding-left: 56px; min-height: 48px; }
.ls-badge {
  flex: 0 0 auto; display: inline-flex; align-items: center; gap: 8px;
  min-height: 44px; padding: 4px 10px 4px 18px;
  background: var(--turquoise); border: 3px solid var(--ink); border-radius: 999px;
  font-weight: 800; font-size: var(--size-body); line-height: 1.2;
}
.ls-badge-icon { font-size: 26px; line-height: 1; }
.ls-title {
  margin: 0; min-width: 0; font-weight: 900; line-height: 1.15;
  font-size: clamp(24px, 3.6vh, 34px); overflow-wrap: anywhere;
}

/* the card itself */
.ls-body {
  flex: 1 1 auto; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
  display: flex; flex-direction: column; outline: none;
  padding: clamp(10px, 2vh, 22px) clamp(12px, 2vw, 28px);
  background: var(--paper); border: 3px solid var(--lilac); border-radius: var(--radius-m);
}
.ls-page { margin: auto 0; display: flex; flex-direction: column; align-items: center; gap: clamp(10px, 2vh, 20px); text-align: center; }
.ls-card-title { margin: 0; font-weight: 900; font-size: clamp(30px, 5vh, 46px); line-height: 1.15; color: var(--orchid-deep); }
.ls-text { margin: 0; max-width: 34em; font-weight: 700; font-size: clamp(22px, 3.3vh, 30px); line-height: 1.4; }
.ls-html {
  width: 100%; max-width: 100%; overflow-x: auto; display: flex; flex-direction: column; align-items: center;
  font-size: clamp(26px, 4.2vh, 40px); line-height: 1.35;
}
.ls-html > * { max-width: 100%; }
.ls-in-next { animation: ls-pop-next 0.4s var(--pop) both; }
.ls-in-back { animation: ls-pop-back 0.4s var(--pop) both; }

/* footer */
.ls-foot { flex: 0 0 auto; display: grid; grid-template-columns: minmax(150px, 1fr) auto minmax(150px, 1fr); align-items: center; gap: 14px; }
.ls-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: clamp(64px, 9.5vh, 84px); padding: 8px 26px;
  background: var(--paper); color: var(--ink); border: var(--outline); border-radius: var(--radius-m);
  box-shadow: var(--shadow-sticker);
  font: inherit; font-weight: 900; font-size: clamp(24px, 3.6vh, 32px); line-height: 1.1; cursor: pointer;
  touch-action: manipulation; -webkit-user-select: none; user-select: none;
  transition: transform 0.12s var(--pop), box-shadow 0.12s;
}
.ls-btn:active:not(:disabled) { transform: translateY(5px); box-shadow: 0 1px 0 var(--ink); }
.ls-btn:focus-visible { outline: 4px solid var(--turquoise); outline-offset: 2px; }
.ls-btn:disabled { opacity: 0.55; cursor: default; }
.ls-btn-back { background: var(--lilac); justify-self: start; min-width: 150px; }
.ls-btn-next { background: var(--turquoise); justify-self: end; min-width: 170px; }
.ls-btn-go { background: var(--gold); font-size: clamp(28px, 4.4vh, 38px); min-width: 240px; animation: ls-pulse 1.4s ease-in-out infinite; }

.ls-dots { display: flex; gap: 10px; align-items: center; justify-content: center; flex-wrap: wrap; }
.ls-dot { width: 16px; height: 16px; border-radius: 50%; background: var(--lilac); border: 3px solid var(--ink); transition: transform 0.2s var(--pop), background 0.2s; }
.ls-dot-done { background: var(--orchid); }
.ls-dot-on { background: var(--gold); transform: scale(1.5); }

@keyframes ls-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes ls-rise { from { opacity: 0; transform: translateY(26px) scale(0.93); } to { opacity: 1; transform: none; } }
@keyframes ls-pop-next { 0% { opacity: 0; transform: translateX(-28px) scale(0.96); } 100% { opacity: 1; transform: none; } }
@keyframes ls-pop-back { 0% { opacity: 0; transform: translateX(28px) scale(0.96); } 100% { opacity: 1; transform: none; } }
@keyframes ls-pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.05); } }

@media (prefers-reduced-motion: reduce) {
  .ls-root *, .ls-root *::before, .ls-root *::after {
    animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important;
  }
  .ls-btn-go { animation: none; outline: 4px solid var(--gold-deep); }
}

@media (max-height: 640px) {
  .ls-badge { min-height: 38px; font-size: 18px; }
  .ls-foot { grid-template-columns: auto 1fr auto; }
}

.ls-body { touch-action: pan-y; }   /* vertical scroll stays, horizontal swipes reach our handler */

/* lead: room for the shell's Done / pause button at the top left */
.ls-head { padding-left: 64px; }

/* ---- Ahmed the tutor: the hello before a new lesson ---- */
.ls-card[hidden] { display: none; }
.ls-tutor {
  position: absolute; inset: 0; z-index: 2;
  display: flex; align-items: flex-end; justify-content: center; gap: clamp(8px, 2vw, 28px);
  padding: 0 clamp(12px, 4vw, 60px) clamp(10px, 4vh, 40px);
  cursor: pointer; transition: opacity 0.3s ease-out;
}
.ls-tutor-out { opacity: 0; pointer-events: none; }
.ls-tutor-img {
  height: min(72vh, 520px); width: auto; flex: 0 0 auto;
  filter: drop-shadow(0 8px 0 rgba(59, 30, 84, 0.25));
  animation: ls-tutor-in 0.5s var(--pop) both;
}
.ls-tutor-say {
  align-self: center; max-width: min(26rem, 46vw);
  display: flex; flex-direction: column; gap: 6px;
  padding: 16px 22px; position: relative;
  background: var(--paper); border: var(--outline); border-radius: var(--radius-l);
  box-shadow: var(--shadow-sticker);
  font-weight: 800; font-size: clamp(20px, 3.4vh, 28px); line-height: 1.3;
  opacity: 0; transform: scale(0.6); transform-origin: right bottom;
  transition: opacity 0.25s ease-out, transform 0.35s var(--pop);
}
.ls-tutor-say b { font-size: 1.3em; color: var(--orchid-deep); }
.ls-tutor-say::before {
  content: ''; position: absolute; right: -16px; bottom: 26px; width: 24px; height: 24px;
  background: var(--paper); border-right: var(--outline); border-top: var(--outline); transform: rotate(45deg);
}
.ls-tutor-say-on { opacity: 1; transform: none; }
.ls-tutor-skip {
  position: absolute; left: clamp(12px, 3vw, 30px); bottom: clamp(10px, 3vh, 24px);
  padding: 4px 14px; font-weight: 800; font-size: 16px; color: var(--ink);
  background: var(--butter); border: 3px solid var(--ink); border-radius: 999px; opacity: 0.85;
}
@keyframes ls-tutor-in { from { transform: translateX(40vw); opacity: 0; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .ls-tutor-img { animation: none; } .ls-tutor-say { opacity: 1; transform: none; } }

/* ---- Ahmed beside the lesson text ---- */
.ls-main { flex: 1 1 auto; min-height: 0; display: flex; align-items: stretch; gap: clamp(6px, 1.2vw, 16px); }
.ls-main .ls-body { flex: 1 1 auto; min-width: 0; }
.ls-guide { flex: 0 0 auto; display: flex; align-items: flex-end; min-height: 0; pointer-events: none; }
.ls-guide[hidden] { display: none; }
.ls-guide-img { display: block; height: min(100%, 440px); width: auto; max-width: 22vw; object-fit: contain; object-position: bottom; filter: drop-shadow(0 6px 0 rgba(59, 30, 84, 0.2)); }

/* ---- lesson v2: what kind of card this is, and the "Your turn" question ---- */
.ls-kind {
  align-self: center; display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 14px 2px 8px; border: 3px solid var(--ink); border-radius: 999px;
  font-weight: 900; font-size: clamp(14px, 2.1vh, 18px); line-height: 1.3; background: var(--butter);
}
.ls-kind-icon { font-size: 1.2em; line-height: 1; }
.ls-kind-goal { background: var(--blush); }
.ls-kind-watch { background: var(--lilac); }
.ls-kind-try { background: var(--turquoise); }
.ls-kind-tips { background: var(--butter); }
.ls-kind-check { background: #c9f2d0; }

.ls-ask { width: 100%; display: flex; flex-direction: column; align-items: center; gap: clamp(6px, 1.2vh, 12px); }
.ls-ask-q { margin: 0; font-weight: 900; font-size: clamp(20px, 3vh, 28px); color: var(--orchid-deep); }
.ls-choices { display: flex; flex-wrap: wrap; justify-content: center; gap: clamp(8px, 1.4vw, 16px); }
.ls-choice {
  position: relative; min-width: 7.5em; min-height: clamp(48px, 7vh, 64px); padding: 6px 22px 6px 34px;
  font: inherit; font-weight: 900; font-size: clamp(20px, 3.2vh, 30px); color: var(--ink);
  background: var(--paper); border: var(--outline); border-radius: var(--radius-m); box-shadow: 0 5px 0 var(--ink);
  cursor: pointer; touch-action: manipulation; transition: transform 0.08s;
}
.ls-choice:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 2px 0 var(--ink); }
.ls-choice-key {
  position: absolute; left: 8px; top: 6px; font-size: 0.5em; font-weight: 800; color: var(--ink-soft); opacity: 0.7;
}
.ls-choice:disabled { cursor: default; }
.ls-choice-wrong { background: var(--butter); opacity: 0.7; text-decoration: line-through; text-decoration-thickness: 3px; animation: ls-nope 0.35s; }
.ls-choice-right { background: #b9efc4; opacity: 1; animation: ls-yes 0.45s var(--pop); }
.ls-fb { margin: 0; min-height: 1.4em; max-width: 36em; font-weight: 800; font-size: clamp(17px, 2.6vh, 24px); line-height: 1.35; }
.ls-fb:empty { display: none; }
.ls-fb-right { color: var(--ink); background: #c9f2d0; border: 3px solid var(--ink); border-radius: var(--radius-s); padding: 4px 14px; }
.ls-fb-wrong { color: var(--ink); background: var(--butter); border: 3px solid var(--ink); border-radius: var(--radius-s); padding: 4px 14px; }   /* never red */
.ls-shake { animation: ls-nope 0.35s; }
.ls-btn-wait { opacity: 0.6; }
.ls-btn-ready { animation: ls-ready 1.2s ease-in-out 2; }
.ls-guide-hop .ls-guide-img { animation: ls-hop 0.42s ease-in-out 2; }
@keyframes ls-nope { 0%, 100% { transform: none; } 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
@keyframes ls-yes { 0% { transform: scale(1); } 50% { transform: scale(1.12); } 100% { transform: scale(1); } }
@keyframes ls-ready { 0%, 100% { transform: none; } 50% { transform: scale(1.06); } }
@keyframes ls-hop { 0%, 100% { transform: none; } 50% { transform: translateY(-10%); } }
@media (prefers-reduced-motion: reduce) { .ls-choice-wrong, .ls-choice-right, .ls-shake, .ls-btn-ready, .ls-guide-hop .ls-guide-img { animation: none; } }

/* ---- نحو cards: Arabic text, tables, the rule list, sentences ---- */
.ls-root { --ls-text: var(--font-text, "Amiri", "Geeza Pro", serif); }
.ls-body { text-align: right; }
.ls-page { width: 100%; text-align: center; }
.ls-text { font-family: var(--ls-text); font-weight: 700; font-size: clamp(24px, 4vh, 36px); line-height: 1.8; max-width: 30em; }
.ls-choice { font-family: var(--ls-text); padding: 6px 34px 6px 22px; }
.ls-choice-key { left: 10px; font-family: var(--font-ui, system-ui, sans-serif); }
.ls-ask-q { font-size: clamp(18px, 2.8vh, 26px); }
.ls-fb { font-family: var(--ls-text); font-size: clamp(18px, 3vh, 26px); line-height: 1.6; }

.ls-sentence {
  margin: 0; display: flex; flex-wrap: wrap; justify-content: center; gap: 0.1em 0.4em;
  font-family: var(--ls-text); font-size: clamp(28px, 5.4vh, 48px); line-height: 1.7; direction: rtl;
}
.ls-ask-s { font-size: clamp(26px, 4.8vh, 42px); }
.ls-target { color: var(--rose-deep); text-decoration: underline; text-decoration-thickness: 4px; text-underline-offset: 0.18em; font-weight: 700; }
.ls-blank { display: inline-block; min-width: 2.4em; height: 1.1em; vertical-align: middle; border: 3px dashed var(--ink-soft); border-radius: var(--radius-s); background: var(--lilac); }

.ls-table { border-collapse: separate; border-spacing: 0; width: 100%; max-width: 46em; font-family: var(--ls-text); font-size: clamp(20px, 3.2vh, 30px); line-height: 1.6; background: var(--cream); border: 3px solid var(--ink); border-radius: var(--radius-m); overflow: hidden; }
.ls-table th { padding: 4px 14px; font-family: var(--font-ui, system-ui, sans-serif); font-weight: 800; font-size: 0.62em; background: var(--lilac); border-bottom: 3px solid var(--ink); text-align: right; }
.ls-table td { padding: 4px 14px; text-align: right; vertical-align: top; border-top: 2px solid var(--lilac); }
.ls-table tbody tr:first-child td { border-top: 0; }
.ls-table td + td, .ls-table th + th { border-right: 2px solid var(--lilac); }
.ls-table .ls-hl { background: var(--butter); color: var(--rose-deep); font-weight: 700; }
.ls-table th.ls-hl { color: var(--ink); background: var(--gold); }
.ls-irab { max-width: 52em; }
.ls-irab td:first-child { white-space: nowrap; }

.ls-points { margin: 0; padding: 0; list-style: none; width: 100%; max-width: 40em; display: flex; flex-direction: column; gap: clamp(6px, 1.2vh, 12px); text-align: right; }
.ls-point { padding: 6px 16px; font-family: var(--ls-text); font-weight: 700; font-size: clamp(22px, 3.6vh, 32px); line-height: 1.7; background: var(--cream); border: 3px solid var(--ink); border-radius: var(--radius-m); }
.ls-warn { background: var(--butter); border-style: dashed; color: var(--ink); }

@media (max-height: 640px) {
  .ls-guide-img { max-width: 14vw; }
  .ls-btn { min-height: 52px; padding: 4px 18px; font-size: 22px; }
  .ls-btn-go { font-size: 24px; }
  .ls-card-title { font-size: clamp(22px, 5vh, 32px); }
}
@media (max-height: 500px) {
  .ls-guide { display: none; }
  .ls-head { min-height: 38px; }
  .ls-title { font-size: 20px; }
  .ls-body { padding: 8px 12px; }
  .ls-choice-key { display: none; }
}
