/* ============================================================
   PatternMastery problem page v2: docs layout
   left sidebar (site nav) | article | right rail (on this page)
   Uses the shared design tokens from chrome.css.
   ============================================================ */

:root {
  --side-w: 232px;
  --rail-w: 236px;
  --docs-max: 1440px;
  --ink: var(--text);
  --card: var(--bg-card);
  --desc-bg: var(--bg-elev);
}
:root[data-theme="light"] {
  --desc-bg: #f3f4f6;
}

body[data-layout="docs"] .pm-crumbs { display: none; }
/* The sidebar carries the site nav on docs pages; the header keeps brand + search + utilities. */
body[data-layout="docs"] .pm-header .pm-nav { display: none; }
body[data-layout="docs"] .pm-header-inner { grid-template-columns: auto 1fr auto; }
.pm-search { display: flex; justify-content: center; }
.pm-search form { position: relative; width: min(420px, 100%); }
.pm-search input {
  width: 100%; height: 36px; padding: 0 12px 0 34px; border-radius: 999px;
  border: 1px solid var(--border-strong); background: var(--bg-elev); color: var(--text); font-size: 13.5px;
}
.pm-search input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.pm-search .ico { position: absolute; left: 12px; top: 9px; color: var(--faint); font-size: 14px; }
@media (max-width: 860px) { .pm-search { display: none; } }

.docs-shell {
  max-width: var(--docs-max);
  margin: 0 auto;
  display: grid;
  grid-template-columns: var(--side-w) minmax(0, 1fr) var(--rail-w);
  gap: 0 32px;
  padding: 0 24px;
  min-height: calc(100vh - var(--nav-h));
}

/* ── Left sidebar ────────────────────────────────────────── */
.docs-side {
  position: sticky;
  top: var(--nav-h);
  align-self: start;
  height: calc(100vh - var(--nav-h));
  overflow-y: auto;
  padding: 18px 12px 24px 0;
  border-right: 1px solid var(--border);
  font-size: 13.5px;
}
.side-nav { display: flex; flex-direction: column; gap: 2px; }
.side-link {
  display: block;
  padding: 6px 10px 6px 26px;
  border-radius: var(--r-sm);
  color: var(--muted);
  text-decoration: none;
  line-height: 1.35;
}
.side-link:hover { color: var(--text); background: var(--bg-hover); text-decoration: none; }
.side-link[aria-current="page"] { color: var(--text); font-weight: 600; background: var(--bg-hover); }
.side-link.side-top { padding-left: 10px; color: var(--text); font-weight: 600; display: flex; gap: 8px; align-items: center; }
.side-ico { display: inline-block; width: 14px; text-align: center; color: var(--accent); font-size: 11px; }
.side-group { margin: 6px 0 2px; }
.side-group summary {
  list-style: none;
  cursor: pointer;
  display: flex; align-items: center; gap: 8px;
  padding: 6px 10px;
  color: var(--text);
  font-weight: 600;
  border-radius: var(--r-sm);
  user-select: none;
}
.side-group summary::-webkit-details-marker { display: none; }
.side-group summary::after { content: "\203A"; margin-left: auto; color: var(--faint); transition: transform 120ms; }
.side-group[open] summary::after { transform: rotate(90deg); }
.side-group summary:hover { background: var(--bg-hover); }

/* ── Article ─────────────────────────────────────────────── */
.docs-main { padding: 26px 0 80px; min-width: 0; }
.prob-loading { display: flex; gap: 12px; align-items: center; padding: 60px 0; }
.prob-loading[hidden], .prob[hidden], [hidden] { display: none !important; }

.prob-back { display: inline-block; font-size: 13px; color: var(--muted); margin-bottom: 18px; }
.prob-back:hover { color: var(--text); }

.prob-title {
  font-size: 30px;
  line-height: 1.2;
  letter-spacing: -0.015em;
  margin: 0 0 12px;
  font-weight: 700;
}
.prob-pm { color: var(--faint); font-weight: 600; }
.prob-summary { font-size: 15.5px; line-height: 1.65; color: var(--text); margin: 0 0 14px; max-width: 78ch; }

.prob-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.tax-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 9px; border-radius: 999px;
  border: 1px solid var(--border-strong);
  font-size: 12px; color: var(--muted); text-decoration: none;
}
.tax-chip:hover { color: var(--text); text-decoration: none; border-color: var(--accent); }
.tax-chip em { font-style: normal; color: var(--faint); font-size: 10.5px; letter-spacing: .06em; text-transform: uppercase; }
.tax-chip.pattern { border-color: var(--accent); color: var(--text); }

.prob-asked { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.prob-asked .lbl { margin-right: 4px; }
.co-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 9px 3px 5px; border-radius: 6px;
  border: 1px solid var(--border); background: var(--bg-elev);
  color: var(--text); font-size: 12.5px; text-decoration: none;
}
.co-chip:hover { border-color: var(--border-strong); text-decoration: none; }
.co-chip .mono {
  width: 16px; height: 16px; border-radius: 4px; display: inline-grid; place-items: center;
  font-size: 10px; font-weight: 800; color: #fff; background: var(--c, #666);
}
.co-chip .tier { color: var(--faint); font-size: 11px; }
.co-more { font-size: 12.5px; color: var(--faint); }

/* Description card */
.desc-card {
  background: var(--desc-bg);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 22px 24px;
  margin: 22px 0 8px;
}
.desc-label { font-size: 12.5px; letter-spacing: .1em; text-transform: uppercase; color: var(--text); margin: 0 0 12px; font-weight: 700; }
.desc-body p { margin: 0 0 10px; line-height: 1.65; }
.desc-body ul { margin: 6px 0 12px 20px; padding: 0; }
.desc-body li { margin: 4px 0; line-height: 1.55; }
.desc-sub { font-size: 15px; margin: 18px 0 8px; font-weight: 700; }
.example {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--r-sm);
  padding: 10px 14px; margin: 8px 0; font-size: 13.5px;
}
.example .ex-h { font-weight: 700; color: var(--muted); font-size: 12px; margin-bottom: 4px; }
.example code { font-family: var(--font-mono); font-size: 12.5px; white-space: pre-wrap; word-break: break-word; }
.example .ex-row { display: grid; grid-template-columns: 64px 1fr; gap: 8px; margin: 2px 0; }
.example .ex-k { color: var(--faint); }
.desc-links { display: flex; gap: 8px; flex-wrap: wrap; margin: 16px 0 0; }
.small { font-size: 12.5px; }

/* Sections */
.sec { padding-top: 26px; scroll-margin-top: calc(var(--nav-h) + 16px); }
.sec > h2 {
  font-size: 22px; letter-spacing: -0.01em; margin: 0 0 12px; font-weight: 700;
}
.sec h3 { font-size: 15.5px; margin: 20px 0 8px; font-weight: 700; }
.sec p { line-height: 1.65; margin: 0 0 10px; }
.sec ul, .sec ol { margin: 6px 0 12px 22px; padding: 0; }
.sec li { margin: 4px 0; line-height: 1.55; }
.desc-card { scroll-margin-top: calc(var(--nav-h) + 16px); }

.callout {
  border-left: 3px solid var(--accent);
  background: var(--bg-elev);
  padding: 10px 14px; border-radius: 0 var(--r-sm) var(--r-sm) 0;
  margin: 12px 0;
}
.callout.good { border-left-color: var(--good); }
.callout strong { color: var(--text); }

.steps { counter-reset: s; list-style: none; margin-left: 0 !important; }
.steps li { position: relative; padding-left: 30px; margin: 6px 0; }
.steps li::before {
  counter-increment: s; content: counter(s);
  position: absolute; left: 0; top: 1px;
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--accent); color: #1a1a1f; font-size: 11.5px; font-weight: 800;
  display: grid; place-items: center;
}

.cmp-table { width: 100%; border-collapse: collapse; font-size: 13.5px; margin: 10px 0 14px; }
.cmp-table th, .cmp-table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
.cmp-table th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; }
.cmp-table .k { color: var(--faint); white-space: nowrap; }

.mistakes li { padding-left: 4px; }
.mistakes li::marker { color: var(--danger); }

/* Code panel */
.code-panel {
  border: 1px solid var(--border); border-radius: var(--r-md); overflow: hidden; margin: 14px 0;
  background: var(--bg-elev);
}
.code-tabs {
  display: flex; align-items: center; gap: 2px;
  background: var(--bg-elev); border-bottom: 1px solid var(--border);
  padding: 4px 8px;
}
.code-tabs [role="tab"] {
  background: none; border: 0; padding: 7px 12px; border-radius: var(--r-sm);
  color: var(--muted); font-weight: 600; font-size: 13px;
}
.code-tabs [role="tab"][aria-selected="true"] { color: var(--text); background: var(--bg-card); box-shadow: inset 0 -2px 0 0 var(--accent); }
.code-tabs [role="tab"]:disabled { opacity: .5; cursor: not-allowed; }
.code-meta { font-size: 12px; color: var(--faint); margin-right: 8px; }
.code-copy { background: none; border: 1px solid var(--border-strong); color: var(--muted); font-size: 12px; padding: 4px 9px; border-radius: var(--r-sm); }
.code-copy:hover { color: var(--text); }
a.code-gh { text-decoration: none; margin-right: 6px; }
.code-block {
  margin: 0; padding: 14px 16px; overflow: auto;
  font-family: var(--font-mono); font-size: 13px; line-height: 1.55;
  color: #e8eaed; background: #1e1f22; tab-size: 4;
}
.code-note { padding: 8px 14px 10px; margin: 0; background: var(--bg-elev); border-top: 1px solid var(--border); }
.alt-wrap .code-panel { margin-top: 8px; }

.complexity { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 6px 0 12px; font-size: 13.5px; }
.complexity .chip {
  display: inline-flex; gap: 6px; padding: 4px 10px; border-radius: 999px;
  border: 1px solid var(--border-strong); background: var(--bg-elev); font-family: var(--font-mono); font-size: 12.5px;
}
.complexity .chip b { font-family: var(--font-ui); font-weight: 600; color: var(--muted); }

/* Video */
.video-panel { margin: 18px 0 6px; scroll-margin-top: calc(var(--nav-h) + 16px); }
.video-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.video-head h3 { margin: 0; }
.video-langs { display: flex; gap: 4px; }
.video-langs button {
  background: var(--bg-elev); border: 1px solid var(--border); color: var(--muted);
  padding: 5px 11px; border-radius: 999px; font-size: 12.5px; font-weight: 600;
}
.video-langs button[aria-pressed="true"] { color: #1a1a1f; background: var(--accent); border-color: var(--accent); }
.video-langs button:disabled { opacity: .45; cursor: not-allowed; }
.video-langs .vl-dur { font-weight: 400; opacity: .8; margin-left: 4px; }
#vid-player { width: 100%; max-height: 480px; background: #000; border-radius: var(--r-md); margin-top: 10px; border: 1px solid var(--border); }
.video-actions { display: flex; align-items: center; gap: 12px; margin: 8px 0 0; }

/* Collapsibles */
details.alt-wrap, details.try-wrap, details.ai-wrap, details.notes-wrap {
  border: 1px solid var(--border); border-radius: var(--r-md); margin: 14px 0; background: var(--bg-elev);
}
details.alt-wrap > summary, details.try-wrap > summary, details.ai-wrap > summary, details.notes-wrap > summary {
  cursor: pointer; padding: 12px 16px; font-weight: 600; color: var(--text); list-style: none; display: flex; align-items: center; gap: 8px;
}
details > summary::-webkit-details-marker { display: none; }
details.alt-wrap > summary::before, details.try-wrap > summary::before, details.ai-wrap > summary::before, details.notes-wrap > summary::before {
  content: "\25B8"; color: var(--accent); font-size: 12px;
}
details[open] > summary::before { content: "\25BE" !important; }
details.alt-wrap > div, details.try-wrap > div, details.ai-wrap > div { padding: 0 16px 16px; }
details.notes-wrap textarea { width: calc(100% - 32px); margin: 0 16px; }
.notes-actions { display: flex; align-items: center; gap: 8px; padding: 8px 16px 14px; }

.alt-approach { margin: 10px 0 18px; }
.alt-approach h4 { margin: 10px 0 4px; font-size: 14.5px; }

/* Editor */
.ed-toolbar, .ed-actions { display: flex; align-items: center; gap: 8px; margin: 8px 0; }
.ed-wrap { border: 1px solid var(--border); border-radius: var(--r-sm); overflow: hidden; }
.ed-wrap .CodeMirror { height: 360px; font-family: var(--font-mono); font-size: 13px; }
.ed-console { margin-top: 10px; border: 1px solid var(--border); border-radius: var(--r-sm); background: #141518; color: #e8eaed; }
.ed-console-head { display: flex; justify-content: space-between; padding: 6px 12px; font-size: 12px; color: #9ba1ac; border-bottom: 1px solid #262a31; }
#ed-console-out { margin: 0; padding: 10px 12px; font-family: var(--font-mono); font-size: 12.5px; white-space: pre-wrap; max-height: 260px; overflow: auto; }
#ed-console-out.is-ok { color: #8be0a4; }
#ed-console-out.is-error { color: #ff9a9a; }
.ed-confidence { display: flex; gap: 8px; align-items: center; padding: 8px 12px; border-top: 1px solid #262a31; }

/* AI tutor */
.ai-transcript { max-height: 320px; overflow: auto; display: flex; flex-direction: column; gap: 8px; margin-bottom: 8px; }
.ai-bubble { padding: 8px 12px; border-radius: var(--r-md); font-size: 13.5px; line-height: 1.5; max-width: 90%; white-space: pre-wrap; }
.ai-bubble.is-user { align-self: flex-end; background: var(--accent); color: #1a1a1f; }
.ai-bubble.is-tutor { align-self: flex-start; background: var(--bg-card); border: 1px solid var(--border); }
.ai-empty { color: var(--muted); font-size: 13.5px; padding: 8px 0; }
.ai-composer textarea { width: 100%; }
.ai-actions { display: flex; align-items: center; gap: 8px; margin-top: 6px; }
.badge-quota { font-size: 11px; color: var(--faint); font-weight: 400; }

/* Learned / related / quiz */
.learned li { margin: 8px 0; }
.rel-block {
  display: grid; grid-template-columns: auto 1fr auto; gap: 14px; align-items: center;
  border: 1px solid var(--border); border-radius: var(--r-md); padding: 14px 16px; background: var(--bg-elev);
  text-decoration: none; color: var(--text);
}
.rel-block:hover { border-color: var(--accent); text-decoration: none; }
.rel-block .rb-id { font-family: var(--font-mono); font-weight: 700; color: var(--accent); }
.rel-block .rb-name { font-weight: 700; }
.rel-block .rb-one { color: var(--muted); font-size: 13.5px; margin-top: 2px; }
.rel-block .rb-arr { color: var(--faint); }
.rel-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.rel-chips a { font-size: 13px; padding: 4px 10px; border: 1px solid var(--border-strong); border-radius: 999px; color: var(--text); }
.rel-chips a:hover { border-color: var(--accent); text-decoration: none; }
.rel-list li { margin: 5px 0; }
.rel-list .cur { font-weight: 700; }
.rel-list .role { font-size: 11px; color: var(--faint); margin-left: 6px; text-transform: uppercase; letter-spacing: .05em; }
.rel-list .done { color: var(--good); margin-left: 6px; }
.prob-nav { display: flex; justify-content: space-between; margin-top: 16px; }

.quiz-q { border: 1px solid var(--border); border-radius: var(--r-md); padding: 14px 16px; margin: 10px 0; background: var(--bg-elev); }
.quiz-q .qq { font-weight: 600; margin-bottom: 10px; }
.quiz-opt {
  display: block; width: 100%; text-align: left; margin: 6px 0; padding: 9px 12px;
  border: 1px solid var(--border-strong); border-radius: var(--r-sm); background: var(--bg-card); color: var(--text); font-size: 14px;
}
.quiz-opt:hover { border-color: var(--accent); }
.quiz-opt.right { border-color: var(--good); background: rgba(95, 207, 131, .12); }
.quiz-opt.wrong { border-color: var(--danger); background: rgba(239, 90, 90, .10); }
.quiz-fb { font-size: 13.5px; color: var(--muted); margin-top: 8px; }

/* ── Right rail ──────────────────────────────────────────── */
.docs-rail {
  position: sticky; top: var(--nav-h); align-self: start;
  max-height: calc(100vh - var(--nav-h)); overflow-y: auto;
  padding: 26px 0 24px 0; font-size: 13px;
}
.rail-card {
  border: 1px solid var(--accent); border-radius: var(--r-md); padding: 14px 14px 12px; margin-bottom: 20px;
  background: var(--bg-elev);
}
.rail-card-top { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; font-size: 14px; }
.rail-free { background: var(--accent); color: #1a1a1f; font-size: 11px; font-weight: 800; padding: 2px 7px; border-radius: 999px; letter-spacing: .04em; }
.rail-perks { margin: 0 0 12px 0; padding: 0; list-style: none; }
.rail-perks li { color: var(--muted); font-size: 12.5px; padding-left: 16px; position: relative; margin: 3px 0; }
.rail-perks li::before { content: "\2713"; color: var(--good); position: absolute; left: 0; }
.rail-cta { display: block; text-align: center; width: 100%; }
.rail-toc h4 { margin: 0 0 8px; font-size: 13.5px; }
.toc-group { font-weight: 700; color: var(--text); margin: 10px 0 2px; font-size: 12.5px; }
.rail-toc a { display: block; padding: 4px 0 4px 12px; color: var(--muted); border-left: 2px solid transparent; line-height: 1.35; }
.rail-toc a:hover { color: var(--text); text-decoration: none; }
.rail-toc a.active { color: var(--text); border-left-color: var(--accent); font-weight: 600; }

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 1200px) {
  .docs-shell { grid-template-columns: var(--side-w) minmax(0, 1fr); }
  .docs-rail { display: none; }
}
@media (max-width: 860px) {
  .docs-shell { grid-template-columns: minmax(0, 1fr); padding: 0 16px; }
  .docs-side { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--border); padding: 10px 0; }
  .docs-side .side-group { display: inline-block; vertical-align: top; min-width: 180px; }
  .prob-title { font-size: 24px; }
  .desc-card { padding: 16px; }
}
