/* Shell, sidebar, buttons, cards, pills — the reusable furniture.
   Layout follows index3.html: fixed sidebar beside a scrolling main column. */

.app-layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
  position: relative;
  z-index: 1;
}

/* ---------- sidebar ---------- */

.sidebar {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  overscroll-behavior: contain;
  z-index: 50;
  transition: transform 0.3s ease;
}
.sidebar::-webkit-scrollbar { width: 6px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 3px; }

.sidebar-header {
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 2;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 18px;
  color: var(--text);
  text-decoration: none;
}
.brand:hover { text-decoration: none; }

.brand-mark {
  width: 32px; height: 32px;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--accent), var(--accent-3));
  display: flex; align-items: center; justify-content: center;
  color: #fff;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 16px;
  box-shadow: 0 4px 12px rgba(255, 77, 109, 0.3);
  flex-shrink: 0;
}

/* The mark is the artificial neuron from module 8: inputs converging on a soma
   that holds a summation sign. currentColor inherits the white set above, so
   the glyph tracks the mark's colour without a second declaration. */
.brand-glyph { width: 24px; height: 24px; display: block; }

.brand-sub {
  font-size: 11px;
  color: var(--text-faint);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  font-weight: 600;
  margin-top: 2px;
}

.search-box { margin-top: 16px; position: relative; }
.search-box input {
  width: 100%;
  padding: 8px 12px 8px 32px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-family: var(--font-body);
  color: var(--text);
  outline: none;
  transition: border-color 0.2s;
}
.search-box input:focus { border-color: var(--accent); background: #fff; }
.search-box svg {
  position: absolute;
  left: 9px; top: 50%;
  transform: translateY(-50%);
  color: var(--text-faint);
  width: 15px; height: 15px;
  pointer-events: none;
}
.search-hint {
  position: absolute;
  right: 9px; top: 50%;
  transform: translateY(-50%);
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-faint);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
  background: var(--surface);
  pointer-events: none;
}

/* XP + streak chip */
.learner-chip {
  display: flex;
  gap: 8px;
  margin-top: 14px;
}
.stat-pill {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  background: var(--bg);
  border: 1px solid var(--border);
}
.stat-pill .v {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 15px;
  line-height: 1.1;
}
.stat-pill .k {
  font-size: 9.5px;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--text-faint);
  font-weight: 700;
}
.stat-pill.xp .v { color: var(--accent); }
.stat-pill.streak .v { color: var(--accent-3); }

/* chapter groups + lesson buttons */
.chapter-group { padding: 14px 12px 0; }
.chapter-group:last-child { padding-bottom: 20px; }

.chapter-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-faint);
  font-weight: 700;
  padding: 8px 12px 6px;
  display: flex;
  align-items: baseline;
  gap: 8px;
}
.chapter-title .count {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0;
  color: var(--text-faint);
}
.chapter-title .count.done { color: var(--accent-2); }

.lesson-btn {
  width: 100%;
  text-align: left;
  padding: 8px 12px;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
  display: flex;
  align-items: center;
  gap: 9px;
  font-family: var(--font-body);
  margin-bottom: 2px;
  line-height: 1.35;
}
.lesson-btn:hover { background: var(--bg); color: var(--text); }
.lesson-btn.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

.lesson-num {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-faint);
  min-width: 18px;
  flex-shrink: 0;
}
.lesson-btn.active .lesson-num { color: var(--accent); }

/* A small tick in the sidebar is the quiet reward for finishing a lesson. */
.lesson-tick {
  margin-left: auto;
  width: 15px; height: 15px;
  flex-shrink: 0;
  color: var(--accent-2);
}
.lesson-btn.started .lesson-tick { color: var(--accent-3); }

.sidebar-empty {
  padding: 20px 24px;
  font-size: 12.5px;
  color: var(--text-faint);
  font-style: italic;
}

/* ---------- main column ---------- */

.main-content {
  grid-column: 2;
  padding: 40px 48px 80px;
  max-width: 100%;
  /* `clip` rather than `hidden`: hidden would make this a scroll container,
     which silently breaks `position: sticky` on the lab column inside it. */
  overflow-x: clip;
}

.top-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 36px;
  flex-wrap: wrap;
}

.breadcrumb { font-size: 13px; color: var(--text-faint); font-weight: 500; }
.breadcrumb span { color: var(--text); }
.breadcrumb a { color: var(--text-dim); }

.nav-actions { display: flex; gap: 10px; align-items: center; }

.nav-btn {
  padding: 8px 16px;
  background: #fff;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-body);
  white-space: nowrap;
}
.nav-btn:hover:not(:disabled) {
  border-color: var(--text);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}
.nav-btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

.nav-btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  box-shadow: 0 4px 12px rgba(255, 77, 109, 0.25);
}
.nav-btn.primary:hover:not(:disabled) { border-color: var(--accent); filter: brightness(1.05); }

.nav-btn.ghost { background: transparent; border-color: var(--border); }

.icon-btn {
  width: 36px; height: 36px;
  padding: 0;
  justify-content: center;
  color: var(--text-dim);
}
.icon-btn.on { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }

/* ---------- page headers ---------- */

.page-header { margin-bottom: 32px; max-width: 780px; }
.page-title {
  font-size: clamp(30px, 4.4vw, 46px);
  font-weight: 700;
  line-height: 1.08;
  margin: 0 0 14px;
}
.page-lede { font-size: 16.5px; color: var(--text-dim); line-height: 1.65; margin: 0; }

.eyebrow {
  font-family: var(--font-mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--accent);
  font-weight: 700;
  margin-bottom: 10px;
}

.lesson-badge {
  padding: 4px 11px;
  background: var(--accent-2-soft);
  color: var(--accent-2);
  border-radius: 100px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  display: inline-block;
}
.meta-dot { color: var(--text-faint); font-size: 12.5px; }

/* ---------- generic cards ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
}

.module-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 20px;
}

.module-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 24px;
  cursor: pointer;
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-align: left;
  font-family: var(--font-body);
  width: 100%;
}
.module-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-lg);
  border-color: var(--border-strong);
}
.module-card-top { display: flex; align-items: flex-start; gap: 14px; }

.module-mark {
  width: 38px; height: 38px;
  border-radius: 11px;
  background: var(--accent-soft);
  color: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 15px;
  flex-shrink: 0;
}
.module-card.done .module-mark { background: var(--accent-2-soft); color: var(--accent-2); }

.module-card h3 { font-size: 17.5px; line-height: 1.25; margin: 0 0 3px; }
.module-card .sub { font-size: 12.5px; color: var(--text-faint); font-weight: 500; }
.module-card .blurb { font-size: 13.5px; color: var(--text-dim); line-height: 1.6; margin: 0; }

.module-card-foot {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: auto;
  padding-top: 6px;
}
.module-count {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--text-faint);
  font-weight: 600;
}

/* progress bar + ring */
.bar {
  flex: 1;
  height: 6px;
  border-radius: 3px;
  background: var(--bg);
  border: 1px solid var(--border);
  overflow: hidden;
}
.bar > i {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-3));
  border-radius: 3px;
  transition: width 0.4s ease;
}
.bar.teal > i { background: linear-gradient(90deg, var(--accent-2), #4ecdc4); }

.ring { --pct: 0; width: 46px; height: 46px; flex-shrink: 0; }
.ring circle { fill: none; stroke-width: 5; }
.ring .track { stroke: var(--border); }
.ring .fill {
  stroke: var(--accent);
  stroke-linecap: round;
  transition: stroke-dashoffset 0.5s ease;
  transform: rotate(-90deg);
  transform-origin: 50% 50%;
}
.ring.done .fill { stroke: var(--accent-2); }
.ring-label {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  fill: var(--text-dim);
}

/* ---------- pills ---------- */

.example-pills { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.pill {
  padding: 6px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 11.5px;
  font-family: var(--font-mono);
  color: var(--text-dim);
  cursor: pointer;
  transition: all 0.15s ease;
  font-weight: 500;
}
.pill:hover { background: var(--accent); color: #fff; border-color: var(--accent); transform: translateY(-1px); }
.pill.active { background: var(--text); color: #fff; border-color: var(--text); }

/* ---------- mobile ---------- */

.menu-toggle {
  display: none;
  position: fixed;
  top: 14px; left: 14px;
  z-index: 60;
  width: 40px; height: 40px;
  background: #fff;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  cursor: pointer;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-sm);
  color: var(--text);
}

.scrim {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(22, 22, 26, 0.35);
  z-index: 45;
  backdrop-filter: blur(2px);
}
.scrim.show { display: block; }

@media (max-width: 1100px) {
  .app-layout { grid-template-columns: 1fr; }
  .sidebar { transform: translateX(-100%); box-shadow: var(--shadow-lg); }
  .sidebar.open { transform: translateX(0); }
  /* min-width: 0 for the same reason as .content-grid: without it a single wide
     descendant widens the whole column past the screen. */
  .main-content { padding: 68px 20px 60px; grid-column: 1; min-width: 0; }
  .menu-toggle { display: flex; }
  .module-grid { grid-template-columns: 1fr; }

  /* The floating menu button sits at 14,14 in a 40x40 box. The drawer's brand
     starts at 24,20 — so with the drawer open the hamburger landed directly on
     top of the logo. Indent the header past it. */
  .sidebar-header { padding-left: 68px; }
}

/* ---------- toast ---------- */

.toast-stack {
  position: fixed;
  right: 20px; bottom: 20px;
  z-index: 120;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}
.toast {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-left: 4px solid var(--accent-2);
  border-radius: 12px;
  padding: 12px 18px;
  box-shadow: var(--shadow-lg);
  font-size: 13.5px;
  font-weight: 600;
  max-width: 340px;
  animation: toast-in 0.28s ease;
}
.toast.xp { border-left-color: var(--accent); }
.toast .sub { font-weight: 500; color: var(--text-dim); font-size: 12.5px; margin-top: 2px; }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- loading & empty states ---------- */

.loading {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-faint);
  font-size: 13.5px;
  padding: 60px 0;
  justify-content: center;
}
.spinner {
  width: 16px; height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-dim);
}
.empty-state h3 { font-size: 18px; margin-bottom: 8px; }
