/* =========================================================
   Learn section — tutorial + runnable playground
   Depends on styles.css design tokens (:root variables).
   ========================================================= */

/* ---------- Track switcher (topbar segmented control) ---------- */
.track-switch {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
}
.track-switch button {
  padding: 5px 14px;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--muted);
  border-radius: 999px;
  transition: color var(--t-fast), background var(--t-fast);
  white-space: nowrap;
}
.track-switch button:hover { color: var(--text); }
.track-switch button.active {
  color: var(--text);
  background: var(--surface);
  box-shadow: 0 1px 2px rgba(0,0,0,0.15);
}

/* ---------- Sidebar filter box ---------- */
.side-filter {
  position: relative;
  margin-bottom: var(--space-4);
}
.side-filter input {
  width: 100%;
  height: 34px;
  padding: 0 var(--space-3) 0 32px;
  font: inherit;
  font-size: 13px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.side-filter input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.side-filter input::placeholder { color: var(--muted-2); }
.side-filter svg {
  position: absolute;
  left: 10px; top: 50%;
  transform: translateY(-50%);
  width: 14px; height: 14px;
  color: var(--muted);
  pointer-events: none;
}

/* ---------- Lesson layout ---------- */
.lesson {
  max-width: 780px;
}
.lesson-breadcrumb {
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: var(--space-3);
  display: flex;
  align-items: center;
  gap: 8px;
}
.lesson-breadcrumb .sep { color: var(--muted-2); }
.lesson h1.lesson-title {
  font-size: 30px;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.2;
  margin-bottom: var(--space-5);
  padding-bottom: var(--space-5);
  border-bottom: 1px solid var(--border-soft);
}

/* Prose blocks */
.lesson .block { margin: 0 0 var(--space-5); }
.lesson p.block {
  color: var(--text);
  font-size: 15.5px;
  line-height: 1.7;
  max-width: 68ch;
}
.lesson h2.block {
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin-top: var(--space-6);
  margin-bottom: var(--space-4);
}
.lesson ul.block {
  list-style: none;
  max-width: 68ch;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.lesson ul.block li {
  position: relative;
  padding-left: var(--space-4);
  color: var(--text);
  line-height: 1.65;
}
.lesson ul.block li::before {
  content: '';
  position: absolute;
  left: 2px; top: 11px;
  width: 5px; height: 5px;
  border-radius: 50%;
  background: var(--accent);
}
.lesson strong { font-weight: 600; }
.lesson code.inline {
  font-family: var(--font-mono);
  font-size: 13px;
  padding: 1.5px 6px;
  background: var(--surface-2);
  border: 1px solid var(--border-soft);
  border-radius: 4px;
  color: var(--text);
}

/* Note callout — reuse when-to-use look */
.lesson .note {
  margin: var(--space-5) 0;
  padding: var(--space-4) var(--space-5);
  background: var(--accent-soft);
  border: 1px solid color-mix(in srgb, var(--accent) 25%, transparent);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  font-size: 14.5px;
  line-height: 1.65;
  color: var(--text);
  max-width: 68ch;
}
.lesson .note .note-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 6px;
}
.lesson .note.warn {
  background: color-mix(in srgb, #E07A8B 12%, transparent);
  border-color: color-mix(in srgb, #E07A8B 30%, transparent);
  border-left-color: #E07A8B;
}
.lesson .note.warn .note-label { color: #E07A8B; }

/* Data table (for SQL sample data, etc.) */
.lesson .data-table-wrap {
  overflow-x: auto;
  margin: var(--space-4) 0 var(--space-5);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}
.lesson table.data-table {
  border-collapse: collapse;
  width: 100%;
  font-size: 13.5px;
}
.lesson table.data-table th,
.lesson table.data-table td {
  text-align: left;
  padding: 8px 14px;
  border-bottom: 1px solid var(--border-soft);
  white-space: nowrap;
}
.lesson table.data-table th {
  background: var(--surface-2);
  font-weight: 600;
  color: var(--muted);
  font-size: 11.5px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.lesson table.data-table tr:last-child td { border-bottom: none; }

/* =========================================================
   Playground (Try it Yourself)
   ========================================================= */
.playground {
  margin: var(--space-5) 0 var(--space-6);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: var(--shadow);
}
.pg-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-3);
  background: var(--surface-2);
  border-bottom: 1px solid var(--border-soft);
}
.pg-lang {
  font: 500 12px var(--font-mono);
  letter-spacing: 0.03em;
  color: var(--muted);
  padding: 10px 4px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
}
.pg-lang .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--accent);
}
.pg-actions { display: flex; align-items: center; gap: 4px; }
.pg-actions button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  transition: color var(--t-fast), background var(--t-fast), border-color var(--t-fast);
}
.pg-actions button:hover { color: var(--text); background: var(--surface); border-color: var(--border); }
.pg-actions button svg { width: 13px; height: 13px; }
.pg-actions .pg-run {
  color: var(--accent);
  font-weight: 600;
}
.pg-actions .pg-run:hover {
  background: var(--accent-soft);
  border-color: color-mix(in srgb, var(--accent) 30%, transparent);
}
.pg-actions button.copied { color: var(--accent); }
.pg-actions button[disabled] { opacity: 0.5; cursor: not-allowed; }

/* Editor: transparent textarea grid-stacked over a highlighted <pre>.
   Grid stacking makes both children size to the taller one (the <pre>),
   so the caret stays aligned even when the code scrolls. */
.pg-editor {
  display: grid;
  overflow: auto;
  max-height: 460px;
}
.pg-editor > pre.pg-highlight,
.pg-editor > textarea.pg-input {
  grid-area: 1 / 1 / 2 / 2;
  margin: 0;
  padding: var(--space-4) var(--space-5);
  font-family: var(--font-mono);
  font-size: 13.5px;
  line-height: 1.65;
  tab-size: 4;
  white-space: pre;
  overflow-wrap: normal;
  word-break: normal;
  border: 0;
}
.pg-editor > pre.pg-highlight {
  pointer-events: none;
  background: transparent !important;
  min-width: 0;
}
.pg-editor > pre.pg-highlight code {
  background: transparent !important;
  padding: 0 !important;
  font: inherit !important;
  white-space: inherit !important;
}
.pg-editor > textarea.pg-input {
  width: 100%;
  height: 100%;
  resize: none;
  outline: none;
  background: transparent;
  color: transparent;
  caret-color: var(--text);
  overflow: hidden;
}
.pg-editor textarea.pg-input::selection { background: color-mix(in srgb, var(--accent) 30%, transparent); }

/* Output console */
.pg-output {
  border-top: 1px solid var(--border-soft);
  background: color-mix(in srgb, var(--bg) 55%, var(--surface));
}
.pg-output-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px var(--space-5);
}
.pg-output-label {
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  gap: 7px;
}
.pg-output-label .status-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--muted-2);
}
.pg-output.ok .status-dot { background: #A8C97A; }
.pg-output.err .status-dot { background: #E07A8B; }
.pg-output.run .status-dot { background: var(--accent); animation: pulse 1s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.3; } }
.pg-output .pg-clear {
  font-size: 11px;
  color: var(--muted);
  padding: 2px 8px;
  border-radius: var(--radius-sm);
}
.pg-output .pg-clear:hover { color: var(--text); background: var(--surface); }
.pg-output-body {
  margin: 0;
  padding: var(--space-3) var(--space-5) var(--space-4);
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.6;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
  overflow-x: auto;
  max-height: 320px;
}
.pg-output-body .out-err { color: #E07A8B; }
.pg-output-body .out-muted { color: var(--muted); font-style: italic; }

/* SQL result table inside output */
.pg-output-body table.sql-result {
  border-collapse: collapse;
  font-size: 12.5px;
  margin: 4px 0 10px;
}
.pg-output-body table.sql-result th,
.pg-output-body table.sql-result td {
  border: 1px solid var(--border);
  padding: 4px 12px;
  text-align: left;
  white-space: nowrap;
}
.pg-output-body table.sql-result th {
  background: var(--surface-2);
  color: var(--muted);
  font-weight: 600;
}

/* ---------- Prev / next lesson nav ---------- */
.lesson-nav {
  display: flex;
  justify-content: space-between;
  gap: var(--space-3);
  margin-top: var(--space-8);
  padding-top: var(--space-5);
  border-top: 1px solid var(--border-soft);
}
.lesson-nav a {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  min-width: 0;
  max-width: 48%;
  transition: border-color var(--t-fast), background var(--t-fast);
}
.lesson-nav a:hover { border-color: var(--accent); background: var(--surface-2); }
.lesson-nav a.next { text-align: right; margin-left: auto; }
.lesson-nav .dir {
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}
.lesson-nav .name {
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.lesson-nav a.disabled { visibility: hidden; }

/* ---------- Track intro (landing per track) ---------- */
.track-badges {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
  margin-top: var(--space-4);
}
.track-badges .chip {
  font: 500 12px var(--font-mono);
  color: var(--muted);
  padding: 4px 11px;
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: 999px;
}

/* Runtime loading banner */
.runtime-note {
  font-size: 12px;
  color: var(--muted);
  margin-top: 6px;
}

@media (max-width: 880px) {
  .track-switch { display: none; }
  .lesson h1.lesson-title { font-size: 24px; }
  .lesson-nav a { max-width: 47%; }
}

/* =========================================================
   User highlights & notes (annotations.js)
   ========================================================= */
mark.uhl {
  color: inherit;
  border-radius: 2px;
  padding: 0 1px;
  cursor: pointer;
  transition: filter var(--t-fast);
}
mark.uhl:hover { filter: brightness(1.15); }
mark.uhl.flash { animation: hl-flash 0.9s ease-out; }
@keyframes hl-flash { 0%, 100% { box-shadow: none; } 30% { box-shadow: 0 0 0 3px var(--accent-soft); } }

.hl-yellow { background: rgba(232, 194, 72, 0.40); }
.hl-green  { background: rgba(122, 202, 122, 0.36); }
.hl-blue   { background: rgba(112, 150, 226, 0.44); }
[data-theme="light"] .hl-yellow { background: rgba(255, 214, 0, 0.45); }
[data-theme="light"] .hl-green  { background: rgba(110, 205, 110, 0.42); }
[data-theme="light"] .hl-blue   { background: rgba(90, 150, 240, 0.28); }

.uhl.has-note { box-shadow: inset 0 -2px 0 var(--accent); }
.uhl.has-note::after {
  content: '';
  display: inline-block;
  width: 5px; height: 5px;
  border-radius: 50%;
  background: var(--accent);
  vertical-align: super;
  margin-left: 2px;
}

/* Floating popovers */
.annot-pop {
  position: absolute;
  z-index: 50;
  display: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.35);
  padding: var(--space-2);
}
.annot-pop.open { display: block; }
.annot-pop .swatches { display: flex; gap: 6px; }
.annot-pop .sw {
  width: 20px; height: 20px;
  border-radius: 50%;
  border: 2px solid transparent;
  box-shadow: 0 0 0 1px var(--border) inset;
  transition: transform var(--t-fast), border-color var(--t-fast);
}
.annot-pop .sw:hover { transform: scale(1.12); }
.annot-pop .sw.active { border-color: var(--text); }
.sw-yellow { background: #E6BE46; }
.sw-green  { background: #78C878; }
.sw-blue   { background: #6E93E0; }

.sel-pop { display: none; }
.sel-pop.open { display: flex; align-items: center; gap: var(--space-2); }
.annot-note-btn {
  font-size: 12.5px;
  color: var(--muted);
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  transition: color var(--t-fast), border-color var(--t-fast);
}
.annot-note-btn:hover { color: var(--text); border-color: var(--accent); }

.edit-pop { width: 260px; }
.edit-pop .swatches { margin-bottom: var(--space-2); }
.annot-ta {
  width: 100%;
  font: inherit;
  font-size: 13px;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  outline: none;
  resize: vertical;
  min-height: 60px;
}
.annot-ta:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.annot-actions { display: flex; align-items: center; gap: 6px; margin-top: var(--space-2); }
.annot-actions .spacer { flex: 1; }
.annot-actions button {
  font-size: 12.5px;
  padding: 5px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  color: var(--muted);
  transition: color var(--t-fast), background var(--t-fast), border-color var(--t-fast);
}
.annot-actions button:hover { color: var(--text); }
.annot-remove:hover { color: #E07A8B; border-color: #E07A8B; }
.annot-save {
  color: #fff !important;
  background: var(--accent);
  border-color: var(--accent) !important;
}
.annot-save:hover { filter: brightness(1.08); }

/* Notes panel (drawer) */
.notes-panel {
  position: fixed;
  top: var(--topbar-h);
  right: 0;
  width: 340px;
  max-width: 88vw;
  height: calc(100vh - var(--topbar-h));
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: -12px 0 32px rgba(0, 0, 0, 0.28);
  transform: translateX(100%);
  transition: transform var(--t-base);
  z-index: 20;
  display: flex;
  flex-direction: column;
}
.notes-panel.open { transform: translateX(0); }
.np-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--border-soft);
}
.np-title { font-size: 12px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.np-close { font-size: 22px; line-height: 1; color: var(--muted); padding: 0 6px; }
.np-close:hover { color: var(--text); }
.np-body { flex: 1; overflow-y: auto; padding: var(--space-3); }
.np-empty { color: var(--muted); font-size: 13.5px; padding: var(--space-4); line-height: 1.6; }
.np-item {
  display: flex; gap: 10px;
  padding: var(--space-3);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--t-fast);
}
.np-item:hover { background: var(--surface-2); }
.np-dot { flex-shrink: 0; width: 10px; height: 10px; border-radius: 3px; margin-top: 4px; }
.dot-yellow { background: #E6BE46; }
.dot-green  { background: #78C878; }
.dot-blue   { background: #6E93E0; }
.np-quote { font-size: 13px; color: var(--text); line-height: 1.5; }
.np-note {
  font-size: 12.5px; color: var(--muted); margin-top: 4px;
  padding-left: 8px; border-left: 2px solid var(--accent);
}
.np-foot { padding: var(--space-3) var(--space-4); border-top: 1px solid var(--border-soft); }
.np-clear {
  width: 100%; font-size: 12.5px; color: var(--muted);
  padding: 7px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  transition: color var(--t-fast), border-color var(--t-fast);
}
.np-clear:hover { color: #E07A8B; border-color: #E07A8B; }

/* Keep the brand compact on small screens */
@media (max-width: 880px) {
  .brand { flex-shrink: 0; white-space: nowrap; }
  .brand .sub { display: none; }
}

/* Mobile track switch inside sidebar */
.side-track-switch { display: none; }
@media (max-width: 880px) {
  .side-track-switch {
    display: flex;
    gap: 2px;
    padding: 3px;
    margin-bottom: var(--space-4);
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 999px;
  }
  .side-track-switch button {
    flex: 1;
    padding: 6px 0;
    font-size: 12.5px;
    font-weight: 500;
    color: var(--muted);
    border-radius: 999px;
  }
  .side-track-switch button.active {
    color: var(--text);
    background: var(--surface);
  }
}
