/* Page chrome for the full-window demo pages (docs/_layouts/demo.html).
   Loaded after the demo's own style.css. The demos define --bg, --surface,
   --border, --text, --text-muted, --accent and --heading for both themes, so
   the bar and the explanation follow the demo's light/dark toggle. */

/* The demos' style.css centre a single .app in a flex <body> (the Playgrounds
   pin it to the window height); undo that so the bar, intro, demo and
   explanation stack vertically and the page scrolls. */
body.qd-body {
    display: block;
    padding: 0;
    margin: 0;
    min-height: 0;
    height: auto;
    overflow: visible;
    font-size: 16px;
    /* Width of the heading and the demo. */
    --qd-w: 760px;
}
/* Board demos (N-Queens, TSP, ...): the board is square, so tie the width to
   the window height to keep the whole board on screen
   (280px = bar + heading + toolbar + status). */
body.qd-board { --qd-w: clamp(600px, calc(100vh - 280px), 760px); }
/* Column demos (graph, SAT): the apps' own 760px, set above. */
/* Wide demos (scheduling): the app sets its own width and padding. */
body.qd-wide { --qd-w: 1400px; }

/* ---- top bar ---- */
.qd-bar {
    display: flex;
    align-items: center;
    gap: 1.25rem;
    padding: 0.55rem 1.25rem;
    background: var(--surface, #fff);
    border-bottom: 1px solid var(--border, #d0d7de);
    font-size: 0.9rem;
}
.qd-bar a {
    color: var(--text, #1f2328);
    text-decoration: none;
    white-space: nowrap;
}
.qd-bar a:hover { color: var(--accent, #0969da); }
.qd-brand {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    font-weight: 700;
    font-size: 1rem;
}
.qd-spacer { flex: 1; }
.qd-lang {
    border: 1px solid var(--border, #d0d7de);
    border-radius: 4px;
    padding: 0.1rem 0.55rem;
}

/* ---- heading and lead ---- */
.qd-intro {
    max-width: calc(var(--qd-w) + 2rem);
    margin: 1rem auto 0.75rem;
    padding: 0 1rem;
}
.qd-wide .qd-intro { max-width: var(--qd-w); padding: 0 16px; }
.qd-fill .qd-intro { max-width: none; margin: 0.75rem 0 0.6rem; padding: 0 1.25rem; }
/* explicit: the demos' style.css have their own h1 rules */
.qd-intro h1 {
    font-size: 1.5rem;
    font-weight: 600;
    line-height: 1.3;
    letter-spacing: normal;
    white-space: normal;
    color: var(--heading, var(--text, #1f2328));
    margin: 0 0 0.3rem;
}
.qd-lead {
    font-size: 0.95rem;
    line-height: 1.55;
    max-width: 900px;
    margin: 0 0 0.2rem;
}
.qd-docs {
    font-size: 0.9rem;
    margin: 0;
    color: var(--text-muted, var(--muted, #656d76));
}
.qd-intro a, .qd-article a, .qd-footer a { color: var(--accent, #0969da); }
.qd-sep {
    margin: 0 0.4rem;
    color: var(--text-muted, var(--muted, #656d76));
}

/* ---- the demo ---- */
.qd-demo {
    display: flex;
    justify-content: center;
    padding: 0 1rem 1.5rem;
}
.qd-demo > .app { max-width: var(--qd-w); }
.qd-board .qd-demo .toolbar { flex-wrap: wrap; }
.qd-board .qd-demo .slider-control input[type="range"] { width: 100px; }
.qd-wide .qd-demo { padding: 0 0 1.5rem; }
.qd-wide .qd-demo > .app { width: 100%; }
/* Playgrounds: the editor and the output fill the window below the heading;
   --qd-top (the top of .qd-demo) is set by the layout's script. */
.qd-fill .qd-demo { display: block; padding: 0; }
.qd-fill .qd-demo > .app {
    max-width: none;
    height: max(480px, calc(100vh - var(--qd-top, 150px)));
    display: flex;
    flex-direction: column;
    border-top: 1px solid var(--border, #d0d7de);
    border-bottom: 1px solid var(--border, #d0d7de);
}

/* ---- explanation below the demo ---- */
.qd-article {
    max-width: calc(min(var(--qd-w), 860px) + 2rem);
    font-size: 1rem;
    margin: 0 auto;
    padding: 1.75rem 1rem 2rem;
    border-top: 1px solid var(--border, #d0d7de);
    line-height: 1.7;
}
.qd-article h2 {
    font-size: 1.25rem;
    color: var(--heading, inherit);
    margin: 2rem 0 0.75rem;
}
.qd-article h2:first-child { margin-top: 0; }
.qd-article p, .qd-article ul, .qd-article ol,
.qd-article .highlighter-rouge, .qd-article table { margin: 0 0 1rem; }
.qd-article ul, .qd-article ol { padding-left: 1.5rem; }
.qd-article li { margin: 0.25rem 0; }
.qd-article code {
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 0.88em;
    background: var(--surface, #fff);
    border: 1px solid var(--border, #d0d7de);
    border-radius: 4px;
    padding: 0.05em 0.35em;
}
.qd-article pre {
    background: var(--surface, #fff);
    border: 1px solid var(--border, #d0d7de);
    border-radius: 6px;
    padding: 0.9rem 1rem;
    overflow-x: auto;
    line-height: 1.5;
}
.qd-article pre code {
    background: none;
    border: 0;
    padding: 0;
    font-size: 0.85rem;
}
.qd-article table {
    border-collapse: collapse;
    width: 100%;
    font-size: 0.9rem;
    line-height: 1.45;
    display: block;
    overflow-x: auto;
}
.qd-article th, .qd-article td {
    border-bottom: 1px solid var(--border, #d0d7de);
    padding: 0.35rem 0.6rem;
    text-align: left;
    vertical-align: top;
    white-space: normal;
}
.qd-article th {
    font-weight: 600;
    color: var(--heading, inherit);
    background: var(--surface, #fff);
    position: static;
}
/* minimal Rouge colours */
.qd-article .highlight .k, .qd-article .highlight .kn, .qd-article .highlight .kd,
.qd-article .highlight .kt, .qd-article .highlight .ow { color: #cf222e; }
.qd-article .highlight .s, .qd-article .highlight .s1, .qd-article .highlight .s2 { color: #0a3069; }
.qd-article .highlight .c, .qd-article .highlight .c1, .qd-article .highlight .cm { color: #6e7781; font-style: italic; }
.qd-article .highlight .mi, .qd-article .highlight .mf { color: #0550ae; }
.qd-article .highlight .nf, .qd-article .highlight .nb { color: #8250df; }
[data-theme="dark"] .qd-article .highlight .k, [data-theme="dark"] .qd-article .highlight .kn,
[data-theme="dark"] .qd-article .highlight .kd, [data-theme="dark"] .qd-article .highlight .kt,
[data-theme="dark"] .qd-article .highlight .ow { color: #ff7b72; }
[data-theme="dark"] .qd-article .highlight .s, [data-theme="dark"] .qd-article .highlight .s1,
[data-theme="dark"] .qd-article .highlight .s2 { color: #a5d6ff; }
[data-theme="dark"] .qd-article .highlight .c, [data-theme="dark"] .qd-article .highlight .c1,
[data-theme="dark"] .qd-article .highlight .cm { color: #8b949e; }
[data-theme="dark"] .qd-article .highlight .mi, [data-theme="dark"] .qd-article .highlight .mf { color: #79c0ff; }
[data-theme="dark"] .qd-article .highlight .nf, [data-theme="dark"] .qd-article .highlight .nb { color: #d2a8ff; }

/* ---- footer ---- */
.qd-footer {
    text-align: center;
    font-size: 0.8rem;
    color: var(--text-muted, var(--muted, #656d76));
    padding: 1rem 1rem 2rem;
}

/* Long display formulas scroll inside the text column. */
.qd-article mjx-container[display="true"] {
    display: block;
    overflow-x: auto;
    overflow-y: hidden;
    max-width: 100%;
}

/* Narrow windows: an app wider than the window (scheduling chart, tables)
   scrolls inside the demo area instead of widening the page, and the
   Playground toolbar wraps. */
@media (max-width: 1440px) {
    .qd-wide .qd-demo { overflow-x: auto; }
}
@media (max-width: 900px) {
    .qd-demo { overflow-x: auto; }
    .qd-fill .qd-demo .toolbar { flex-wrap: wrap; }
}

@media (max-width: 600px) {
    .qd-bar { flex-wrap: wrap; gap: 0.5rem 1rem; padding: 0.5rem 1rem; }
    .qd-spacer { display: none; }
    .qd-intro h1 { font-size: 1.35rem; }
}

/* Graph demo: the app's own header shows the selected problem; the sync
   script turned its <h1> into an <h2> (the page has one <h1>). */
.qd-demo .app > header h2 {
    font-size: 1.4rem;
    font-weight: 600;
    letter-spacing: -0.02em;
    color: var(--heading);
}
