/* Question page. Uses tokens.css + questions.css (crumbs, fields, text buttons). Prefix: qd- */

.qd { position: relative; padding-top: 8px }
/* reading pages are narrower than lists: one column of text + one side column, centred */

/* ---------- head ---------- */
.qd-head { grid-area: head; position: relative; isolation: isolate; padding: 0 0 32px }
/* way back to the exact place in the list: the list's name is the link */
.qd-back {
    grid-area: back; justify-self: start; display: inline-flex; align-items: center; gap: 10px; margin: 32px 0 22px;
    color: var(--sr-muted); font-size: 14px; text-decoration: none; transition: color .15s;
}
.qd-back b { font-weight: 500; color: var(--sr-text) }
.qd-back:hover { color: var(--sr-text) }
.qd-back svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; transform: scaleX(-1); transition: transform .2s var(--sr-ease) }
.qd-back:hover svg { transform: scaleX(-1) translateX(3px) }
/* the topic is its own element: a labelled pill that leads to all its questions */
.qd-topic {
    display: inline-flex; align-items: center; gap: 8px; height: 32px; padding: 0 12px;
    border-radius: var(--sr-r-pill); background: var(--sr-raise); color: var(--sr-text);
    font: 600 13.5px/1 var(--sr-font); text-decoration: none; transition: background-color .15s;
}
.qd-topic svg { width: 14px; height: 14px; fill: none; stroke: var(--sr-muted); stroke-width: 2.2; stroke-linecap: round }
.qd-topic__sub { font-weight: 400; color: var(--sr-muted) }
.qd-topic__sub::before { content: "/"; margin-right: 8px; color: var(--sr-faint) }
.qd-topic:hover { color: var(--sr-text); background: var(--sr-line) }
.qd-title {
    margin: 0 0 18px; max-width: 30ch;
    font: 600 var(--sr-h1)/1.08 var(--sr-font); letter-spacing: -0.03em; text-wrap: balance; color: var(--sr-text);
}
.qd-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px }
.qd-meta__text { font-size: 14px; color: var(--sr-muted) }

/* studied toggle: the circle fills clockwise, then the check draws (0.6 s) */
.qd-study {
    display: inline-flex; align-items: center; gap: 8px; height: 36px; margin-left: auto; padding: 0 14px 0 10px;
    border-radius: var(--sr-r-pill); border: 1px solid var(--sr-line); background: var(--sr-surface); color: var(--sr-text);
    font: 500 13.5px/1 var(--sr-font); cursor: pointer; transition: border-color .15s, background-color .2s;
}
.qd-study:hover { border-color: var(--sr-line-strong) }
.qd-study:disabled { cursor: progress }
.qd-study__mark { width: 20px; height: 20px; transform: rotate(-90deg) }
.qd-study__ring { fill: none; stroke: var(--sr-line-strong); stroke-width: 1.6 }
.qd-study__fill { fill: none; stroke: var(--sr-success); stroke-width: 16; stroke-dasharray: 1; stroke-dashoffset: 1; transform: scale(.5); transform-origin: center; transition: stroke-dashoffset .4s var(--sr-ease) }
.qd-study__check { fill: none; stroke: var(--sr-accent-ink); stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; stroke-dasharray: 1; stroke-dashoffset: 1; transform: rotate(90deg); transform-origin: center; transition: stroke-dashoffset .2s ease .35s }
.qd-study.is-done { border-color: color-mix(in srgb, var(--sr-success) 40%, var(--sr-line)); background: color-mix(in srgb, var(--sr-success) 12%, transparent) }
.qd-study.is-done .qd-study__ring { stroke: var(--sr-success) }
.qd-study.is-done .qd-study__fill { stroke-dashoffset: 0 }
.qd-study.is-done .qd-study__check { stroke-dashoffset: 0 }

/* favorites: a ribbon that fills in; cream like the other personal marks */
.qd-fav {
    display: inline-flex; align-items: center; gap: 7px; height: 36px; padding: 0 14px 0 11px;
    border-radius: var(--sr-r-pill); border: 1px solid var(--sr-line); background: var(--sr-surface); color: var(--sr-text);
    font: 500 13.5px/1 var(--sr-font); cursor: pointer; transition: border-color .15s, background-color .2s;
}
.qd-fav:hover { border-color: var(--sr-line-strong) }
.qd-fav:disabled { cursor: progress }
.qd-fav svg { width: 17px; height: 17px; fill: transparent; stroke: var(--sr-muted); stroke-width: 1.8; stroke-linejoin: round; transition: fill .2s, stroke .2s, transform .3s var(--sr-ease) }
.qd-fav.is-on { border-color: color-mix(in srgb, var(--sr-done) 40%, var(--sr-line)); background: var(--sr-done-soft) }
.qd-fav.is-on svg { fill: var(--sr-done); stroke: var(--sr-done); transform: translateY(-1px) }

/* ---------- layout ---------- */
/* reading pages keep a 760px text column, but their edges line up with the header like every other page:
   text on the left edge, the side column on the right edge */
.qd-layout {
    /* the last row takes the side column's extra height, so a short answer never opens a gap under the title */
    display: grid; grid-template-columns: minmax(0, var(--sr-read-col)) var(--sr-side-col); grid-template-rows: auto auto 1fr; grid-template-areas: "back ." "head side" "article side";
    justify-content: space-between; column-gap: var(--sr-col-gap); align-items: start;
}
.qd-article { grid-area: article; position: relative; min-width: 0 }

/* reading track: a thin line on the left, the logo's dot shows how far you have read */
.qd-read { display: none; position: absolute; left: -22px; top: 6px; bottom: 6px; width: 2px; border-radius: 2px; background: var(--sr-line) }
.qd-read.is-on { display: block }
.qd-read i { position: absolute; inset: 0; border-radius: inherit; background: var(--sr-done); transform-origin: top; transform: scaleY(0); will-change: transform }
/* the reading line is the snake: it crawls down the answer with you, the cream body is what you have read */
.qd-read b { position: absolute; left: 50%; top: 0; width: 14px; height: 14px; margin: -7px 0 0 -7px; will-change: transform; border-radius: 50%; background: radial-gradient(circle at 50% 66%, #1D0D06 0 1.4px, #FFF7F2 1.6px 3.2px, transparent 3.4px), var(--sr-accent); box-shadow: 0 0 0 3px var(--sr-bg) }

/* ---------- answer typography: built for long reading ---------- */
.qd-answer { font-size: 17px; line-height: 1.72; color: var(--sr-read); overflow-wrap: break-word }
.qd-answer > *:first-child { margin-top: 0 }
.qd-answer p { margin: 0 0 1em; text-wrap: pretty }
.qd-answer h2, .qd-answer h3, .qd-answer h4 {
    display: flex; align-items: baseline; gap: 12px; scroll-margin-top: calc(var(--sr-header-h) + 24px);
    margin: 2em 0 .7em; font-family: var(--sr-font); font-weight: 600; letter-spacing: -0.02em; line-height: 1.3; color: var(--sr-text);
}
.qd-answer h2 { font-size: 24px }
.qd-answer h3 { font-size: 21px }
.qd-answer h4 { font-size: 18px }
.qd-hnum { flex: none; font: 500 12px/1 var(--sr-mono); letter-spacing: .06em; color: var(--sr-faint); transform: translateY(-2px) }
.qd-answer ul, .qd-answer ol { margin: 0 0 1.2em; padding-left: 1.4em }
.qd-answer li { margin: .35em 0; padding-left: .2em }
.qd-answer li::marker { color: var(--sr-muted) }
.qd-answer ol li::marker { font: 500 .85em var(--sr-mono) }
.qd-answer strong { color: var(--sr-text); font-weight: 600 }
.qd-answer a { color: var(--sr-accent-text); text-decoration: underline; text-underline-offset: 3px; text-decoration-color: color-mix(in srgb, currentColor 40%, transparent) }
.qd-answer a:hover { text-decoration-color: currentColor }
.qd-answer blockquote { margin: 1.2em 0; padding: 2px 0 2px 18px; border-left: 2px solid var(--sr-line-strong); color: var(--sr-muted) }
.qd code { color: inherit }
.qd-answer :not(pre) > code { padding: .12em .38em; border-radius: 6px; background: var(--sr-raise); font: 500 .86em/1.4 var(--sr-mono); color: var(--sr-text) }
.qd-answer table { width: 100%; margin: 1.2em 0; border-collapse: collapse; font-size: 15px; line-height: 1.5; display: block; overflow-x: auto }
.qd-answer th, .qd-answer td { padding: 10px 12px; border-bottom: 1px solid var(--sr-line); text-align: left; vertical-align: top }
.qd-answer th { font-weight: 600; color: var(--sr-text); border-bottom-color: var(--sr-line-strong) }
.qd-answer__empty { color: var(--sr-muted) }

/* code: dark-on-well in both themes' own colours, language + copy on top */
.qd-code { margin: 1.4em 0; border-radius: var(--sr-r-md); background: var(--sr-well); border: 1px solid var(--sr-line); overflow: hidden }
.qd-code figcaption { display: flex; justify-content: space-between; align-items: center; height: 40px; padding: 0 8px 0 16px; border-bottom: 1px solid var(--sr-line) }
.qd-code__copy { display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 10px; border: 0; border-radius: var(--sr-r-pill); background: none; color: var(--sr-muted); font: 500 12.5px/1 var(--sr-font); cursor: pointer; transition: background-color .15s, color .15s }
.qd-code__copy:hover { background: var(--sr-raise); color: var(--sr-text) }
.qd-code__copy.is-done { color: var(--sr-accent-text) }
.qd-code__copy svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round }
.qd-code pre { margin: 0; padding: 16px; border-radius: 0; background: none; color: var(--sr-text); white-space: pre; overflow-x: auto; scrollbar-width: thin; scrollbar-color: var(--sr-line-strong) transparent }
.qd-code code, .qd-code .hljs { display: block; padding: 0 !important; background: none !important; font: 400 14px/1.65 var(--sr-mono); color: var(--sr-text); font-variant-ligatures: none; tab-size: 4; white-space: pre !important }
.qd .hljs-keyword, .qd .hljs-built_in, .qd .hljs-selector-tag { color: #C94F25 }
.qd .hljs-string, .qd .hljs-attr { color: #4E7A2E }
.qd .hljs-number, .qd .hljs-literal { color: #8A5A05 }
.qd .hljs-comment, .qd .hljs-quote { color: var(--sr-muted); font-style: italic }
.qd .hljs-title, .qd .hljs-title.function_, .qd .hljs-section { color: #2E5F8A }
.qd .hljs-params, .qd .hljs-variable, .qd .hljs-subst { color: var(--sr-text) }
[data-theme="dark"] .qd .hljs-keyword, [data-theme="dark"] .qd .hljs-built_in, [data-theme="dark"] .qd .hljs-selector-tag { color: #F2895F }
[data-theme="dark"] .qd .hljs-string, [data-theme="dark"] .qd .hljs-attr { color: #A9CF86 }
[data-theme="dark"] .qd .hljs-number, [data-theme="dark"] .qd .hljs-literal { color: #F0C178 }
[data-theme="dark"] .qd .hljs-title, [data-theme="dark"] .qd .hljs-title.function_, [data-theme="dark"] .qd .hljs-section { color: #8EC6EC }

/* callouts: the short answer ("for the interview") and the author's comment */
.qd-callout { margin: 0 0 1.6em; padding: 18px 20px 6px; border-radius: var(--sr-r-md); background: var(--sr-surface); border: 1px solid var(--sr-line); box-shadow: var(--sr-e1) }
.qd-callout--short { border-left: 3px solid var(--sr-done) }
.qd-answer .qd-callout--short > h2:first-child, .qd-answer .qd-callout--short > h3:first-child {
    margin: 0 0 10px; font: 500 11.5px/1.3 var(--sr-mono); letter-spacing: .06em; text-transform: uppercase; color: var(--sr-muted)
}
.qd-callout--short .qd-hnum { display: none }
.qd-callout--short p { font-size: 17.5px; color: var(--sr-text) }
.qd-callout--comment { margin-top: 1.6em; padding-bottom: 16px }
.qd-callout--comment .sr-mono-label { display: block; margin-bottom: 8px }

/* access */
.qd-lock { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 16px 24px; margin-top: 32px; padding: 20px; border-radius: var(--sr-r-lg); border: 1px dashed var(--sr-line-strong) }
.qd-lock b { display: block; margin-bottom: 4px; font-size: 16px; font-weight: 600 }
.qd-lock p { margin: 0; max-width: 52ch; font-size: 14px; line-height: 1.5; color: var(--sr-muted) }
.qd-lock__actions { display: flex; gap: 8px }

/* ---------- pager ---------- */
/* two equal cards; alone, the next card takes the whole row */
.qd-pager { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 14px; margin-top: 48px }
.qd-pager a { display: flex; flex-direction: column; gap: 8px; min-height: 112px; padding: 18px 20px; border-radius: var(--sr-r-lg); text-decoration: none; transition: transform .25s var(--sr-ease), border-color .15s }
.qd-pager__prev { background: var(--sr-surface); border: 1px solid var(--sr-line); color: var(--sr-text) }
.qd-pager__prev:hover { color: var(--sr-text); border-color: var(--sr-line-strong) }
.qd-pager__next { color: var(--sr-feature-ink); padding-right: 76px !important }
.qd-pager__next:hover { color: var(--sr-feature-ink); transform: translateY(-2px) }
.qd-pager__next .sr-mono-label { color: var(--sr-feature-muted) }
.qd-pager__next--end { background: var(--sr-surface); border: 1px dashed var(--sr-line-strong); color: var(--sr-text) }
.qd-pager__next--end .sr-mono-label { color: var(--sr-muted) }
.qd-pager__q { font-size: 16px; font-weight: 600; line-height: 1.35; letter-spacing: -0.01em; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; overflow: hidden }

/* ---------- side ---------- */
/* the side column always fits the screen: the topic list scrolls inside its card, the notes card stays whole */
.qd-side { grid-area: side; position: sticky; top: calc(var(--sr-header-h) + 16px); display: flex; flex-direction: column; gap: 16px }
.qd-box { padding: 16px; border-radius: var(--sr-r-lg); background: var(--sr-surface); border: 1px solid var(--sr-line) }
.qd-box h2 { margin: 0 0 10px }

.qd-note.sr-glass { background: var(--sr-glass) }
.qd-note__list { list-style: none; margin: 0 0 10px; padding: 0; display: flex; flex-direction: column; gap: 8px }
.qd-note__list:empty { display: none }
.qd-note__list li { padding: 10px 12px; border-radius: var(--sr-r-sm); background: var(--sr-raise) }
.qd-note__list p { margin: 0 0 6px; font-size: 14px; line-height: 1.5; white-space: pre-wrap; overflow-wrap: anywhere }
.qd-note__actions { display: flex; gap: 12px }
.qd-note__actions button { padding: 0; border: 0; background: none; color: var(--sr-muted); font: 500 12.5px/1.4 var(--sr-font); cursor: pointer }
.qd-note__actions button:hover { color: var(--sr-text) }
.qd-note__actions [data-note-delete]:hover { color: var(--sr-error) }
.qd-note__field {
    width: 100%; min-height: 84px; padding: 10px 12px; resize: vertical;
    border-radius: var(--sr-r-sm); border: 1px solid transparent; background: var(--sr-well); color: var(--sr-text);
    box-shadow: inset 0 1px 3px rgb(var(--sr-shadow-color) / .28); font: 400 14px/1.5 var(--sr-font);
}
.qd-note__field::placeholder { color: var(--sr-muted) }
.qd-note__field:focus-visible { outline: none; border-color: var(--sr-accent); box-shadow: inset 0 1px 3px rgb(var(--sr-shadow-color) / .28), 0 0 0 4px var(--sr-accent-soft) }
.qd-note__bar { display: flex; justify-content: flex-end; align-items: center; gap: 12px; margin-top: 10px }

.qd-related ul { list-style: none; margin: 0 0 8px; padding: 0; max-height: max(180px, calc(100vh - var(--sr-header-h) - 400px)); overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; scrollbar-color: var(--sr-line-strong) transparent }
.qd-answer__empty { padding: 18px 20px; border-radius: var(--sr-r-md); border: 1px dashed var(--sr-line-strong); color: var(--sr-muted) }
.qd-related a { display: flex; gap: 10px; align-items: baseline; padding: 7px 8px; margin: 0 -8px; border-radius: 8px; color: var(--sr-muted); text-decoration: none; font-size: 14px; line-height: 1.4; transition: background-color .15s, color .15s }
.qd-related a:hover { background: var(--sr-raise); color: var(--sr-text) }
.qd-related .sr-status { width: 10px; height: 10px; border-width: 1.4px; transform: translateY(1px) }

/* ---------- toast: bottom centre, always with undo when it can ---------- */
.qd-toast {
    position: fixed; left: 50%; bottom: 24px; z-index: 300; display: flex; align-items: center; gap: 16px;
    padding: 10px 10px 10px 18px; border-radius: var(--sr-r-pill); background: var(--sr-text); color: var(--sr-bg); box-shadow: var(--sr-e3);
    font: 500 14px/1.3 var(--sr-font); transform: translate(-50%, 16px); opacity: 0; transition: opacity .2s, transform .25s var(--sr-ease);
}
.qd-toast.is-on { opacity: 1; transform: translate(-50%, 0) }
.qd-toast button { height: 30px; padding: 0 12px; border: 0; border-radius: var(--sr-r-pill); background: color-mix(in srgb, var(--sr-bg) 14%, transparent); color: inherit; font: 600 13px/1 var(--sr-font); cursor: pointer }
.qd-toast button:hover { background: color-mix(in srgb, var(--sr-bg) 24%, transparent) }

/* ---------- tablet & phone ---------- */
@media (max-width: 1100px) {
    .qd-layout { grid-template-columns: minmax(0, var(--sr-read-col)); grid-template-areas: "back" "head" "article" "side" }
    .qd-side { margin-top: 40px }
    .qd-related ul { max-height: none }
    .qd-side { position: static; display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)) }
        .qd-read { display: none !important }
}
@media (max-width: 640px) {
    .qd-head { padding-bottom: 24px }
    .qd-back { margin: 18px 0 16px }
    .qd-study { margin-left: 0 }
    .qd-answer { font-size: 16.5px }
    .qd-pager { grid-auto-flow: row }
    .qd-pager__prev { order: 2 }
    .qd-toast { left: 16px; right: 16px; transform: translateY(16px); justify-content: space-between }
    .qd-toast.is-on { transform: none }
}
@media (prefers-reduced-motion: reduce) {
    .qd-study__fill, .qd-study__check, .qd-fav svg, .qd-toast, .qd-pager a { transition: none }
}

/* code: the wrap toggle is shown only when lines are longer than the block; the right edge fades while there is more */
.qd-code figcaption { gap: 4px }
.qd-code figcaption .sr-mono-label { margin-right: auto }
.qd-code__wrap { display: none }
.qd-code.has-overflow .qd-code__wrap, .qd-code.is-wrapped .qd-code__wrap { display: inline-flex }
.qd-code__wrap[aria-pressed="true"] { color: var(--sr-text); background: var(--sr-raise) }
.qd-code.has-overflow:not(.is-end) pre { -webkit-mask-image: linear-gradient(90deg, #000 calc(100% - 56px), transparent); mask-image: linear-gradient(90deg, #000 calc(100% - 56px), transparent) }
.qd-code.is-wrapped pre, .qd-code.is-wrapped code, .qd-code.is-wrapped .hljs { white-space: pre-wrap !important; overflow-wrap: anywhere }
.qd-code pre::-webkit-scrollbar { height: 8px }
.qd-code pre::-webkit-scrollbar-thumb { border-radius: 4px; background: var(--sr-line-strong) }
/* highlight.js makes <code> its own scroll box and clips long lines; the <pre> is the one that scrolls */
.qd-code code, .qd-code .hljs { overflow: visible !important; width: max-content; min-width: 100% }
.qd-code.is-wrapped code, .qd-code.is-wrapped .hljs { width: auto }
