/* =========================================================
   منصة جافا التدريبية — الطابع الأكاديمي
   Flat Design + Accessible & Ethical + Swiss Minimalism
   ========================================================= */

/* ============ الألوان والمتغيرات ============ */
:root {
  --bg: #f1f7f6;
  --surface: #ffffff;
  --surface-2: #f6faf9;
  --surface-3: #e8f1f0;
  --border: #dfe9e7;
  --border-strong: #c2d3d0;
  --text: #123b38;
  --muted: #4d6663;
  --primary: #0f766e;
  --primary-hover: #0b5f58;
  --primary-soft: #e3f4f1;
  --primary-text: #0f766e;
  --on-primary: #ffffff;
  --accent: #0f766e;
  --accent-soft: #e3f4f1;
  --gold: #d97706;
  --header-bg: #0a3f3b;
  --header-2: #0f766e;
  --header-text: #ffffff;
  --header-muted: #e0f4f0;
  --success: #15803d;
  --success-soft: #e7f5ec;
  --success-text: #166534;
  --warn: #b45309;
  --warn-soft: #fef4e6;
  --warn-text: #8a3c07;
  --danger: #b91c1c;
  --danger-soft: #fdecec;
  --danger-text: #991b1b;
  --lvl-easy: #15803d;
  --lvl-medium: #b45309;
  --lvl-hard: #b91c1c;
  --shadow-sm: 0 1px 2px rgba(13, 60, 56, .05);
  --shadow: 0 2px 4px rgba(13, 60, 56, .04), 0 12px 28px -12px rgba(13, 60, 56, .16);
  --shadow-lg: 0 24px 56px -16px rgba(13, 60, 56, .38);
  --radius: 12px;
  --radius-sm: 8px;

  --t-fast: 200ms;
  --t-base: 250ms;
  --t-slow: 400ms;
  --ease: cubic-bezier(.2, .7, .2, 1);

  --font: 'Alexandria', 'Segoe UI', Tahoma, system-ui, sans-serif;
  --font-head: 'Alexandria', 'Segoe UI', Tahoma, system-ui, sans-serif;
  --mono: 'JetBrains Mono', 'Cascadia Code', Consolas, 'Courier New', monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1416;
    --surface: #121e21;
    --surface-2: #162629;
    --surface-3: #1c3033;
    --border: #24393d;
    --border-strong: #36525a;
    --text: #e7f2f0;
    --muted: #a3b9b6;
    --primary: #2dd4bf;
    --primary-hover: #5eead4;
    --primary-soft: #0f3330;
    --primary-text: #5eead4;
    --on-primary: #04201d;
    --accent: #5eead4;
    --accent-soft: #0f3330;
    --gold: #f59e0b;
    --header-bg: #0c2a2a;
    --header-2: #0f4a46;
    --header-muted: #b5cfcb;
    --success: #22a052;
    --success-soft: #0f2a1b;
    --success-text: #86efac;
    --warn: #d97706;
    --warn-soft: #2e2210;
    --warn-text: #fcd34d;
    --danger: #dc4a4a;
    --danger-soft: #2e1515;
    --danger-text: #fca5a5;
    --lvl-easy: #4ade80;
    --lvl-medium: #fbbf24;
    --lvl-hard: #f87171;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .35);
    --shadow: 0 2px 4px rgba(0, 0, 0, .25), 0 12px 28px -12px rgba(0, 0, 0, .6);
    --shadow-lg: 0 24px 56px -16px rgba(0, 0, 0, .8);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0b1416;
  --surface: #121e21;
  --surface-2: #162629;
  --surface-3: #1c3033;
  --border: #24393d;
  --border-strong: #36525a;
  --text: #e7f2f0;
  --muted: #a3b9b6;
  --primary: #2dd4bf;
  --primary-hover: #5eead4;
  --primary-soft: #0f3330;
  --primary-text: #5eead4;
  --on-primary: #04201d;
  --accent: #5eead4;
  --accent-soft: #0f3330;
  --gold: #f59e0b;
  --header-bg: #0c2a2a;
  --header-2: #0f4a46;
  --header-muted: #b5cfcb;
  --success: #22a052;
  --success-soft: #0f2a1b;
  --success-text: #86efac;
  --warn: #d97706;
  --warn-soft: #2e2210;
  --warn-text: #fcd34d;
  --danger: #dc4a4a;
  --danger-soft: #2e1515;
  --danger-text: #fca5a5;
  --lvl-easy: #4ade80;
  --lvl-medium: #fbbf24;
  --lvl-hard: #f87171;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .35);
  --shadow: 0 2px 4px rgba(0, 0, 0, .25), 0 12px 28px -12px rgba(0, 0, 0, .6);
  --shadow-lg: 0 24px 56px -16px rgba(0, 0, 0, .8);
  color-scheme: dark;
}

/* لوحة الكود داكنة في الوضعين، كما في بيئات البرمجة */
.code-pane, .code-wrap, .code-block {
  --ed-bg: #0e1b1e;
  --ed-gutter: #0e1b1e;
  --ed-text: #dfeeec;
  --ed-lnum: #7a9490;
  --ed-active: rgba(94, 234, 212, .06);
  --tk-kw: #5eead4;
  --tk-type: #7dd3fc;
  --tk-str: #fcd34d;
  --tk-num: #d8b4fe;
  --tk-com: #7f9793;
  --tk-fn: #a5b4fc;
  --tk-lit: #fca5a5;
}
.code-pane, .code-wrap {
  --surface: #122125;
  --surface-2: #16282c;
  --surface-3: #1c3033;
  --border: #24393d;
  --border-strong: #36525a;
  --text: #e7f2f0;
  --muted: #a3b9b6;
  --primary-text: #5eead4;
  --primary-soft: #0f3330;
  color: var(--text);
}

/* ============ الأساسيات ============ */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.7;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3, h4, p, dl, dd, dt { margin: 0; }
.ic { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.ic-sm { width: 16px; height: 16px; }
.muted { color: var(--muted); }
[hidden] { display: none !important; }
code, pre, kbd, .mono { font-family: var(--mono); }
:focus-visible { outline: 2px solid var(--primary-text); outline-offset: 2px; border-radius: 4px; }
.skip-link { position: absolute; inset-inline-start: 12px; top: -60px; z-index: 100; background: var(--primary); color: var(--on-primary); padding: 8px 14px; border-radius: var(--radius-sm); text-decoration: none; }
.skip-link:focus { top: 12px; }

/* ============ الشريط العلوي ============ */
.hero {
  color: var(--header-text);
  background: linear-gradient(120deg, var(--header-bg), var(--header-2));
  padding-bottom: 48px;
}
.hero :focus-visible { outline-color: #fff; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  max-width: 1480px; margin-inline: auto; padding: 14px 28px 6px;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; margin-inline-end: auto; }
.brand-mark {
  width: 42px; height: 42px; border-radius: 12px; flex: none;
  display: grid; place-items: center; background: #ffffff;
  box-shadow: 0 4px 12px -4px rgba(0, 0, 0, .35);
}
.brand-mark img { width: 31px; height: 31px; display: block; }
.brand h1 { font-family: var(--font-head); font-size: 20px; font-weight: 700; line-height: 1.3; white-space: nowrap; }
.brand p { font-size: 12.5px; line-height: 1.5; color: var(--header-muted); white-space: nowrap; }
/* اسم المنصة وسطر الإعداد في سطر واحد بينهما مسافة واضحة */
.brand-line { display: flex; align-items: baseline; flex-wrap: wrap; column-gap: 28px; row-gap: 2px; }
.brand .brand-credit { font-size: 13px; font-weight: 600; color: #99f6e4; }
.top-actions { display: flex; gap: 8px; align-items: center; }
.top-btn {
  display: inline-flex; align-items: center; gap: 8px; min-height: 44px;
  padding: 0 14px; border-radius: var(--radius-sm);
  border: 1px solid rgba(255,255,255,.22); background: rgba(255,255,255,.06); color: var(--header-text);
  font-size: 14px; font-weight: 500;
  transition: background var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease);
}
.top-btn:hover { background: rgba(255,255,255,.14); border-color: rgba(255,255,255,.4); }
.top-btn.icon-only { width: 44px; padding: 0; justify-content: center; }
.ic-sun { display: none; }
:root[data-theme="dark"] .ic-sun { display: block; }
:root[data-theme="dark"] .ic-moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .ic-sun { display: block; }
  :root:not([data-theme="light"]) .ic-moon { display: none; }
}

.banner {
  padding: 12px 16px; border-radius: var(--radius);
  background: var(--warn-soft); color: var(--warn-text);
  border: 1px solid color-mix(in srgb, var(--warn) 35%, transparent);
  font-size: 14.5px; box-shadow: var(--shadow);
}
.banner code { background: rgba(0,0,0,.06); padding: 1px 6px; border-radius: 4px; }

/* ============ التخطيط ============ */
.content { position: relative; min-width: 0; width: 100%; max-width: 1480px; margin: -30px auto 0; padding: 0 28px 28px; display: flex; flex-direction: column; gap: 16px; }

/* ============ الصف العلوي: القائمة المنسدلة والتمارين ============ */
.head-row { display: flex; align-items: center; gap: 12px 28px; max-width: 1480px; margin-inline: auto; padding: 10px 28px 0; }
.unit-picker { position: relative; z-index: 40; flex: 0 1 340px; min-width: 0; }
.unit-trigger {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  width: 100%; min-height: 62px; padding: 6px 16px; text-align: start; color: #fff;
  background: rgba(255, 255, 255, .12); border: 1px solid rgba(255, 255, 255, .28); border-radius: var(--radius);
  transition: background var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease);
}
.unit-trigger:hover, .unit-trigger[aria-expanded="true"] { background: rgba(255, 255, 255, .2); border-color: rgba(255, 255, 255, .55); }
.ut-text { display: flex; flex-direction: column; min-width: 0; }
.ut-text small { font-size: 12.5px; font-weight: 500; color: var(--header-muted); line-height: 1.5; }
.ut-text b { font-family: var(--font-head); font-size: 19px; font-weight: 700; line-height: 1.4; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ut-chevron { transition: transform var(--t-fast) var(--ease); }
.unit-trigger[aria-expanded="true"] .ut-chevron { transform: rotate(180deg); }

.sidebar {
  display: none; position: absolute; top: calc(100% + 8px); inset-inline-start: 0;
  width: min(420px, calc(100vw - 32px)); max-height: calc(100vh - 170px); overflow: auto; scrollbar-width: thin;
  background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
}
.sidebar :focus-visible { outline-color: var(--primary-text); }
body.side-open .sidebar { display: block; animation: pop var(--t-fast) var(--ease); }
.side-head { padding: 16px 18px 14px; border-bottom: 1px solid var(--border); }
.side-progress-row { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); }
.side-progress-row b { font-family: var(--mono); color: var(--text); }
.side-progress-bar { height: 5px; border-radius: 3px; background: var(--surface-3); overflow: hidden; margin-top: 6px; }
.side-progress-bar i { display: block; height: 100%; width: 0; background: var(--success); transition: width var(--t-slow) var(--ease); }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 12px; }
.stat { display: flex; flex-direction: column; min-width: 0; }
.stat dd { font-family: var(--mono); font-size: 16px; font-weight: 700; line-height: 1.4; }
.stat dd small { font-size: 12px; color: var(--muted); font-weight: 500; }
.stat dt { font-size: 12px; color: var(--muted); }
.unit-about { padding: 14px 18px 16px; border-top: 1px solid var(--border); }
.about-title { display: flex; justify-content: space-between; gap: 12px; font-size: 13px; font-weight: 700; color: var(--muted); }
.about-title span { font-weight: 400; }
.unit-about .summary { font-size: 14px; color: var(--text); margin-top: 4px; }
.topics { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.topic { font-size: 12.5px; padding: 1px 9px; border-radius: 6px; background: var(--surface-3); color: var(--text); }
.uh-stats { display: flex; gap: 24px; flex: none; margin-inline-start: auto; }
.uh-stats div { display: flex; flex-direction: column; align-items: center; }
.uh-stats dd { font-family: var(--mono); font-size: 18px; font-weight: 700; line-height: 1.4; }
.uh-stats dt { font-size: 12.5px; color: var(--header-muted); }

/* ============ الوحدات ============ */
.units { display: flex; flex-direction: column; gap: 2px; padding: 10px; }
.unit-tab {
  display: grid; grid-template-columns: 28px 1fr auto; gap: 10px; align-items: center;
  width: 100%; min-height: 46px; padding: 6px 10px; text-align: start;
  border: 0; border-radius: var(--radius-sm); background: transparent;
  transition: background var(--t-fast) var(--ease);
}
.unit-tab:hover { background: var(--surface-2); }
.u-index {
  width: 28px; height: 28px; border-radius: 7px; display: grid; place-items: center;
  font-family: var(--mono); font-weight: 700; font-size: 13px;
  background: var(--surface-3); color: var(--muted);
}
.u-body { min-width: 0; }
.u-title { display: block; font-size: 14px; font-weight: 500; line-height: 1.45; }
.u-count { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.unit-tab.active { background: var(--primary-soft); }
.unit-tab.active .u-index { background: var(--primary); color: var(--on-primary); }
.unit-tab.active .u-title { color: var(--primary-text); font-weight: 700; }
.unit-tab.done .u-index { background: var(--success); color: #fff; }

/* ============ أرقام التمارين ============ */
.ex-strip { display: flex; align-items: center; gap: 7px; min-width: 0; overflow-x: auto; scrollbar-width: thin; padding: 6px; }
/* البلاطات فاتحة في الوضعين حتى تبقى خطوط المستويات واضحة */
.ex-pill {
  --lvl-easy: #15803d; --lvl-medium: #b45309; --lvl-hard: #b91c1c;
  flex: none; position: relative; width: 42px; height: 42px; border-radius: 10px;
  display: grid; place-items: center; padding-bottom: 4px;
  font-family: var(--mono); font-weight: 700; font-size: 14px;
  background: #ffffff; border: 2px solid transparent; color: #123b38;
  box-shadow: 0 2px 6px -2px rgba(0, 0, 0, .3);
  transition: transform var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease);
}
.ex-pill:hover { transform: translateY(-2px); box-shadow: 0 6px 12px -4px rgba(0, 0, 0, .4); }
.ex-pill .lvl { position: absolute; bottom: 4px; left: 50%; transform: translateX(-50%); width: 18px; height: 3px; border-radius: 2px; }
.lvl.easy { background: var(--lvl-easy); }
.lvl.medium { background: var(--lvl-medium); }
.lvl.hard { background: var(--lvl-hard); }
.ex-pill.passed { background: #dcfce7; border-color: #16a34a; color: #14532d; }
.ex-pill.improve { background: #fef3c7; border-color: #f59e0b; color: #78350f; }
.ex-pill.active { box-shadow: 0 0 0 2px var(--header-bg), 0 0 0 4px #fff; }

/* ============ مساحة العمل ============ */
.workspace {
  display: grid; gap: 18px;
  grid-template-columns: minmax(0, 1.35fr) minmax(340px, 1fr);
  grid-template-areas: "code task";
  align-items: start;
}
.task-pane { grid-area: task; min-width: 0; }
.code-pane {
  grid-area: code; display: flex; flex-direction: column; min-width: 0; position: sticky; top: 16px;
  border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); background: var(--surface);
}

.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.task-card { animation: rise var(--t-base) var(--ease); }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }
.task-head { padding: 20px 24px 16px; }
.task-meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.task-num { font-size: 13px; font-weight: 600; color: var(--accent); margin-inline-end: 4px; }
.task-head h3 { font-family: var(--font-head); font-size: 23px; font-weight: 700; line-height: 1.45; margin-top: 4px; }
.badge { display: inline-flex; align-items: center; gap: 5px; font-size: 12.5px; font-weight: 600; padding: 1px 10px; border-radius: 6px; border: 1px solid transparent; }
.badge.easy { color: var(--lvl-easy); border-color: currentColor; }
.badge.medium { color: var(--lvl-medium); border-color: currentColor; }
.badge.hard { color: var(--lvl-hard); border-color: currentColor; }
.badge.best { background: var(--success-soft); color: var(--success-text); }
.badge.tries { background: var(--surface-3); color: var(--muted); }
.badge.ai { background: var(--primary-soft); color: var(--primary-text); }
.t-sec { padding: 16px 24px 20px; border-top: 1px solid var(--border); }
section.t-sec:first-of-type { background: var(--primary-soft); border-top: 0; }
.section-label { font-size: 13.5px; font-weight: 700; color: var(--primary-text); margin: 0 0 6px; }
.fold { padding-block: 0; }
.fold > summary {
  display: flex; align-items: center; justify-content: space-between; min-height: 48px; margin: 0;
  list-style: none; cursor: pointer; font-size: 14.5px; transition: opacity var(--t-fast) var(--ease);
}
.fold > summary::-webkit-details-marker { display: none; }
.fold > summary:hover { opacity: .8; }
.fold > summary::after {
  content: ''; width: 8px; height: 8px; margin-inline-end: 4px;
  border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor;
  transform: translateY(-2px) rotate(45deg); transition: transform var(--t-fast) var(--ease);
}
.fold[open] > summary::after { transform: translateY(2px) rotate(225deg); }
.fold[open] { padding-bottom: 18px; }
.info-text { font-size: 15px; }
.task-text { font-size: 16px; font-weight: 500; }

.code-block {
  position: relative; direction: ltr; text-align: left;
  background: var(--ed-bg); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 12px 14px; margin: 0; overflow-x: auto;
  font-family: var(--mono); font-size: 13.5px; line-height: 1.65; color: var(--ed-text);
  white-space: pre;
}
.code-wrap { position: relative; }
.copy-btn {
  position: absolute; top: 8px; right: 8px; font-family: var(--font);
  min-height: 32px; font-size: 12.5px; padding: 0 12px; border-radius: 6px; border: 1px solid var(--border);
  background: var(--surface); color: var(--muted);
  transition: color var(--t-fast), border-color var(--t-fast);
}
.copy-btn:hover { color: var(--primary-text); border-color: var(--primary-text); }
.io-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; }
.io-grid.single { grid-template-columns: 1fr; }
.io-box { border-radius: var(--radius-sm); overflow: hidden; border: 1px solid var(--border); background: var(--surface); }
.io-box .io-head { font-size: 12.5px; font-weight: 600; padding: 5px 12px; background: var(--surface-3); color: var(--muted); }
.io-box pre { margin: 0; padding: 10px 12px; font-size: 13.5px; direction: ltr; text-align: left; white-space: pre; overflow-x: auto; }

/* ============ المحرر ============ */
.editor-card { background: var(--surface); }
.editor-bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 6px 10px; border-bottom: 1px solid var(--border); background: var(--surface); }
.file-tab { display: inline-flex; align-items: center; gap: 8px; font-family: var(--mono); font-size: 13.5px; padding: 4px 6px; color: var(--text); }
.file-tab .ic { width: 16px; height: 16px; color: var(--gold); }
.editor-tools { display: flex; align-items: center; gap: 12px; }
.ghost-btn {
  display: inline-flex; align-items: center; gap: 7px; min-height: 40px;
  border: 1px solid var(--border-strong); background: var(--surface);
  border-radius: var(--radius-sm); padding: 0 14px; font-size: 14px; font-weight: 500;
  transition: background var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease), color var(--t-fast);
}
.ghost-btn:hover { border-color: var(--primary-text); color: var(--primary-text); }
.ghost-btn .ic { width: 18px; height: 18px; }

.ed {
  --ed-lh: 22px; --ed-pad: 14px; --ed-fs: 14px;
  position: relative; display: flex; height: clamp(280px, calc(100vh - 430px), 660px);
  background: var(--ed-bg); direction: ltr;
  font-family: var(--mono); font-size: var(--ed-fs); line-height: var(--ed-lh);
}
.ed-gutter { flex: none; width: 52px; overflow: hidden; background: var(--ed-gutter); border-right: 1px solid var(--border); user-select: none; }
.ed-lines { padding: var(--ed-pad) 0; will-change: transform; }
.ed-lines span { display: block; height: var(--ed-lh); padding-right: 12px; text-align: right; color: var(--ed-lnum); font-size: 12.5px; }
.ed-lines span.cur { color: var(--ed-text); font-weight: 700; }
.ed-lines span.err { color: #fff; background: var(--danger); }
.ed-main { position: relative; flex: 1; min-width: 0; overflow: hidden; }
.ed-hl, .ed-input {
  margin: 0; border: 0; padding: var(--ed-pad) 16px;
  font: inherit; line-height: var(--ed-lh); letter-spacing: 0;
  white-space: pre; tab-size: 4; word-wrap: normal; text-align: left; direction: ltr;
}
.ed-hl { position: absolute; top: 0; left: 0; min-width: 100%; color: var(--ed-text); pointer-events: none; will-change: transform; }
.ed-hl code { font: inherit; }
.ed-input {
  position: absolute; inset: 0; width: 100%; height: 100%; resize: none; outline: none;
  background: transparent; color: transparent; caret-color: var(--primary-text);
  overflow: auto; -webkit-text-fill-color: transparent;
}
.ed-input::selection { background: color-mix(in srgb, var(--primary-text) 25%, transparent); -webkit-text-fill-color: transparent; }
.ed-marks { position: absolute; inset: 0; pointer-events: none; will-change: transform; }
.ed-mark { position: absolute; left: 0; right: 0; height: var(--ed-lh); }
.ed-mark.active { background: var(--ed-active); }
.ed-mark.err { background: color-mix(in srgb, var(--danger) 12%, transparent); border-left: 3px solid var(--danger); }
.ed.focused { box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--primary-text) 35%, transparent); }
.tk-kw { color: var(--tk-kw); font-weight: 600; }
.tk-type { color: var(--tk-type); }
.tk-str { color: var(--tk-str); }
.tk-num { color: var(--tk-num); }
.tk-com { color: var(--tk-com); font-style: italic; }
.tk-fn { color: var(--tk-fn); }
.tk-lit { color: var(--tk-lit); }
.tk-ann { color: var(--warn); }

.stdin-box { padding: 10px 14px; border-top: 1px solid var(--border); background: var(--surface-2); }
.stdin-box label { display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 600; margin-bottom: 6px; }
.stdin-box label .ic { width: 18px; height: 18px; color: var(--accent); }
.stdin-box textarea {
  width: 100%; resize: vertical; min-height: 44px; border-radius: var(--radius-sm); padding: 8px 12px;
  border: 1px solid var(--border-strong); background: var(--ed-bg); font-family: var(--mono); font-size: 14px; text-align: left;
}
.stdin-box textarea:focus { outline: none; border-color: var(--primary-text); box-shadow: 0 0 0 3px var(--primary-soft); }
.help { font-size: 13px; color: var(--muted); margin-top: 4px; }

.actions { display: flex; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--border); flex-wrap: wrap; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; border: 1px solid transparent; border-radius: var(--radius-sm); padding: 0 18px;
  font-weight: 600; font-size: 15px; white-space: nowrap;
  transition: background var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease);
}
.btn:active:not(:disabled) { box-shadow: inset 0 2px 4px rgba(0,0,0,.2); }
.btn:disabled { opacity: .6; cursor: progress; }
.btn-run { background: #2dd4bf; color: #04201d; }
.btn-run:hover:not(:disabled) { background: #5eead4; }
.btn-eval { background: #f59e0b; color: #241301; }
.btn-eval:hover:not(:disabled) { background: #fbbf24; }
.btn-hint { background: transparent; color: var(--muted); border-color: var(--border-strong); margin-inline-start: auto; }
.btn-hint:hover:not(:disabled) { color: var(--primary-text); border-color: var(--primary-text); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: color-mix(in srgb, var(--danger) 88%, #000); }
.spinner { width: 16px; height: 16px; border-radius: 50%; border: 2.5px solid transparent; border-top-color: currentColor; border-right-color: currentColor; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ============ Console ============ */
.console { background: #0b181b; color: #e2efed; border-top: 1px solid #24393d; }
.console-bar { display: flex; align-items: center; gap: 12px; padding: 6px 12px; background: #0f1d20; border-bottom: 1px solid #24393d; direction: ltr; min-height: 44px; }
.console-toggle {
  display: inline-flex; align-items: center; gap: 8px; min-height: 36px; padding: 0 8px; margin-left: -8px;
  border: 0; border-radius: 6px; background: transparent; color: #a3b9b6; font-family: var(--mono); font-size: 13px;
  transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}
.console-toggle:hover { background: #16292d; color: #fff; }
.console-toggle .ic { width: 16px; height: 16px; }
.console-toggle .ic:first-child { color: var(--gold); }
.console-chevron { transition: transform var(--t-fast) var(--ease); }
.console[data-open="true"] .console-chevron { transform: rotate(180deg); }
.console[data-open="false"] .console-body { display: none; }
.console[data-open="false"] .console-bar { border-bottom: 0; }
.console-status { font-size: 13px; font-family: var(--font); direction: rtl; }
.console-clear { margin-left: auto; min-height: 32px; background: transparent; border: 1px solid #36525a; color: #a3b9b6; border-radius: 6px; font-size: 13px; padding: 0 12px; }
.console-clear:hover { border-color: #a3b9b6; color: #fff; }
.console-body { padding: 12px 16px; min-height: 84px; max-height: 340px; overflow: auto; font-size: 14px; }
.console-empty { color: #7f9793; font-size: 14px; }
.console-out { margin: 0; font-family: var(--mono); white-space: pre-wrap; word-break: break-word; direction: ltr; text-align: left; color: #e2efed; line-height: 1.6; }
.console-out:empty::before { content: '(لا توجد مخرجات)'; color: #7f9793; font-family: var(--font); }
.status-pill { display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: 4px; font-weight: 600; }
.status-pill .ic { width: 15px; height: 15px; stroke-width: 2.4; }
.status-pill.ok { background: rgba(34,197,94,.14); color: #86efac; }
.status-pill.err { background: rgba(248,113,113,.14); color: #fca5a5; }
.status-pill.warn { background: rgba(245,158,11,.14); color: #fcd34d; }
.status-pill.info { background: rgba(138,180,248,.14); color: #bcd3fb; }
.err-list { display: flex; flex-direction: column; gap: 8px; }
.err-item { display: flex; gap: 12px; align-items: flex-start; min-height: 44px; padding: 10px 12px; border-radius: var(--radius-sm); background: rgba(248,113,113,.07); border: 1px solid rgba(248,113,113,.24); cursor: pointer; text-align: start; color: inherit; width: 100%; transition: background var(--t-fast); }
.err-item:hover { background: rgba(248,113,113,.13); }
.err-line { flex: none; font-family: var(--mono); font-size: 12.5px; font-weight: 700; padding: 1px 8px; border-radius: 4px; background: #f87171; color: #1a0b0b; }
.err-msg { font-size: 14.5px; color: #fde2e2; }
.err-orig { display: block; font-family: var(--mono); font-size: 12.5px; color: #a3b9b6; direction: ltr; text-align: left; margin-top: 2px; }
.retry-box { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; color: #fcd34d; }
.retry-box button { min-height: 36px; border: 1px solid #fcd34d; color: #fcd34d; background: transparent; border-radius: 6px; padding: 0 14px; font-size: 13.5px; }
.stderr { margin-top: 10px; color: #fca5a5; }

/* ============ النوافذ ============ */
.modal {
  border: 0; padding: 0; border-radius: 12px; width: min(560px, calc(100vw - 32px));
  background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg);
  max-height: calc(100vh - 40px); border-top: 4px solid var(--primary);
}
.modal-wide { width: min(780px, calc(100vw - 32px)); }
.modal-sm { width: min(420px, calc(100vw - 32px)); }
.modal::backdrop { background: rgba(8, 15, 30, .6); }
.modal[open] { animation: pop var(--t-base) var(--ease); }
@keyframes pop { from { opacity: 0; transform: translateY(8px); } }
.modal-body { padding: 24px; display: flex; flex-direction: column; gap: 16px; }
.modal-title { font-family: var(--font-head); font-size: 21px; font-weight: 700; display: flex; align-items: center; gap: 10px; }
.modal-title .ic { width: 22px; height: 22px; color: var(--gold); }
.modal-actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-top: 4px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 14px; font-weight: 600; }
.field input { min-height: 46px; border: 1px solid var(--border-strong); background: var(--surface); border-radius: var(--radius-sm); padding: 0 14px; font-weight: 400; font-size: 16px; }
.field input:focus { outline: none; border-color: var(--primary-text); box-shadow: 0 0 0 3px var(--primary-soft); }
.student-list { display: flex; flex-wrap: wrap; gap: 6px; }
.student-list button { min-height: 36px; border: 1px solid var(--border-strong); background: var(--surface); border-radius: 6px; padding: 0 12px; font-size: 14px; }
.student-list button.current { border-color: var(--primary-text); color: var(--primary-text); background: var(--primary-soft); }
.file-btn { cursor: pointer; }

.result-top { display: grid; grid-template-columns: auto 1fr; gap: 24px; align-items: center; padding-bottom: 16px; border-bottom: 1px solid var(--border); }
.score-ring { position: relative; width: 124px; height: 124px; }
.score-ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.score-ring circle { fill: none; stroke-width: 10; }
.score-ring .track { stroke: var(--surface-3); }
.score-ring .value { stroke-linecap: round; transition: stroke-dashoffset 900ms var(--ease); }
.score-ring .num { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.score-ring .num b { font-size: 36px; font-family: var(--mono); line-height: 1; }
.score-ring .num small { font-size: 12.5px; color: var(--muted); margin-top: 4px; }
.score-ring.pass .value { stroke: var(--success); }
.score-ring.pass .num b { color: var(--success); }
.score-ring.fail .value { stroke: var(--danger); }
.score-ring.fail .num b { color: var(--danger); }
.verdict { font-family: var(--font-head); font-size: 22px; font-weight: 700; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.verdict .ic { width: 24px; height: 24px; stroke-width: 2.4; }
.verdict.pass { color: var(--success); }
.verdict.fail { color: var(--danger); }
.result-meta { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.result-summary { font-size: 15.5px; margin-top: 10px; }
.notice { padding: 12px 14px; border-radius: var(--radius-sm); background: var(--warn-soft); color: var(--warn-text); font-size: 14px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; border-inline-start: 4px solid var(--warn); }
.notice .ic { width: 18px; height: 18px; }
.notice button { min-height: 34px; border: 1px solid currentColor; background: transparent; color: inherit; border-radius: 6px; padding: 0 12px; font-size: 13.5px; }
.r-section h4 { margin: 0 0 10px; font-size: 14px; color: var(--muted); font-weight: 700; display: flex; align-items: center; gap: 8px; }
.tests { display: flex; flex-direction: column; gap: 6px; }
.test-row { border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2); }
.test-row summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: 10px; min-height: 44px; padding: 6px 12px; font-size: 14.5px; }
.test-row summary::-webkit-details-marker { display: none; }
.test-row .mark { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; color: #fff; flex: none; }
.test-row .mark .ic { width: 14px; height: 14px; stroke-width: 3; }
.test-row.ok .mark { background: var(--success); }
.test-row.no .mark { background: var(--danger); }
.test-row .t-detail { padding: 0 12px 12px; display: grid; gap: 8px; grid-template-columns: 1fr 1fr; }
.test-row .t-detail .full { grid-column: 1 / -1; }
.test-row .t-detail .io-box pre { max-height: 160px; }
.issues { display: flex; flex-direction: column; gap: 10px; }
.issue { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; padding: 12px 14px; border-radius: var(--radius-sm); border: 1px solid var(--border); border-inline-start: 4px solid var(--danger); background: var(--surface); }
.issue .line-tag { grid-row: span 2; align-self: start; min-height: 30px; font-family: var(--mono); font-size: 12.5px; font-weight: 700; padding: 0 10px; border-radius: 4px; background: var(--danger); color: #fff; border: 0; white-space: nowrap; }
.issue .line-tag.none { display: grid; place-items: center; background: var(--surface-3); color: var(--muted); cursor: default; }
.issue .problem { font-weight: 600; }
.issue .fix { color: var(--muted); font-size: 14.5px; }
.issue .fix b { color: var(--accent); }
.good-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; }
.good-list li { display: flex; gap: 8px; align-items: flex-start; }
.good-list li .ic { width: 18px; height: 18px; color: var(--success); stroke-width: 2.6; margin-top: 4px; }
.tip { padding: 14px 16px; border-radius: var(--radius-sm); background: var(--accent-soft); border-inline-start: 4px solid var(--accent); display: flex; gap: 10px; align-items: flex-start; }
.tip .ic { color: var(--accent); margin-top: 3px; }
.tip b { color: var(--accent); white-space: nowrap; }
.hint-box { padding: 14px 16px; border-radius: var(--radius-sm); background: var(--warn-soft); color: var(--warn-text); font-size: 15.5px; border-inline-start: 4px solid var(--warn); }
.locked { display: flex; gap: 10px; align-items: center; justify-content: center; padding: 16px; border-radius: var(--radius-sm); border: 1.5px dashed var(--border-strong); color: var(--muted); text-align: center; }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translate(-50%, 20px);
  padding: 12px 18px; border-radius: var(--radius-sm); background: var(--header-bg); color: #fff; font-size: 14.5px;
  opacity: 0; pointer-events: none; transition: opacity var(--t-base), transform var(--t-base) var(--ease); z-index: 50; box-shadow: var(--shadow-lg);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.footer { text-align: center; padding: 18px 24px 22px; color: var(--muted); font-size: 13.5px; border-top: 1px solid var(--border); }
.footer .credit { margin-top: 2px; font-family: var(--font-head); font-size: 15px; font-weight: 700; color: var(--primary-text); }

.skeleton { height: 140px; border-radius: var(--radius); background: linear-gradient(90deg, var(--surface-2), var(--surface-3), var(--surface-2)); background-size: 200% 100%; animation: shimmer 1.4s infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* عند ظهور خانة المدخلات يصغر المحرر لتبقى الأزرار ظاهرة */
.editor-card:has(.stdin-box:not([hidden])) .ed { height: clamp(240px, calc(100vh - 570px), 540px); }

/* ============ الحركة المخفّضة ============ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; animation-iteration-count: 1 !important; transition-duration: 1ms !important; scroll-behavior: auto !important; }
}

/* ============ التجاوب ============ */
@media (max-width: 1180px) {
  .workspace { grid-template-columns: minmax(0, 1fr); grid-template-areas: "task" "code"; }
  .code-pane { position: static; }
  .ed { height: 420px; }
}
@media (max-width: 1120px) {
  .head-row { flex-wrap: wrap; }
  .unit-picker { flex: 1 1 280px; }
  .ex-strip { order: 3; flex-basis: 100%; }
}
@media (max-width: 720px) {
  body { font-size: 16px; }
  .topbar { padding: 10px 16px 4px; gap: 8px; }
  .head-row { padding: 8px 16px 0; }
  .hero { padding-bottom: 40px; }
  .brand { gap: 8px; }
  .brand h1 { font-size: 16px; }
  .brand p { display: none; }
  .brand .brand-credit { display: block; font-size: 11.5px; white-space: normal; line-height: 1.4; }
  .brand-line { column-gap: 12px; }
  .brand { flex: 1; min-width: 0; }
  .brand-text { min-width: 0; }
  .content { padding: 0 16px 24px; gap: 14px; margin-top: -26px; }
  .uh-stats { gap: 14px; }
  .uh-stats dd { font-size: 15px; }
  .uh-stats dt { font-size: 12px; }
  .unit-picker { flex-basis: 200px; }
  .ex-pill { width: 44px; height: 44px; }
  .task-head, .t-sec { padding-inline: 18px; }
  .ed { height: 380px; --ed-fs: 13px; --ed-lh: 20px; --ed-pad: 10px; }
  .ed-gutter { width: 40px; }
  .ed-lines span { padding-right: 8px; font-size: 11.5px; }
  .actions { padding: 10px; }
  .btn { padding: 0 14px; flex: 1; }
  .btn-hint { margin-inline-start: 0; }
  .io-grid, .test-row .t-detail { grid-template-columns: 1fr; }
  .result-top { grid-template-columns: 1fr; justify-items: center; text-align: center; }
  .result-meta { justify-content: center; }
  .modal-body { padding: 20px 16px; }
  .top-btn span { max-width: 90px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}
