:root {
    --bg: #f2f4f5;
    --bg-glow: rgba(35, 229, 219, .22);
    --surface: #ffffff;
    --surface-2: #f6f8f9;
    --ink: #002f34;
    --muted: #5c7275;
    --line: #dde4e5;
    --accent: #23e5db;
    --accent-ink: #002f34;
    --accent-soft: rgba(35, 229, 219, .16);
    --warn: #b36b00;
    --danger: #c0392b;
    --shadow: 0 1px 2px rgba(0, 47, 52, .06), 0 12px 32px -12px rgba(0, 47, 52, .18);
    --radius: 18px;
    --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #001c1f;
        --bg-glow: rgba(35, 229, 219, .10);
        --surface: #062a2e;
        --surface-2: #0a3439;
        --ink: #e6f4f4;
        --muted: #8fb0b2;
        --line: #12454a;
        --accent-soft: rgba(35, 229, 219, .12);
        --warn: #f0b45a;
        --danger: #ff8a7a;
        --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 16px 40px -16px rgba(0, 0, 0, .6);
        color-scheme: dark;
    }
}

* { box-sizing: border-box; }

body {
    margin: 0;
    min-height: 100vh;
    font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
    color: var(--ink);
    background:
        radial-gradient(900px 420px at 50% -120px, var(--bg-glow), transparent 70%),
        var(--bg);
    -webkit-font-smoothing: antialiased;
}

.shell {
    max-width: 760px;
    margin: 0 auto;
    padding: 56px 16px 64px;
}

.sr-only {
    position: absolute; width: 1px; height: 1px; overflow: hidden;
    clip: rect(0 0 0 0); white-space: nowrap;
}

/* brand */
.brand { display: flex; align-items: baseline; flex-wrap: wrap; gap: 6px 12px; margin-bottom: 22px; }
.brand h1 { margin: 0; font-size: 26px; letter-spacing: -.02em; font-weight: 750; }
.logo {
    width: 22px; height: 22px; border-radius: 50%;
    border: 5px solid var(--accent); align-self: center;
    box-shadow: 0 0 0 4px var(--accent-soft);
}
.tagline { color: var(--muted); font-size: 14px; }

/* ask box */
.ask {
    position: relative;
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 10px 10px 10px 18px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    transition: border-color .15s, box-shadow .15s;
}
.ask:focus-within { border-color: var(--accent); box-shadow: var(--shadow), 0 0 0 4px var(--accent-soft); }
.ask textarea {
    flex: 1;
    min-height: 44px;
    max-height: 220px;
    padding: 10px 0;
    border: 0;
    outline: 0;
    resize: none;
    background: transparent;
    color: inherit;
    font: inherit;
    font-size: 17px;
    line-height: 24px;
}
.ask textarea::placeholder { color: var(--muted); opacity: .75; }

.send {
    flex: none;
    display: grid;
    place-items: center;
    width: 44px; height: 44px;
    border: 0;
    border-radius: 13px;
    background: var(--accent);
    color: var(--accent-ink);
    cursor: pointer;
    transition: transform .12s, filter .12s;
}
.send:hover { filter: brightness(1.05); }
.send:active { transform: scale(.94); }
.send svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.send .spinner {
    display: none;
    width: 20px; height: 20px;
    border-radius: 50%;
    border: 2.5px solid currentColor;
    border-right-color: transparent;
    animation: spin .7s linear infinite;
}
.busy .send svg { display: none; }
.busy .send .spinner { display: block; }
.busy .send { cursor: progress; }

@keyframes spin { to { transform: rotate(360deg); } }

.under { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px; margin: 8px 4px 0; }
.keys { margin: 0; font-size: 12px; color: var(--muted); }

/* backend switch: radios of the GET form, styled as a segmented control */
.backend {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    margin: 0;
    padding: 2px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--surface);
    font-size: 12px;
}
.backend legend { float: left; padding: 0 6px 0 8px; color: var(--muted); }
.backend label { position: relative; cursor: pointer; }
.backend input { position: absolute; inset: 0; margin: 0; opacity: 0; cursor: pointer; }
.backend span { display: block; padding: 3px 10px; border-radius: 999px; color: var(--muted); }
.backend label:hover span { color: var(--ink); }
.backend input:checked + span { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.backend input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 1px; }
.history .tag { flex: none; font: 11px var(--mono); color: var(--muted); }
kbd {
    font: 11px var(--mono);
    padding: 1px 5px;
    border: 1px solid var(--line);
    border-bottom-width: 2px;
    border-radius: 5px;
    background: var(--surface);
}

/* examples */
.examples { display: flex; flex-wrap: wrap; gap: 8px; margin: 18px 0 26px; }
.example {
    max-width: 100%;
    padding: 6px 12px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: transparent;
    color: var(--muted);
    font: inherit;
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    cursor: pointer;
    transition: color .12s, border-color .12s, background .12s;
}
.example:hover { color: var(--ink); border-color: var(--accent); background: var(--accent-soft); }

/* result card */
.card {
    padding: 18px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    animation: rise .25s ease-out;
}
.card.found { border-top: 3px solid var(--accent); }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }

.url-row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.url-row + .url-row { margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--line); }
.url {
    flex: 1 1 260px;
    min-width: 0;
    padding: 10px 12px;
    border-radius: 11px;
    background: var(--surface-2);
    color: var(--ink);
    font: 13px/1.4 var(--mono);
    text-decoration: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.url:hover { text-decoration: underline; text-decoration-color: var(--accent); }
.alt-label { flex-basis: 100%; font-size: 12px; font-weight: 600; color: var(--warn); }
.actions { display: flex; gap: 8px; }

.btn {
    display: inline-flex;
    align-items: center;
    height: 38px;
    padding: 0 14px;
    border: 1px solid var(--line);
    border-radius: 11px;
    background: var(--surface);
    color: var(--ink);
    font: inherit;
    font-size: 14px;
    font-weight: 600;
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
    transition: background .12s, border-color .12s;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.05); }
.btn.ghost { background: transparent; }
.btn.done { border-color: var(--accent); background: var(--accent-soft); }

.hint { margin: 0; color: var(--warn); }
.suggestions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.suggest {
    max-width: 100%;
    padding: 7px 12px;
    border: 1px solid var(--line);
    border-radius: 11px;
    background: var(--surface-2);
    color: var(--ink);
    font-size: 14px;
    font-weight: 600;
    text-decoration: none;
    overflow-wrap: anywhere;
    transition: border-color .12s, background .12s;
}
.suggest:hover { border-color: var(--accent); background: var(--accent-soft); }
.error { margin: 0; color: var(--danger); font-size: 14px; word-break: break-word; }
.url-row ~ .hint, .url-row ~ .error { margin-top: 12px; }

/* understood fields */
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 16px 0 0; padding: 0; list-style: none; }
.chip {
    position: relative;
    display: flex;
    flex-direction: column;
    max-width: 100%;
    padding: 7px 12px 9px;
    border-radius: 12px;
    background: var(--surface-2);
    overflow: hidden;
}
.chip-title { font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.chip-value { font-size: 14px; font-weight: 600; overflow-wrap: anywhere; }
.chip-conf {
    position: absolute; left: 0; bottom: 0; height: 3px;
    width: calc(var(--c) * 1%);
    background: var(--accent);
}
.chip.unsure .chip-conf { background: var(--warn); }

.meta { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 6px 16px; margin-top: 14px; font-size: 12px; color: var(--muted); }
.meta:empty { display: none; }
.elapsed { margin-left: auto; }

/* loading placeholder */
.skeleton { display: grid; gap: 12px; }
.skeleton i {
    display: block; height: 14px; border-radius: 7px;
    background: linear-gradient(90deg, var(--surface-2), var(--line), var(--surface-2));
    background-size: 200% 100%;
    animation: shimmer 1.2s linear infinite;
}
.skeleton i:first-child { height: 40px; border-radius: 11px; }
.skeleton i:nth-child(2) { width: 70%; }
.skeleton i:nth-child(3) { width: 45%; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* history */
.history { margin-top: 34px; }
.history-head { display: flex; align-items: baseline; justify-content: space-between; }
.history h2 { margin: 0 0 8px; font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.history ul { margin: 0; padding: 0; list-style: none; }
.history li { display: flex; align-items: center; gap: 10px; border-bottom: 1px solid var(--line); }
.history li:last-child { border-bottom: 0; }
.history .again {
    flex: 1; min-width: 0;
    padding: 9px 0;
    border: 0; background: none;
    color: var(--ink); font: inherit; font-size: 14px; text-align: left;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    cursor: pointer;
}
.history .again:hover { color: var(--muted); }
.history .open { flex: none; font-size: 13px; color: var(--muted); text-decoration: none; }
.history .open:hover { color: var(--ink); }
.link { border: 0; background: none; padding: 0; color: var(--muted); font: inherit; font-size: 12px; cursor: pointer; }
.link:hover { color: var(--ink); text-decoration: underline; }

/* -web-debug panel */
.debug { margin-top: 18px; padding-top: 14px; border-top: 1px dashed var(--line); font-size: 13px; }
.dbg-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.dbg-badge {
    padding: 2px 8px; border-radius: 6px;
    background: var(--warn); color: var(--surface);
    font: 700 11px/1.6 var(--mono); text-transform: uppercase; letter-spacing: .06em;
}
.brand .dbg-badge { align-self: center; }
.debug summary { cursor: pointer; list-style: none; }
.debug summary::-webkit-details-marker { display: none; }
.dbg-stage, .dbg-category { margin-top: 8px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface-2); }
.dbg-stage > summary, .dbg-category > summary {
    display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; padding: 10px 12px;
}
.dbg-stage > summary::before, .dbg-category > summary::before, .dbg-filter > details > summary::before {
    content: "▸"; color: var(--muted); transition: transform .12s;
}
.debug details[open] > summary::before { transform: rotate(90deg); }
.dbg-cat-label { font-weight: 700; }
.dbg-category.accepted { border-color: var(--accent); }
.dbg-tag { color: var(--warn); font-weight: 600; }
.dbg-category.accepted .dbg-tag { color: var(--muted); }
.dbg-count { margin-left: auto; color: var(--muted); }
.dbg-note { margin: 0 12px 8px; color: var(--muted); }
.dbg-filters { margin: 0; padding: 0 6px 6px; list-style: none; }
.dbg-filter { border-top: 1px solid var(--line); }
.dbg-filter > details > summary {
    display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 10px; padding: 7px 6px; border-radius: 8px;
}
.dbg-filter > details > summary:hover { background: var(--accent-soft); }
.dbg-title { font-weight: 600; }
.dbg-filter:not(.set) .dbg-title { color: var(--muted); font-weight: 500; }
.dbg-key, .debug code { font-family: var(--mono); font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }
.dbg-kind { padding: 0 6px; border: 1px solid var(--line); border-radius: 6px; font: 11px/1.6 var(--mono); color: var(--muted); }
.dbg-outcome { color: var(--muted); }
.dbg-filter.set .dbg-outcome { color: var(--ink); font-weight: 600; }
.dbg-more {
    margin-left: auto; padding: 0 8px; border: 1px solid var(--line); border-radius: 7px;
    background: var(--surface); font-size: 12px; font-weight: 600;
}
.dbg-filter details[open] .dbg-more { border-color: var(--accent); background: var(--accent-soft); }
.dbg-body { padding: 4px 6px 12px 22px; }
.dbg-q + .dbg-q { margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--line); }
.dbg-answer { font-family: var(--mono); font-size: 12px; font-weight: 700; }
.dbg-instr { margin: 4px 0; white-space: pre-wrap; }
.dbg-options { width: 100%; border-collapse: collapse; font-size: 12px; }
.dbg-options td { padding: 2px 6px; border-top: 1px solid var(--line); vertical-align: top; overflow-wrap: anywhere; }
.dbg-options td:first-child { width: 1%; white-space: nowrap; }
.dbg-options .num { width: 1%; text-align: right; font-family: var(--mono); white-space: nowrap; }
.dbg-options tr.chosen td { background: var(--accent-soft); font-weight: 600; }
.dbg-json { position: relative; margin-top: 8px; }
.dbg-json > summary { display: inline-block; padding: 2px 10px; border: 1px solid var(--line); border-radius: 7px; font-size: 12px; font-weight: 600; }
.dbg-json[open] > summary { border-color: var(--accent); background: var(--accent-soft); }
.dbg-json .btn.small { position: absolute; top: 0; right: 0; height: 24px; padding: 0 10px; font-size: 12px; }
.dbg-json pre {
    max-height: 420px; margin: 6px 0 0; padding: 10px 12px; overflow: auto;
    border: 1px solid var(--line); border-radius: 10px; background: var(--surface);
    font: 12px/1.45 var(--mono); white-space: pre;
}

@media (max-width: 560px) {
    .shell { padding-top: 32px; }
    .actions { flex: 1 1 100%; }
    .actions .btn { flex: 1; justify-content: center; }
    .keys { display: none; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: .01ms !important; transition: none !important; }
}
