:root {
  --bg: #F4F6FF;
  --surface: #FFFFFF;
  --surface-2: #EEF1FF;
  --text: #191D3A;
  --muted: #5C6488;
  --line: #DFE4F7;
  --primary: #5B4BFF;
  --primary-edge: #3D30C7;
  --primary-soft: #EAE8FF;
  --on-primary: #FFFFFF;
  --good: #12B76A;
  --good-edge: #0B8A4E;
  --good-soft: #DFF8EB;
  --good-ink: #065F46;
  --bad: #F04463;
  --bad-edge: #C22B47;
  --bad-soft: #FFE7EB;
  --bad-ink: #C22B47;
  --xp: #FFB020;
  --xp-soft: #FFF3D1;
  --xp-ink: #8A4B08;
  --info: #0EA5E9;
  --info-soft: #E0F4FE;
  --info-ink: #0369A1;
  --on-xp: #191D3A;
  --shadow: 0 10px 28px rgba(25, 29, 58, .08);
  --radius: 20px;
  --tap: 56px;
  --font: "Tajawal", "Segoe UI", Tahoma, sans-serif;
  --a1: #5B4BFF; --a1-on: #FFFFFF; --a1-ink: #3D30C7;
  --a2: #0EA5E9; --a2-on: #191D3A; --a2-ink: #0369A1;
  --a3: #F97316; --a3-on: #191D3A; --a3-ink: #C2410C;
  --a4: #12B76A; --a4-on: #191D3A; --a4-ink: #065F46;
  --b1: #EC4899; --b1-on: #191D3A; --b1-ink: #BE185D;
  --b2: #F59E0B; --b2-on: #191D3A; --b2-ink: #B45309;
  --b3: #2563EB; --b3-on: #FFFFFF; --b3-ink: #1D4ED8;
  --b4: #E11D48; --b4-on: #FFFFFF; --b4-ink: #BE123C;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0E1124;
    --surface: #191D3B;
    --surface-2: #222852;
    --text: #F3F5FF;
    --muted: #A6ADD3;
    --line: #2F3668;
    --primary: #8B80FF;
    --primary-edge: #5B4BFF;
    --primary-soft: #2A2A66;
    --on-primary: #0E1124;
    --good: #34D399;
    --good-edge: #12B76A;
    --good-soft: #103B2C;
    --good-ink: #34D399;
    --bad: #FF6B84;
    --bad-edge: #F04463;
    --bad-soft: #47182A;
    --bad-ink: #FF6B84;
    --xp: #FFC24D;
    --xp-soft: #3D3214;
    --xp-ink: #FFC24D;
    --info: #38BDF8;
    --info-soft: #0F3247;
    --info-ink: #38BDF8;
    --on-xp: #191D3A;
    --shadow: 0 12px 32px rgba(0, 0, 0, .35);
    --a1: #8B80FF; --a1-on: #0E1124; --a1-ink: #8B80FF;
    --a2: #38BDF8; --a2-on: #0E1124; --a2-ink: #38BDF8;
    --a3: #FB923C; --a3-on: #0E1124; --a3-ink: #FB923C;
    --a4: #34D399; --a4-on: #0E1124; --a4-ink: #34D399;
    --b1: #F472B6; --b1-on: #0E1124; --b1-ink: #F472B6;
    --b2: #FBBF24; --b2-on: #0E1124; --b2-ink: #FBBF24;
    --b3: #60A5FA; --b3-on: #0E1124; --b3-ink: #60A5FA;
    --b4: #FB7185; --b4-on: #0E1124; --b4-ink: #FB7185;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0E1124;
  --surface: #191D3B;
  --surface-2: #222852;
  --text: #F3F5FF;
  --muted: #A6ADD3;
  --line: #2F3668;
  --primary: #8B80FF;
  --primary-edge: #5B4BFF;
  --primary-soft: #2A2A66;
  --on-primary: #0E1124;
  --good: #34D399;
  --good-edge: #12B76A;
  --good-soft: #103B2C;
  --good-ink: #34D399;
  --bad: #FF6B84;
  --bad-edge: #F04463;
  --bad-soft: #47182A;
  --bad-ink: #FF6B84;
  --xp: #FFC24D;
  --xp-soft: #3D3214;
  --xp-ink: #FFC24D;
  --info: #38BDF8;
  --info-soft: #0F3247;
  --info-ink: #38BDF8;
  --on-xp: #191D3A;
  --shadow: 0 12px 32px rgba(0, 0, 0, .35);
  --a1: #8B80FF; --a1-on: #0E1124; --a1-ink: #8B80FF;
  --a2: #38BDF8; --a2-on: #0E1124; --a2-ink: #38BDF8;
  --a3: #FB923C; --a3-on: #0E1124; --a3-ink: #FB923C;
  --a4: #34D399; --a4-on: #0E1124; --a4-ink: #34D399;
  --b1: #F472B6; --b1-on: #0E1124; --b1-ink: #F472B6;
  --b2: #FBBF24; --b2-on: #0E1124; --b2-ink: #FBBF24;
  --b3: #60A5FA; --b3-on: #0E1124; --b3-ink: #60A5FA;
  --b4: #FB7185; --b4-on: #0E1124; --b4-ink: #FB7185;
  color-scheme: dark;
}

:root[data-theme="light"] { color-scheme: light; }

.accent-a1 { --unit: var(--a1); --on-unit: var(--a1-on); --unit-ink: var(--a1-ink); }
.accent-a2 { --unit: var(--a2); --on-unit: var(--a2-on); --unit-ink: var(--a2-ink); }
.accent-a3 { --unit: var(--a3); --on-unit: var(--a3-on); --unit-ink: var(--a3-ink); }
.accent-a4 { --unit: var(--a4); --on-unit: var(--a4-on); --unit-ink: var(--a4-ink); }
.accent-b1 { --unit: var(--b1); --on-unit: var(--b1-on); --unit-ink: var(--b1-ink); }
.accent-b2 { --unit: var(--b2); --on-unit: var(--b2-on); --unit-ink: var(--b2-ink); }
.accent-b3 { --unit: var(--b3); --on-unit: var(--b3-on); --unit-ink: var(--b3-ink); }
.accent-b4 { --unit: var(--b4); --on-unit: var(--b4-on); --unit-ink: var(--b4-ink); }

* { box-sizing: border-box; }
html { max-width: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  background:
    radial-gradient(720px 280px at 100% -8%, color-mix(in srgb, var(--primary) 22%, transparent), transparent 60%),
    var(--bg);
  color: var(--text);
  font: 17px/1.65 var(--font);
  text-rendering: optimizeLegibility;
}
img, svg { max-width: 100%; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; -webkit-tap-highlight-color: transparent; -webkit-user-select: none; user-select: none; }
a { color: var(--primary); font-weight: 700; }
:root[data-theme="dark"] a,
:root:not([data-theme="light"]) a { color: var(--primary); }
h1, h2, h3, p { overflow-wrap: anywhere; }
h1 { font-size: clamp(1.8rem, 4vw, 2.5rem); line-height: 1.25; margin: 0; font-weight: 800; }
h2 { font-size: 1.35rem; line-height: 1.35; margin: 0; font-weight: 800; }
h3 { font-size: 1.05rem; margin: 0; font-weight: 800; }
p { margin: 0; }
ul, ol { margin: 0; padding: 0; }
[hidden] { display: none !important; }
bdi { unicode-bidi: isolate; }
.rich { min-width: 0; }
.rich bdi[dir="ltr"] {
  direction: ltr;
  unicode-bidi: isolate;
  display: inline-block;
  max-width: 100%;
  overflow-wrap: anywhere;
  vertical-align: bottom;
}

/* In-text data tables ("1 — سعد — الفصل 2" lines) rendered as a small card. */
.rich.has-table { display: block; }
.rich-line { display: block; }
.mini-table {
  display: block;
  margin: 6px 0 12px;
  max-width: 100%;
  font-size: 16px;
  font-weight: 500;
  line-height: 1.5;
  color: var(--text);
}
.rich-line + .mini-table { margin-top: 10px; }
.mt-caption {
  display: block;
  margin-bottom: 6px;
  font-size: 15px;
  font-weight: 700;
  color: var(--muted);
}
.mt-caption strong { color: var(--text); font-weight: 800; }
.mt-scroll {
  display: block;
  width: fit-content;
  max-width: 100%;
  overflow-x: auto;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
}
.mt { display: table; border-collapse: collapse; }
.mt-row { display: table-row; }
.mt-row:nth-child(even) { background: var(--surface-2); }
.mt-row + .mt-row > .mt-cell { border-top: 1px solid var(--line); }
.mt-cell {
  display: table-cell;
  padding: 6px 14px;
  /* Short data cells stay on one line because they fit; long text cells wrap instead of being cut off. */
  white-space: normal;
  vertical-align: middle;
  text-align: start;
}
.mt-cell + .mt-cell { border-inline-start: 1px solid var(--line); }
.mt-cell strong { font-weight: 800; }
.mt-v { unicode-bidi: isolate; }

:focus { outline: none; }
:focus-visible {
  outline: 3px solid var(--primary);
  outline-offset: 3px;
}
::selection { background: var(--primary-soft); color: var(--text); }

.skip {
  position: absolute;
  inset-inline-start: 12px;
  top: -60px;
  z-index: 30;
  background: var(--primary);
  color: var(--on-primary);
  padding: 10px 14px;
  border-radius: 16px;
  text-decoration: none;
  font-weight: 800;
}
.skip:focus { top: 8px; }

.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;
}

.wrap { width: min(1120px, calc(100% - 28px)); margin-inline: auto; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.kicker { color: var(--unit-ink, var(--primary)); font-weight: 800; font-size: 17px; }
.muted { color: var(--muted); }
.fine { color: var(--muted); font-size: 17px; }
.lede { font-size: 1.15rem; font-weight: 700; }
.helper { color: var(--muted); font-weight: 800; }

.page { padding: 8px 0 40px; }
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  width: min(1120px, calc(100% - 20px));
  margin: 10px auto 0;
  padding: 8px 4px;
  flex-wrap: wrap;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: inherit;
  text-decoration: none;
  min-width: 0;
  min-height: 48px;
  font-weight: 800;
}
.brand svg { color: var(--primary); flex: none; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.brand-text small { color: var(--muted); font-size: 15px; font-weight: 700; }
.header-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.who { color: var(--muted); max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 700; }

.icon-btn, .btn, .tile, .tf-btn, .bucket-btn, .starter, .slot, .spot-part, .text-link {
  min-height: var(--tap);
}
.icon-btn, .btn {
  border-radius: 16px;
  border: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-decoration: none;
  font-weight: 800;
  box-shadow: 0 4px 0 var(--edge, var(--muted));
}
.icon-btn {
  position: relative;
  --edge: var(--muted);
  min-width: var(--tap);
  padding: 0 10px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--line);
}
.icon-btn .lbl { display: none; }
.redo-dot {
  position: absolute;
  top: 8px;
  inset-inline-end: 8px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--bad);
  box-shadow: 0 0 0 2px var(--surface);
}
.btn {
  --edge: var(--muted);
  padding: 0 18px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--line);
}
.btn.primary {
  --edge: var(--primary-edge);
  background: var(--primary);
  color: var(--on-primary);
  border-color: transparent;
}
.btn.ghost { background: var(--surface); color: var(--text); }
.btn.block, .action-dock .btn, .signin .btn.primary, .rating .btn { width: 100%; }
.btn.small { min-height: var(--tap); }
.btn:active:not(:disabled),
.icon-btn:active:not(:disabled),
.tile:active:not(:disabled),
.tf-btn:active:not(:disabled),
.bucket-btn:active:not(:disabled),
.starter:active:not(:disabled),
.slot:active:not(:disabled),
.spot-part:active:not(:disabled) {
  transform: translateY(2px);
  box-shadow: 0 2px 0 var(--edge, var(--muted));
}
.btn:disabled, .icon-btn:disabled, .tile:disabled, .tf-btn:disabled, .bucket-btn:disabled, .spot-part:disabled {
  cursor: not-allowed;
}
.btn:disabled {
  background: var(--surface-2);
  color: var(--muted);
  box-shadow: none;
  transform: none;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.input, .composer {
  width: 100%;
  min-height: var(--tap);
  border-radius: 16px;
  border: 2px solid var(--line);
  background: var(--surface);
  padding: 12px 14px;
  color: var(--text);
}
.composer { min-height: 150px; resize: vertical; line-height: 1.6; font-size: 17px; }
.composer:disabled { opacity: 1; background: var(--surface-2); color: var(--text); }
.ltr { direction: ltr; text-align: start; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label, .role-set legend { font-weight: 800; }
.form-error { color: var(--bad-ink); font-weight: 800; }
.alert {
  border-radius: 16px;
  padding: 12px 14px;
  background: var(--xp-soft);
  color: var(--text);
  font-weight: 700;
}
.alert.bad { background: var(--bad-soft); color: var(--text); }

.loading-block { display: grid; justify-items: center; gap: 10px; padding: 48px 16px; color: var(--muted); font-weight: 700; }
.loading {
  width: 140px;
  height: 12px;
  border-radius: 99px;
  background: linear-gradient(90deg, var(--surface-2), var(--primary), var(--surface-2));
  background-size: 200% 100%;
  animation: load 1s linear infinite;
}
.error-panel { max-width: 520px; margin: 32px auto; padding: 8px 16px 32px; }

.signin {
  min-height: 100dvh;
  display: grid;
  align-items: center;
  padding: 24px 16px 40px;
}
.signin-panel { width: min(480px, 100%); margin-inline: auto; display: flex; flex-direction: column; gap: 8px; }
.signin-card { padding: 22px 18px 18px; gap: 12px; }
.account-who { font-size: 1.2rem; font-weight: 800; }
.signin-card svg { color: var(--primary); }
.signin .text-link { align-self: center; width: auto; padding-inline: 12px; }

.dev-card { border-style: solid; }
.role-set { border: 0; margin: 0; padding: 0; display: flex; gap: 8px; }
.role-set .choice { flex: 1; }

.greet { padding-top: 6px; }
.stats-grid, .journey-parts, .unit-layout, .record-layout { display: grid; gap: 12px; min-width: 0; }
.stats-grid { grid-template-columns: minmax(0, 1.4fr) minmax(0, .8fr); }
.stats-grid > *, .journey-parts > *, .unit-layout > *, .record-layout > * { min-width: 0; }
.xp-card, .streak { padding: 14px; }
.xp-score { font-size: 1.35rem; font-weight: 800; }
.xp-bar, .step-progress, .mini-bar {
  height: 12px;
  border-radius: 99px;
  background: var(--surface-2);
  overflow: hidden;
}
.step-progress { background: color-mix(in srgb, var(--primary) 22%, var(--surface)); }
.xp-bar > span, .step-progress > span, .mini-bar > span {
  display: block;
  height: 100%;
  background: var(--primary);
  border-radius: inherit;
  width: 0;
}
.xp-bar > span, .step-progress > span { transition: width .45s ease; }
.streak { align-items: flex-start; }
.streak svg { color: var(--xp-ink); }
.streak-num { font-size: 1.6rem; font-weight: 800; line-height: 1.1; }
.review-card, .teacher-link {
  display: flex;
  align-items: center;
  gap: 12px;
  text-align: start;
  width: 100%;
  color: var(--text);
  text-decoration: none;
  border: 1px solid var(--primary);
  background: var(--primary-soft);
  font-weight: 800;
}
.review-card { cursor: pointer; font: inherit; min-height: var(--tap); }

.badge-list { display: flex; flex-wrap: wrap; gap: 8px; list-style: none; }
.badge {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 10px 12px;
  border-radius: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  min-height: 56px;
  min-width: 0;
}
.badge small { display: block; color: var(--muted); font-weight: 700; }
.badge.is-on { border-color: var(--primary); background: var(--primary-soft); }
.badge.is-on svg { color: var(--primary); }
.badge.is-off { background: var(--surface); border-style: dashed; box-shadow: none; }
.badge.is-off svg { color: var(--muted); }
.part-title { color: var(--text); font-weight: 800; }
.track { display: flex; flex-direction: column; gap: 12px; }
.node {
  position: relative;
  display: grid;
  grid-template-columns: 56px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  width: 100%;
  text-align: start;
  padding: 14px;
  border-radius: 20px;
  border: 1px solid var(--line);
  border-top: 6px solid var(--unit, var(--primary));
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
  min-height: 92px;
}
/* Locked = calm but crisp: no fading, full-contrast text, grey lock instead of the unit colour. */
.node.is-locked { border-top-color: var(--line); box-shadow: none; border-style: dashed; border-top-style: solid; }
.node.is-locked .node-index { background: var(--surface-2); color: var(--muted); }
.node.is-locked .node-role, .node.is-locked .node-meta { color: var(--muted); }
.node-index {
  width: 56px;
  height: 56px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  background: var(--unit, var(--primary));
  color: var(--on-unit, var(--on-primary));
  font-weight: 800;
  font-size: 1.35rem;
}
.node-body { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.node-title { font-weight: 800; font-size: 1.08rem; }
.node-role { color: var(--unit-ink, var(--primary)); font-weight: 800; }
.node-meta { font-weight: 700; }
.pill {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 0 10px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--text);
  font-weight: 800;
}
.pill.soon { background: var(--surface); color: var(--muted); border: 1px solid var(--line); }
.class-list { list-style: none; display: flex; flex-direction: column; gap: 6px; font-weight: 700; }
.join-form { display: flex; flex-direction: column; gap: 8px; }
.join-row { display: flex; flex-direction: column; gap: 8px; }
.continue-card {
  background: #5B4BFF;
  color: #FFFFFF;
  border: 0;
  padding: 20px 18px;
  gap: 10px;
}
.continue-card .kicker,
.continue-card h2,
.continue-card p { color: #FFFFFF; }
.continue-card h2 { font-size: clamp(1.45rem, 3vw, 1.9rem); }
.continue-card .btn {
  --edge: #D9D6FF;
  background: #FFFFFF;
  color: #3D30C7;
  border-color: transparent;
  min-height: 56px;
}

.unit-hero { display: flex; gap: 14px; align-items: flex-start; }
.unit-hero svg { color: var(--unit, var(--primary)); flex: none; }
.lesson-list { display: flex; flex-direction: column; gap: 10px; }
.lesson-row {
  width: 100%;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  text-align: start;
  padding: 14px;
  border-radius: 20px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  min-height: 72px;
  box-shadow: var(--shadow);
  font: inherit;
}
.lesson-row.is-locked { box-shadow: none; border-style: dashed; }
.lesson-row.is-locked .row-main, .lesson-row.is-locked .choice-text { color: var(--muted); }
.lesson-side, .stars { display: inline-flex; gap: 2px; align-items: center; color: var(--xp); flex: none; }
.mini-bar { display: block; margin-top: 8px; }
.skill-list { list-style: none; display: flex; flex-direction: column; }
.skill-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 56px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}
.skill-line:last-child { border-bottom: 0; }
.skill-name { font-weight: 800; min-width: 0; }
.skill-table { width: 100%; border-collapse: collapse; table-layout: fixed; }
.skill-table th, .skill-table td {
  padding: 10px 6px;
  border-bottom: 1px solid var(--line);
  text-align: center;
  vertical-align: middle;
  overflow-wrap: anywhere;
}
.skill-table th:first-child, .skill-table td:first-child { width: 46%; }
.skill-table th:first-child, .skill-table td:first-child, .skill-table th[scope="row"] { text-align: start; font-weight: 700; }
.skill-table .mark { color: var(--good-ink); }
.skill-table .mark.is-mastered { background: var(--good-soft); }
.skill-table .mark.is-practicing { background: var(--xp-soft); color: var(--xp-ink); }
.glossary-list { display: grid; gap: 8px; }
.term-row, .term {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface-2);
  min-height: 48px;
}
.term-row { justify-content: space-between; background: var(--surface); }
.term-row dd { margin: 0; color: var(--muted); }
.terms { display: flex; flex-wrap: wrap; gap: 8px; }
.term { width: auto; background: var(--primary-soft); border-color: transparent; font-weight: 800; color: var(--text); }
.term bdi { font-weight: 700; color: var(--muted); }

.player {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
}
.player-top {
  display: grid;
  grid-template-columns: 56px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 10px 12px 8px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
}
.close-btn { border-radius: 16px; }
.progress-col { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.stage-label {
  text-align: center;
  font-weight: 800;
  font-size: 15px;
  color: var(--muted);
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.player-top .xp-pill { min-height: 34px; padding: 0 10px; font-size: 15px; }
.xp-pill, .xp-chip {
  margin: 0;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 36px;
  padding: 0 12px;
  border-radius: 999px;
  background: var(--xp);
  color: var(--on-xp);
  font-weight: 800;
  white-space: nowrap;
  width: fit-content;
}
.player-scroll { flex: 1; overflow: auto; min-height: 0; }
.player-body { width: min(720px, calc(100% - 28px)); margin: 8px auto 18px; }
/* Robot steps put the arena and the block editor side by side on wide screens. */
.player[data-type="robot"] .player-body { width: min(1240px, calc(100% - 20px)); }
.prompt { font-size: 22px; font-weight: 800; line-height: 1.45; }
.prompt[tabindex="-1"]:focus,
.prompt[tabindex="-1"]:focus-visible { outline: none; }
.widget { display: flex; flex-direction: column; gap: 12px; }
.body { font-size: 18px; }
.read-card, .mail, .model, .tip, .banner {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 16px;
}
.read-card, .model, .tip, .banner { display: flex; flex-direction: column; gap: 10px; }
.page-chip {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  min-height: 36px;
  padding: 0 12px;
  border-radius: 999px;
  background: var(--info-soft);
  color: var(--text);
  font-weight: 800;
}
.intro-line { font-weight: 700; }

.choice-list, .checks, .starters, .bucket-actions { display: flex; flex-direction: column; gap: 10px; }
.tile, .tf-btn, .bucket-btn, .starter, .slot, .spot-part, .choice {
  width: 100%;
  text-align: start;
  border-radius: 16px;
  border: 2px solid var(--line);
  background: var(--surface);
  color: var(--text);
  padding: 10px 12px;
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 800;
  box-shadow: 0 4px 0 var(--line);
  --edge: var(--line);
}
.choice-text { flex: 1; min-width: 0; font-weight: 700; line-height: 1.45; }
.letter, .swatch, .tick, .avatar {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  flex: none;
  font-weight: 800;
}
.letter.h0, .swatch.h0 { background: #5B4BFF; color: #FFFFFF; }
.letter.h1, .swatch.h1 { background: #0EA5E9; color: #191D3A; }
.letter.h2, .swatch.h2 { background: #F97316; color: #191D3A; }
.letter.h3, .swatch.h3 { background: #EC4899; color: #191D3A; }
:root[data-theme="dark"] .letter.h0, :root[data-theme="dark"] .swatch.h0 { background: #8B80FF; color: #0E1124; }
:root[data-theme="dark"] .letter.h1, :root[data-theme="dark"] .swatch.h1 { background: #38BDF8; color: #0E1124; }
:root[data-theme="dark"] .letter.h2, :root[data-theme="dark"] .swatch.h2 { background: #FB923C; color: #0E1124; }
:root[data-theme="dark"] .letter.h3, :root[data-theme="dark"] .swatch.h3 { background: #F472B6; color: #0E1124; }
.tick {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  border: 2px solid var(--primary);
  background: var(--surface);
  color: var(--on-primary);
}
.check-tile.is-on .tick { background: var(--primary); border-color: var(--primary-edge); }
.tile.is-pending { border-color: var(--primary); background: var(--primary-soft); --edge: var(--primary-edge); box-shadow: 0 4px 0 var(--primary-edge); }
.tile.is-correct, .slot.is-correct, .spot-part.is-correct, .tf-btn.is-correct, .pair-result.is-correct, .result-list .is-correct {
  border-color: var(--good-edge);
  background: var(--good-soft);
  --edge: var(--good-edge);
  box-shadow: 0 4px 0 var(--good-edge);
}
.tile.is-wrong, .slot.is-wrong, .spot-part.is-wrong, .tf-btn.is-wrong, .pair-result.is-wrong, .result-list .is-wrong {
  border-color: var(--bad-edge);
  background: var(--bad-soft);
  --edge: var(--bad-edge);
  box-shadow: 0 4px 0 var(--bad-edge);
}
.tile.is-spent:not(.is-correct), .tf-btn.is-spent:not(.is-correct) {
  opacity: 1;
  background: var(--surface-2);
  color: var(--muted);
  border-color: var(--bad);
  box-shadow: none;
}
.tile.is-missed, .spot-part.is-missed { border-style: dashed; }
.choice input { width: 1.25rem; height: 1.25rem; accent-color: var(--primary); flex: none; }

.tf-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tf-row > *, .player-top > *, .choice-list > *, .mail-who, .node-body { min-width: 0; }
.tf-btn { justify-content: center; font-size: 1.35rem; min-height: 84px; }
.tf-btn.yes { border-color: var(--good-edge); --edge: var(--good-edge); box-shadow: 0 4px 0 var(--good-edge); color: var(--good-ink); }
.tf-btn.no { border-color: var(--bad-edge); --edge: var(--bad-edge); box-shadow: 0 4px 0 var(--bad-edge); color: var(--bad-ink); }
.tf-btn svg { flex: none; }

.deal { display: flex; flex-direction: column; gap: 10px; }
.deal-count { text-align: center; font-weight: 800; color: var(--primary); font-size: 17px; }
.deal-card {
  min-height: 140px;
  border-radius: 20px;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  display: grid;
  place-items: center;
  text-align: center;
  padding: 22px 16px;
  font-size: 22px;
  font-weight: 800;
  line-height: 1.45;
}
.deal-card.is-flying { animation: fly .32s ease forwards; }
.bucket-btn { --edge: var(--primary-edge); }
.bucket-btn.hue-0 { border-color: var(--primary); --edge: var(--primary-edge); box-shadow: 0 4px 0 var(--primary-edge); }
.bucket-btn.hue-1 { border-color: var(--info-ink); --edge: var(--info-ink); box-shadow: 0 4px 0 var(--info-ink); }
.bucket-btn.hue-2 { border-color: #C2410C; --edge: #C2410C; box-shadow: 0 4px 0 #C2410C; }
.bucket-btn.hue-3 { border-color: #BE185D; --edge: #BE185D; box-shadow: 0 4px 0 #BE185D; }
.count-pill {
  margin-inline-start: auto;
  min-width: 32px;
  height: 32px;
  padding: 0 8px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  background: var(--surface-2);
  color: var(--text);
  font-weight: 800;
}
.swatch { width: 18px; height: 18px; border-radius: 6px; }
.text-link {
  appearance: none;
  background: transparent;
  border: 0;
  box-shadow: none;
  color: var(--primary);
  font-weight: 800;
  min-height: 56px;
  padding: 8px;
  width: 100%;
}
.text-link:active { transform: translateY(1px); }
.result-bucket { display: flex; flex-direction: column; gap: 8px; }
.result-list { list-style: none; display: flex; flex-direction: column; gap: 8px; }
.result-list li, .pair-result {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 12px;
  border-radius: 16px;
  background: var(--surface);
  border: 2px solid var(--line);
  font-weight: 700;
}
.result-list .is-correct, .pair-result.is-correct { color: var(--text); }
.result-list .is-placed, .pair-result.is-placed { border-color: var(--primary); background: var(--primary-soft); color: var(--text); }
.result-list .is-correct svg, .pair-result.is-correct svg { color: var(--good-ink); flex: none; }
.result-list .is-wrong svg, .pair-result.is-wrong svg { color: var(--bad-ink); flex: none; }
.pair-copy { display: flex; flex-wrap: wrap; gap: 6px; align-items: baseline; min-width: 0; }
.pair-join { color: var(--muted); font-weight: 800; }

.slots { list-style: none; display: flex; flex-direction: column; gap: 8px; }
.slot, .slot.is-empty {
  min-height: 56px;
  border-radius: 16px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.slot.is-empty {
  border: 2px dashed color-mix(in srgb, var(--primary) 55%, var(--line));
  background: var(--surface);
  box-shadow: none;
  color: var(--primary);
  font-weight: 800;
  justify-content: center;
}
.slot-num {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  background: var(--primary);
  color: var(--on-primary);
  font-weight: 800;
  flex: none;
}
.tray { display: flex; flex-direction: column; gap: 8px; }

.mail { padding: 0; overflow: hidden; }
.mail-head {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 14px;
  background: var(--surface-2);
}
.avatar { background: var(--primary); color: var(--on-primary); font-size: 1.1rem; }
.mail-who { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.mail-from { font-weight: 800; }
.mail-subject { color: var(--muted); font-weight: 700; }
.mail-body { display: flex; flex-direction: column; gap: 8px; padding: 12px; }
.spot-row { display: flex; flex-direction: column; gap: 4px; }
.spot-part.is-picked {
  text-decoration: underline;
  text-decoration-color: var(--bad);
  text-decoration-thickness: 3px;
  text-underline-offset: 4px;
  font-weight: 800;
  border-color: var(--bad-edge);
}
.spot-part svg { color: var(--bad-ink); flex: none; }
.spot-part.is-correct svg { color: var(--good-ink); }
.why { color: var(--text); font-weight: 700; padding-inline-start: 8px; }

.composer-row { display: flex; gap: 10px; align-items: stretch; }
.ring-host { flex: none; }
.ring {
  width: 64px;
  height: 64px;
  position: relative;
  color: var(--primary);
  display: grid;
  place-items: center;
}
.ring-svg { width: 64px; height: 64px; position: absolute; inset: 0; }
.ring-track { fill: none; stroke: color-mix(in srgb, var(--primary) 40%, var(--line)); stroke-width: 6; }
.ring-value {
  fill: none;
  stroke: currentColor;
  stroke-width: 6;
  stroke-linecap: round;
  transform: rotate(-90deg);
  transform-origin: 24px 24px;
}
.ring.is-ready { color: var(--good-ink); }
.ring > svg:last-child, .ring > .ring-check { position: relative; }
.starters { display: flex; flex-direction: row; flex-wrap: wrap; gap: 8px; }
.starter {
  flex: 1 1 auto;
  width: auto;
  min-height: 48px;
  background: var(--surface);
  border: 2px solid var(--primary);
  color: var(--text);
  --edge: var(--primary-edge);
  box-shadow: 0 4px 0 var(--primary-edge);
  justify-content: center;
  text-align: center;
  padding: 8px 10px;
}
.rubric-list { list-style: none; display: flex; flex-direction: column; gap: 8px; }
.rubric-list li {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  min-height: 44px;
  font-weight: 700;
}
.rubric-list svg { color: var(--good-ink); flex: none; margin-top: 3px; }

.action-dock {
  flex: none;
  padding: 8px 12px calc(12px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--bg) 94%, transparent);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.action-dock:empty { display: none; }
.dock-choices { max-height: min(42dvh, 252px); overflow: auto; padding: 4px 4px 8px; margin: -4px; }
.live-count { font-weight: 800; text-align: center; }
.live-count.is-full { color: var(--good-ink); }
.action-dock.is-sheet { padding: 0; background: transparent; }
.feedback-sheet {
  max-height: 58dvh;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px 16px calc(14px + env(safe-area-inset-bottom));
  border-radius: 24px 24px 0 0;
  box-shadow: 0 -10px 30px rgba(25, 29, 58, .12);
  animation: sheet-up .32s ease;
}
.feedback-sheet.is-good { background: var(--good-soft); }
.feedback-sheet.is-bad { background: var(--bad-soft); }
.feedback-sheet.is-info { background: var(--info-soft); }
.sheet-body { overflow: auto; min-height: 0; display: flex; flex-direction: column; gap: 8px; }
.sheet-head { display: flex; align-items: center; gap: 10px; }
.sheet-mark {
  width: 40px;
  height: 40px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  flex: none;
  background: var(--surface);
}
.sheet-mark.is-good { color: var(--good-ink); }
.sheet-mark.is-bad { color: var(--bad-ink); }
.sheet-mark.is-info { color: var(--info-ink); }
.feedback-title { font-weight: 800; font-size: 22px; line-height: 1.35; }
.xp-gain { font-weight: 800; font-size: 1.6rem; }
.badge-pop { display: flex; align-items: center; gap: 6px; font-weight: 800; }
.rating { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; width: 100%; }
.rate-btn { background: var(--surface); padding: 6px 8px; line-height: 1.3; text-align: center; }
.rating-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.rating-q { font-weight: 800; }
.sheet-chips { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.stage-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  padding: 0 12px;
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font-weight: 800;
  font-size: 15px;
}
.stage-chip svg { color: var(--primary); flex: none; }
.actions { display: flex; flex-direction: column; gap: 10px; }
.actions .btn { width: 100%; }

.complete { padding-top: 12px; padding-bottom: 40px; }
.complete .stars svg { width: 52px; height: 52px; }
.complete .stars { gap: 6px; }
.skill-results { list-style: none; display: flex; flex-direction: column; gap: 8px; }
.skill-results li, .open-card {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}
.open-card { flex-direction: column; align-items: stretch; border: 1px solid var(--line); border-radius: 20px; padding: 14px; background: var(--surface); box-shadow: var(--shadow); }
.answer-text { white-space: pre-wrap; }
.status {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 0 10px;
  border-radius: 999px;
  font-weight: 800;
  background: var(--surface-2);
  color: var(--text);
  flex: none;
}
.status.mastered, .status.accepted { background: var(--good-soft); color: var(--good-ink); }
.status.practicing { background: var(--xp-soft); color: var(--xp-ink); }
.status.redo { background: var(--bad-soft); color: var(--bad-ink); }
.bars { display: flex; align-items: flex-end; gap: 3px; height: 120px; }
.bar {
  flex: 1 1 0;
  min-width: 0;
  background: var(--primary);
  border-radius: 4px 4px 0 0;
}
.bar.is-empty { background: var(--line); }
.bar.is-today { background: var(--xp); }
.bar-labels { display: flex; justify-content: space-between; }

.sheet { border: 0; padding: 0; background: transparent; max-width: calc(100% - 24px); }
.sheet::backdrop { background: rgba(14, 17, 36, .55); }
.sheet-card {
  width: min(440px, 100%);
  background: var(--surface);
  color: var(--text);
  border-radius: 20px;
  padding: 18px;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}
.toaster {
  position: fixed;
  inset-inline: 16px;
  top: 84px;
  z-index: 40;
  display: flex;
  justify-content: center;
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  max-width: min(520px, 100%);
  background: var(--primary);
  color: var(--on-primary);
  border-radius: 16px;
  padding: 12px 16px;
  font-weight: 800;
  box-shadow: var(--shadow);
}


/* ---------- Unit page: mission path ---------- */
.unit-hero { align-items: center; }
.unit-icon {
  width: 64px;
  height: 64px;
  flex: none;
  border-radius: 20px;
  display: grid;
  place-items: center;
  background: var(--unit, var(--primary));
  color: var(--on-unit, var(--on-primary));
}
.unit-hero .unit-icon svg { color: inherit; }
.unit-copy { gap: 6px; min-width: 0; flex: 1; }
.unit-meter { display: flex; flex-direction: column; gap: 4px; }
.unit-bar, .node-bar { margin-top: 0; height: 10px; }
.unit-bar > span, .node-bar > span { background: var(--unit, var(--primary)); }
.path { gap: 16px; }
.path-group { display: flex; flex-direction: column; gap: 10px; }
.group-title {
  color: var(--unit-ink, var(--primary));
  font-size: 1rem;
  padding-inline-start: 4px;
}
.mission-list { list-style: none; display: flex; flex-direction: column; gap: 10px; }
.mission, .challenge-card {
  width: 100%;
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  text-align: start;
  padding: 12px 14px;
  border-radius: 20px;
  border: 2px solid var(--line);
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 4px 0 var(--line);
  min-height: 76px;
  font: inherit;
}
.mission:active:not([aria-disabled="true"]), .challenge-card:active:not([aria-disabled="true"]) {
  transform: translateY(2px);
  box-shadow: 0 2px 0 var(--line);
}
.m-num {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 1.25rem;
  background: var(--surface-2);
  color: var(--muted);
}
.m-body { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.m-title { font-weight: 800; font-size: 1.08rem; line-height: 1.35; }
.m-meta { color: var(--muted); font-weight: 700; font-size: 15px; }
.m-side { display: inline-flex; align-items: center; flex: none; }
.m-side .stars svg { width: 18px; height: 18px; }
.m-go {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 0 14px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--text);
  font-weight: 800;
}
.mission.is-completed .m-num { background: var(--good-soft); color: var(--good-ink); }
.mission.is-in-progress { border-color: var(--unit, var(--primary)); }
.mission.is-in-progress .m-num { background: color-mix(in srgb, var(--unit, var(--primary)) 18%, var(--surface)); color: var(--unit-ink, var(--primary)); }
.mission.is-in-progress .mini-bar { margin-top: 6px; height: 8px; }
.mission.is-in-progress .mini-bar > span { background: var(--unit, var(--primary)); }
.mission.is-locked, .challenge-card.is-locked { box-shadow: none; cursor: default; border-style: dashed; }
.mission.is-locked .m-title { color: var(--text); }
.mission.is-locked .m-num { background: var(--surface-2); color: var(--muted); }
.mission.is-next {
  border-color: transparent;
  background: var(--unit, var(--primary));
  color: var(--on-unit, var(--on-primary));
  box-shadow: 0 5px 0 color-mix(in srgb, var(--unit, var(--primary)) 55%, #000);
  min-height: 92px;
  padding-block: 16px;
}
.mission.is-next .m-meta { color: inherit; }
.mission.is-next .m-title { font-size: 1.2rem; }
.mission.is-next .m-num { background: var(--surface); color: var(--unit-ink, var(--primary)); }
.mission.is-next .m-go { background: var(--surface); color: var(--unit-ink, var(--primary)); min-height: 44px; padding: 0 18px; }
.mission.is-next .mini-bar { background: color-mix(in srgb, var(--on-unit, #fff) 25%, transparent); }
.mission.is-next .mini-bar > span { background: var(--on-unit, #fff); }
.challenge-card {
  grid-template-columns: 56px minmax(0, 1fr) auto;
  border: 2px dashed color-mix(in srgb, var(--xp) 70%, var(--line));
  background: var(--xp-soft);
  box-shadow: none;
  min-height: 92px;
}
.challenge-card:not(.is-locked) { border-style: solid; border-color: var(--xp); box-shadow: 0 4px 0 color-mix(in srgb, var(--xp) 70%, #000); }
.challenge-card.is-next { background: var(--xp); color: var(--on-xp); }
.challenge-card.is-next .m-meta, .challenge-card.is-next .c-kicker { color: var(--on-xp); }
.c-icon {
  width: 56px;
  height: 56px;
  border-radius: 18px;
  display: grid;
  place-items: center;
  background: var(--xp);
  color: var(--on-xp);
}
.challenge-card.is-locked { background: var(--surface); border-color: color-mix(in srgb, var(--xp) 75%, var(--line)); }
.challenge-card.is-locked .c-icon { background: var(--xp-soft); color: var(--xp-ink); }
.challenge-card.is-next .c-icon { background: var(--surface); color: var(--xp-ink); }
.c-kicker { color: var(--xp-ink); font-weight: 800; font-size: 15px; }
.fold { padding: 0; }
.fold > summary {
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: var(--tap);
  padding: 10px 16px;
  cursor: pointer;
  border-radius: var(--radius);
}
.fold > summary::-webkit-details-marker { display: none; }
.fold > summary h2 { font-size: 1.15rem; }
.fold-icon { display: grid; place-items: center; color: var(--muted); transition: transform .2s ease; }
.fold[open] > .fold-icon, .fold[open] > summary .fold-icon { transform: rotate(180deg); }
.fold > :not(summary) { margin: 0 16px 16px; }
.fold[open] > summary { padding-bottom: 4px; }
.skill-name { display: flex; flex-direction: column; }
.skill-count { font-size: 15px; font-weight: 700; }

/* ---------- Home ---------- */
.continue-meta { font-weight: 800; }
.continue-group { font-weight: 700; font-size: 15px; }
.continue-card .btn svg { flex: none; }
.review-card {
  padding: 14px 16px;
  border-width: 2px;
  box-shadow: 0 4px 0 var(--primary-edge);
  border-radius: var(--radius);
}
.review-icon {
  width: 48px;
  height: 48px;
  flex: none;
  border-radius: 14px;
  display: grid;
  place-items: center;
  background: var(--primary);
  color: var(--on-primary);
}
.review-card .m-body { flex: 1; }
.review-card .m-go { background: var(--surface); }
.redo-card { border-color: var(--bad); box-shadow: 0 4px 0 var(--bad-edge); }
.redo-card .review-icon { background: var(--bad); color: var(--on-primary); }
.node.is-ready .node-meta { color: var(--unit-ink, var(--primary)); font-weight: 800; }
.node-bar { display: block; margin-top: 6px; }

/* ---------- Mission start / complete ---------- */
.start { max-width: 640px; padding-top: 8px; }
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 48px;
  width: fit-content;
  color: var(--muted);
  text-decoration: none;
  font-weight: 800;
}
.start-card { display: flex; flex-direction: column; gap: 14px; padding: 22px 18px; }
.start-icon {
  width: 64px;
  height: 64px;
  border-radius: 20px;
  display: grid;
  place-items: center;
  background: var(--unit, var(--primary));
  color: var(--on-unit, var(--on-primary));
}
.start-card.is-challenge .start-icon, .complete.is-challenge .start-icon { background: var(--xp); color: var(--on-xp); }
.chip-row { list-style: none; display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 38px;
  padding: 0 12px;
  border-radius: 999px;
  background: var(--surface-2);
  font-weight: 800;
}
.chip svg { color: var(--unit-ink, var(--primary)); flex: none; }
.start-intro { font-size: 18px; font-weight: 500; }
.rule-list { list-style: none; display: flex; flex-direction: column; gap: 8px; }
.rule-list li { display: flex; gap: 8px; align-items: flex-start; font-weight: 700; }
.rule-list svg { color: var(--good-ink); flex: none; margin-top: 4px; }
.stage-strip { list-style: none; display: flex; flex-wrap: wrap; gap: 6px; counter-reset: stage; }
.stage-strip li {
  counter-increment: stage;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 700;
  font-size: 15px;
  color: var(--muted);
}
.stage-strip li::before {
  content: counter(stage);
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: color-mix(in srgb, var(--unit, var(--primary)) 18%, var(--surface));
  color: var(--unit-ink, var(--primary));
  font-weight: 800;
  font-size: 13px;
}
.stage-strip li:not(:last-child)::after { content: "←"; color: var(--line); margin-inline-start: 2px; }
.start-btn { min-height: 64px; font-size: 1.25rem; width: 100%; }
.complete-head { align-items: center; text-align: center; gap: 8px; }
.complete-head .start-icon { margin-bottom: 4px; }
.complete .actions { max-width: 520px; width: 100%; margin-inline: auto; }
.complete > .start-icon { align-self: center; }
.review-empty, .complete:not(:has(.complete-head)) { text-align: center; align-items: center; }
.review-empty .actions, .complete .actions { align-self: stretch; }
.score { font-size: 3rem; font-weight: 800; line-height: 1.1; }
.score strong { color: var(--unit-ink, var(--primary)); }
.score span { font-size: 1.6rem; color: var(--muted); }
.missed-list { list-style: none; display: flex; flex-direction: column; gap: 10px; }
.missed {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 12px 14px;
  border-radius: 16px;
  border: 1px solid var(--line);
  border-inline-start: 5px solid var(--bad);
  background: var(--surface);
}
.missed-q { font-weight: 800; }
.missed-why { color: var(--text); }
.text-link.inline-link { width: fit-content; min-height: 48px; padding: 4px 0; text-align: start; }
.mistake-list .lesson-row svg { flex: none; color: var(--muted); }
.context-chip {
  width: fit-content;
  padding: 4px 12px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-weight: 800;
  font-size: 15px;
}

/* ---------- Order: in-place numbering ---------- */
.order-list { gap: 8px; }
.order-tile { min-height: 56px; padding: 8px 12px; }
.order-num {
  width: 36px;
  height: 36px;
  flex: none;
  border-radius: 50%;
  display: grid;
  place-items: center;
  border: 2px dashed color-mix(in srgb, var(--primary) 50%, var(--line));
  font-weight: 800;
  font-size: 1.1rem;
  transition: transform .15s ease;
}
.order-tile.is-numbered { border-color: var(--primary); background: var(--primary-soft); box-shadow: 0 4px 0 var(--primary-edge); --edge: var(--primary-edge); }
.order-tile.is-numbered .order-num { border: 0; background: var(--primary); color: var(--on-primary); transform: scale(1.06); }
.order-tile.is-correct .order-num { background: var(--good-ink); color: var(--surface); border: 0; }
.order-tile.is-wrong .order-num { background: var(--bad-ink); color: var(--surface); border: 0; }
.order-copy { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.order-note { color: var(--bad-ink); font-size: 15px; font-weight: 800; }
.order-tile:disabled { cursor: default; }
.dock-row { display: grid; grid-template-columns: auto 1fr; gap: 8px; }
.action-dock .dock-row .btn.ghost { width: auto; padding: 0 18px; }

/* ---------- Record ---------- */
.record-unit { gap: 10px; }
.record-unit + .record-unit { padding-top: 6px; border-top: 1px solid var(--line); }
.record-unit .unit-title { color: var(--unit-ink, var(--primary)); }
.row-main { gap: 2px; min-width: 0; flex: 1; }
.row-group { color: var(--muted); font-weight: 700; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.record-unit .lesson-row { min-height: 64px; padding: 10px 14px; }

@media (min-width: 768px) {
  .icon-btn .lbl { display: inline; }
  .signin-card { padding: 32px 28px; }
  .join-form { max-width: 520px; }
  .join-row { flex-direction: row; align-items: flex-end; }
  .join-row .field { flex: 1; }
  .join-row .btn { flex: none; width: auto; min-width: 140px; }
  .glossary-list { grid-template-columns: 1fr 1fr; }
  .rating { flex-direction: row; }
  .rating .btn { flex: 1; }
  .continue-card .btn { width: auto; min-width: 240px; }
  .action-dock .btn.primary { width: 100%; }
}

.unit-body { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.unit-body > * { min-width: 0; }

@media (min-width: 900px) {
  .player-top { width: min(860px, 100%); margin-inline: auto; }
  .action-dock { width: min(760px, 100%); margin-inline: auto; }
  .action-dock.is-sheet { width: min(760px, 100%); }
}

@media (min-width: 1024px) {
  .unit-body { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: 20px; align-items: start; }
  .unit-side { position: sticky; top: 12px; }
  .unit-side .glossary-list { grid-template-columns: 1fr; }
}

@media (min-width: 1280px) {
  .journey-parts, .unit-layout, .record-layout { grid-template-columns: 1fr 1fr; align-items: start; }
  .who { display: inline; }
}

@media (max-width: 767px) {
  .who, .brand-text small { display: none; }
  .btn.primary { width: 100%; }
  .header-actions .btn { width: auto; }
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .letter.h0,
  :root:not([data-theme="light"]) .swatch.h0 { background: #8B80FF; color: #0E1124; }
  :root:not([data-theme="light"]) .letter.h1,
  :root:not([data-theme="light"]) .swatch.h1 { background: #38BDF8; color: #0E1124; }
  :root:not([data-theme="light"]) .letter.h2,
  :root:not([data-theme="light"]) .swatch.h2 { background: #FB923C; color: #0E1124; }
  :root:not([data-theme="light"]) .letter.h3,
  :root:not([data-theme="light"]) .swatch.h3 { background: #F472B6; color: #0E1124; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
  }
}

@keyframes load {
  from { background-position: 100% 0; }
  to { background-position: -100% 0; }
}
@keyframes sheet-up {
  from { transform: translateY(24%); }
  to { transform: none; }
}
@keyframes fly {
  to { transform: translate(var(--fly-x), var(--fly-y)) scale(.55); opacity: .15; }
}

/* ---------- Acceptance pass ---------- */
.start-icon.is-locked { background: var(--surface-2); color: var(--muted); }
.complete-meter { padding: 12px 14px; gap: 8px; }
.complete-meter .fine { color: var(--text); font-weight: 800; }
.next-review { display: inline-flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: center; font-weight: 700; padding: 12px 16px; }
.next-review svg { color: var(--primary); flex: none; }
.next-review strong { color: var(--primary-edge); }
:root[data-theme="dark"] .next-review strong { color: var(--primary); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .next-review strong { color: var(--primary); } }

/* Phone turned sideways (or a short window): keep the card and its answer buttons on one screen. */
@media (max-height: 520px) {
  .player-top { padding-block: 4px; }
  .prompt { font-size: 19px; }
  .player-body { margin-top: 4px; }
  .deal-card { min-height: 72px; padding: 10px 14px; font-size: 19px; }
  .bucket-actions { flex-direction: row; }
  .bucket-actions > * { flex: 1 1 0; }
  .dock-choices { max-height: 46dvh; }
  .tf-btn { min-height: 64px; }
  .feedback-sheet { max-height: 72dvh; padding-top: 10px; }
}
.challenge-card.is-next .m-go { background: var(--surface); color: var(--xp-ink); }
html:root a.skip { color: var(--on-primary); }

/* Desktop: one comfortable reading column instead of a 1120px stretch (the unit page keeps its two columns). */
.wrap.home, .wrap.record { max-width: 820px; }
.wrap.complete { max-width: 640px; }
.app-header { max-width: 1120px; }
@media (min-width: 1024px) {
  .home .journey-parts { grid-template-columns: 1fr 1fr; align-items: start; }
}

/* ---------- Keep what was right (sort / match / order retry) ---------- */
.kept-block { display: flex; flex-direction: column; gap: 6px; }
.kept-title { font-size: 15px; font-weight: 800; color: var(--good-ink); }
.result-list.kept-list { gap: 6px; }
.result-list.kept-list li.is-kept, .result-list.kept-list .pair-result.is-kept {
  padding: 6px 10px;
  font-size: 14px;
  line-height: 1.5;
  border-width: 1px;
  border-radius: 12px;
  box-shadow: none;
}
.kept-where { margin-inline-start: auto; color: var(--muted); font-weight: 800; font-size: 13px; flex: none; }
.order-tile.is-kept { border-color: var(--good-edge); background: var(--good-soft); box-shadow: 0 4px 0 var(--good-edge); --edge: var(--good-edge); opacity: 1; }
.order-tile.is-kept .order-num { background: var(--good-ink); color: var(--surface); border: 0; }
.order-tile.is-kept .order-note { color: var(--good-ink); }
.skill-why { margin-top: 4px; }
.deal:has(.kept-list) .deal-card { min-height: 100px; padding: 16px; }

/* ---------- Five units: compact map, badges, record ---------- */
.journey .track { gap: 8px; }
.journey .node {
  grid-template-columns: 44px minmax(0, 1fr);
  gap: 10px;
  padding: 10px 12px;
  border-top-width: 4px;
  border-radius: 16px;
  min-height: 72px;
}
.journey .node-index { width: 44px; height: 44px; border-radius: 12px; font-size: 1.15rem; }
.journey .node-top { display: flex; align-items: center; gap: 8px; min-width: 0; flex-wrap: wrap; }
.journey .node-title { font-size: 1rem; line-height: 1.35; min-width: 0; }
.journey .node-meta { font-size: 14px; line-height: 1.4; }
.journey .node-bar { height: 8px; margin-top: 4px; }
.journey .node.is-locked {
  min-height: 52px;
  padding-block: 6px;
  grid-template-columns: 36px minmax(0, 1fr);
  border-top-width: 1px;
}
.journey .node.is-locked .node-index { width: 36px; height: 36px; border-radius: 10px; }
.journey .node.is-locked .node-title { font-weight: 700; color: var(--text); }
.node-soon {
  font-size: 13px;
  font-weight: 800;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 8px;
  line-height: 1.6;
}
.node-flag {
  font-size: 13px;
  font-weight: 800;
  color: var(--on-unit, var(--on-primary));
  background: var(--unit, var(--primary));
  border-radius: 999px;
  padding: 0 8px;
  line-height: 1.6;
}
.node-redo {
  font-size: 13px;
  font-weight: 800;
  color: var(--bad-ink);
  background: var(--bad-soft);
  border-radius: 999px;
  padding: 0 8px;
  line-height: 1.6;
}
.m-redo { align-self: flex-start; margin-top: 4px; }
.mission.is-next .m-redo { background: var(--surface); color: var(--bad-ink); }
.journey .node.is-current { border-color: var(--unit, var(--primary)); border-width: 2px; border-top-width: 4px; }
.journey .node.is-done .node-index { background: var(--good-soft); color: var(--good-ink); }
.journey .node.is-done .node-meta { color: var(--good-ink); }
.journey .node.is-done .node-bar > span { background: var(--good); }
.continue-done {
  font-weight: 700;
  font-size: 15px;
  background: rgba(255, 255, 255, .16);
  border-radius: 12px;
  padding: 6px 10px;
}

.badge-board .badge-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 220px), 1fr)); gap: 8px; }
.badge-board .badge { min-height: 52px; padding: 8px 12px; box-shadow: none; }
.badge-board .badge svg { flex: none; }
.badge-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.4; }
.badge-text strong { font-size: 15px; }
.badge-text small { font-size: 13px; }
.badge-count { font-weight: 800; }
.badge-more > summary {
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 44px;
  padding: 6px 12px;
  border: 1px dashed var(--line);
  border-radius: 14px;
  background: var(--surface);
  color: var(--primary);
  font-weight: 800;
  cursor: pointer;
}
.badge-more > summary::-webkit-details-marker { display: none; }
.badge-more[open] > summary .fold-icon { transform: rotate(180deg); }
.badge-more > .badge-list { margin-top: 8px; }
.badge-board .badge-list.is-locked .badge { min-height: 44px; padding: 6px 10px; }
.totals { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; padding: 12px; }
.total-tile { display: flex; flex-direction: column; gap: 0; padding: 8px 10px; border-radius: 14px; background: var(--surface-2); min-width: 0; }
.total-tile strong { font-size: 1.3rem; line-height: 1.3; }
.total-tile .fine { font-weight: 700; }
@media (min-width: 640px) { .totals { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.record-units { gap: 10px; }
.record-units > .record-unit { gap: 0; border-top: 4px solid var(--unit, var(--primary)); }
.record-units > .record-unit + .record-unit { padding-top: 0; border-top: 4px solid var(--unit, var(--primary)); }
.record-unit > summary { align-items: center; padding: 12px 16px; }
.ru-head { display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0; }
.ru-head .unit-bar { height: 8px; margin-top: 4px; }
.ru-sub { font-size: 1rem; font-weight: 800; margin: 4px 0 0; }
.record-unit.is-current { box-shadow: 0 0 0 2px var(--unit, var(--primary)), var(--shadow); }
.path-group + .path-group { margin-top: 6px; }
.group-title {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  column-gap: 10px;
  padding: 0 4px 6px;
  border-bottom: 2px solid color-mix(in srgb, var(--unit, var(--primary)) 35%, var(--line));
  color: var(--text);
}
.group-kicker { grid-column: 1; font-size: 14px; font-weight: 800; color: var(--unit-ink, var(--primary)); line-height: 1.4; }
.group-name { grid-column: 1; font-size: 1.05rem; font-weight: 800; line-height: 1.4; }
.group-count { grid-column: 2; grid-row: 1 / span 2; align-self: end; font-size: 14px; font-weight: 700; color: var(--muted); white-space: nowrap; }
.record-unit .skill-results { gap: 0; }
.record-unit .skill-results li { padding: 8px 0; font-size: 15px; line-height: 1.5; }
.record-unit .skill-results li > span:first-child { display: flex; flex-direction: column; min-width: 0; }
.record-unit .skill-count { font-size: 13px; font-weight: 700; }
.record-unit .status { flex: none; }

/* ---------- Code: in text and the Python step (unit a4) ---------- */
/*
 * The device's own monospace font, limited to Latin, digits and symbols: Arabic letters in
 * strings and comments then fall through to Tajawal and stay joined and readable, instead of
 * being squeezed into fixed-width cells.
 */
@font-face {
  font-family: "PortalMono";
  src: local("SF Mono"), local("SFMono-Regular"), local("Menlo"), local("Menlo-Regular"),
    local("Cascadia Mono"), local("Consolas"), local("Roboto Mono"), local("Droid Sans Mono"),
    local("DroidSansMono"), local("Noto Sans Mono"), local("DejaVu Sans Mono"), local("Liberation Mono"),
    local("Courier New");
  unicode-range: U+0000-02FF, U+2000-206F, U+2190-21FF, U+2200-22FF, U+25A0-25FF;
  font-display: swap;
}
:root {
  --mono: "PortalMono", "Tajawal", ui-monospace, "SFMono-Regular", Menlo, Consolas, "Liberation Mono", monospace;
  --code-bg: #F7F8FE;
  --code-edge: #D5DBF5;
  --code-num: #8A91B4;
  --tk-kw: #7C3AED;
  --tk-bi: #0369A1;
  --tk-str: #047857;
  --tk-com: #6B7280;
  --tk-num: #C2410C;
  --run: #12B76A;
  --run-edge: #0B8A4E;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --code-bg: #12162F;
    --code-edge: #2F3668;
    --code-num: #7D85B3;
    --tk-kw: #C4B5FD;
    --tk-bi: #7DD3FC;
    --tk-str: #6EE7B7;
    --tk-com: #9AA3C7;
    --tk-num: #FDBA74;
    --run: #34D399;
    --run-edge: #12B76A;
  }
}
:root[data-theme="dark"] {
  --code-bg: #12162F;
  --code-edge: #2F3668;
  --code-num: #7D85B3;
  --tk-kw: #C4B5FD;
  --tk-bi: #7DD3FC;
  --tk-str: #6EE7B7;
  --tk-com: #9AA3C7;
  --tk-num: #FDBA74;
  --run: #34D399;
  --run-edge: #12B76A;
}

.tk-kw { color: var(--tk-kw); font-weight: 700; }
.tk-bi { color: var(--tk-bi); }
.tk-str { color: var(--tk-str); }
.tk-com { color: var(--tk-com); font-style: normal; }
.tk-num { color: var(--tk-num); }
.tk-iso { unicode-bidi: isolate; }

/* Inline `code` inside Arabic text: its own left-to-right island. */
code.ic {
  direction: ltr;
  unicode-bidi: isolate;
  font-family: var(--mono);
  font-size: .9em;
  font-weight: 600;
  padding: .05em .4em;
  margin-inline: .1em;
  border-radius: 7px;
  background: var(--code-bg);
  border: 1px solid var(--code-edge);
  color: var(--text);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
}

/* Fenced block: spans so it is valid inside headings, paragraphs and buttons. */
.rich.has-code { display: block; }
.code-block {
  display: block;
  direction: ltr;
  unicode-bidi: isolate;
  text-align: left;
  margin: 8px 0;
  max-width: 100%;
  font-size: 16px;
  font-weight: 500;
  line-height: 1.6;
}
.rich-line + .code-block, .code-block + .rich-line { margin-top: 10px; }
.cb-scroll {
  display: block;
  max-width: 100%;
  overflow-x: auto;
  border: 1.5px solid var(--code-edge);
  border-radius: 12px;
  background: var(--code-bg);
  -webkit-overflow-scrolling: touch;
}
code.cb {
  display: block;
  width: max-content;
  min-width: 100%;
  padding: 8px 14px;
  font-family: var(--mono);
  color: var(--text);
  counter-reset: cb-ln;
  -webkit-user-select: text;
  user-select: text;
}
.cb-line { display: block; white-space: pre; min-height: 1.6em; }
.has-num .cb-line { counter-increment: cb-ln; }
.has-num code.cb { padding-left: 8px; }
.has-num .cb-line::before {
  content: counter(cb-ln);
  display: inline-block;
  width: 2ch;
  margin-right: 12px;
  text-align: right;
  color: var(--code-num);
  font-weight: 500;
  -webkit-user-select: none;
  user-select: none;
}
.tile .code-block, .choice-text .code-block { font-size: 15px; margin: 4px 0; }
.prompt .code-block { font-size: 16px; font-weight: 500; }

/* ---------- Code step ---------- */
.code-widget { gap: 14px; }
.code-card {
  background: var(--surface);
  border: 2px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.code-card:focus-within { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary), var(--shadow); }
.code-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 4px 6px 4px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
}
.code-title { display: inline-flex; align-items: center; gap: 6px; font-weight: 800; color: var(--muted); font-size: 15px; }
.code-title svg { color: var(--primary); }
.code-tool {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 12px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--primary-edge);
  font-weight: 800;
  font-size: 15px;
}
:root[data-theme="dark"] .code-tool { color: var(--primary); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .code-tool { color: var(--primary); } }
.code-tool:hover { background: var(--primary-soft); }

/* CodeMirror 6 editor (vendor/codemirror): our colours, 16 px, line numbers on the left.
 * Selectors carry .cm-editor twice-deep so they win over CodeMirror's adopted base theme. */
.code-editor { direction: ltr; background: var(--code-bg); }
.code-editor .cm-editor { background: var(--code-bg); color: var(--text); font-size: 16px; }
.code-editor .cm-editor.cm-focused { outline: none; }
.code-editor .cm-editor .cm-scroller {
  font-family: var(--mono);
  line-height: 26px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.code-editor .cm-editor .cm-content {
  padding: 10px 0;
  min-height: calc(26px * 6 + 20px);
  caret-color: var(--text);
  font-variant-ligatures: none;
}
.code-editor .cm-editor .cm-line { padding: 0 14px 0 10px; }
.code-editor .cm-editor .cm-content ::selection { background: color-mix(in srgb, var(--primary) 30%, transparent); }
.code-editor .cm-editor .cm-selectionBackground { background: color-mix(in srgb, var(--primary) 30%, transparent) !important; }
.code-editor .cm-editor .cm-gutters {
  min-height: calc(26px * 6 + 20px);
  background: var(--code-bg);
  color: var(--code-num);
  border-right: 1px solid var(--code-edge);
  font-variant-numeric: tabular-nums;
}
.code-editor .cm-editor .cm-lineNumbers .cm-gutterElement { padding: 0 8px 0 10px; min-width: 2.6em; text-align: right; }
.code-editor .cm-editor .cm-lineNumbers .cm-gutterElement.cm-error-num { background: var(--bad); color: #FFFFFF; font-weight: 800; border-radius: 6px; }
.code-editor .cm-editor .cm-error-line { background: color-mix(in srgb, var(--bad) 18%, transparent); box-shadow: inset 3px 0 0 var(--bad); }
.code-editor .tk-iso { unicode-bidi: isolate; }
.code-editor.is-readonly .cm-editor .cm-content { caret-color: transparent; }

.code-sub { display: inline-flex; align-items: center; gap: 6px; font-weight: 800; font-size: 16px; color: var(--text); margin: 0; }
.code-sub svg { color: var(--primary); flex: none; }
.code-note { color: var(--muted); font-size: 15px; font-weight: 700; }
.code-inputs { display: flex; flex-direction: column; gap: 6px; }
.code-in {
  width: 100%;
  min-height: 84px;
  border-radius: 14px;
  border: 2px solid var(--line);
  background: var(--surface);
  color: var(--text);
  padding: 8px 12px;
  font-family: var(--mono);
  font-size: 16px;
  line-height: 1.6;
  resize: vertical;
  unicode-bidi: plaintext;
}
.code-in:focus-visible { border-color: var(--primary); }

.code-out, .code-files, .code-tests {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 14px;
  border-radius: 18px;
  border: 2px solid var(--line);
  background: var(--surface);
}
.code-out[data-state="error"], .code-out[data-state="timeout"] { border-color: color-mix(in srgb, var(--bad) 55%, var(--line)); }
.code-out[data-state="ok"] { border-color: color-mix(in srgb, var(--good) 55%, var(--line)); }
.code-out.is-stale { opacity: .6; }
.out-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.out-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 30px;
  padding: 0 10px;
  border-radius: 999px;
  font-size: 15px;
  font-weight: 800;
}
.out-chip.is-ok { background: var(--good-soft); color: var(--good-ink); }
.out-chip.is-error, .out-chip.is-timeout { background: var(--bad-soft); color: var(--bad-ink); }
.out-chip.is-running { background: var(--info-soft); color: var(--info-ink); }
.spin {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2.5px solid currentColor;
  border-right-color: transparent;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.out-pre, .file-body, .cmp-pre {
  margin: 0;
  direction: ltr;
  text-align: left;
  font-family: var(--mono);
  font-size: 16px;
  line-height: 1.55;
  background: var(--code-bg);
  border: 1px solid var(--code-edge);
  border-radius: 12px;
  padding: 8px 12px;
  overflow-x: auto;
  max-height: 320px;
  overflow-y: auto;
  color: var(--text);
}
/* Each output line has its own direction (set in term-line.js); numbers and quoted text are islands. */
.out-line { display: block; white-space: pre; unicode-bidi: isolate; text-align: start; min-height: 1.55em; }
.out-line bdi { unicode-bidi: isolate; }
/* Note row inside program output: older lines hidden while a run is going, or lines
   left out of the middle of a long result (term-line.js). */
.out-line.out-note { white-space: normal; font: 600 14px/1.6 var(--font); margin-block: 4px; }
.out-err {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--bad-soft);
}
.err-en {
  direction: ltr;
  text-align: left;
  unicode-bidi: isolate;
  font-family: var(--mono);
  font-size: 15px;
  font-weight: 600;
  color: var(--bad-ink);
  overflow-wrap: anywhere;
}
.err-line { display: inline-block; padding: 0 6px; border-radius: 6px; background: var(--bad); color: #FFFFFF; font-weight: 800; }
.err-ar { font-weight: 700; color: var(--text); }

.file-strip { display: flex; flex-direction: column; gap: 6px; }
.file-item { border: 1px solid var(--line); border-radius: 12px; background: var(--surface-2); }
.file-name {
  min-height: 44px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  font-weight: 800;
  cursor: pointer;
  list-style: none;
}
.file-name::-webkit-details-marker { display: none; }
.file-name bdi { font-family: var(--mono); font-size: 15px; }
.file-name svg { color: var(--info-ink); flex: none; }
.file-tag { margin-inline-start: auto; padding: 0 8px; border-radius: 999px; background: var(--xp-soft); color: var(--xp-ink); font-size: 14px; }
.file-body { margin: 0 8px 8px; }

.tests-title:focus-visible { outline: 3px solid var(--primary); outline-offset: 3px; border-radius: 6px; }
.test-list { list-style: none; display: flex; flex-direction: column; gap: 6px; }
.test-row { border-radius: 12px; padding: 6px 10px; background: var(--surface-2); }
.test-row.is-pass { background: var(--good-soft); }
.test-row.is-fail { background: var(--bad-soft); }
.test-line { display: flex; align-items: center; gap: 8px; min-height: 36px; font-weight: 700; }
.test-label { flex: 1; min-width: 0; }
.test-mark { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; flex: none; color: #FFFFFF; }
.is-pass .test-mark { background: var(--good-edge); }
.is-fail .test-mark { background: var(--bad-edge); }
.test-tag { font-size: 13px; font-weight: 800; padding: 0 8px; border-radius: 999px; background: var(--surface); color: var(--muted); }
.test-more > summary { min-height: 40px; display: flex; align-items: center; cursor: pointer; font-weight: 800; color: var(--primary-edge); }
:root[data-theme="dark"] .test-more > summary { color: var(--primary); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .test-more > summary { color: var(--primary); } }
.compare { display: flex; flex-direction: column; gap: 8px; padding-bottom: 6px; }
.cmp-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; }
.cmp-col { min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.cmp-label { font-size: 14px; font-weight: 800; color: var(--muted); }
.cmp-col.is-expected .cmp-pre { border-color: var(--good-edge); }
.cmp-col.is-got .cmp-pre { border-color: var(--bad-edge); }
.cmp-pre { max-height: 180px; background: var(--surface); }
.cmp-empty { color: var(--muted); font-family: var(--font); }
@media (min-width: 560px) { .cmp-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); } }
.sheet-test { font-weight: 700; }
.feedback-sheet .cmp-pre { max-height: 120px; }

.solution-box { border: 2px dashed var(--line); border-radius: 18px; padding: 4px 12px 8px; background: var(--surface); }
.solution-box > summary { min-height: 48px; cursor: pointer; }

/* Dock: helper keys over Run / Check. */
.key-row {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
  padding: 2px 0 4px;
  direction: ltr;
}
.key-row::-webkit-scrollbar { display: none; }
.key-btn {
  flex: 1 0 auto;
  min-width: 44px;
  min-height: 44px;
  padding: 0 10px;
  border-radius: 12px;
  border: 1.5px solid var(--line);
  background: var(--surface);
  color: var(--text);
  font-family: var(--mono);
  font-size: 17px;
  font-weight: 700;
  box-shadow: 0 2px 0 var(--line);
}
.key-btn:active { transform: translateY(1px); box-shadow: none; }
.code-actions { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; }
.code-actions.is-single { grid-template-columns: minmax(0, 1fr); }
.action-dock .code-actions .btn { width: 100%; }
.btn.run-btn {
  --edge: var(--run-edge);
  background: var(--surface);
  color: var(--good-ink);
  border: 2px solid var(--run);
}
.btn.run-btn svg { color: var(--run); }
.btn.run-btn:disabled svg { color: var(--muted); }
@media (max-height: 520px) {
  .code-dock { padding-top: 4px; gap: 4px; }
  .code-dock .btn { min-height: 48px; }
  .code-bar { padding-block: 0; }
}
.sheet-foot { font-weight: 700; color: var(--text); }

.code-rules { font-size: 16px; font-weight: 600; color: var(--text); padding: 8px 12px; border-radius: 14px; background: var(--info-soft); }
.cmp-file { font-family: var(--mono); font-size: 14px; color: var(--text); }
.contains-list { list-style: none; display: flex; flex-direction: column; gap: 6px; padding: 8px 10px; border-radius: 12px; background: var(--surface); border: 1px solid var(--good-edge); }
.contains-list li { display: flex; align-items: center; gap: 8px; min-width: 0; }
.contains-list .test-mark { width: 22px; height: 22px; }
.contains-list .is-found .test-mark { background: var(--good-edge); }
.contains-list .is-missing .test-mark { background: var(--bad-edge); }
.contains-text { flex: 1; min-width: 0; overflow-x: auto; font-family: var(--mono); font-size: 15px; background: var(--code-bg); border-radius: 8px; padding: 2px 8px; }
.btn .spin { flex: none; }
.contains-list.is-avoid { border-color: var(--bad-edge); }
.cmp-col.is-expected .contains-list + .cmp-label { margin-top: 6px; }
.test-row.is-skip { background: var(--surface-2); }
.is-skip .test-mark { background: var(--muted); }
.contains-list li { align-items: flex-start; }
.contains-list .test-mark { margin-top: 4px; }
.contains-part { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.contains-note { font-size: 13px; font-weight: 800; color: var(--muted); }
.contains-text.is-multi { border: 1px dashed var(--code-edge); }
.contains-text { display: block; }
.code-fold { border: 1.5px solid var(--line); border-radius: 16px; background: var(--surface); }
.code-fold-head { min-height: var(--tap); display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 4px 12px; padding: 8px 14px; cursor: pointer; font-weight: 800; }
.code-fold[open] > .code-fold-head { border-bottom: 1px solid var(--line); }
.code-fold-body { padding: 12px; }
.code-fold-body .open-card { box-shadow: none; }
.code-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; }
.code-chip { display: inline-flex; align-items: center; min-height: 30px; padding: 0 10px; border-radius: 999px; font-size: 15px; font-weight: 800; background: var(--surface-2); color: var(--text); }
.code-chip.is-good { background: var(--good-soft); color: var(--good-ink); }
.code-chip.is-warn { background: var(--xp-soft); color: var(--xp-ink); }

/* Robot programs in the record: the block text, read right-to-left, one block per line. */
.robot-record-text {
  margin: 0;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--code-bg, var(--surface-2));
  border: 1px solid var(--code-edge, var(--line));
  font: 600 15px/1.7 var(--font);
  white-space: pre-wrap;
  overflow-x: auto;
  unicode-bidi: plaintext;
}
.robot-record-btn { width: auto; align-self: flex-start; }
