/* ============================================================
   NUWAA — نواة · Design System
   Clean premium scientific identity · light/dark · RTL/LTR (logical properties)
   System fonts only · zero external requests · reduced-motion aware
   ============================================================ */

:root {
  /* identity */
  --blue-700: #1d4ed8; --blue-800: #1e40af; --blue-100: #dbeafe; --blue-50: #eff6ff;
  --cyan-600: #0891b2; --cyan-500: #06b6d4; --cyan-400: #22d3ee;
  /* surfaces (light) */
  --bg: #f6f8fb;
  --surface: #ffffff;
  --surface-2: #eef2f7;
  --surface-3: #e4e9f1;
  --border: #dde4ee;
  --border-strong: #c4cedd;
  /* ink */
  --ink: #0f1c2e;
  --ink-2: #33415c;
  --muted: #5b6b82;
  --on-primary: #ffffff;
  /* semantic */
  --ok: #15803d; --ok-bg: #ecfdf3; --warn: #b45309; --warn-bg: #fef6e6; --danger: #b91c1c; --danger-bg: #fef1f1; --info-bg: var(--blue-50);
  /* effects */
  --radius: 14px; --radius-sm: 9px; --radius-lg: 20px;
  --shadow-sm: 0 1px 2px rgba(15, 28, 46, .06), 0 1px 3px rgba(15, 28, 46, .08);
  --shadow-md: 0 6px 16px rgba(15, 28, 46, .08), 0 2px 6px rgba(15, 28, 46, .06);
  --shadow-lg: 0 24px 60px rgba(15, 28, 46, .18);
  --focus: 0 0 0 3px rgba(6, 182, 212, .45);
  --header-h: 60px;
  --sidebar-w: 264px;
  --font: "Segoe UI", "Noto Kufi Arabic", "Noto Sans Arabic", Tahoma, "Helvetica Neue", system-ui, Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --blue-700: #60a5fa; --blue-800: #93c5fd; --blue-100: #1e3a5f; --blue-50: #16233b;
  --cyan-600: #22d3ee; --cyan-500: #22d3ee; --cyan-400: #67e8f9;
  --bg: #070d1a;
  --surface: #101a2e;
  --surface-2: #17233c;
  --surface-3: #1f2d4d;
  --border: #21304f;
  --border-strong: #32466e;
  --ink: #e9eef8;
  --ink-2: #b9c6de;
  --muted: #8d9db9;
  --on-primary: #081226;
  --ok: #4ade80; --ok-bg: #10261a; --warn: #fbbf24; --warn-bg: #2a1f0a; --danger: #f87171; --danger-bg: #2a1214; --info-bg: #12224a;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.4);
  --shadow-md: 0 8px 22px rgba(0,0,0,.45);
  --shadow-lg: 0 30px 70px rgba(0,0,0,.55);
  --focus: 0 0 0 3px rgba(34, 211, 238, .4);
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --blue-700: #60a5fa; --blue-800: #93c5fd; --blue-100: #1e3a5f; --blue-50: #16233b;
    --cyan-600: #22d3ee; --cyan-500: #22d3ee; --cyan-400: #67e8f9;
    --bg: #070d1a; --surface: #101a2e; --surface-2: #17233c; --surface-3: #1f2d4d;
    --border: #21304f; --border-strong: #32466e;
    --ink: #e9eef8; --ink-2: #b9c6de; --muted: #8d9db9; --on-primary: #081226;
    --ok: #4ade80; --ok-bg: #10261a; --warn: #fbbf24; --warn-bg: #2a1f0a; --danger: #f87171; --danger-bg: #2a1214; --info-bg: #12224a;
    --shadow-sm: 0 1px 2px rgba(0,0,0,.4); --shadow-md: 0 8px 22px rgba(0,0,0,.45); --shadow-lg: 0 30px 70px rgba(0,0,0,.55);
    --focus: 0 0 0 3px rgba(34, 211, 238, .4);
    color-scheme: dark;
  }
}

/* ---------- base ---------- */
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
[hidden] { display: none !important; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: var(--font); font-size: 16px; line-height: 1.6;
  -webkit-font-smoothing: antialiased; text-wrap: pretty;
}
h1, h2, h3, h4 { line-height: 1.25; letter-spacing: -0.015em; margin: 0 0 .5em; text-wrap: balance; }
h1 { font-size: clamp(1.7rem, 4vw, 2.6rem); font-weight: 750; }
h2 { font-size: clamp(1.3rem, 2.6vw, 1.7rem); font-weight: 700; }
h3 { font-size: 1.05rem; font-weight: 650; }
p { margin: 0 0 1em; color: var(--ink-2); }
a { color: var(--blue-700); text-decoration: none; }
a:hover { text-decoration: underline; }
code, kbd, samp { font-family: var(--mono); font-size: .88em; background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; padding: .1em .4em; }
pre { font-family: var(--mono); background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 1rem; overflow-x: auto; direction: ltr; text-align: start; }
:focus-visible { outline: 2.5px solid var(--cyan-500); outline-offset: 2px; border-radius: 4px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip-link { position: absolute; inset-block-start: 8px; inset-inline-start: 8px; z-index: 100; background: var(--surface); border: 1px solid var(--border-strong); padding: .6rem 1rem; border-radius: var(--radius-sm); transform: translateY(-200%); transition: transform .18s ease; }
.skip-link:focus { transform: translateY(0); }

/* ---------- shell layout ---------- */
.app-header {
  position: sticky; inset-block-start: 0; z-index: 40; height: var(--header-h);
  display: flex; align-items: center; gap: .75rem; padding-inline: .9rem;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-block-end: 1px solid var(--border);
}
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 42px; height: 42px; border: 1px solid transparent; border-radius: var(--radius-sm); background: transparent; color: var(--ink-2); cursor: pointer; transition: background .15s, color .15s, border-color .15s; }
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.icon-btn:focus-visible { box-shadow: var(--focus); outline: none; }
.brand { display: flex; align-items: center; gap: .6rem; min-width: 0; }
.brand-mark { width: 38px; height: 38px; flex: 0 0 auto; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.brand-name { font-weight: 800; font-size: 1.02rem; letter-spacing: .01em; white-space: nowrap; }
.brand-name small { color: var(--muted); font-weight: 600; }
.brand-tag { font-size: .68rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.header-spacer { flex: 1; }
.lang-toggle, .theme-toggle { display: inline-flex; gap: .4rem; align-items: center; height: 38px; padding-inline: .8rem; border: 1px solid var(--border-strong); background: var(--surface); color: var(--ink-2); border-radius: 999px; font-family: var(--font); font-size: .82rem; font-weight: 650; cursor: pointer; transition: border-color .15s, transform .12s; }
.lang-toggle:hover, .theme-toggle:hover { border-color: var(--cyan-500); }
.lang-toggle:active, .theme-toggle:active { transform: scale(.96); }
.lang-toggle b { color: var(--blue-700); }

.sidebar {
  position: fixed; inset-block-start: var(--header-h); inset-block-end: 0; inset-inline-start: 0;
  width: var(--sidebar-w); z-index: 35; background: var(--surface); border-inline-end: 1px solid var(--border);
  overflow-y: auto; padding: .9rem .7rem 2rem; transition: transform .22s ease;
  display: flex; flex-direction: column; gap: .25rem;
}
.sidebar[hidden] { display: none; }
.nav-section-label { font-size: .68rem; font-weight: 750; text-transform: uppercase; letter-spacing: .09em; color: var(--muted); padding: .85rem .65rem .3rem; }
.nav-link { display: flex; align-items: center; gap: .65rem; padding: .52rem .65rem; border-radius: var(--radius-sm); color: var(--ink-2); font-size: .92rem; font-weight: 550; border: 1px solid transparent; transition: background .14s, color .14s; text-decoration: none; }
.nav-link svg { flex: 0 0 auto; opacity: .85; }
.nav-link:hover { background: var(--surface-2); color: var(--ink); text-decoration: none; }
.nav-link[aria-current="page"] { background: linear-gradient(135deg, var(--blue-50), color-mix(in srgb, var(--cyan-500) 10%, var(--surface))); border-color: color-mix(in srgb, var(--blue-700) 25%, transparent); color: var(--blue-800); font-weight: 700; }
:root[data-theme="dark"] .nav-link[aria-current="page"] { color: var(--blue-800); }
.scrim { position: fixed; inset: 0; z-index: 34; background: rgba(7, 13, 26, .5); backdrop-filter: blur(2px); }

.main-wrap { padding-inline-start: var(--sidebar-w); }
.main-content { max-width: 1200px; margin-inline: auto; padding: 1.4rem clamp(1rem, 3vw, 2rem) 4rem; }

/* ---------- footer ---------- */
.app-footer { border-block-start: 1px solid var(--border); background: var(--surface); padding: 1.1rem clamp(1rem, 3vw, 2rem); display: flex; flex-wrap: wrap; gap: .8rem; align-items: center; justify-content: space-between; font-size: .8rem; color: var(--muted); }
.app-footer .attribution { font-size: .88rem; font-weight: 750; color: var(--ink); letter-spacing: .01em; }
.app-footer .attribution b { color: var(--blue-700); }
.app-footer .sep { margin-inline: .5rem; opacity: .5; }

/* ---------- components ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); padding: 1.1rem; }
.card-flush { padding: 0; overflow: hidden; }
.card-title { display: flex; align-items: center; gap: .5rem; font-size: .8rem; font-weight: 800; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); margin-block-end: .7rem; }
.btn { display: inline-flex; align-items: center; gap: .45rem; font-family: var(--font); font-size: .9rem; font-weight: 700; border-radius: var(--radius-sm); border: 1px solid var(--border-strong); background: var(--surface); color: var(--ink); padding: .6rem 1.05rem; cursor: pointer; transition: transform .12s, box-shadow .15s, background .15s, border-color .15s; text-decoration: none; }
.btn:hover { border-color: var(--blue-700); box-shadow: var(--shadow-sm); text-decoration: none; }
.btn:active { transform: translateY(1px) scale(.99); }
.btn-primary { background: linear-gradient(160deg, var(--blue-700), var(--blue-800)); border-color: transparent; color: var(--on-primary); box-shadow: var(--shadow-md); }
.btn-primary:hover { filter: brightness(1.07); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--blue-700); }
.btn-ghost:hover { background: var(--blue-50); }
.btn-danger { background: var(--danger-bg); border-color: color-mix(in srgb, var(--danger) 40%, transparent); color: var(--danger); }
.btn-sm { padding: .38rem .75rem; font-size: .82rem; }
.btn[disabled] { opacity: .5; cursor: not-allowed; transform: none; box-shadow: none; }
.chip { display: inline-flex; align-items: center; gap: .35rem; font-size: .75rem; font-weight: 700; padding: .28rem .65rem; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); color: var(--ink-2); white-space: nowrap; }
.badge { display: inline-flex; align-items: center; font-size: .68rem; font-weight: 800; letter-spacing: .05em; padding: .16rem .5rem; border-radius: 6px; text-transform: uppercase; }
.tier-1 { background: var(--ok-bg); color: var(--ok); border: 1px solid color-mix(in srgb, var(--ok) 35%, transparent); }
.tier-2 { background: var(--warn-bg); color: var(--warn); border: 1px solid color-mix(in srgb, var(--warn) 35%, transparent); }
.tier-3 { background: var(--surface-2); color: var(--muted); border: 1px solid var(--border-strong); }

.field { display: flex; flex-direction: column; gap: .28rem; margin-block-end: .85rem; }
.field label { font-size: .82rem; font-weight: 700; color: var(--ink); }
.field .help { font-size: .74rem; color: var(--muted); line-height: 1.45; }
.field .error-text { font-size: .76rem; color: var(--danger); font-weight: 650; }
input[type="text"], input[type="number"], input[type="search"], select, textarea { font-family: var(--font); font-size: .92rem; color: var(--ink); background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius-sm); padding: .55rem .7rem; transition: border-color .15s, box-shadow .15s; width: 100%; }
textarea { resize: vertical; min-height: 90px; line-height: 1.5; }
:is(input, select, textarea):focus { outline: none; border-color: var(--cyan-500); box-shadow: var(--focus); }
:is(input, select, textarea)[aria-invalid="true"] { border-color: var(--danger); }
.check { display: flex; align-items: center; gap: .5rem; cursor: pointer; font-size: .9rem; }
.check input { width: 18px; height: 18px; accent-color: var(--blue-700); }
.segmented { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); padding: 3px; border-radius: 999px; gap: 2px; }
.segmented button { border: none; background: transparent; padding: .35rem .95rem; border-radius: 999px; font-family: var(--font); font-weight: 650; font-size: .82rem; color: var(--muted); cursor: pointer; }
.segmented button[aria-pressed="true"] { background: var(--surface); color: var(--blue-800); box-shadow: var(--shadow-sm); }

.tabs { display: flex; gap: .25rem; border-block-end: 2px solid var(--border); margin-block-end: 1rem; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { border: none; background: none; padding: .55rem .9rem; font-family: var(--font); font-size: .88rem; font-weight: 650; color: var(--muted); cursor: pointer; border-block-end: 2px solid transparent; margin-block-end: -2px; white-space: nowrap; }
.tab[aria-selected="true"] { color: var(--blue-800); border-color: var(--blue-700); }

.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius-sm); }
table { border-collapse: collapse; width: 100%; font-size: .85rem; }
th, td { text-align: start; padding: .5rem .7rem; border-block-end: 1px solid var(--border); }
thead th { background: var(--surface-2); font-size: .73rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
tbody tr:nth-child(even) { background: color-mix(in srgb, var(--surface-2) 45%, transparent); }
.num { font-family: var(--mono); direction: ltr; unicode-bidi: embed; text-align: end; }

.grid { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.stack { display: flex; flex-direction: column; gap: .75rem; }
.row { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: .75rem; flex-wrap: wrap; }
.muted { color: var(--muted); font-size: .85rem; }
.mono { font-family: var(--mono); }
.divider { height: 1px; background: var(--border); border: none; margin-block: 1rem; }

.notice { display: flex; gap: .6rem; align-items: flex-start; border-radius: var(--radius-sm); padding: .7rem .8rem; border: 1px solid; font-size: .86rem; }
.notice-info { background: var(--info-bg); border-color: color-mix(in srgb, var(--blue-700) 30%, transparent); color: var(--ink-2); }
.notice-warn { background: var(--warn-bg); border-color: color-mix(in srgb, var(--warn) 35%, transparent); color: var(--ink-2); }
.notice-ok { background: var(--ok-bg); border-color: color-mix(in srgb, var(--ok) 35%, transparent); color: var(--ink-2); }
.notice-danger { background: var(--danger-bg); border-color: color-mix(in srgb, var(--danger) 35%, transparent); color: var(--ink-2); }

.progress { height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.progress > div { height: 100%; width: 0%; background: linear-gradient(90deg, var(--blue-700), var(--cyan-500)); transition: width .25s ease; }
@keyframes spin { to { transform: rotate(360deg); } }
.spinner { width: 20px; height: 20px; border: 2px solid var(--border-strong); border-block-start-color: var(--blue-700); border-radius: 50%; animation: spin .7s linear infinite; }

.toast-region { position: fixed; inset-block-end: 18px; inset-inline-end: 18px; z-index: 60; display: flex; flex-direction: column; gap: .5rem; max-width: min(380px, 90vw); }
.toast { background: var(--surface); border: 1px solid var(--border-strong); border-inline-start: 4px solid var(--blue-700); box-shadow: var(--shadow-md); padding: .65rem .85rem; border-radius: var(--radius-sm); font-size: .86rem; animation: toast-in .25s ease; }
.toast-error { border-inline-start-color: var(--danger); }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } }

.modal-overlay { position: fixed; inset: 0; z-index: 55; background: rgba(7,13,26,.55); backdrop-filter: blur(3px); display: flex; align-items: center; justify-content: center; padding: 1rem; }
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); max-width: 560px; width: 100%; max-height: 88vh; overflow: auto; padding: 1.4rem; }
.modal h2 { margin-block-end: .4rem; }

/* ---------- hero & marketing ---------- */
.hero { position: relative; overflow: hidden; border: 1px solid var(--border); border-radius: var(--radius-lg); padding: clamp(1.6rem, 4vw, 3.2rem); background: radial-gradient(1200px 500px at 85% -10%, color-mix(in srgb, var(--cyan-500) 16%, transparent), transparent 60%), radial-gradient(900px 500px at -15% 110%, color-mix(in srgb, var(--blue-700) 16%, transparent), transparent 55%), var(--surface); box-shadow: var(--shadow-md); margin-block-end: 1.4rem; }
.hero-badge { display: inline-flex; align-items: center; gap: .45rem; font-size: .76rem; font-weight: 800; color: var(--blue-800); background: var(--blue-50); border: 1px solid color-mix(in srgb, var(--blue-700) 30%, transparent); padding: .35rem .8rem; border-radius: 999px; margin-block-end: 1rem; }
.hero h1 { max-width: 20ch; }
.hero .accent { color: transparent; background: linear-gradient(120deg, var(--blue-700), var(--cyan-600)); -webkit-background-clip: text; background-clip: text; }
.hero p.lead { font-size: 1.08rem; color: var(--ink-2); max-width: 62ch; }
.hero-ctas { display: flex; gap: .7rem; flex-wrap: wrap; margin-block: 1.2rem; }
.chip-row { display: flex; gap: .5rem; flex-wrap: wrap; }
.section { margin-block: 2rem; }
.section-head { display: flex; align-items: end; justify-content: space-between; gap: 1rem; margin-block-end: .9rem; }
.step-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: .9rem; counter-reset: step; }
.step-card { position: relative; padding: 1rem; padding-block-start: 2.1rem; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.step-card::before { counter-increment: step; content: counter(step); position: absolute; inset-block-start: .8rem; inset-inline-start: .9rem; width: 1.6rem; height: 1.6rem; border-radius: 8px; background: linear-gradient(140deg, var(--blue-700), var(--cyan-600)); color: #fff; font-size: .85rem; font-weight: 800; display: flex; align-items: center; justify-content: center; }
.arch-card { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); padding: .85rem; display: flex; flex-direction: column; gap: .4rem; transition: transform .16s, box-shadow .16s; }
.arch-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); }
.arch-card h3 { margin: 0; font-size: .95rem; }
.path-card { border: 1px solid var(--border); border-radius: var(--radius); padding: 1.1rem; background: var(--surface); display: flex; flex-direction: column; gap: .5rem; }
.path-card.beginner { border-block-start: 4px solid var(--ok); }
.path-card.advanced { border-block-start: 4px solid var(--blue-700); }

/* ---------- studio diagram ---------- */
.diagram-canvas { width: 100%; border: 1px dashed var(--border-strong); border-radius: var(--radius-sm); background: var(--surface-2); direction: ltr; }
.config-grid { display: grid; grid-template-columns: 1fr 380px; gap: 1.1rem; align-items: start; }
.param-pill { font-family: var(--mono); font-size: .85rem; background: var(--surface-2); border-radius: 8px; padding: .15rem .5rem; direction: ltr; unicode-bidi: embed; }

/* ---------- charts & canvases ---------- */
.chart-box { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); padding: .9rem; }
.chart-canvas { width: 100%; height: 220px; direction: ltr; }
.chart-canvas.tall { height: 300px; }
.hm-canvas { width: 100%; image-rendering: pixelated; direction: ltr; border-radius: var(--radius-sm); border: 1px solid var(--border); }

/* ---------- academy ---------- */
.level-chip { font-size: .7rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.level-beginner { color: var(--ok); } .level-intermediate { color: var(--warn); } .level-advanced { color: var(--blue-700); }
.lesson-row { display: flex; align-items: center; gap: .7rem; padding: .6rem .7rem; border-radius: var(--radius-sm); border: 1px solid transparent; text-decoration: none; color: var(--ink-2); }
.lesson-row:hover { background: var(--surface-2); text-decoration: none; }
.lesson-row .tick { width: 20px; height: 20px; border-radius: 50%; border: 2px solid var(--border-strong); flex: 0 0 auto; display: flex; align-items: center; justify-content: center; color: transparent; }
.lesson-row[data-done="true"] .tick { background: var(--ok); border-color: var(--ok); color: #fff; }
.lesson-layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 1.2rem; align-items: start; }
.prose h2 { font-size: 1.15rem; margin-block: 1.2rem .4rem; }
.prose p, .prose li { color: var(--ink-2); }
.math-block { direction: ltr; unicode-bidi: embed; font-family: var(--mono); background: var(--surface-2); border-inline-start: 3px solid var(--cyan-600); padding: .7rem .9rem; border-radius: var(--radius-sm); overflow-x: auto; font-size: .9rem; margin-block: .5rem; }
.check-option { display: flex; gap: .55rem; align-items: flex-start; text-align: start; width: 100%; border: 1px solid var(--border-strong); background: var(--surface); border-radius: var(--radius-sm); padding: .6rem .75rem; font-family: var(--font); cursor: pointer; transition: border-color .15s; font-size: .9rem; }
.check-option:hover { border-color: var(--blue-700); }
.check-option[data-state="correct"] { border-color: var(--ok); background: var(--ok-bg); }
.check-option[data-state="wrong"] { border-color: var(--danger); background: var(--danger-bg); }

/* ---------- playground chat ---------- */
.chat-log { display: flex; flex-direction: column; gap: .6rem; max-height: 380px; overflow-y: auto; padding: .6rem; background: var(--surface-2); border-radius: var(--radius); border: 1px solid var(--border); }
.msg { max-width: 82%; padding: .55rem .8rem; border-radius: 14px; font-size: .92rem; line-height: 1.55; white-space: pre-wrap; }
.msg-user { align-self: flex-end; background: var(--blue-700); color: var(--on-primary); border-end-end-radius: 4px; }
.msg-model { align-self: flex-start; background: var(--surface); border: 1px solid var(--border); border-end-start-radius: 4px; }
.token-chip { font-family: var(--mono); font-size: .72rem; background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; padding: .1rem .35rem; margin: .1rem; display: inline-block; }

/* ---------- misc views ---------- */
.kv { display: grid; grid-template-columns: auto 1fr; gap: .2rem .9rem; font-size: .87rem; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; color: var(--ink); font-family: var(--mono); direction: ltr; unicode-bidi: embed; text-align: start; }
.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .45rem; }
.split-bar { display: flex; height: 26px; border-radius: 8px; overflow: hidden; border: 1px solid var(--border-strong); font-size: .72rem; font-weight: 800; color: #fff; }
.split-train { background: var(--blue-700); } .split-val { background: var(--cyan-600); } .split-test { background: var(--muted); }
.usage-bar { height: 12px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.usage-bar > div { height: 100%; background: linear-gradient(90deg, var(--cyan-600), var(--blue-700)); }
.danger-zone { border: 1.5px dashed color-mix(in srgb, var(--danger) 55%, transparent); border-radius: var(--radius); padding: 1rem; }
.docs-layout { display: grid; grid-template-columns: 250px minmax(0, 1fr); gap: 1.2rem; align-items: start; }
.docs-nav { display: flex; flex-direction: column; gap: .2rem; position: sticky; inset-block-start: calc(var(--header-h) + 1rem); max-height: 70vh; overflow: auto; }
.docs-nav button { text-align: start; border: none; background: none; padding: .45rem .6rem; border-radius: var(--radius-sm); cursor: pointer; font-family: var(--font); font-size: .86rem; color: var(--ink-2); }
.docs-nav button:hover { background: var(--surface-2); }
.docs-nav button[aria-current="true"] { background: var(--blue-50); color: var(--blue-800); font-weight: 700; }
.docs-body { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: clamp(1rem, 3vw, 1.8rem); }
.docs-body h1 { font-size: 1.5rem; } .docs-body h2 { font-size: 1.2rem; margin-block-start: 1.4rem; } .docs-body h3 { margin-block-start: 1rem; }
.docs-body table { font-size: .82rem; }
.docs-body a { font-weight: 600; }
.empty-state { text-align: center; padding: 2.4rem 1rem; color: var(--muted); }
.empty-state .big { font-size: 2.2rem; line-height: 1; margin-block-end: .5rem; }
canvas { max-width: 100%; }

/* ---------- responsive ---------- */
@media (max-width: 1180px) {
  :root { --sidebar-w: 230px; }
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .step-grid { grid-template-columns: repeat(2, 1fr); }
  .config-grid, .lesson-layout, .docs-layout { grid-template-columns: 1fr; }
  .docs-nav { position: static; flex-direction: row; overflow-x: auto; max-height: none; }
}
@media (max-width: 900px) {
  .sidebar { transform: translateX(-105%); box-shadow: var(--shadow-lg); width: min(300px, 85vw); }
  [dir="rtl"] .sidebar { transform: translateX(105%); }
  .sidebar.open { transform: translateX(0); }
  .main-wrap { padding-inline-start: 0; }
  .brand-tag { display: none; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .app-footer { flex-direction: column; text-align: center; }
  .main-content { padding-block-start: 1rem; }
}
@media (max-width: 560px) {
  .grid-4 { grid-template-columns: 1fr; }
  .step-grid { grid-template-columns: 1fr; }
  .hero-ctas .btn { flex: 1 1 auto; justify-content: center; }
  .msg { max-width: 95%; }
}

/* ---------- print (documentation) ---------- */
@media print {
  .app-header, .sidebar, .app-footer, .skip-link, .toast-region, .docs-nav, .no-print { display: none !important; }
  .main-wrap { padding: 0; }
  .docs-layout, .main-content { display: block; max-width: none; padding: 0; }
  .docs-body { border: none; padding: 0; }
  body { background: #fff; color: #000; font-size: 11pt; }
  a { color: #000; text-decoration: underline; }
}

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

/* ---------- forced colors (Windows High Contrast) ---------- */
@media (forced-colors: active) {
  .btn, .icon-btn, .nav-link, .quiz-opt, .chip, input, select, textarea { border: 1px solid CanvasText; }
  .btn-primary, .nav-link.active { background: Highlight; color: HighlightText; }
  :focus-visible { outline: 2px solid Highlight; outline-offset: 2px; }
  .chart-canvas { border: 1px solid CanvasText; }
}
