/*
 * Live scanner demo — /scanner-api/#demo
 *
 * Composes from the primitives in /css/style.css and uses its tokens only. No hex
 * literals: the palette is defined once in that file and the site's own README treats
 * class names as a public API. Everything here is namespaced .demo-* / .quickstart-*
 * so nothing leaks onto the ~50 pages that share the stylesheet.
 */

/* --- the two-column frame ------------------------------------------------- */
.demo {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr);
    gap: var(--s-6);
    align-items: start;
    margin-top: var(--s-8);
}

.demo-scope {
    max-width: 820px;
    margin: 0 auto var(--s-6);
}

/* --- drop zone ------------------------------------------------------------ */
.demo-drop {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--s-2);
    min-height: 220px;
    padding: var(--s-8) var(--s-6);
    text-align: center;
    cursor: pointer;
    background: var(--surface);
    border: 1px dashed var(--line-strong);
    border-radius: var(--r-card);
    transition: border-color var(--t-micro-ms) var(--curve),
                background var(--t-micro-ms) var(--curve);
}
.demo-drop:hover,
.demo-drop:focus-within {
    border-color: var(--brand);
    background: var(--surface-subtle);
}
/* Dragging is the one state worth a colour: it confirms the drop will land. */
.demo-drop.is-dragging {
    border-color: var(--brand);
    border-style: solid;
    background: var(--brand-soft);
}
.demo-drop-icon { color: var(--brand-ink); }
.demo-drop-title { font-weight: 600; color: var(--fg); }
.demo-drop-hint { font-size: var(--t-caption); color: var(--fg-subtle); }

/* --- game picker ----------------------------------------------------------- */
.demo-game {
    display: flex;
    align-items: center;
    gap: var(--s-2);
    margin-bottom: var(--s-4);
}
.demo-game-label {
    font-size: var(--t-caption);
    font-weight: 600;
    color: var(--fg-subtle);
}
.demo-game-select {
    flex: 1;
    min-width: 0;
    font: inherit;
    color: var(--fg);
    background: var(--surface);
    border: 1px solid var(--line-strong);
    border-radius: var(--r-card);
    padding: var(--s-2) var(--s-3);
}
.demo-game-select:focus-visible {
    outline: 2px solid var(--brand);
    outline-offset: 1px;
}

/* --- per-game accuracy (scope note) --------------------------------------- */
.scan-games {
    width: 100%;
    border-collapse: collapse;
    margin: var(--s-3) 0;
    font-size: var(--t-caption);
}
.scan-games th,
.scan-games td {
    text-align: left;
    padding: var(--s-2) var(--s-3);
    border-bottom: 1px solid var(--line-soft);
    white-space: nowrap;
}
.scan-games th { color: var(--fg-subtle); font-weight: 600; }
/* The note is a flex row; without this its text column grows to the table's width and
   the whole note is clipped on a phone. With it, the table scrolls inside .table-wrap. */
.method-note > div { min-width: 0; }

/* --- samples -------------------------------------------------------------- */
.demo-samples {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--s-2);
    margin-top: var(--s-4);
}
.demo-samples-label {
    font-size: var(--t-caption);
    color: var(--fg-subtle);
    margin-right: var(--s-1);
}

.demo-preview {
    margin-top: var(--s-4);
    border: 1px solid var(--line-soft);
    border-radius: var(--r-card);
    overflow: hidden;
    background: var(--surface-sunken);
}
.demo-preview img { display: block; width: 100%; height: auto; }

/* --- output --------------------------------------------------------------- */
.demo-output {
    min-height: 220px;
    padding: var(--s-6);
    background: var(--surface);
    border: 1px solid var(--line-soft);
    border-radius: var(--r-card);
    box-shadow: var(--e-card);
}
.demo-idle,
.demo-status {
    margin: 0;
    font-size: var(--t-caption);
    color: var(--fg-subtle);
}

/* The verdict line. This pair — confidence and auto-accept — is the product, so it
   sits above the candidate list rather than beside it. */
.demo-verdict {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--s-2);
    padding-bottom: var(--s-4);
    margin-bottom: var(--s-4);
    border-bottom: 1px solid var(--line-soft);
}
.demo-meta {
    margin-left: auto;
    font-size: var(--t-tiny);
    color: var(--fg-subtle);
}

.demo-reasons {
    display: flex;
    flex-wrap: wrap;
    gap: var(--s-1);
    margin-bottom: var(--s-4);
}

/* --- candidates ----------------------------------------------------------- */
.demo-candidates { display: flex; flex-direction: column; gap: var(--s-2); }

.demo-candidate {
    display: grid;
    grid-template-columns: 44px minmax(0, 1fr) auto;
    gap: var(--s-3);
    align-items: center;
    padding: var(--s-3);
    border: 1px solid var(--line-soft);
    border-radius: var(--r-ctrl);
    background: var(--surface);
}
/* Rank 1 is emphasised, but never so hard that the alternatives read as noise —
   when auto_accept is false, the alternatives are the answer. */
.demo-candidate.is-top { border-color: var(--line-strong); background: var(--surface-subtle); }

.demo-candidate-img {
    width: 44px;
    height: 61px;
    object-fit: cover;
    border-radius: var(--r-sm);
    background: var(--surface-sunken);
}
.demo-candidate-name { font-weight: 600; color: var(--fg); }
.demo-candidate-sub {
    font-size: var(--t-tiny);
    color: var(--fg-subtle);
    font-family: var(--f-mono);
    font-variant-numeric: tabular-nums;
}
.demo-candidate-right { text-align: right; }
.demo-candidate-price {
    display: block;
    font-weight: 700;
    color: var(--fg);
    font-family: var(--f-mono);
    font-variant-numeric: tabular-nums;
}
.demo-candidate-score {
    display: block;
    font-size: var(--t-tiny);
    color: var(--fg-subtle);
    font-family: var(--f-mono);
    font-variant-numeric: tabular-nums;
}

/* --- raw JSON ------------------------------------------------------------- */
/* A developer evaluating a recognition API wants the response, not a rendering of it. */
.demo-raw { margin-top: var(--s-4); }
.demo-raw > summary {
    cursor: pointer;
    font-size: var(--t-caption);
    color: var(--fg-muted);
}
.demo-raw > summary:hover { color: var(--fg); }

.demo-json,
.quickstart-code {
    margin: var(--s-3) 0 0;
    padding: var(--s-4);
    overflow-x: auto;
    background: var(--surface-sunken);
    border: 1px solid var(--line-soft);
    border-radius: var(--r-ctrl);
    font-family: var(--f-mono);
    font-size: var(--t-tiny);
    line-height: 1.65;
    color: var(--fg);
    white-space: pre;
    tab-size: 2;
}

.demo-error { color: var(--negative); font-weight: 600; }
.demo-foot {
    margin-top: var(--s-6);
    text-align: center;
    font-size: var(--t-caption);
    color: var(--fg-subtle);
}

/* Entrance animations elsewhere on the page start from opacity 0 and are gated on
   html.js. This section is interactive, so it must never inherit a hidden state. */
.demo, .demo * { opacity: 1; }

/* --- quickstart ----------------------------------------------------------- */
.quickstart-grid { gap: var(--s-4); margin-top: var(--s-8); align-items: start; }
.quickstart-card { display: flex; flex-direction: column; }
.quickstart-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--s-2);
}
.quickstart-code { flex: 1; }
.quickstart-note { max-width: 820px; margin: var(--s-6) auto 0; }

/* --- no JS ---------------------------------------------------------------- */
/* header.php sets html.js in <head>. Without it the interactive parts are hidden and
   the section explains itself instead of rendering a dead drop zone. */
html:not(.js) .demo,
html:not(.js) .demo-foot { display: none; }
html:not(.js) .demo-scope::after {
    content: 'The interactive demo needs JavaScript. The API itself is a plain HTTPS request — see the quickstart below.';
    display: block;
    margin-top: var(--s-3);
    font-size: var(--t-caption);
    color: var(--fg-subtle);
}

@media (prefers-reduced-motion: reduce) {
    .demo-drop { transition: none; }
}

@media (max-width: 900px) {
    .demo { grid-template-columns: minmax(0, 1fr); }
    .quickstart-grid { grid-template-columns: minmax(0, 1fr); }
}
