:root {
  --bg: #ffffff;
  --panel: #f7f7f7;
  --page: #fff9e6;
  --border: #e6e6e6;
  --text: #1f1f1f;
  --muted: #666;
  --brand: #f4b400;
  --brand-2: #e2a100;
  --brand-ink: #1f1f1f;
  --link: #0b57d0;
  --code-bg: #f3f6ff;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
  --sidebar-w: 320px;
}

body.theme-dark {
  --bg: #0b1220;
  --panel: #0f172a;
  --page: #0b1220;
  --border: rgba(255, 255, 255, 0.12);
  --text: rgba(255, 255, 255, 0.92);
  --muted: rgba(255, 255, 255, 0.68);
  --link: #93c5fd;
  --code-bg: rgba(255, 255, 255, 0.06);
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Arial, "Noto Sans", "Liberation Sans", sans-serif;
  color: var(--text);
  background: var(--page);
}

::selection {
  background: rgba(4, 170, 109, 0.25);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  height: 56px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  padding: 0 14px;
  background: var(--brand);
  color: var(--brand-ink);
  box-shadow: var(--shadow);
}

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

.topbar__center {
  display: flex;
  justify-content: center;
  min-width: 260px;
}

.topbar__title {
  font-weight: 700;
  letter-spacing: 0.2px;
  white-space: nowrap;
}

.topbar__right {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

.progress {
  display: grid;
  gap: 4px;
  min-width: 260px;
}

.progress__text {
  font-size: 12px;
  font-weight: 800;
  color: rgba(31, 31, 31, 0.9);
  line-height: 1.1;
  text-align: center;
}

.progress__bar {
  height: 8px;
  border-radius: 999px;
  background: rgba(31, 31, 31, 0.16);
  overflow: hidden;
  border: 1px solid rgba(31, 31, 31, 0.18);
}

.progress__fill {
  height: 100%;
  width: 0%;
  background: rgba(31, 31, 31, 0.9);
}

.search-wrapper {
  display: flex;
  align-items: center;
  position: relative;
}

.search {
  width: 0;
  height: 38px;
  padding: 0;
  border-radius: 10px;
  border: 1px solid transparent;
  outline: none;
  background: transparent;
  color: var(--brand-ink);
  opacity: 0;
  transition: width 200ms ease, opacity 200ms ease, padding 200ms ease, background 200ms ease;
  pointer-events: none;
}

.search.search--expanded {
  width: min(300px, 50vw);
  padding: 0 12px;
  border-color: rgba(31, 31, 31, 0.22);
  background: rgba(255, 255, 255, 0.35);
  opacity: 1;
  pointer-events: auto;
  margin-right: 8px;
}

.search::placeholder {
  color: rgba(31, 31, 31, 0.65);
}

.search:focus {
  border-color: rgba(31, 31, 31, 0.35);
  background: rgba(255, 255, 255, 0.5);
}

.theme-btn {
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: 10px;
  border: 1px solid rgba(31, 31, 31, 0.22);
  background: rgba(255, 255, 255, 0.28);
  color: var(--brand-ink);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background 120ms ease, transform 120ms ease;
}

.theme-btn:hover {
  background: rgba(255, 255, 255, 0.4);
}

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

.icon-sun {
  display: none;
}

.icon-moon {
  display: block;
}

body.theme-dark .icon-sun {
  display: block;
}

body.theme-dark .icon-moon {
  display: none;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  border: 1px solid rgba(31, 31, 31, 0.22);
  background: rgba(255, 255, 255, 0.28);
  color: var(--brand-ink);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background 120ms ease, transform 120ms ease;
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.4);
}

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

.icon-btn__bar {
  display: block;
  width: 16px;
  height: 2px;
  background: var(--brand-ink);
  margin: 2px 0;
  border-radius: 999px;
}

.layout {
  height: calc(100vh - 56px);
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
}

.sidebar {
  border-right: 1px solid var(--border);
  background: var(--panel);
  overflow: auto;
}

.sidebar::-webkit-scrollbar {
  width: 10px;
}

.sidebar::-webkit-scrollbar-thumb {
  background: #d7d7d7;
  border-radius: 999px;
  border: 2px solid var(--panel);
}

.sidebar__header {
  position: sticky;
  top: 0;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  padding: 14px 14px 10px 14px;
}

.sidebar__heading {
  font-weight: 800;
  margin-bottom: 6px;
}

.sidebar__subheading {
  color: var(--muted);
  font-size: 13px;
}

.lesson-list {
  padding: 8px;
  display: grid;
  gap: 4px;
}

.lesson-link {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 10px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: transparent;
  text-align: left;
  cursor: pointer;
  color: var(--text);
  transition: background 120ms ease, border-color 120ms ease;
}

.lesson-link:hover {
  background: #efefef;
}

body.theme-dark .lesson-link:hover {
  background: rgba(255, 255, 255, 0.06);
}

.lesson-link[aria-current="page"] {
  background: #fff2c2;
  border-color: rgba(244, 180, 0, 0.45);
}

body.theme-dark .lesson-link[aria-current="page"] {
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.18);
}

.lesson-link:active {
  transform: translateY(1px);
}

.lesson-link__num {
  width: 26px;
  height: 26px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: white;
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 12px;
  flex: 0 0 auto;
}

body.theme-dark .lesson-link__num {
  background: rgba(255, 255, 255, 0.06);
}

.lesson-link__title {
  font-weight: 600;
  line-height: 1.2;
}

.lesson-link__meta {
  margin-left: auto;
  color: var(--muted);
  font-size: 12px;
}

.chapter-chip {
  margin-left: 8px;
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid rgba(244, 180, 0, 0.45);
  background: #fff2c2;
  color: #6a4a00;
  font-weight: 900;
  font-size: 11px;
  text-transform: none;
}

.content {
  overflow: auto;
  padding: 22px;
  background: var(--page);
}

.content::-webkit-scrollbar {
  width: 10px;
}

.content::-webkit-scrollbar-thumb {
  background: #d7d7d7;
  border-radius: 999px;
  border: 2px solid var(--page);
}

.breadcrumbs {
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 12px;
}

.breadcrumbs-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  max-width: 980px;
  margin-left: auto;
  margin-right: auto;
}

.chapter-badge {
  font-size: 12px;
  font-weight: 900;
  color: #6a4a00;
  background: #fff2c2;
  border: 1px solid rgba(244, 180, 0, 0.45);
  padding: 6px 10px;
  border-radius: 999px;
  white-space: nowrap;
}

.lesson-nav {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0 16px 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
  max-width: 980px;
  margin-left: auto;
  margin-right: auto;
  justify-content: space-between;
}

.lesson-nav--bottom {
  border-bottom: 0;
  border-top: 1px solid var(--border);
  margin-top: 18px;
  padding-top: 16px;
  margin-bottom: 30px;
}

.nav-btn {
  height: 38px;
  padding: 0 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #fff;
  cursor: pointer;
  font-weight: 700;
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.02);
  transition: background 120ms ease, transform 120ms ease;
}

.nav-btn:hover {
  background: #f3f3f3;
}

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

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

.lesson-progress {
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  margin: 0 auto;
  text-align: center;
}

.lesson {
  max-width: 980px;
  margin-left: auto;
  margin-right: auto;
  background: #fffdf2;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px;
}

body.theme-dark .lesson {
  background: rgba(255, 255, 255, 0.04);
}

.lesson h1 {
  margin: 0 0 12px 0;
  font-size: 34px;
  letter-spacing: -0.2px;
}

.lesson h2 {
  margin-top: 22px;
  margin-bottom: 10px;
  font-size: 20px;
}

.lesson p {
  line-height: 1.6;
}

.lesson ul {
  line-height: 1.7;
}

.lesson a {
  color: var(--link);
}

.lesson pre {
  background: var(--code-bg);
  border: 1px solid rgba(11, 87, 208, 0.12);
  padding: 14px;
  border-radius: 12px;
  overflow: auto;
}

.lesson code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
}

.callout {
  border: 1px solid rgba(244, 180, 0, 0.45);
  background: #fff2c2;
  padding: 12px 14px;
  border-radius: 12px;
}

.tryit {
  max-width: 980px;
  margin-top: 18px;
  margin-left: auto;
  margin-right: auto;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: #fff;
  overflow: hidden;
}

body.theme-dark .tryit {
  background: rgba(255, 255, 255, 0.03);
}

.tryit__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 12px;
  background: #f4b400;
  border-bottom: 1px solid rgba(244, 180, 0, 0.35);
}

.tryit__title {
  font-weight: 900;
}

.tryit__actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.run-btn {
  height: 38px;
  padding: 0 14px;
  border-radius: 10px;
  border: 1px solid rgba(31, 31, 31, 0.18);
  background: var(--brand);
  color: var(--brand-ink);
  font-weight: 800;
  cursor: pointer;
  transition: background 120ms ease, transform 120ms ease;
}

.run-btn:hover {
  background: var(--brand-2);
}

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

.reset-btn {
  height: 38px;
  padding: 0 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #fff;
  font-weight: 700;
  cursor: pointer;
  transition: background 120ms ease, transform 120ms ease;
}

.reset-btn:hover {
  background: #f3f3f3;
}

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

.tryit__grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
}

.tryit__panel {
  padding: 12px;
}

.tryit__panel + .tryit__panel {
  border-left: 1px solid var(--border);
}

.tryit__label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  margin-bottom: 8px;
}

.editor {
  width: 100%;
  min-height: 260px;
  resize: vertical;
  border-radius: 12px;
  border: 1px solid var(--border);
  padding: 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 13px;
  line-height: 1.45;
  background: #0b1020;
  color: #e6e6e6;
  outline: none;
}

.editor:focus {
  border-color: rgba(11, 87, 208, 0.35);
}

.output {
  min-height: 124px;
  border-radius: 12px;
  border: 1px solid var(--border);
  padding: 10px;
  background: #111827;
  color: #e5e7eb;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 13px;
  line-height: 1.45;
  white-space: pre-wrap;
  overflow: auto;
}

.sandbox {
  width: 100%;
  height: 0;
  border: 0;
}

.quiz {
  max-width: 980px;
  margin: 18px auto 36px auto;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: #fff;
  overflow: hidden;
}

 body.theme-dark .quiz {
  background: rgba(255, 255, 255, 0.03);
 }

.quiz__header {
  padding: 12px;
  background: #f7f7f7;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

body.theme-dark .quiz__header {
  background: rgba(255, 255, 255, 0.04);
}

.quiz__title {
  font-weight: 900;
}

.quiz__meta {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.quiz__form {
  padding: 12px;
  display: grid;
  gap: 10px;
}

.quiz-q {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  background: #fff;
}

body.theme-dark .quiz-q {
  background: rgba(255, 255, 255, 0.03);
}

.quiz-q__title {
  font-weight: 800;
  margin-bottom: 8px;
}

.quiz-blank__template {
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 13px;
  padding: 8px 10px;
  border: 1px dashed var(--border);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.45);
  margin-bottom: 10px;
}

body.theme-dark .quiz-blank__template {
  background: rgba(255, 255, 255, 0.04);
}

.quiz-blank__input {
  width: min(360px, 100%);
  height: 38px;
  border-radius: 10px;
  border: 1px solid var(--border);
  padding: 0 10px;
  outline: none;
  background: var(--bg);
  color: var(--text);
}

.quiz-blank__input:focus {
  border-color: rgba(244, 180, 0, 0.55);
  box-shadow: 0 0 0 3px rgba(244, 180, 0, 0.18);
}

.quiz-blank__input--correct {
  border-color: rgba(244, 180, 0, 0.65);
  background: rgba(244, 180, 0, 0.16);
}

.quiz-blank__input--wrong {
  border-color: rgba(220, 38, 38, 0.55);
  background: rgba(220, 38, 38, 0.12);
}

.quiz-opt {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid transparent;
  cursor: pointer;
}

.quiz-opt:hover {
  background: #f3f3f3;
}

body.theme-dark .quiz-opt:hover {
  background: rgba(255, 255, 255, 0.06);
}

.quiz-opt input {
  margin-top: 3px;
}

.quiz-opt--correct {
  background: #fff2c2;
  border-color: rgba(244, 180, 0, 0.55);
}

body.theme-dark .quiz-opt--correct {
  background: rgba(244, 180, 0, 0.18);
  border-color: rgba(244, 180, 0, 0.45);
}

.quiz-opt--wrong {
  background: #ffecec;
  border-color: rgba(220, 38, 38, 0.35);
}

body.theme-dark .quiz-opt--wrong {
  background: rgba(220, 38, 38, 0.18);
  border-color: rgba(220, 38, 38, 0.45);
}

.quiz-q--unanswered {
  border-color: rgba(220, 38, 38, 0.25);
  background: #fff7f7;
}

body.theme-dark .quiz-q--unanswered {
  background: rgba(220, 38, 38, 0.12);
}

.quiz__footer {
  padding: 12px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

 body.theme-dark .quiz__footer {
  background: rgba(255, 255, 255, 0.02);
 }

.quiz__result {
  margin-left: auto;
  font-weight: 900;
  color: var(--muted);
}

@media (max-width: 900px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    top: 56px;
    left: 0;
    width: min(var(--sidebar-w), 86vw);
    height: calc(100vh - 56px);
    box-shadow: var(--shadow);
    transform: translateX(-110%);
    transition: transform 180ms ease;
    z-index: 30;
  }

  body.sidebar-open .sidebar {
    transform: translateX(0);
  }

  .content {
    padding: 16px;
  }

  .lesson {
    padding: 14px;
  }

  .lesson-nav {
    gap: 10px;
  }

  .nav-btn {
    padding: 0 12px;
  }

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

  .tryit__panel + .tryit__panel {
    border-left: 0;
    border-top: 1px solid var(--border);
  }

  .search {
    width: min(360px, 46vw);
  }

  /* Header responsive adjustments */
  .topbar {
    grid-template-columns: auto 1fr auto;
    gap: 8px;
    padding: 0 12px;
  }

  .topbar__left {
    gap: 8px;
  }

  /* Hide raw title on mobile, we can use progress text or just hide it */
  .topbar__title {
    display: none;
  }

  .topbar__center {
    min-width: 0;
    justify-content: center; /* Center progress bar */
  }

  .progress {
    min-width: 0;
    max-width: 200px; /* Constrain width on mobile */
  }

  .progress__text {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    /* Optional: hide text completely on very small screens if needed */
  }

  .theme-btn {
    padding: 0; /* Icon only, no padding text needed */
  }

  /* Search expansion on mobile */
  .search-wrapper {
    position: static; /* Allow search to expand relative to topbar or remain flex */
  }

  .search.search--expanded {
    position: absolute;
    top: 8px; /* Match typical padding */
    left: 12px;
    right: 56px; /* Leave room for close/toggle or just right side */
    width: calc(100% - 70px) !important; /* Override width min */
    z-index: 25;
    background: #fff;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  }

  body.theme-dark .search.search--expanded {
    background: #1e293b;
    border-color: rgba(255,255,255,0.1);
  }
}

@media (max-width: 600px) {
  .progress__text {
    display: none; /* Hide progress text on very small screens to save space */
  }
  
  .progress {
    display: none; /* Hide entire progress bar on very small screens to give space to Title if wanted, OR keep bar only. Let's keep bar only */
    display: grid;
  }

  /* If we want to show Title instead of Progress on mobile, we could swap display properties. 
     For now, let's keep Progress Bar without text. */
  .progress__bar {
    width: 60px; /* Small pill */
  }

  .progress {
    min-width: 0;
    justify-content: center;
  }
}

/* Extra small screens (phones) */
@media (max-width: 480px) {
  .topbar {
    padding: 0 8px;
    gap: 6px;
  }

  .topbar__left {
    gap: 6px;
  }

  .topbar__right {
    gap: 6px;
  }



  .progress__text {
    font-size: 11px;
  }
}
