/* ==========================================================================
   Mahdi_Genius — السبورة الذكية
   Design direction: an engineering drafting sheet pinned to a studio wall.
   Paper, ink, brass registration marks, one emerald accent, and a chalk line.
   ========================================================================== */

/* ---------- 1. Tokens ---------- */
:root {
  color-scheme: light;
  --font-display: "Alexandria", "IBM Plex Sans Arabic", "Segoe UI", Tahoma, sans-serif;
  --font-body: "IBM Plex Sans Arabic", "Segoe UI", Tahoma, sans-serif;
  --font-mono: "IBM Plex Mono", "Cascadia Code", Consolas, monospace;
  --font-hand: "Marhey", "Caveat", "IBM Plex Sans Arabic", cursive;

  --bg: #eeeade;
  --bg-deep: #e4dfd1;
  --sheet: #fbf9f2;
  --sheet-warm: #f6f2e7;
  --ink: #13211e;
  --ink-soft: #3d4b46;
  --muted: #68766f;
  --line: #d8d2c2;
  --line-strong: #b9b1a0;
  --accent: #0c6b5a;
  --accent-deep: #08483d;
  --accent-soft: #dcece5;
  --brass: #b97f22;
  --brass-soft: #f0e0bd;
  --chalk-yellow: #f0d36a;
  --danger: #b4432f;
  --danger-soft: #f5dfd9;
  --white: #fffdf7;

  --paper-dot: rgba(19, 33, 30, 0.14);
  --paper-line: rgba(19, 33, 30, 0.045);
  --grid-dot: rgba(19, 33, 30, 0.17);
  --grid-line: rgba(19, 33, 30, 0.035);

  --shadow-hard: 6px 6px 0 rgba(19, 33, 30, 0.07);
  --shadow-soft: 0 24px 60px -30px rgba(19, 33, 30, 0.45);
  --shadow-dialog: 0 40px 120px -40px rgba(8, 18, 15, 0.65);

  --radius-lg: 18px;
  --radius: 12px;
  --radius-sm: 8px;

  --topbar-h: 76px;
  --chat-w: 386px;
  --gutter: 18px;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0a1210;
  --bg-deep: #07100e;
  --sheet: #101b18;
  --sheet-warm: #13211d;
  --ink: #e8efe9;
  --ink-soft: #c3d0c9;
  --muted: #8fa39a;
  --line: #26362f;
  --line-strong: #3a5047;
  --accent: #6fe0be;
  --accent-deep: #9aecd3;
  --accent-soft: #12352c;
  --brass: #e7b85b;
  --brass-soft: #332816;
  --chalk-yellow: #f0d36a;
  --danger: #ff8a73;
  --danger-soft: #3a211c;
  --white: #f3f7f1;

  --paper-dot: rgba(232, 239, 233, 0.12);
  --paper-line: rgba(232, 239, 233, 0.035);
  --grid-dot: rgba(232, 239, 233, 0.13);
  --grid-line: rgba(232, 239, 233, 0.025);

  --shadow-hard: 6px 6px 0 rgba(0, 0, 0, 0.26);
  --shadow-soft: 0 30px 70px -34px rgba(0, 0, 0, 0.85);
  --shadow-dialog: 0 40px 140px -30px rgba(0, 0, 0, 0.9);
}

/* ---------- 2. Base ---------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.7;
  color: var(--ink);
  background-color: var(--bg);
  background-image:
    radial-gradient(circle at 1px 1px, var(--grid-dot) 1px, transparent 1.25px),
    linear-gradient(to left, var(--grid-line) 1px, transparent 1px),
    linear-gradient(to bottom, var(--grid-line) 1px, transparent 1px);
  background-size: 22px 22px, 88px 88px, 88px 88px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(ellipse 90% 60% at 18% 0%, rgba(185, 127, 34, 0.08), transparent 60%),
    radial-gradient(ellipse 70% 55% at 90% 12%, rgba(12, 107, 90, 0.07), transparent 65%);
}

[data-theme="dark"] body::before {
  background:
    radial-gradient(ellipse 80% 50% at 20% 0%, rgba(231, 184, 91, 0.06), transparent 60%),
    radial-gradient(ellipse 70% 55% at 90% 10%, rgba(111, 224, 190, 0.05), transparent 65%);
}

h1, h2, h3, h4, p, ol, ul {
  margin: 0;
}

h1, h2, h3, h4 {
  font-family: var(--font-display);
  font-weight: 600;
  line-height: 1.3;
}

button,
input,
textarea,
select {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

a {
  color: var(--accent);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

img,
svg {
  display: block;
}

::selection {
  background: var(--accent);
  color: var(--sheet);
}

:focus-visible {
  outline: 2px solid var(--brass);
  outline-offset: 3px;
}

[hidden] {
  display: none !important;
}

.svg-sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

.icon {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: fixed;
  inset-block-start: -100px;
  inset-inline-start: 16px;
  z-index: 200;
  padding: 10px 16px;
  border-radius: 0 0 8px 8px;
  background: var(--ink);
  color: var(--sheet);
  font-size: 13px;
  transition: inset-block-start 0.2s var(--ease);
}

.skip-link:focus {
  inset-block-start: 0;
}

/* ---------- 3. Shared type & controls ---------- */
.eyebrow {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-body);
  font-size: 12px;
  font-weight: 500;
  line-height: 1.5;
  color: var(--muted);
}

.eyebrow__mark {
  width: 6px;
  height: 6px;
  flex: 0 0 auto;
  background: var(--brass);
  transform: rotate(45deg);
}

.block-label {
  display: block;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 500;
  line-height: 1.4;
  color: var(--muted);
  margin-block-end: 8px;
}

.mark {
  position: relative;
  display: inline-block;
  padding-inline: 0.06em;
  color: var(--accent-deep);
  background: linear-gradient(
    180deg,
    transparent 56%,
    color-mix(in srgb, var(--chalk-yellow) 72%, transparent) 56%,
    color-mix(in srgb, var(--chalk-yellow) 72%, transparent) 92%,
    transparent 92%
  );
}

[data-theme="dark"] .mark {
  color: var(--accent);
  background: linear-gradient(
    180deg,
    transparent 56%,
    color-mix(in srgb, var(--chalk-yellow) 26%, transparent) 56%,
    color-mix(in srgb, var(--chalk-yellow) 26%, transparent) 92%,
    transparent 92%
  );
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
  transition:
    background-color 0.18s var(--ease),
    border-color 0.18s var(--ease),
    color 0.18s var(--ease),
    transform 0.18s var(--ease),
    box-shadow 0.18s var(--ease);
}

.btn:active {
  transform: translateY(1px);
}

.btn:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.btn--ink {
  background: var(--ink);
  color: var(--sheet);
  border-color: var(--ink);
}

.btn--ink:hover:not(:disabled) {
  background: var(--accent-deep);
  border-color: var(--accent-deep);
  color: var(--white);
}

[data-theme="dark"] .btn--ink:hover:not(:disabled) {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--bg);
}

.btn--accent {
  background: var(--accent);
  color: var(--sheet);
  border-color: var(--accent);
}

.btn--accent:hover:not(:disabled) {
  background: var(--accent-deep);
  border-color: var(--accent-deep);
}

[data-theme="dark"] .btn--accent {
  color: var(--bg);
}

[data-theme="dark"] .btn--accent:hover:not(:disabled) {
  background: var(--accent-deep);
  border-color: var(--accent-deep);
}

.btn--ghost {
  background: color-mix(in srgb, var(--sheet) 60%, transparent);
  border-color: var(--line);
  color: var(--ink-soft);
}

.btn--ghost:hover:not(:disabled) {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent-deep);
}

[data-theme="dark"] .btn--ghost:hover:not(:disabled) {
  color: var(--accent);
}

.btn--lg {
  min-height: 52px;
  padding-inline: 22px;
  font-size: 15.5px;
  border-radius: 12px;
}

.btn--sm {
  min-height: 34px;
  padding-inline: 10px;
  font-size: 12.5px;
  border-radius: 8px;
}

.text-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 0;
  border: 0;
  background: transparent;
  color: var(--accent-deep);
  font-size: 12.5px;
  font-weight: 600;
  line-height: 1.4;
}

[data-theme="dark"] .text-btn {
  color: var(--accent);
}

.text-btn .icon {
  width: 14px;
  height: 14px;
  transition: transform 0.2s var(--ease);
}

.text-btn:hover .icon {
  transform: translateX(-3px);
}

.text-btn:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-width: 38px;
  min-height: 38px;
  padding: 0 9px;
  border: 1px solid transparent;
  border-radius: 9px;
  background: transparent;
  color: var(--ink-soft);
  font-size: 12.5px;
  font-weight: 500;
  line-height: 1;
  transition:
    background-color 0.18s var(--ease),
    border-color 0.18s var(--ease),
    color 0.18s var(--ease);
}

.icon-btn:hover {
  background: var(--accent-soft);
  color: var(--accent-deep);
}

[data-theme="dark"] .icon-btn:hover {
  color: var(--accent);
}

.icon-btn--bordered {
  border-color: var(--line);
  background: var(--sheet);
}

.icon-btn__label {
  font-size: 12.5px;
}

/* ---------- 4. Top bar ---------- */
.app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

.topbar {
  position: sticky;
  inset-block-start: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 24px;
  height: var(--topbar-h);
  padding: 0 28px;
  border-block-end: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 84%, transparent);
  backdrop-filter: blur(16px) saturate(1.15);
  -webkit-backdrop-filter: blur(16px) saturate(1.15);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  flex: 0 0 auto;
  color: var(--ink);
  text-decoration: none;
}

.brand__seal {
  position: relative;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 11px;
  background: var(--accent-deep);
  box-shadow: 3px 3px 0 var(--brass-soft);
  transform: rotate(-2deg);
}

.brand__seal svg {
  width: 34px;
  height: 34px;
  overflow: visible;
}

.brand__seal rect {
  fill: none;
  stroke: var(--sheet);
  stroke-width: 2.6;
}

.brand__seal path {
  fill: none;
  stroke: var(--chalk-yellow);
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.brand__words {
  display: flex;
  flex-direction: column;
  gap: 1px;
  line-height: 1.2;
}

.brand__words strong {
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.brand__words span {
  font-size: 10.5px;
  color: var(--muted);
}

.subjects {
  display: flex;
  align-items: center;
  gap: 2px;
  min-width: 0;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: color-mix(in srgb, var(--bg-deep) 72%, transparent);
  overflow-x: auto;
  scrollbar-width: none;
}

.subjects::-webkit-scrollbar {
  display: none;
}

.subject-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  flex: 0 0 auto;
  min-height: 34px;
  padding: 0 10px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 500;
  white-space: nowrap;
  transition:
    background-color 0.18s var(--ease),
    color 0.18s var(--ease),
    box-shadow 0.18s var(--ease);
}

.subject-btn__code {
  min-width: 17px;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  color: var(--accent);
  text-align: center;
}

.subject-btn:hover {
  color: var(--ink);
  background: color-mix(in srgb, var(--sheet) 55%, transparent);
}

.subject-btn.is-active {
  color: var(--ink);
  background: var(--sheet);
  border-color: var(--line);
  box-shadow: 0 2px 0 color-mix(in srgb, var(--ink) 8%, transparent);
}

[data-theme="dark"] .subject-btn.is-active {
  border-color: var(--line-strong);
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.35);
}

.topbar__actions {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-inline-start: auto;
  flex: 0 0 auto;
}

.ai-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 30px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: color-mix(in srgb, var(--sheet) 60%, transparent);
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
  white-space: nowrap;
}

.ai-pill__dot {
  width: 7px;
  height: 7px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--brass);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brass) 18%, transparent);
}

.ai-pill[data-mode="live"] {
  color: var(--accent-deep);
  border-color: color-mix(in srgb, var(--accent) 35%, var(--line));
  background: var(--accent-soft);
}

[data-theme="dark"] .ai-pill[data-mode="live"] {
  color: var(--accent);
}

.ai-pill[data-mode="live"] .ai-pill__dot {
  background: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent);
}

.ai-pill[data-mode="checking"] .ai-pill__dot {
  animation: pulse-dot 1.1s ease-in-out infinite;
}

.ai-pill[data-mode="error"] {
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 35%, var(--line));
}

.ai-pill[data-mode="error"] .ai-pill__dot {
  background: var(--danger);
}

.theme-icon--moon,
[data-theme="dark"] .theme-icon--sun {
  display: none;
}

[data-theme="dark"] .theme-icon--moon {
  display: block;
}

/* ---------- 5. Layout ---------- */
.workspace {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--chat-w);
  gap: var(--gutter);
  width: 100%;
  max-width: 1800px;
  min-height: 0;
  margin: 0 auto;
  padding: var(--gutter) 24px 22px;
}

.board-panel,
.chat-panel {
  min-width: 0;
  min-height: 0;
}

.mobile-tabs {
  display: none;
}

/* ---------- 6. The sheet ---------- */
.sheet {
  position: relative;
  display: flex;
  flex-direction: column;
  height: calc(100dvh - var(--topbar-h) - 40px);
  min-height: 580px;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-lg);
  background: var(--sheet);
  box-shadow: var(--shadow-hard), var(--shadow-soft);
  animation: sheet-in 0.65s var(--ease-out) both;
}

.sheet::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background-image:
    radial-gradient(circle at 1px 1px, var(--paper-dot) 1px, transparent 1.2px),
    linear-gradient(to left, var(--paper-line) 1px, transparent 1px),
    linear-gradient(to bottom, var(--paper-line) 1px, transparent 1px);
  background-size: 18px 18px, 90px 90px, 90px 90px;
  opacity: 0.7;
}

.sheet > * {
  position: relative;
  z-index: 1;
}

.reg {
  position: absolute;
  z-index: 2;
  width: 14px;
  height: 14px;
  pointer-events: none;
  opacity: 0.8;
}

.reg--tl {
  inset-block-start: 10px;
  inset-inline-start: 10px;
  border-block-start: 1px solid var(--brass);
  border-inline-start: 1px solid var(--brass);
}

.reg--tr {
  inset-block-start: 10px;
  inset-inline-end: 10px;
  border-block-start: 1px solid var(--brass);
  border-inline-end: 1px solid var(--brass);
}

.reg--bl {
  inset-block-end: 10px;
  inset-inline-start: 10px;
  border-block-end: 1px solid var(--brass);
  border-inline-start: 1px solid var(--brass);
}

.reg--br {
  inset-block-end: 10px;
  inset-inline-end: 10px;
  border-block-end: 1px solid var(--brass);
  border-inline-end: 1px solid var(--brass);
}

.sheet__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  padding: 20px 28px 15px;
  border-block-end: 1px solid var(--line);
  background: color-mix(in srgb, var(--sheet) 70%, transparent);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}

.sheet__title {
  min-width: 0;
}

.sheet__title h1 {
  margin-block-start: 4px;
  font-size: clamp(21px, 2.2vw, 27px);
  font-weight: 600;
  line-height: 1.35;
}

.sheet__tools {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
  padding-block-start: 2px;
}

.sheet__status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 30px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: color-mix(in srgb, var(--sheet) 70%, transparent);
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
}

.sheet__status > span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
}

.sheet__status[data-state="thinking"] > span {
  background: var(--brass);
  animation: pulse-dot 1.1s ease-in-out infinite;
}

.sheet__status[data-state="error"] > span {
  background: var(--danger);
}

.sheet__body {
  flex: 1;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 26px clamp(18px, 3vw, 34px) 34px;
  scroll-behavior: smooth;
}

.sheet__body::-webkit-scrollbar,
.chat-log::-webkit-scrollbar,
.library__grid::-webkit-scrollbar,
.check-panel__body::-webkit-scrollbar {
  width: 9px;
  height: 9px;
}

.sheet__body::-webkit-scrollbar-thumb,
.chat-log::-webkit-scrollbar-thumb,
.library__grid::-webkit-scrollbar-thumb,
.check-panel__body::-webkit-scrollbar-thumb {
  border: 2px solid transparent;
  border-radius: 20px;
  background: var(--line-strong);
  background-clip: content-box;
}

/* ---------- 7. Welcome ---------- */
.welcome {
  width: 100%;
  max-width: 1040px;
  margin: 0 auto;
  padding-block-start: 4px;
}

.welcome__hero {
  display: grid;
  grid-template-columns: minmax(0, 1.12fr) minmax(260px, 0.88fr);
  align-items: center;
  gap: clamp(18px, 3vw, 40px);
  min-height: 330px;
}

.welcome__copy {
  min-width: 0;
  padding-block: 10px;
}

.welcome__copy h2 {
  margin-block: 12px 14px;
  font-size: clamp(38px, 4.7vw, 62px);
  font-weight: 700;
  line-height: 1.12;
}

.welcome__lead {
  max-width: 54ch;
  color: var(--ink-soft);
  font-size: clamp(14.5px, 1.3vw, 16.5px);
  line-height: 1.95;
}

.welcome__actions {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  margin-block-start: 22px;
}

.welcome__note {
  color: var(--muted);
  font-size: 11.5px;
  line-height: 1.6;
}

.welcome__art {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 0;
  color: var(--ink);
}

.welcome__art svg {
  width: min(100%, 370px);
  height: auto;
  overflow: visible;
}

.art-ring {
  fill: none;
  stroke: var(--line-strong);
  stroke-width: 1.4;
}

.art-ring--thin {
  stroke: var(--line);
  stroke-dasharray: 2 7;
}

.art-ticks path {
  stroke: var(--line-strong);
  stroke-width: 1.4;
  stroke-linecap: round;
}

.art-grid path {
  stroke: var(--line);
  stroke-width: 1;
}

.art-triangle {
  fill: color-mix(in srgb, var(--accent-soft) 72%, transparent);
  stroke: var(--accent);
  stroke-width: 2;
  stroke-linejoin: round;
}

.art-triangle-line {
  stroke: var(--accent);
  stroke-width: 1.6;
  stroke-linecap: round;
  opacity: 0.65;
}

.art-draw {
  fill: none;
  stroke: var(--brass);
  stroke-width: 3.2;
  stroke-linecap: round;
  stroke-dasharray: 600;
  stroke-dashoffset: 600;
  animation: draw-line 1.8s var(--ease-out) 0.25s forwards;
}

.art-pivot {
  fill: var(--ink);
}

.art-pivot--brass {
  fill: var(--brass);
}

.art-label rect {
  fill: var(--sheet);
  stroke: var(--line);
  stroke-width: 1;
}

.art-label text {
  fill: var(--ink-soft);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
}

.art-label {
  opacity: 0;
  animation: fade-in 0.55s var(--ease) 1.1s forwards;
}

.art-label--two {
  animation-delay: 1.25s;
}

.art-label--three {
  animation-delay: 1.4s;
}

.art-caption {
  margin-block-start: -4px;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 10px;
  line-height: 1.5;
}

/* ---------- 8. Lesson shelf ---------- */
.lesson-shelf {
  margin-block-start: 24px;
  padding-block-start: 20px;
  border-block-start: 1px solid var(--line);
}

.lesson-shelf__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
}

.lesson-shelf__head h3 {
  font-size: 18px;
  font-weight: 600;
}

.lesson-cards {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-block-start: 12px;
}

.lesson-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 7px;
  min-height: 146px;
  padding: 15px 16px 13px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--sheet);
  color: var(--ink);
  text-align: start;
  box-shadow: 3px 3px 0 color-mix(in srgb, var(--ink) 5%, transparent);
  transition:
    transform 0.2s var(--ease),
    border-color 0.2s var(--ease),
    box-shadow 0.2s var(--ease);
}

.lesson-card:hover {
  transform: translateY(-2px);
  border-color: var(--accent);
  box-shadow: 5px 5px 0 var(--accent-soft);
}

.lesson-card__code {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 10px;
  line-height: 1.4;
}

.lesson-card__code::before {
  content: "";
  width: 5px;
  height: 5px;
  background: var(--brass);
  transform: rotate(45deg);
}

.lesson-card__title {
  font-family: var(--font-display);
  font-size: 15.5px;
  font-weight: 600;
  line-height: 1.5;
}

.lesson-card__meta {
  margin-block-start: auto;
  color: var(--muted);
  font-size: 11px;
}

.lesson-card__arrow {
  position: absolute;
  inset-block-end: 13px;
  inset-inline-end: 14px;
  color: var(--accent);
  opacity: 0;
  transform: translateX(4px);
  transition:
    opacity 0.2s var(--ease),
    transform 0.2s var(--ease);
}

.lesson-card:hover .lesson-card__arrow {
  opacity: 1;
  transform: translateX(0);
}

.lesson-card__arrow .icon {
  width: 16px;
  height: 16px;
}

/* ---------- 9. How it works ---------- */
.howto {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
  list-style: none;
  margin-block-start: 24px;
  padding: 17px 0 2px;
  border-block-start: 1px dashed var(--line-strong);
}

.howto li {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  min-width: 0;
}

.howto__num {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  flex: 0 0 auto;
  border: 1px solid var(--brass);
  border-radius: 7px;
  color: var(--brass);
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 500;
}

.howto strong {
  display: block;
  font-size: 13px;
  font-weight: 600;
}

.howto p {
  color: var(--muted);
  font-size: 11.5px;
  line-height: 1.7;
}

/* ---------- 10. Loading ---------- */
.board-loading {
  display: grid;
  place-items: center;
  min-height: 58vh;
  text-align: center;
}

.board-loading__inner {
  max-width: 460px;
  padding: 28px;
}

.board-loading h2 {
  margin-block: 12px 8px;
  font-size: clamp(22px, 2.6vw, 30px);
  font-weight: 600;
}

.board-loading p:not(.eyebrow) {
  color: var(--muted);
  font-size: 13.5px;
  line-height: 1.8;
}

.chalk-spinner {
  position: relative;
  width: 54px;
  height: 54px;
  margin: 0 auto 8px;
  border: 1px dashed var(--line-strong);
  border-radius: 50%;
}

.chalk-spinner span {
  position: absolute;
  inset-block-start: 50%;
  inset-inline-start: 50%;
  width: 2px;
  height: 18px;
  background: var(--accent);
  border-radius: 2px;
  transform-origin: 1px 0;
  animation: chalk-write 1.4s ease-in-out infinite;
}

.chalk-spinner span:nth-child(1) {
  transform: rotate(0deg) translateY(-23px);
}

.chalk-spinner span:nth-child(2) {
  transform: rotate(120deg) translateY(-23px);
  animation-delay: 0.18s;
  background: var(--brass);
}

.chalk-spinner span:nth-child(3) {
  transform: rotate(240deg) translateY(-23px);
  animation-delay: 0.36s;
}

/* ---------- 11. Lesson ---------- */
.lesson {
  width: 100%;
  max-width: 1000px;
  margin: 0 auto;
  animation: step-in 0.45s var(--ease-out) both;
}

.lesson__head {
  padding-block-end: 18px;
  margin-block-end: 22px;
  border-block-end: 1px solid var(--line);
}

.lesson__head h2 {
  max-width: 24ch;
  margin-block: 5px 8px;
  font-size: clamp(25px, 3vw, 35px);
  font-weight: 600;
  line-height: 1.35;
}

.lesson__summary {
  max-width: 72ch;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.85;
}

.lesson__grid {
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr);
  align-items: start;
  gap: 18px;
}

.spine {
  position: sticky;
  inset-block-start: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-block: 4px;
}

.spine::before {
  content: "";
  position: absolute;
  inset-block: 18px;
  inset-inline-start: 50%;
  width: 1px;
  background: var(--line);
}

.spine__step {
  position: relative;
  z-index: 1;
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  margin-block-end: 12px;
  border: 1px solid var(--line-strong);
  border-radius: 50%;
  background: var(--sheet);
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  transition:
    background-color 0.18s var(--ease),
    border-color 0.18s var(--ease),
    color 0.18s var(--ease),
    box-shadow 0.18s var(--ease);
}

.spine__step:hover {
  border-color: var(--accent);
  color: var(--accent-deep);
}

.spine__step.is-done {
  border-color: color-mix(in srgb, var(--accent) 55%, var(--line));
  background: var(--accent-soft);
  color: var(--accent-deep);
}

[data-theme="dark"] .spine__step.is-done,
[data-theme="dark"] .spine__step:hover {
  color: var(--accent);
}

.spine__step.is-active {
  border-color: var(--ink);
  background: var(--ink);
  color: var(--sheet);
  box-shadow: 0 0 0 4px var(--accent-soft);
}

.step {
  position: relative;
  min-height: 340px;
  padding: 24px clamp(18px, 2.6vw, 32px) 28px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background:
    linear-gradient(135deg, color-mix(in srgb, var(--accent-soft) 22%, transparent), transparent 42%),
    var(--sheet);
  box-shadow: var(--shadow-hard);
}

.step::before {
  content: "";
  position: absolute;
  inset-block: 0;
  inset-inline-start: 0;
  width: 3px;
  background: var(--accent);
  opacity: 0.7;
}

.step__ghost {
  position: absolute;
  inset-block-start: -28px;
  inset-inline-end: 4px;
  z-index: 0;
  color: color-mix(in srgb, var(--ink) 4.5%, transparent);
  font-family: var(--font-display);
  font-size: clamp(120px, 16vw, 190px);
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.04em;
  pointer-events: none;
  user-select: none;
}

.step__body {
  position: relative;
  z-index: 1;
  max-width: 72ch;
}

.step__meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-block-end: 14px;
}

.step__count {
  display: inline-flex;
  align-items: center;
  min-height: 25px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: color-mix(in srgb, var(--sheet) 75%, transparent);
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 10.5px;
}

.step__tag {
  display: inline-flex;
  align-items: center;
  min-height: 25px;
  padding: 0 8px;
  border: 1px solid color-mix(in srgb, var(--brass) 38%, var(--line));
  border-radius: 6px;
  background: var(--brass-soft);
  color: color-mix(in srgb, var(--brass) 76%, var(--ink));
  font-size: 10.5px;
  font-weight: 600;
}

[data-theme="dark"] .step__tag {
  color: var(--brass);
}

.step h3 {
  max-width: 30ch;
  margin-block-end: 12px;
  font-size: clamp(22px, 2.5vw, 29px);
  font-weight: 600;
  line-height: 1.4;
}

.step.is-entering .step__body {
  animation: step-in 0.4s var(--ease-out) both;
}

/* ---------- 12. Markdown ---------- */
.md {
  color: var(--ink-soft);
  font-size: 15.5px;
  line-height: 1.95;
}

.md p {
  margin-block: 0 12px;
}

.md p:last-child {
  margin-block-end: 0;
}

.md strong {
  color: var(--ink);
  font-weight: 600;
}

.md em {
  color: var(--ink);
}

.md ul,
.md ol {
  margin-block: 4px 12px;
  padding-inline-start: 22px;
}

.md li {
  margin-block: 5px;
  padding-inline-start: 2px;
}

.md li::marker {
  color: var(--accent);
}

.md blockquote {
  margin-block: 12px;
  padding: 8px 14px;
  border-inline-start: 2px solid var(--brass);
  background: color-mix(in srgb, var(--brass-soft) 28%, transparent);
  color: var(--muted);
  border-radius: 0 6px 6px 0;
}

.md code {
  direction: ltr;
  unicode-bidi: isolate;
  display: inline-block;
  padding: 1px 5px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: color-mix(in srgb, var(--ink) 5%, transparent);
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 0.86em;
  line-height: 1.6;
}

.md a {
  color: var(--accent-deep);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.md h4,
.md h5,
.md h6 {
  margin-block: 14px 8px;
  color: var(--ink);
  font-size: 1em;
  font-weight: 600;
}

.md .md-pre {
  margin-block: 10px;
  padding: 11px 13px;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: color-mix(in srgb, var(--ink) 5%, transparent);
  direction: ltr;
  text-align: left;
}

.md .md-pre code {
  display: block;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  font-size: 12px;
  line-height: 1.7;
  white-space: pre;
}

[data-theme="dark"] .md a {
  color: var(--accent);
}

/* ---------- 13. Code ---------- */
.step__code {
  margin-block-start: 16px;
}

.code-card {
  overflow: hidden;
  border: 1px solid #263b34;
  border-radius: 10px;
  background: #0d1916;
  box-shadow: 3px 3px 0 color-mix(in srgb, var(--ink) 5%, transparent);
}

.code-card__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 7px 12px;
  border-block-end: 1px solid #243a33;
  background: #101f1b;
}

.code-card__lang {
  color: #9fb7ad;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 500;
}

.code-card__copy {
  border: 1px solid #314a42;
  border-radius: 5px;
  background: transparent;
  color: #a9bdb4;
  font-size: 10.5px;
  line-height: 1;
  padding: 5px 8px;
  transition:
    color 0.18s var(--ease),
    border-color 0.18s var(--ease),
    background-color 0.18s var(--ease);
}

.code-card__copy:hover {
  color: #f1f6f2;
  border-color: #5b7d70;
  background: #172a25;
}

.code-card pre {
  margin: 0;
  padding: 15px 16px 17px;
  overflow-x: auto;
  direction: ltr;
  text-align: left;
  scrollbar-width: thin;
}

.code-card code {
  display: block;
  color: #dce8e1;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.75;
  white-space: pre;
  tab-size: 2;
}

.hljs-keyword,
.hljs-selector-tag,
.hljs-literal,
.hljs-type {
  color: #f0b56b;
}

.hljs-string,
.hljs-attr,
.hljs-template-tag {
  color: #93d9b8;
}

.hljs-number,
.hljs-symbol,
.hljs-bullet {
  color: #e8c66e;
}

.hljs-comment,
.hljs-quote {
  color: #718a80;
  font-style: italic;
}

.hljs-function,
.hljs-title,
.hljs-section {
  color: #9dc7f2;
}

.hljs-built_in,
.hljs-name {
  color: #d7a8e8;
}

.hljs-variable,
.hljs-params {
  color: #dce8e1;
}

.hljs-meta,
.hljs-preprocessor {
  color: #d98d7a;
}

/* ---------- 14. Math ---------- */
.step__math {
  margin-block-start: 16px;
  padding: 13px 16px 15px;
  border: 1px dashed var(--line-strong);
  border-radius: 10px;
  background: color-mix(in srgb, var(--sheet) 85%, var(--bg));
}

.math-body {
  overflow-x: auto;
  color: var(--ink);
  text-align: center;
  direction: ltr;
  font-family: var(--font-mono);
  font-size: 14px;
  line-height: 1.8;
}

.math-body .katex-display {
  margin: 0;
}

.math-body .katex {
  font-size: 1.12em;
}

.math-fallback {
  display: inline-block;
  padding: 4px 8px;
  color: var(--ink-soft);
  font-family: var(--font-mono);
  font-size: 12.5px;
  direction: ltr;
  unicode-bidi: isolate;
  white-space: pre-wrap;
  text-align: left;
}

/* ---------- 15. Table ---------- */
.step__table {
  margin-block-start: 16px;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--sheet);
}

.table-wrap table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  line-height: 1.65;
}

.table-wrap th,
.table-wrap td {
  padding: 9px 12px;
  border: 1px solid var(--line);
  text-align: start;
  vertical-align: top;
}

.table-wrap th {
  background: var(--accent-soft);
  color: var(--ink);
  font-weight: 600;
  white-space: nowrap;
}

.table-wrap tbody tr:nth-child(even) {
  background: color-mix(in srgb, var(--bg) 30%, transparent);
}

.table-wrap code {
  direction: ltr;
  unicode-bidi: isolate;
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 0.9em;
  color: var(--accent-deep);
}

[data-theme="dark"] .table-wrap code {
  color: var(--accent);
}

/* ---------- 16. Diagram ---------- */
.step__diagram {
  margin-block-start: 16px;
}

.diagram-wrap {
  overflow-x: auto;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: color-mix(in srgb, var(--sheet) 88%, var(--bg));
  text-align: center;
}

.diagram-wrap svg {
  max-width: 100%;
  height: auto;
  margin: 0 auto;
}

.diagram-fallback {
  text-align: start;
}

.diagram-fallback pre {
  margin: 8px 0 0;
  padding: 10px 12px;
  overflow-x: auto;
  border-radius: 6px;
  background: color-mix(in srgb, var(--ink) 6%, transparent);
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 11.5px;
  line-height: 1.7;
  direction: ltr;
  text-align: left;
}

.diagram-note {
  display: block;
  margin-block-start: 7px;
  color: var(--muted);
  font-size: 10.5px;
}

/* ---------- 17. Transport ---------- */
.transport {
  display: flex;
  align-items: center;
  gap: 13px;
  flex-wrap: nowrap;
  padding: 10px 18px;
  border-block-start: 1px solid var(--line);
  background: color-mix(in srgb, var(--sheet) 91%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.transport__controls {
  display: flex;
  align-items: center;
  gap: 7px;
  flex: 0 0 auto;
}

.transport__play {
  min-width: 134px;
  min-height: 38px;
  padding-inline: 12px;
  font-size: 12.5px;
}

.transport__play .icon--pause {
  display: none;
}

.transport__play.is-playing .icon--play {
  display: none;
}

.transport__play.is-playing .icon--pause {
  display: block;
}

.ruler {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 70px;
  height: 30px;
}

.ruler__tick {
  position: relative;
  flex: 1;
  height: 4px;
  padding: 0;
  border: 0;
  border-radius: 3px;
  background: var(--line);
  transition:
    background-color 0.2s var(--ease),
    height 0.2s var(--ease);
}

.ruler__tick:hover {
  background: var(--brass);
}

.ruler__tick.is-done {
  background: color-mix(in srgb, var(--accent) 42%, var(--line));
}

.ruler__tick.is-active {
  height: 8px;
  background: var(--accent);
}

.transport__extras {
  display: flex;
  align-items: center;
  gap: 9px;
  flex: 0 0 auto;
}

.switch {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  user-select: none;
}

.switch input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.switch__track {
  position: relative;
  width: 30px;
  height: 17px;
  border-radius: 20px;
  background: var(--line-strong);
  transition: background-color 0.18s var(--ease);
}

.switch__track::after {
  content: "";
  position: absolute;
  inset-block-start: 2px;
  inset-inline-start: 2px;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: var(--sheet);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.18);
  transition: transform 0.18s var(--ease);
}

.switch input:checked + .switch__track {
  background: var(--accent);
}

.switch input:checked + .switch__track::after {
  transform: translateX(-13px);
}

[dir="rtl"] .switch input:checked + .switch__track::after {
  transform: translateX(-13px);
}

.switch__label {
  color: var(--muted);
  font-size: 11px;
}

/* ---------- 18. Chat ---------- */
.chat-panel {
  position: relative;
  display: flex;
  flex-direction: column;
  height: calc(100dvh - var(--topbar-h) - 40px);
  min-height: 580px;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-lg);
  background: var(--sheet);
  box-shadow: var(--shadow-hard), var(--shadow-soft);
  animation: sheet-in 0.65s var(--ease-out) 0.08s both;
}

.chat-panel::before {
  content: "";
  position: absolute;
  inset-block: 0;
  inset-inline-start: 17px;
  z-index: 0;
  width: 1px;
  background: color-mix(in srgb, var(--brass) 22%, transparent);
  pointer-events: none;
}

.chat-panel > * {
  position: relative;
  z-index: 1;
}

.chat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 16px 14px 22px;
  border-block-end: 1px solid var(--line);
}

.prof {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.prof__avatar {
  display: grid;
  place-items: center;
  width: 41px;
  height: 41px;
  flex: 0 0 auto;
  border-radius: 10px;
  background: var(--ink);
  color: var(--sheet);
  font-family: var(--font-display);
  font-size: 19px;
  font-weight: 700;
  box-shadow: 3px 3px 0 var(--brass-soft);
}

.prof > div {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.35;
}

.prof strong {
  font-size: 13.5px;
  font-weight: 600;
}

.prof span:not(.prof__avatar) {
  color: var(--muted);
  font-size: 10.5px;
}

.quick {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 9px 16px 9px 22px;
  border-block-end: 1px solid var(--line);
}

.quick::-webkit-scrollbar {
  display: none;
}

.quick__chip {
  flex: 0 0 auto;
  max-width: 230px;
  overflow: hidden;
  padding: 6px 9px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--sheet);
  color: var(--ink-soft);
  font-size: 11.5px;
  line-height: 1.4;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition:
    border-color 0.18s var(--ease),
    background-color 0.18s var(--ease),
    color 0.18s var(--ease);
}

.quick__chip:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-deep);
}

[data-theme="dark"] .quick__chip:hover {
  color: var(--accent);
}

.chat-log {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 13px;
  padding: 17px 16px 18px 22px;
  overflow-y: auto;
  scroll-behavior: smooth;
}

.msg {
  display: flex;
  flex-direction: column;
  max-width: 100%;
}

.msg--prof {
  align-items: flex-start;
}

.msg--user {
  align-items: flex-end;
}

.msg__bubble {
  max-width: 94%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  border-start-start-radius: 3px;
  background: color-mix(in srgb, var(--bg) 30%, var(--sheet));
  color: var(--ink-soft);
  font-size: 13px;
  line-height: 1.8;
  box-shadow: 2px 2px 0 color-mix(in srgb, var(--ink) 4%, transparent);
}

.msg__bubble p + p {
  margin-block-start: 6px;
}

.msg__bubble strong {
  color: var(--ink);
  font-weight: 600;
}

.msg__hint {
  color: var(--muted);
  font-size: 11.5px;
  line-height: 1.7;
}

.msg--user .msg__bubble {
  border-color: var(--accent);
  border-start-start-radius: 12px;
  border-start-end-radius: 3px;
  background: var(--accent);
  color: var(--sheet);
}

[data-theme="dark"] .msg--user .msg__bubble {
  color: var(--bg);
}

.msg--user .msg__bubble strong {
  color: inherit;
}

.msg--user .msg__hint {
  color: color-mix(in srgb, var(--sheet) 76%, transparent);
}

.msg__actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-block-start: 7px;
  padding-inline: 2px;
}

.msg__action {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 7px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--sheet);
  color: var(--accent-deep);
  font-size: 10.5px;
  font-weight: 600;
  line-height: 1.3;
}

[data-theme="dark"] .msg__action {
  color: var(--accent);
}

.msg__action:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.msg__action .icon {
  width: 13px;
  height: 13px;
}

.msg--typing .msg__bubble {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 36px;
}

.typing-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--muted);
  animation: typing 1.1s ease-in-out infinite;
}

.typing-dot:nth-child(2) {
  animation-delay: 0.15s;
}

.typing-dot:nth-child(3) {
  animation-delay: 0.3s;
}

.composer {
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom)) 22px;
  border-block-start: 1px solid var(--line);
  background: color-mix(in srgb, var(--sheet) 94%, transparent);
}

.composer__field {
  display: flex;
  align-items: flex-end;
  gap: 5px;
  padding: 5px;
  border: 1px solid var(--line-strong);
  border-radius: 11px;
  background: var(--sheet);
  transition:
    border-color 0.18s var(--ease),
    box-shadow 0.18s var(--ease);
}

.composer__field:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.composer__field textarea {
  flex: 1;
  min-width: 0;
  min-height: 36px;
  max-height: 120px;
  padding: 8px 7px 7px;
  border: 0;
  outline: 0;
  background: transparent;
  resize: none;
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 13.5px;
  line-height: 1.6;
}

.composer__field textarea::placeholder {
  color: var(--muted);
}

.composer__attach {
  width: 34px;
  min-width: 34px;
  min-height: 34px;
  padding: 0;
  color: var(--muted);
}

.send-btn {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  flex: 0 0 auto;
  padding: 0;
  border: 1px solid var(--accent);
  border-radius: 9px;
  background: var(--accent);
  color: var(--sheet);
  transition:
    background-color 0.18s var(--ease),
    border-color 0.18s var(--ease),
    opacity 0.18s var(--ease);
}

[data-theme="dark"] .send-btn {
  color: var(--bg);
}

.send-btn:hover {
  background: var(--accent-deep);
  border-color: var(--accent-deep);
}

.send-btn:disabled {
  opacity: 0.45;
  cursor: wait;
}

.send-btn .icon {
  width: 17px;
  height: 17px;
}

.composer__note {
  margin-block-start: 6px;
  color: var(--muted);
  font-size: 10.5px;
  line-height: 1.5;
}

.attachment {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-block-end: 8px;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
}

.attachment img {
  width: 40px;
  height: 40px;
  flex: 0 0 auto;
  border-radius: 5px;
  object-fit: cover;
}

.attachment__meta {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.45;
}

.attachment__meta strong {
  font-size: 11px;
  font-weight: 600;
}

.attachment__meta span {
  overflow: hidden;
  color: var(--muted);
  font-size: 10px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.attachment .icon-btn {
  min-width: 28px;
  min-height: 28px;
  margin-inline-start: auto;
}

/* ---------- 18ب. إطار تطبيق مشابه (ديسكتوب): سبورة كاملة ودردشة عائمة ---------- */
@media (min-width: 981px) {
  html,
  body {
    height: 100%;
  }

  .app-shell {
    height: 100%;
    min-height: 0;
  }

  body {
    background:
      radial-gradient(920px 520px at 86% -12%, rgba(99, 124, 255, 0.55), transparent 62%),
      radial-gradient(760px 520px at 8% 112%, rgba(124, 58, 237, 0.38), transparent 62%),
      linear-gradient(158deg, #1c2394 0%, #2e34c6 52%, #222a7d 100%);
    background-attachment: fixed;
  }

  .topbar {
    position: relative;
    flex-wrap: wrap;
    justify-content: center;
    align-content: flex-start;
    height: 118px;
    padding: 10px 26px 0;
    border-block-end: none;
    background: transparent;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }

  .brand {
    position: absolute;
    top: 8px;
    left: 50%;
    transform: translateX(-50%);
    color: #fff;
  }

  .brand__seal {
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.14);
    border: 1px solid rgba(255, 255, 255, 0.38);
    box-shadow: none;
    transform: none;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
  }

  .brand__words strong {
    color: #fff;
    font-size: 18px;
  }

  .brand__words span {
    color: rgba(255, 255, 255, 0.74);
  }

  .topbar__actions {
    position: absolute;
    top: 14px;
    inset-inline-end: 22px;
    margin: 0;
    gap: 8px;
  }

  .topbar__actions .icon-btn {
    width: 42px;
    height: 42px;
    min-height: 42px;
    padding: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.14);
    border: 1px solid rgba(255, 255, 255, 0.30);
    color: #fff;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
  }

  .topbar__actions .icon-btn__label {
    display: none;
  }

  .ai-pill {
    min-height: 42px;
    padding: 0 14px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.14);
    border-color: rgba(255, 255, 255, 0.30);
    color: #fff;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
  }

  .ai-pill[data-mode="live"] {
    background: rgba(52, 211, 153, 0.22);
    border-color: rgba(52, 211, 153, 0.48);
    color: #d1fae5;
  }

  .subjects {
    margin: 60px auto 0;
    padding: 5px;
    border-radius: 999px;
    background: rgba(10, 14, 60, 0.40);
    border-color: rgba(255, 255, 255, 0.24);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
  }

  .subject-btn {
    min-height: 36px;
    padding: 0 16px;
    border-radius: 999px;
    color: rgba(255, 255, 255, 0.80);
  }

  .subject-btn__code {
    color: #a5b4fc;
  }

  .subject-btn:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.12);
  }

  .subject-btn.is-active {
    background: #fff;
    border-color: #fff;
    color: #1e2565;
    box-shadow: 0 4px 14px rgba(2, 6, 40, 0.35);
  }

  .subject-btn.is-active .subject-btn__code {
    color: #4f46e5;
  }

  .workspace {
    position: relative;
    display: block;
    max-width: none;
    height: auto;
    min-height: 0;
    padding: 4px 22px 18px;
  }

  .board-panel {
    height: 100%;
  }

  .sheet {
    height: 100%;
    min-height: 0;
    border-radius: 26px;
    border-color: rgba(255, 255, 255, 0.28);
    box-shadow: 0 24px 70px -24px rgba(2, 6, 40, 0.60);
  }

  .sheet__body {
    padding-bottom: 172px;
  }

  #appShell .transport {
    position: absolute;
    top: 44%;
    inset-inline-end: 14px;
    inset-inline-start: auto;
    transform: translateY(-50%);
    flex-direction: column;
    width: auto;
    gap: 10px;
    padding: 12px 8px;
    border: 1px solid var(--line);
    border-block-start: 1px solid var(--line);
    border-radius: 999px;
    box-shadow: 0 14px 34px -12px rgba(2, 6, 40, 0.45);
    z-index: 6;
  }

  #appShell .transport__controls {
    flex-direction: column;
  }

  #appShell .transport__play {
    min-width: 58px;
    padding: 8px 6px;
  }

  #appShell .transport__extras {
    flex-direction: column;
    gap: 8px;
  }

  #appShell .transport .ruler {
    display: none;
  }

  .chat-panel {
    position: absolute;
    z-index: 30;
    left: 50%;
    transform: translateX(-50%);
    bottom: 16px;
    width: min(920px, calc(100vw - 300px));
    height: auto;
    min-height: 0;
    max-height: calc(100% - 20px);
    display: flex;
    flex-direction: column;
    background: transparent;
    border: none;
    box-shadow: none;
    overflow: visible;
    animation: none;
    pointer-events: none;
  }

  .chat-panel::before {
    display: none;
  }

  .chat-panel > * {
    pointer-events: auto;
  }

  .chat-head {
    align-self: flex-start;
    gap: 8px;
    margin-bottom: 8px;
    padding: 6px 8px 6px 12px;
    border: 1px solid rgba(255, 255, 255, 0.28);
    border-radius: 999px;
    background: rgba(13, 18, 64, 0.58);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
  }

  .prof__avatar {
    width: 29px;
    height: 29px;
    border-radius: 50%;
    background: #fff;
    color: #1e2565;
    font-size: 13px;
    box-shadow: none;
  }

  .prof strong {
    color: #fff;
    font-size: 12px;
  }

  .prof span:not(.prof__avatar) {
    color: rgba(255, 255, 255, 0.72);
    font-size: 10px;
  }

  .chat-head .icon-btn {
    width: 30px;
    height: 30px;
    min-height: 30px;
    border-radius: 50%;
    color: #fff;
  }

  .quick {
    flex-wrap: nowrap;
    overflow-x: auto;
    padding: 0 2px 8px;
    border-block-end: none;
  }

  .quick__chip {
    border-radius: 999px;
    padding: 7px 13px;
    background: rgba(255, 255, 255, 0.94);
    border-color: rgba(255, 255, 255, 0.45);
    box-shadow: 0 6px 16px rgba(2, 6, 40, 0.20);
  }

  .chat-log {
    flex: 0 1 auto;
    max-height: min(30dvh, 280px);
    margin-bottom: 10px;
    padding: 14px;
    border: 1px solid rgba(255, 255, 255, 0.38);
    border-radius: 20px;
    background: color-mix(in srgb, var(--sheet) 95%, transparent);
    box-shadow: 0 18px 44px -18px rgba(2, 6, 40, 0.55);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
  }

  .composer {
    padding: 0;
    border-block-start: none;
    background: transparent;
  }

  .composer__field {
    padding: 6px;
    border-radius: 999px;
    background: #0b1120;
    border-color: rgba(255, 255, 255, 0.20);
    box-shadow: 0 18px 44px -12px rgba(2, 6, 40, 0.70);
  }

  .composer__field:focus-within {
    border-color: rgba(255, 255, 255, 0.48);
    box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.20), 0 18px 44px -12px rgba(2, 6, 40, 0.70);
  }

  .composer__field textarea {
    min-height: 42px;
    color: #fff;
  }

  .composer__field textarea::placeholder {
    color: rgba(255, 255, 255, 0.55);
  }

  .composer__attach {
    width: 40px;
    height: 40px;
    min-width: 40px;
    min-height: 40px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.08);
    color: #c7d2fe;
  }

  .composer__attach:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.17);
  }

  #micBtn.is-recording {
    color: #fca5a5;
    background: rgba(248, 113, 113, 0.20);
  }

  .send-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: #10b981;
    border-color: #10b981;
    color: #fff;
  }

  .send-btn:hover {
    background: #059669;
  }

  .composer__note {
    margin-top: 6px;
    color: rgba(255, 255, 255, 0.74);
    text-align: center;
    text-shadow: 0 1px 10px rgba(2, 6, 40, 0.55);
  }

  .attachment {
    border: 1px solid rgba(255, 255, 255, 0.22);
    border-radius: 16px;
    background: rgba(11, 17, 32, 0.92);
    margin-bottom: 8px;
    color: #fff;
  }

  .attachment strong {
    color: #fff;
  }

  .attachment span {
    color: rgba(255, 255, 255, 0.72);
  }

  .lecture-bar {
    background: rgba(69, 10, 10, 0.88);
    border-color: rgba(248, 113, 113, 0.42);
  }

  .lecture-text {
    color: #fecaca;
  }
}

/* ---------- 19. Drawing drawer ---------- */
.drawer {
  position: absolute;
  inset: 10px;
  z-index: 15;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  background: var(--sheet);
  box-shadow: var(--shadow-dialog);
  animation: dialog-in 0.32s var(--ease-out) both;
}

.drawer__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  padding: 13px 17px 11px;
  border-block-end: 1px solid var(--line);
}

.drawer__head h2 {
  margin-block-start: 2px;
  font-size: clamp(17px, 2.2vw, 22px);
  font-weight: 600;
}

.drawer__tools {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 9px 13px;
  border-block-end: 1px solid var(--line);
  background: color-mix(in srgb, var(--sheet) 62%, var(--bg));
}

.tool-group {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--sheet);
}

.tool {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-width: 32px;
  min-height: 32px;
  padding: 0 7px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 10.5px;
  line-height: 1;
  transition:
    background-color 0.18s var(--ease),
    color 0.18s var(--ease),
    border-color 0.18s var(--ease);
}

.tool:hover {
  color: var(--ink);
  background: var(--bg);
}

.tool:disabled {
  cursor: not-allowed;
  opacity: 0.35;
}

.tool:disabled:hover {
  color: var(--muted);
  background: transparent;
}

.tool.is-active {
  border-color: color-mix(in srgb, var(--accent) 35%, var(--line));
  background: var(--accent-soft);
  color: var(--accent-deep);
}

[data-theme="dark"] .tool.is-active {
  color: var(--accent);
}

.tool__label {
  display: none;
}

.swatches {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--sheet);
}

.swatch {
  width: 18px;
  height: 18px;
  padding: 0;
  border: 2px solid transparent;
  border-radius: 50%;
  background: var(--sw);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.18);
  transition: transform 0.15s var(--ease);
}

.swatch:hover {
  transform: scale(1.12);
}

.swatch.is-active {
  border-color: var(--sheet);
  outline: 1px solid var(--sw);
  outline-offset: 1px;
}

.check-btn {
  margin-inline-start: auto;
  min-height: 36px;
  font-size: 12px;
}

.canvas-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  /* يبقى ورق الرسم فاتحاً في المظهرين، كصفحة مرسومة فوق سبورة داكنة. */
  background-color: #fbf9f2;
  background-image: radial-gradient(circle at 1px 1px, rgba(19, 33, 30, 0.14) 1px, transparent 1.2px);
  background-size: 20px 20px;
  touch-action: none;
}

#drawCanvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: crosshair;
}

.canvas-hint {
  position: absolute;
  inset-block-start: 50%;
  inset-inline: 0;
  width: max-content;
  max-width: 80%;
  margin-inline: auto;
  padding: 8px 13px;
  border: 1px dashed #b9b1a0;
  border-radius: 8px;
  background: rgba(251, 249, 242, 0.92);
  color: #68766f;
  font-size: 12px;
  text-align: center;
  transform: translateY(-50%);
  pointer-events: none;
  transition: opacity 0.2s var(--ease);
}

.canvas-hint.is-hidden {
  opacity: 0;
}

.check-panel {
  position: absolute;
  inset-inline: 10px;
  inset-block-end: 10px;
  z-index: 5;
  max-height: 46%;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: var(--sheet);
  box-shadow: var(--shadow-dialog);
  animation: check-in 0.32s var(--ease-out) both;
}

.check-panel__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  border-block-end: 1px solid var(--line);
  background: color-mix(in srgb, var(--accent-soft) 38%, var(--sheet));
}

.check-panel__head strong {
  display: block;
  margin-block-start: 1px;
  font-size: 13px;
  font-weight: 600;
}

.check-panel__body {
  max-height: 240px;
  overflow-y: auto;
  padding: 12px 14px 15px;
  color: var(--ink-soft);
  font-size: 13px;
  line-height: 1.85;
}

.check-panel__body p {
  margin-block: 0 8px;
}

.check-panel__body ul {
  margin-block: 4px 8px;
  padding-inline-start: 20px;
}

.check-panel__body li {
  margin-block: 3px;
}

.check-panel__body strong {
  color: var(--ink);
}

.check-verdict {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 8px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--bg);
  color: var(--accent-deep);
  font-size: 11px;
  font-weight: 600;
}

[data-theme="dark"] .check-verdict {
  color: var(--accent);
}

.check-verdict--warn {
  color: var(--brass);
  border-color: color-mix(in srgb, var(--brass) 35%, var(--line));
}

.check-verdict--bad {
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 35%, var(--line));
}

.check-loading {
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--muted);
  font-size: 12px;
}

.check-loading .chalk-spinner {
  width: 30px;
  height: 30px;
  margin: 0;
}

.check-loading .chalk-spinner span {
  height: 10px;
  transform-origin: 1px 0;
}

.check-loading .chalk-spinner span:nth-child(1) {
  transform: rotate(0deg) translateY(-13px);
}

.check-loading .chalk-spinner span:nth-child(2) {
  transform: rotate(120deg) translateY(-13px);
}

.check-loading .chalk-spinner span:nth-child(3) {
  transform: rotate(240deg) translateY(-13px);
}

/* ---------- 20. Library dialog ---------- */
.library {
  width: min(1000px, 94vw);
  max-width: none;
  max-height: 88dvh;
  margin: auto;
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-lg);
  background: var(--sheet);
  color: var(--ink);
  box-shadow: var(--shadow-dialog);
}

.library::backdrop {
  background: rgba(7, 15, 12, 0.55);
  backdrop-filter: blur(7px);
  -webkit-backdrop-filter: blur(7px);
}

.library[open] {
  animation: dialog-in 0.35s var(--ease-out) both;
}

.library__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 24px 14px;
  border-block-end: 1px solid var(--line);
}

.library__head h2 {
  margin-block-start: 3px;
  font-size: clamp(23px, 3vw, 30px);
  font-weight: 600;
}

/* ---------- ميزات الترحيب الأربع ---------- */
.feat-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-block: 18px 4px;
}

.feat {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  padding: 14px 15px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--sheet);
  color: var(--ink);
  text-align: start;
  cursor: pointer;
  transition: transform 0.18s var(--ease), box-shadow 0.18s var(--ease), border-color 0.18s var(--ease);
}

.feat:hover {
  transform: translateY(-2px);
  border-color: var(--line-strong);
  box-shadow: var(--shadow-card, 0 6px 18px rgba(19, 33, 30, 0.10));
}

.feat .icon {
  width: 38px;
  height: 38px;
  padding: 9px;
  border-radius: 10px;
  background: var(--accent-soft);
  color: var(--accent-deep);
  margin-block-end: 4px;
}

[data-theme="dark"] .feat .icon {
  color: var(--accent);
}

.feat strong {
  font-size: 14px;
  font-weight: 700;
}

.feat span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.6;
}

@media (max-width: 760px) {
  .feat-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

/* ---------- شريط تسجيل المحاضرة ---------- */
.lecture-bar {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-block-end: 9px;
  padding: 8px 11px;
  border: 1px solid color-mix(in srgb, var(--danger, #c0392b) 35%, var(--line));
  border-radius: 10px;
  background: color-mix(in srgb, var(--danger, #c0392b) 8%, var(--sheet));
}

.lecture-dot {
  flex: 0 0 auto;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--danger, #c0392b);
  animation: lecture-pulse 1.1s ease-in-out infinite;
}

@keyframes lecture-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.45; transform: scale(0.78); }
}

.lecture-text {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  color: var(--ink-soft);
  font-size: 12.5px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lecture-stop {
  flex: 0 0 auto;
  padding: 5px 12px;
  font-size: 12px;
}

#micBtn.is-recording {
  color: var(--danger, #c0392b);
  border-color: color-mix(in srgb, var(--danger, #c0392b) 45%, transparent);
}

/* ---------- السبورة الحية: كتابة يد تظهر مع الصوت ---------- */
.title-squiggle {
  display: none;
  width: min(430px, 92%);
  height: 12px;
  margin-block-start: 4px;
  overflow: visible;
}

.title-squiggle path {
  stroke: #2456c8;
  stroke-width: 3;
  fill: none;
  stroke-linecap: round;
  stroke-dasharray: 640;
  stroke-dashoffset: 640;
}

.is-live .sheet:has(.sheet__body > #lessonView:not([hidden])) {
  background-color: #fffdf6;
}

.is-live .sheet__body:has(> #lessonView:not([hidden])) {
  background-color: #fffdf6;
  background-image: radial-gradient(circle at 1px 1px, rgba(23, 35, 59, 0.07) 1px, transparent 1.3px);
  background-size: 22px 22px;
}

.is-live .sheet__head {
  border-block-end-color: rgba(23, 35, 59, 0.10);
  background: rgba(255, 253, 246, 0.88);
}

.is-live .sheet__head h1,
.is-live .sheet__head .eyebrow {
  color: #17233b;
}

.is-live .sheet__head .eyebrow {
  color: #5b6b82;
}

.is-live .lesson__head .eyebrow {
  color: #5b6b82;
}

.is-live .lesson__head h2 {
  font-family: var(--font-hand);
  font-size: clamp(30px, 4.6vw, 46px);
  font-weight: 700;
  line-height: 1.5;
  color: #17233b;
}

.is-live .title-squiggle {
  display: block;
}

.is-live .title-squiggle path {
  animation: squiggle-draw 1.1s 0.25s var(--ease-out) both;
}

@keyframes squiggle-draw {
  to { stroke-dashoffset: 0; }
}

.is-live .lesson__summary {
  font-family: var(--font-hand);
  font-size: clamp(18px, 2.4vw, 23px);
  line-height: 1.8;
  color: #40506b;
}

.is-live .lesson__grid {
  grid-template-columns: 1fr;
}

.is-live .spine {
  display: none;
}

.is-live .step {
  border-color: transparent;
  background: transparent;
  box-shadow: none;
  padding-inline: 4px;
}

.is-live .step__ghost {
  display: none;
}

.is-live .step h3 {
  font-family: var(--font-hand);
  font-size: clamp(26px, 3.8vw, 40px);
  font-weight: 700;
  line-height: 1.55;
  color: #17233b;
}

.is-live .step__explain,
.is-live .step__explain p,
.is-live .step__explain li {
  font-family: var(--font-hand);
  font-size: clamp(20px, 2.7vw, 28px);
  line-height: 1.95;
  color: #22314d;
}

.is-live .step__explain strong {
  color: #2456c8;
}

.is-live .step__explain code {
  padding: 0 2px;
  border: none;
  background: transparent;
  color: #c2410c;
  font-family: var(--font-hand);
  font-size: 1em;
}

.is-live .step__explain a {
  color: #2456c8;
}

.w-reveal {
  display: inline-block;
  opacity: 0;
  animation: w-in 0.28s var(--ease-out) both;
}

@keyframes w-in {
  from {
    opacity: 0;
    transform: translateY(5px) rotate(-0.4deg);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.is-live .transport {
  width: min(660px, calc(100% - 24px));
  margin: 10px auto 14px;
  border-radius: 999px;
  box-shadow: 0 10px 30px rgba(23, 35, 59, 0.16);
}

.is-live .ruler {
  display: none;
}

@media (prefers-reduced-motion: reduce) {
  .is-live .title-squiggle path {
    animation: none;
    stroke-dashoffset: 0;
  }

  .w-reveal {
    animation: none;
    opacity: 1;
  }
}

@media (max-width: 680px) {
  .sheet__head {
    flex-wrap: wrap;
    row-gap: 8px;
  }

  .sheet__tools {
    flex-wrap: wrap;
  }
}

/* ---------- البطاقات والاختبار ---------- */
.study {
  width: min(720px, 94vw);
  max-width: none;
  max-height: 88dvh;
  margin: auto;
  padding-block-end: 20px;
  overflow-y: auto;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-lg);
  background: var(--sheet);
  color: var(--ink);
  box-shadow: var(--shadow-dialog);
}

.study::backdrop {
  background: rgba(7, 15, 12, 0.55);
  backdrop-filter: blur(7px);
  -webkit-backdrop-filter: blur(7px);
}

.study[open] {
  animation: dialog-in 0.35s var(--ease-out) both;
}

.study__tabs {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  padding: 12px 24px 0;
}

.study__tabs .filter-chip .icon {
  width: 15px;
  height: 15px;
  vertical-align: -3px;
}

.study__status {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 44px 24px;
  color: var(--muted);
  font-size: 13.5px;
  text-align: center;
}

.study__cards,
.study__quiz {
  padding: 16px 24px 0;
}

.flashcard {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  width: 100%;
  min-height: 230px;
  padding: 26px 22px;
  border: 1.5px dashed var(--line-strong);
  border-radius: 16px;
  background: color-mix(in srgb, var(--accent-soft) 45%, var(--sheet));
  color: var(--ink);
  text-align: center;
  cursor: pointer;
  transition: background 0.2s var(--ease), border-color 0.2s var(--ease);
}

.flashcard.is-back {
  border-style: solid;
  border-color: var(--accent);
  background: var(--accent-soft);
}

.flashcard__side {
  padding: 3px 12px;
  border-radius: 999px;
  background: var(--sheet);
  border: 1px solid var(--line);
  color: var(--accent-deep);
  font-size: 11.5px;
  font-weight: 700;
}

[data-theme="dark"] .flashcard__side {
  color: var(--accent);
}

.flashcard__text {
  font-size: clamp(18px, 3.4vw, 24px);
  font-weight: 600;
  line-height: 1.7;
}

.flashcard__hint {
  color: var(--muted);
  font-size: 11.5px;
}

.study__nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-block-start: 14px;
}

.study__count {
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 12.5px;
}

.quiz__score {
  color: var(--muted);
  font-size: 12.5px;
  margin-block-end: 6px;
}

.quiz__question {
  font-size: clamp(17px, 3vw, 21px);
  font-weight: 700;
  line-height: 1.65;
  margin-block-end: 14px;
}

.quiz__options {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.quiz__opt {
  padding: 11px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--sheet);
  color: var(--ink);
  font-size: 14px;
  text-align: start;
  cursor: pointer;
  transition: border-color 0.15s var(--ease), background 0.15s var(--ease);
}

.quiz__opt:hover:not(:disabled) {
  border-color: var(--accent);
}

.quiz__opt:disabled {
  cursor: default;
  opacity: 0.85;
}

.quiz__opt.is-correct {
  border-color: var(--accent);
  background: var(--accent-soft);
  font-weight: 700;
}

.quiz__opt.is-wrong {
  border-color: var(--danger, #c0392b);
  background: color-mix(in srgb, var(--danger, #c0392b) 10%, var(--sheet));
}

.quiz__feedback {
  min-height: 24px;
  margin-block-start: 12px;
  color: var(--ink-soft);
  font-size: 13.5px;
  line-height: 1.7;
}

.library__filters {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  padding: 12px 24px 0;
}

.filter-chip {
  padding: 5px 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--sheet);
  color: var(--muted);
  font-size: 11.5px;
  line-height: 1.5;
  transition:
    background-color 0.18s var(--ease),
    border-color 0.18s var(--ease),
    color 0.18s var(--ease);
}

.filter-chip:hover {
  border-color: var(--accent);
  color: var(--accent-deep);
}

.filter-chip.is-active {
  border-color: var(--ink);
  background: var(--ink);
  color: var(--sheet);
}

.library__grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  max-height: calc(88dvh - 165px);
  padding: 16px 24px 24px;
  overflow-y: auto;
}

.library-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 7px;
  min-height: 174px;
  padding: 15px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--sheet);
  color: var(--ink);
  text-align: start;
  box-shadow: 3px 3px 0 color-mix(in srgb, var(--ink) 5%, transparent);
  transition:
    transform 0.2s var(--ease),
    border-color 0.2s var(--ease),
    box-shadow 0.2s var(--ease);
}

.library-card:hover {
  transform: translateY(-2px);
  border-color: var(--accent);
  box-shadow: 5px 5px 0 var(--accent-soft);
}

.library-card__subject {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--accent-deep);
  font-family: var(--font-mono);
  font-size: 9.5px;
  font-weight: 500;
}

[data-theme="dark"] .library-card__subject {
  color: var(--accent);
}

.library-card__subject::before {
  content: "";
  width: 5px;
  height: 5px;
  background: var(--brass);
  transform: rotate(45deg);
}

.library-card h3 {
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 600;
  line-height: 1.55;
}

.library-card p {
  display: -webkit-box;
  overflow: hidden;
  color: var(--muted);
  font-size: 11.5px;
  line-height: 1.7;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.library-card__meta {
  margin-block-start: auto;
  color: var(--muted);
  font-size: 10px;
}

.library-empty {
  grid-column: 1 / -1;
  padding: 40px 20px;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

/* ---------- 21. Toasts ---------- */
.toast-region {
  position: fixed;
  inset-inline-start: 50%;
  inset-block-end: 22px;
  z-index: 120;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
  width: max-content;
  max-width: min(92vw, 420px);
  transform: translateX(-50%);
  pointer-events: none;
}

.toast {
  padding: 9px 14px;
  border: 1px solid color-mix(in srgb, var(--ink) 18%, transparent);
  border-radius: 8px;
  background: var(--ink);
  color: var(--sheet);
  font-size: 12px;
  line-height: 1.6;
  text-align: center;
  box-shadow: 0 12px 35px -14px rgba(0, 0, 0, 0.55);
  animation: toast-in 0.28s var(--ease-out) both;
}

.toast--accent {
  background: var(--accent-deep);
  color: var(--white);
}

.toast--error {
  background: var(--danger);
  color: var(--white);
}

.toast.is-leaving {
  animation: toast-out 0.22s var(--ease) both;
}

/* ---------- 22. Motion ---------- */
@keyframes sheet-in {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes step-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes dialog-in {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.985);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes check-in {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes toast-out {
  to {
    opacity: 0;
    transform: translateY(6px);
  }
}

@keyframes draw-line {
  to {
    stroke-dashoffset: 0;
  }
}

@keyframes fade-in {
  to {
    opacity: 1;
  }
}

@keyframes pulse-dot {
  0%,
  100% {
    opacity: 1;
    transform: scale(1);
  }
  50% {
    opacity: 0.45;
    transform: scale(0.82);
  }
}

@keyframes typing {
  0%,
  60%,
  100% {
    opacity: 0.35;
    transform: translateY(0);
  }
  30% {
    opacity: 1;
    transform: translateY(-3px);
  }
}

@keyframes chalk-write {
  0%,
  100% {
    opacity: 0.3;
    transform: translateY(-23px) scaleY(0.7);
  }
  45% {
    opacity: 1;
    transform: translateY(-23px) scaleY(1);
  }
}

/* ---------- 23. Responsive ---------- */
@media (max-width: 1240px) {
  :root {
    --chat-w: 348px;
  }

  .topbar {
    gap: 16px;
    padding-inline: 20px;
  }

  .workspace {
    padding-inline: 18px;
  }

  .icon-btn__label {
    display: none;
  }

  .icon-btn {
    min-width: 36px;
    min-height: 36px;
    padding: 0 8px;
  }
}

@media (max-width: 1060px) {
  .welcome__hero {
    grid-template-columns: minmax(0, 1fr) minmax(220px, 0.72fr);
  }

  .welcome__art svg {
    width: min(100%, 300px);
  }

  .lesson-cards {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .lesson-card:last-child {
    display: none;
  }

  .howto {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
  }
}

@media (max-width: 980px) {
  .topbar {
    position: static;
    height: auto;
    flex-wrap: wrap;
    gap: 9px;
    padding: 10px 14px;
  }

  .brand__seal {
    width: 38px;
    height: 38px;
    border-radius: 9px;
  }

  .brand__seal svg {
    width: 29px;
    height: 29px;
  }

  .brand__words strong {
    font-size: 14.5px;
  }

  .brand__words span {
    font-size: 9.5px;
  }

  .subjects {
    order: 3;
    width: 100%;
    padding: 3px;
  }

  .subject-btn {
    flex: 1;
    justify-content: center;
    min-height: 32px;
    padding-inline: 6px;
    font-size: 11.5px;
  }

  .subject-btn__name {
    display: none;
  }

  .subject-btn__code {
    font-size: 12px;
  }

  .topbar__actions {
    gap: 1px;
  }

  .ai-pill {
    min-height: 28px;
    font-size: 10px;
    padding-inline: 7px;
  }

  .mobile-tabs {
    position: sticky;
    inset-block-start: 0;
    z-index: 25;
    display: flex;
    gap: 6px;
    padding: 8px 12px;
    border-block-end: 1px solid var(--line);
    background: color-mix(in srgb, var(--bg) 92%, transparent);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
  }

  .mobile-tab {
    position: relative;
    flex: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 38px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--sheet);
    color: var(--muted);
    font-size: 12px;
    font-weight: 600;
    transition:
      background-color 0.18s var(--ease),
      color 0.18s var(--ease),
      border-color 0.18s var(--ease);
  }

  .mobile-tab.is-active {
    border-color: var(--ink);
    background: var(--ink);
    color: var(--sheet);
  }

  .tab-badge {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--brass);
  }

  .app-shell {
    height: 100dvh;
    min-height: 0;
    overflow: hidden;
  }

  .workspace {
    display: block;
    flex: 1;
    min-height: 0;
    padding: 10px 10px 10px;
    overflow: hidden;
  }

  .board-panel,
  .chat-panel {
    height: 100%;
  }

  .chat-panel {
    display: none;
  }

  .app-shell[data-mobile-view="chat"] .board-panel {
    display: none;
  }

  .app-shell[data-mobile-view="chat"] .chat-panel {
    display: flex;
  }

  .sheet {
    height: 100%;
    min-height: 0;
    border-radius: 14px;
  }

  .chat-panel {
    height: 100%;
    min-height: 0;
    border-radius: 14px;
  }

  .sheet__head {
    padding: 14px 16px 12px;
  }

  .sheet__body {
    padding: 18px 16px 24px;
  }

  .sheet__tools {
    gap: 5px;
  }

  .sheet__status {
    display: none;
  }

  .welcome__hero {
    grid-template-columns: 1fr;
    min-height: 0;
    gap: 10px;
  }

  .welcome__art {
    display: none;
  }

  .welcome__copy h2 {
    font-size: clamp(35px, 9vw, 48px);
  }

  .welcome__lead {
    font-size: 14.5px;
  }

  .lesson-shelf {
    margin-block-start: 20px;
  }

  .lesson-cards {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .lesson-card:last-child {
    display: flex;
  }

  .howto {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .howto p {
    font-size: 11px;
  }

  .lesson__grid {
    grid-template-columns: 1fr;
    gap: 0;
  }

  .spine {
    display: none;
  }

  .step {
    min-height: 0;
    padding: 19px 17px 22px;
  }

  .step__ghost {
    font-size: 120px;
    inset-block-start: -18px;
  }

  .step h3 {
    font-size: 22px;
  }

  .md {
    font-size: 14.5px;
  }

  .transport {
    flex-wrap: wrap;
    gap: 8px;
    padding: 9px 12px;
  }

  .transport__controls {
    order: 1;
  }

  .transport__extras {
    order: 2;
    margin-inline-start: auto;
  }

  .ruler {
    order: 3;
    flex-basis: 100%;
    height: 22px;
  }

  .transport__play {
    min-width: 112px;
    min-height: 36px;
    padding-inline: 9px;
    font-size: 11.5px;
  }

  .transport__play .icon {
    width: 16px;
    height: 16px;
  }

  .transport .btn--sm {
    font-size: 11.5px;
  }

  .chat-panel::before {
    inset-inline-start: 12px;
  }

  .chat-head {
    padding: 12px 14px 12px 18px;
  }

  .quick {
    padding-inline: 14px 18px;
  }

  .chat-log {
    padding: 14px 14px 16px 18px;
  }

  .composer {
    padding: 9px 14px calc(9px + env(safe-area-inset-bottom)) 18px;
  }

  .drawer {
    inset: 6px;
  }

  .drawer__tools {
    gap: 6px;
    padding: 7px 10px;
  }

  .tool__label {
    display: none;
  }

  .check-btn {
    min-height: 34px;
    padding-inline: 10px;
    font-size: 11px;
  }

  .library {
    width: 96vw;
    max-height: 92dvh;
  }

  .library__head {
    padding: 16px 18px 12px;
  }

  .library__filters {
    padding-inline: 18px;
  }

  .library__grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    max-height: calc(92dvh - 170px);
    padding: 14px 18px 20px;
  }
}

@media (max-width: 640px) {
  .brand__words span {
    display: none;
  }

  .ai-pill span:last-child {
    display: none;
  }

  .ai-pill {
    display: none;
  }

  .welcome__actions {
    align-items: flex-start;
    flex-direction: column;
    gap: 8px;
  }

  .welcome__note {
    font-size: 10.5px;
  }

  .lesson-cards {
    grid-template-columns: 1fr;
  }

  .lesson-card {
    min-height: 112px;
  }

  .lesson-card:last-child {
    display: flex;
  }

  .lesson__head h2 {
    font-size: 25px;
  }

  .lesson__summary {
    font-size: 12.5px;
  }

  .step__meta {
    gap: 5px;
  }

  .step__count,
  .step__tag {
    font-size: 9.5px;
    min-height: 22px;
  }

  .step h3 {
    font-size: 20px;
  }

  .md {
    font-size: 14px;
  }

  .code-card code {
    font-size: 12px;
  }

  .table-wrap table {
    font-size: 12px;
  }

  .transport__controls {
    width: 100%;
    min-width: 0;
    justify-content: space-between;
  }

  .transport__extras {
    margin-inline-start: 0;
  }

  .ruler {
    flex: 1;
    flex-basis: auto;
    min-width: 0;
    height: 22px;
  }

  .transport__play {
    flex: 1;
    max-width: 160px;
  }

  .drawer {
    inset: 0;
    border-radius: 0;
  }

  .drawer__head {
    padding: 10px 12px;
  }

  .drawer__head h2 {
    font-size: 15px;
  }

  .drawer__tools {
    gap: 5px;
    padding: 6px 8px;
  }

  .tool {
    min-width: 30px;
    min-height: 30px;
    padding: 0 5px;
  }

  .swatches {
    gap: 3px;
    padding: 3px 4px;
  }

  .swatch {
    width: 15px;
    height: 15px;
  }

  .check-btn {
    margin-inline-start: 0;
    width: 100%;
    order: 10;
  }

  .library__grid {
    grid-template-columns: 1fr;
  }

  .library-card {
    min-height: 0;
  }

  .library__filters {
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
  }

  .library__filters::-webkit-scrollbar {
    display: none;
  }

  .filter-chip {
    flex: 0 0 auto;
  }

  .toast-region {
    inset-block-end: 14px;
  }

  .check-panel {
    inset-inline: 6px;
    inset-block-end: 6px;
    max-height: 50%;
  }
}

@media (max-width: 400px) {
  .brand__words strong {
    font-size: 13px;
  }

  .brand__seal {
    width: 34px;
    height: 34px;
  }

  .subject-btn {
    font-size: 10.5px;
  }

  .sheet__head {
    padding-inline: 12px;
  }

  .sheet__body {
    padding-inline: 12px;
  }

  .welcome__copy h2 {
    font-size: 31px;
  }

  .transport .btn--sm span {
    display: none;
  }

  .transport__play {
    min-width: 0;
  }
}

/* ---------- 24. Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  .art-draw {
    stroke-dashoffset: 0;
  }

  .art-label {
    opacity: 1;
  }
}
