:root {
  --bg: #0b0d0f;
  --surface: #15181c;
  --surface-strong: #1d2126;
  --border: #30363d;
  --text: #f4f5f6;
  --muted: #a8afb8;
  --red: #ff3d5a;
  --red-soft: rgba(255, 61, 90, 0.12);
  --green: #29d391;
  --amber: #ffbd4a;
  --cyan: #49c6e5;
  --font: "Tajawal", sans-serif;
  --code: "Fira Code", monospace;
}

* { box-sizing: border-box; }
html { color-scheme: dark; }
body { margin: 0; min-height: 100vh; background: var(--bg); color: var(--text); font-family: var(--font); }
button, input { font: inherit; }
button:focus-visible, input:focus-visible, a:focus-visible { outline: 3px solid var(--cyan); outline-offset: 3px; }
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  background-image: linear-gradient(rgba(255,255,255,.025) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,.025) 1px, transparent 1px);
  background-size: 36px 36px;
  mask-image: linear-gradient(to bottom, #000, transparent 78%);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  min-height: 68px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 12px 28px;
  background: rgba(11, 13, 15, .94);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(14px);
}
.brand, .stats, .stat-item { display: flex; align-items: center; }
.brand { gap: 14px; min-width: 0; }
.back-btn {
  width: 40px;
  height: 40px;
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  color: var(--muted);
  text-decoration: none;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface);
}
.back-btn:hover { color: var(--text); border-color: var(--red); }
.brand-mark { color: var(--red); font-size: 1.45rem; }
.brand-copy { min-width: 0; }
.brand-copy strong { display: block; font-size: 1rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-copy span { color: var(--muted); font-size: .78rem; }
.stats { gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.stat-item {
  min-height: 36px;
  gap: 7px;
  padding: 6px 11px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface);
  font-weight: 800;
  direction: ltr;
}
.stat-item.energy i { color: var(--amber); }
.stat-item.xp i { color: var(--green); }
.stat-max { color: var(--muted); font-size: .78em; }

.app-shell { min-height: calc(100vh - 68px); display: grid; grid-template-columns: 310px minmax(0, 1fr); }
.sidebar {
  position: sticky;
  top: 68px;
  height: calc(100vh - 68px);
  overflow-y: auto;
  border-left: 1px solid var(--border);
  background: rgba(21, 24, 28, .76);
}
.sidebar-head { padding: 24px 20px 18px; border-bottom: 1px solid var(--border); }
.eyebrow { color: var(--red); font-size: .75rem; font-weight: 900; text-transform: uppercase; }
.sidebar h1 { margin: 7px 0 6px; font-size: 1.35rem; line-height: 1.35; }
.sidebar-head p { margin: 0; color: var(--muted); font-size: .88rem; line-height: 1.6; }
.progress-meta { display: flex; justify-content: space-between; gap: 10px; margin-top: 18px; color: var(--muted); font-size: .78rem; }
.progress-track { height: 7px; margin-top: 7px; overflow: hidden; border-radius: 3px; background: #262b31; }
.progress-fill { height: 100%; width: 0; background: var(--red); transition: width .35s ease; }
.module-list { display: grid; gap: 8px; margin: 0; padding: 14px; list-style: none; }
.module-btn {
  width: 100%;
  min-height: 80px;
  display: grid;
  grid-template-columns: 34px 1fr auto;
  align-items: center;
  gap: 11px;
  padding: 12px;
  color: var(--text);
  text-align: right;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 7px;
  cursor: pointer;
}
.module-btn:hover:not(:disabled) { background: var(--surface-strong); border-color: var(--border); }
.module-btn.active { background: var(--red-soft); border-color: rgba(255, 61, 90, .45); }
.module-btn:disabled { cursor: not-allowed; opacity: .45; }
.module-number { width: 32px; height: 32px; display: grid; place-items: center; border: 1px solid var(--border); border-radius: 6px; color: var(--muted); font-weight: 900; }
.module-btn.done .module-number { color: #071b13; border-color: var(--green); background: var(--green); }
.module-copy { min-width: 0; }
.module-copy strong { display: block; font-size: .9rem; line-height: 1.4; }
.module-copy span { display: block; margin-top: 4px; color: var(--muted); font-size: .74rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.module-state { color: var(--muted); font-size: .8rem; }
.module-btn.done .module-state { color: var(--green); }

.content { min-width: 0; padding: 34px clamp(20px, 4vw, 64px) 70px; }
.module-header { max-width: 980px; margin: 0 auto 22px; }
.module-kicker { color: var(--red); font-weight: 900; font-size: .82rem; }
.module-header h2 { margin: 8px 0 10px; max-width: 850px; font-size: clamp(1.65rem, 3vw, 2.45rem); line-height: 1.35; }
.module-header p { max-width: 800px; margin: 0; color: var(--muted); line-height: 1.75; }
.tabs { max-width: 980px; display: flex; gap: 8px; margin: 0 auto 18px; padding-bottom: 12px; border-bottom: 1px solid var(--border); }
.tab-btn {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 16px;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-weight: 800;
  cursor: pointer;
}
.tab-btn:hover:not(:disabled) { color: var(--text); background: var(--surface); }
.tab-btn.active { color: #fff; border-color: var(--red); background: var(--red); }
.tab-btn:disabled { opacity: .42; cursor: not-allowed; }
.panel { max-width: 980px; margin: 0 auto; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); overflow: hidden; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 18px 22px; border-bottom: 1px solid var(--border); }
.panel-head h3 { display: flex; align-items: center; gap: 10px; margin: 0; font-size: 1.12rem; }
.panel-head h3 i { color: var(--red); }
.reward-chip { color: var(--green); font-size: .78rem; font-weight: 900; direction: ltr; }
.panel-body { padding: clamp(20px, 4vw, 36px); }
.lesson-body { color: #d8dce1; line-height: 1.9; }
.lesson-body h4 { margin: 28px 0 10px; color: #fff; font-size: 1.14rem; }
.lesson-body h4:first-child { margin-top: 0; }
.lesson-body p { margin: 0 0 16px; }
.lesson-body ul { margin: 0 0 18px; padding-right: 23px; }
.lesson-body li { margin-bottom: 8px; }
.callout { margin: 22px 0; padding: 16px 18px; border-right: 3px solid var(--cyan); background: rgba(73, 198, 229, .08); }
.callout strong { color: var(--cyan); }
code { font-family: var(--code); font-size: .88em; direction: ltr; unicode-bidi: embed; }
.code-block { overflow-x: auto; margin: 18px 0; padding: 17px; color: #8de5bd; border: 1px solid #2f3f38; border-radius: 6px; background: #090c0b; direction: ltr; text-align: left; font-family: var(--code); }
.panel-actions { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-top: 28px; padding-top: 20px; border-top: 1px solid var(--border); }
.action-note { color: var(--muted); font-size: .82rem; }
.primary-btn {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  padding: 9px 18px;
  color: #fff;
  border: 1px solid var(--red);
  border-radius: 6px;
  background: var(--red);
  font-weight: 900;
  cursor: pointer;
}
.primary-btn:hover:not(:disabled) { background: #e9324e; }
.primary-btn:disabled { opacity: .55; cursor: wait; }
.quiz-question { margin: 0 0 18px; font-size: 1.2rem; line-height: 1.6; }
.option-list { display: grid; gap: 10px; }
.option-btn { min-height: 50px; display: flex; align-items: center; gap: 12px; padding: 12px 15px; color: var(--text); text-align: right; background: #191d21; border: 1px solid var(--border); border-radius: 6px; cursor: pointer; }
.option-btn:hover:not(:disabled), .option-btn.selected { border-color: var(--cyan); background: rgba(73, 198, 229, .08); }
.option-btn.correct { border-color: var(--green); background: rgba(41, 211, 145, .1); }
.option-btn.wrong { border-color: var(--red); background: var(--red-soft); }
.option-dot { width: 18px; height: 18px; flex: 0 0 auto; border: 2px solid currentColor; border-radius: 50%; }
.feedback { display: none; margin-top: 18px; padding: 14px 16px; border-right: 3px solid var(--green); background: rgba(41, 211, 145, .08); line-height: 1.7; }
.feedback.show { display: block; }
.feedback.error { border-color: var(--red); background: var(--red-soft); }
.lab-brief { color: var(--muted); line-height: 1.8; }
.terminal { min-height: 170px; max-height: 320px; overflow: auto; margin: 20px 0 12px; padding: 17px; color: #c8f7df; background: #070908; border: 1px solid #2d3832; border-radius: 6px; direction: ltr; text-align: left; font-family: var(--code); font-size: .86rem; line-height: 1.7; }
.prompt { color: var(--red); }
.terminal-form { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 9px; direction: ltr; }
.terminal-input { min-width: 0; height: 46px; padding: 0 14px; color: var(--text); border: 1px solid var(--border); border-radius: 6px; background: #101316; font-family: var(--code); }

.modal-overlay { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 18px; background: rgba(0,0,0,.82); opacity: 0; pointer-events: none; transition: opacity .2s ease; }
.modal-overlay.show { opacity: 1; pointer-events: auto; }
.modal { width: min(460px, 100%); padding: 30px; text-align: center; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); }
.modal-icon { width: 62px; height: 62px; display: grid; place-items: center; margin: 0 auto 18px; color: var(--amber); border: 1px solid currentColor; border-radius: 50%; font-size: 1.7rem; }
.modal-icon.success { color: var(--green); }
.modal h2 { margin: 0 0 10px; }
.modal p { margin: 0 0 18px; color: var(--muted); line-height: 1.7; }
.timer { margin-bottom: 18px; padding: 11px; color: var(--amber); border: 1px solid rgba(255,189,74,.3); background: rgba(255,189,74,.08); font-weight: 900; }
.timer.success { color: var(--green); border-color: rgba(41,211,145,.3); background: rgba(41,211,145,.08); }
.modal .primary-btn { width: 100%; text-decoration: none; }
.toast { position: fixed; z-index: 70; left: 24px; bottom: 24px; max-width: min(420px, calc(100vw - 48px)); display: flex; align-items: center; gap: 10px; padding: 13px 16px; color: var(--text); border: 1px solid var(--border); border-radius: 6px; background: #20252a; box-shadow: 0 16px 40px rgba(0,0,0,.35); transform: translateY(120px); opacity: 0; transition: .25s ease; }
.toast.show { transform: translateY(0); opacity: 1; }
.toast i { color: var(--green); }

@media (max-width: 860px) {
  .topbar { align-items: flex-start; padding: 10px 14px; }
  .brand-copy span { display: none; }
  .stats { gap: 6px; }
  .stat-item { padding: 5px 8px; }
  .rank-badge { display: none !important; }
  .app-shell { display: block; }
  .sidebar { position: static; width: 100%; height: auto; border-left: 0; border-bottom: 1px solid var(--border); }
  .module-list { display: flex; overflow-x: auto; scroll-snap-type: x mandatory; }
  .module-list li { min-width: min(82vw, 300px); scroll-snap-align: start; }
  .content { padding: 24px 16px 56px; }
}

@media (max-width: 560px) {
  .brand-mark, .brand-copy { display: none; }
  .topbar { min-height: 60px; }
  .app-shell { min-height: calc(100vh - 60px); }
  .tabs { display: grid; grid-template-columns: repeat(3, 1fr); }
  .tab-btn { padding: 8px 6px; font-size: .78rem; }
  .panel-head { align-items: flex-start; padding: 15px; }
  .panel-body { padding: 18px 15px; }
  .panel-actions { align-items: stretch; flex-direction: column; }
  .primary-btn { width: 100%; }
  .terminal-form { grid-template-columns: 1fr; }
}