:root {
    --bg: #081116;
    --bg-raise: #102029;
    --surface: rgba(16, 32, 41, 0.92);
    --line: rgba(214, 236, 232, 0.14);
    --line-strong: rgba(214, 236, 232, 0.28);
    --text: #f3f7f6;
    --muted: #c5d5d2;
    --faint: #9bb0ac;
    --accent: #3ee0c5;
    --accent-ink: #04241c;
    --amber: #f2c27a;
    --danger: #ffb4a8;
    --danger-bg: rgba(255, 120, 96, 0.12);
    --ok: #8ee0b5;
    --paper: #f4f7f4;
    --paper-ink: #172226;
    --sans: "IBM Plex Sans", "Segoe UI", sans-serif;
    --display: Outfit, "Segoe UI", sans-serif;
    --mono: "IBM Plex Mono", "Cascadia Mono", ui-monospace, monospace;
    --shadow: 0 24px 60px rgba(0, 0, 0, 0.28);
    color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
    margin: 0;
    font-family: var(--sans);
    font-size: 15px;
    line-height: 1.5;
    color: var(--text);
    background:
        radial-gradient(900px 480px at 8% -10%, rgba(62, 224, 197, 0.16), transparent 55%),
        radial-gradient(700px 420px at 100% 0%, rgba(242, 194, 122, 0.08), transparent 46%),
        var(--bg);
}

button, input, select { font: inherit; color: inherit; }

button { cursor: pointer; }

button:disabled { cursor: not-allowed; }

::selection { background: rgba(62, 224, 197, 0.28); color: white; }

.skip {
    position: absolute;
    left: 12px;
    top: -40px;
    background: var(--accent);
    color: var(--accent-ink);
    padding: 8px 12px;
    border-radius: 8px;
    z-index: 5;
}

.skip:focus { top: 12px; }

.deck {
    height: 100dvh;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    position: relative;
}

.deck::before {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
    background-image:
        linear-gradient(rgba(255, 255, 255, 0.025) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 255, 255, 0.025) 1px, transparent 1px);
    background-size: 72px 72px;
    mask-image: radial-gradient(ellipse at 15% 0%, #000 15%, transparent 68%);
}

.topbar, .workspace { position: relative; z-index: 1; }

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    height: 64px;
    padding: 0 22px;
    border-bottom: 1px solid var(--line);
    background: rgba(8, 17, 22, 0.8);
    backdrop-filter: blur(16px);
}

.brand, .topbar-actions, .top-link, .health, .mode-btn, .command-row, .check-row, .history-heading {
    display: flex;
    align-items: center;
}

.brand { gap: 10px; }

.mark {
    width: 34px;
    height: 34px;
    display: block;
    flex: 0 0 auto;
}

.brand-name {
    font-family: var(--display);
    font-weight: 600;
    font-size: 18px;
    letter-spacing: -0.03em;
}

.brand-version, .pill, .meta-chip, .sample-kicker, .eyebrow, legend, .field > span {
    font-family: var(--mono);
    font-size: 11px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.brand-version {
    color: var(--faint);
    border: 1px solid var(--line);
    border-radius: 99px;
    padding: 2px 7px;
}

.topbar-actions { gap: 8px; }

.health {
    gap: 8px;
    padding: 6px 10px;
    border-radius: 99px;
    border: 1px solid var(--line);
    color: var(--muted);
    font-size: 12.5px;
}

.health-dot {
    width: 8px;
    height: 8px;
    border-radius: 99px;
    background: var(--amber);
}

.health[data-state="online"] { color: var(--ok); }
.health[data-state="online"] .health-dot {
    background: var(--ok);
    box-shadow: 0 0 0 4px rgba(142, 224, 181, 0.12);
}
.health[data-state="offline"] { color: var(--danger); }
.health[data-state="offline"] .health-dot { background: var(--danger); }

.top-link {
    gap: 6px;
    color: var(--muted);
    text-decoration: none;
    padding: 6px 8px;
    border-radius: 8px;
    font-size: 13.5px;
}

.top-link:hover { color: var(--text); background: rgba(255, 255, 255, 0.04); }

.top-link svg, .mode-btn svg, .advanced-toggle svg { width: 16px; height: 16px; }

.workspace {
    min-height: 0;
    display: grid;
    grid-template-columns: 280px minmax(0, 1fr);
}

.rail {
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 22px;
    padding: 18px;
    border-right: 1px solid var(--line);
    background: rgba(6, 14, 18, 0.45);
}

.mode-nav { display: grid; gap: 8px; }

.mode-btn {
    width: 100%;
    text-align: left;
    gap: 12px;
    padding: 10px 12px;
    border-radius: 14px;
    border: 1px solid transparent;
    background: transparent;
    color: var(--muted);
}

.mode-btn strong, .mode-btn small { display: block; }

.mode-btn strong {
    font-family: var(--display);
    font-weight: 600;
    color: var(--text);
    letter-spacing: -0.02em;
}

.mode-btn small { color: var(--faint); font-size: 12px; }

.mode-btn:hover { background: rgba(255, 255, 255, 0.03); }

.mode-btn.is-on {
    background: rgba(62, 224, 197, 0.08);
    border-color: rgba(62, 224, 197, 0.35);
    color: var(--accent);
}

.history-block {
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.history-heading { justify-content: space-between; }

.history-heading h2 {
    margin: 0;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--faint);
}

.history-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    overflow: auto;
    padding-right: 2px;
}

.history-empty, .rail-note, .field-hint, .shortcut, .sample-body, .result-desc {
    color: var(--faint);
    font-size: 13px;
}

.history-empty, .rail-note { margin: 0; }

.rail-note { margin-top: auto; }

.history-item {
    width: 100%;
    min-width: 0;
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 2px 8px;
    text-align: left;
    padding: 8px 10px;
    border-radius: 12px;
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.02);
}

.history-item.is-active { border-color: rgba(62, 224, 197, 0.45); }

.history-label {
    grid-column: 1 / -1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 13px;
}

.history-time {
    justify-self: end;
    color: var(--faint);
    font-family: var(--mono);
    font-size: 11px;
}

.pill {
    color: var(--accent);
    border: 1px solid rgba(62, 224, 197, 0.35);
    border-radius: 99px;
    padding: 1px 6px;
}

.main-pane {
    min-width: 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
    padding: 22px 24px 28px;
    gap: 14px;
}

.command-panel {
    position: relative;
    border: 1px solid var(--line);
    border-radius: 20px;
    padding: 18px 18px 14px;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.035), rgba(255, 255, 255, 0.015));
    box-shadow: var(--shadow);
}

.command-panel::before {
    content: "";
    position: absolute;
    left: 22px;
    right: 22px;
    top: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(62, 224, 197, 0.75), transparent);
}

.eyebrow, legend, .field > span {
    margin: 0 0 6px;
    color: var(--faint);
}

.command-hint { margin: 4px 0 0; color: var(--muted); max-width: 68ch; }

.command-row { gap: 10px; margin-top: 14px; }

.command-input, .field-input {
    width: 100%;
    background: rgba(4, 12, 16, 0.55);
    border: 1px solid var(--line-strong);
    border-radius: 12px;
    padding: 0 14px;
    outline: none;
}

.command-input {
    height: 48px;
    font-family: var(--mono);
    font-size: 14.5px;
}

.command-input:focus, .field-input:focus {
    border-color: rgba(62, 224, 197, 0.7);
    box-shadow: 0 0 0 4px rgba(62, 224, 197, 0.12);
}

.run-btn {
    height: 48px;
    min-width: 148px;
    padding: 0 18px;
    border: 0;
    border-radius: 12px;
    background: var(--accent);
    color: var(--accent-ink);
    font-family: var(--display);
    font-weight: 600;
    letter-spacing: -0.02em;
}

.run-btn:hover { filter: brightness(1.06); }

.run-btn:disabled { filter: saturate(0.7) brightness(0.8); }

.run-btn.is-busy {
    background-image: linear-gradient(100deg, transparent 0%, rgba(255, 255, 255, 0.35) 45%, transparent 80%);
    background-size: 45% 100%;
    background-repeat: no-repeat;
    animation: sheen 1.05s linear infinite;
}

.shortcut { margin: 8px 0 0; }

.shortcut kbd, kbd {
    font-family: var(--mono);
    font-size: 11px;
    border: 1px solid var(--line-strong);
    border-bottom-width: 2px;
    border-radius: 6px;
    padding: 1px 6px;
    color: var(--muted);
}

.controls { margin-top: 16px; }

.option-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.4fr) minmax(220px, 0.8fr);
    gap: 18px;
}

.field { border: 0; margin: 0; padding: 0; min-width: 0; }

.chip-row, .segment, .search-grid, .meta-row, .tab-list, .toolbar-actions, .sample-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.chip, .segment button, .text-btn, .tab {
    border-radius: 999px;
    border: 1px solid var(--line-strong);
    background: transparent;
    color: var(--muted);
}

.chip, .segment button, .tab {
    padding: 6px 11px;
    font-size: 13px;
}

.chip.is-on, .segment button.is-on, .tab.is-on {
    background: rgba(62, 224, 197, 0.14);
    border-color: rgba(62, 224, 197, 0.5);
    color: #dcfff6;
}

.segment {
    padding: 4px;
    border-radius: 999px;
    border: 1px solid var(--line);
    width: fit-content;
}

.segment button { border-color: transparent; }

.field-hint { margin: 8px 0 0; }

.warn-hint { color: var(--amber); }

.advanced-toggle {
    margin-top: 12px;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.advanced-toggle[aria-expanded="true"] svg { transform: rotate(180deg); }

.advanced {
    margin-top: 12px;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 180px;
    gap: 12px;
}

.field-input { height: 40px; font-size: 14px; }

.field-input.narrow { width: 96px; }

.search-grid { align-items: end; }

.check-row {
    gap: 8px;
    height: 40px;
    color: var(--muted);
    font-size: 14px;
}

input[type="checkbox"] { accent-color: #14b8a6; width: 15px; height: 15px; }

.text-btn {
    padding: 4px 8px;
    font-size: 12.5px;
}

.text-btn:hover, .tab:hover, .chip:hover { color: var(--text); border-color: var(--line-strong); }

.text-btn:disabled { opacity: 0.4; }

.error-banner {
    margin-top: 14px;
    padding: 10px 12px;
    border-radius: 12px;
    background: var(--danger-bg);
    border: 1px solid rgba(255, 180, 168, 0.35);
    color: var(--danger);
    font-size: 14px;
}

.progress {
    height: 2px;
    border-radius: 99px;
    overflow: hidden;
    background: rgba(255, 255, 255, 0.06);
}

.progress span {
    display: block;
    height: 100%;
    width: 35%;
    background: var(--accent);
    animation: slide 1s ease-in-out infinite;
}

.stage {
    min-height: 0;
    overflow: auto;
    padding-bottom: 12px;
}

.stage.is-busy { opacity: 0.62; }

.empty { max-width: 820px; padding: 12px 4px 24px; }

.empty h2, .result-title, .sample-title {
    font-family: var(--display);
    letter-spacing: -0.03em;
    margin: 0;
}

.empty h2 {
    font-size: 34px;
    line-height: 1.15;
    font-weight: 600;
    max-width: 16ch;
}

.empty-lead { color: var(--muted); max-width: 62ch; }

.sample-grid { margin-top: 18px; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }

.sample {
    text-align: left;
    padding: 14px;
    border-radius: 16px;
    border: 1px solid var(--line);
    background: rgba(16, 32, 41, 0.65);
    display: grid;
    gap: 4px;
}

.sample:hover { border-color: rgba(62, 224, 197, 0.45); }

.sample-kicker { color: var(--accent); }

.sample-title { font-size: 16px; font-weight: 600; }

.result { display: grid; gap: 12px; }

.result-kicker {
    margin: 0;
    color: var(--accent);
    font-family: var(--mono);
    font-size: 11px;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.result-title { font-size: 28px; line-height: 1.2; font-weight: 600; }

.result-desc { margin: 6px 0 0; max-width: 70ch; }

.result-url {
    display: inline-block;
    margin-top: 6px;
    color: var(--accent);
    font-family: var(--mono);
    font-size: 12.5px;
    word-break: break-all;
}

.meta-chip {
    color: var(--muted);
    border: 1px solid var(--line);
    border-radius: 99px;
    padding: 4px 8px;
    letter-spacing: 0.04em;
}

.meta-chip.ok { color: var(--ok); border-color: rgba(142, 224, 181, 0.35); }
.meta-chip.warn { color: var(--amber); border-color: rgba(242, 194, 122, 0.4); }
.meta-chip.danger { color: var(--danger); border-color: rgba(255, 180, 168, 0.4); }

.history-note { margin: 0; color: var(--faint); font-size: 12.5px; }

.result-toolbar {
    position: sticky;
    top: 0;
    z-index: 2;
    display: flex;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    padding: 8px 0;
    background: rgba(8, 17, 22, 0.92);
    backdrop-filter: blur(12px);
}

.paper {
    color-scheme: light;
    background: linear-gradient(180deg, #f7faf7, #eef3ef);
    color: var(--paper-ink);
    border-radius: 18px;
    padding: 28px 32px;
    max-width: 860px;
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.18);
}

.paper ::selection { background: rgba(15, 110, 98, 0.18); color: var(--paper-ink); }

.paper .prose { max-width: none; color: var(--paper-ink); }

.paper .prose a { color: #0f6b5e; }

.paper .prose :not(pre) > code {
    color: #0f6e62;
    background: rgba(15, 110, 98, 0.08);
    padding: 0.1em 0.35em;
    border-radius: 4px;
    font-size: 0.88em;
}

.paper .prose pre {
    background: #102028;
    color: #e7fff8;
    border-radius: 12px;
}

.paper .prose pre code { color: inherit; background: transparent; padding: 0; }

.paper h1, .paper h2, .paper h3 { letter-spacing: -0.03em; }

.paper p, .paper ul, .paper ol { line-height: 1.65; }

.paper a { color: #0f6b5e; }

.code-view {
    margin: 0;
    padding: 16px 18px;
    border-radius: 16px;
    background: #07141c;
    color: #d9fff6;
    border: 1px solid var(--line);
    font-family: var(--mono);
    font-size: 12.5px;
    line-height: 1.6;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.panel-note { margin: 0 0 8px; color: var(--faint); font-size: 12.5px; }

.link-tools { display: flex; gap: 10px; align-items: center; margin-bottom: 8px; }

.link-tools .field-input { max-width: 360px; }

.link-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }

.link-row {
    display: grid;
    grid-template-columns: 42px minmax(0, 1fr) auto;
    gap: 8px;
    align-items: center;
    padding: 8px 10px;
    border-radius: 12px;
    border: 1px solid var(--line);
}

.link-index, .idx {
    font-family: var(--mono);
    font-variant-numeric: tabular-nums;
    color: var(--faint);
    font-size: 12px;
}

.link-row a, .result-card a.title-link {
    color: var(--text);
    text-decoration: none;
}

.link-row a {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.link-row a:hover, .title-link:hover { color: var(--accent); }

.result-list { display: grid; gap: 10px; max-width: 860px; }

.result-card {
    padding: 14px 16px;
    border-radius: 16px;
    border: 1px solid var(--line);
    background: rgba(16, 32, 41, 0.72);
}

.result-card-top { display: flex; justify-content: space-between; gap: 12px; align-items: start; }

.domain {
    margin: 2px 0 0;
    color: var(--faint);
    font-family: var(--mono);
    font-size: 12px;
}

.title-link {
    font-family: var(--display);
    font-size: 18px;
    font-weight: 600;
    letter-spacing: -0.02em;
}

.quote {
    margin: 10px 0 0;
    padding-left: 12px;
    border-left: 2px solid rgba(62, 224, 197, 0.55);
    color: var(--muted);
}

.card-actions { display: flex; gap: 8px; flex-shrink: 0; }

.shot-frame {
    max-width: 960px;
    padding: 16px;
    border-radius: 18px;
    border: 1px solid var(--line);
    background:
        linear-gradient(45deg, rgba(255, 255, 255, 0.03) 25%, transparent 25%),
        linear-gradient(-45deg, rgba(255, 255, 255, 0.03) 25%, transparent 25%),
        #0c181f;
    background-size: 22px 22px;
}

.shot-frame img {
    display: block;
    max-width: 100%;
    max-height: min(72vh, 880px);
    margin: 0 auto;
    border-radius: 8px;
    box-shadow: 0 18px 40px rgba(0, 0, 0, 0.35);
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

* { scrollbar-width: thin; scrollbar-color: rgba(186, 214, 210, 0.35) transparent; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: rgba(186, 214, 210, 0.28); border-radius: 99px; }

@keyframes sheen {
    from { background-position: -40% 0; }
    to { background-position: 140% 0; }
}

@keyframes slide {
    0% { transform: translateX(-120%); }
    100% { transform: translateX(320%); }
}

@media (max-width: 920px) {
    .deck { height: auto; min-height: 100dvh; }
    .workspace { display: flex; flex-direction: column; }
    .rail {
        border-right: 0;
        border-bottom: 1px solid var(--line);
        gap: 14px;
    }
    .history-list { flex-direction: row; overflow-x: auto; }
    .history-item { min-width: 210px; }
    .rail-note { margin-top: 0; }
    .stage { min-height: 60vh; }
    .sample-grid, .option-grid, .advanced { grid-template-columns: 1fr; }
}

@media (max-width: 720px) {
    .topbar { padding: 0 14px; }
    .top-link span { display: none; }
    .main-pane { padding: 16px 14px 24px; }
    .command-row { flex-direction: column; align-items: stretch; }
    .run-btn { width: 100%; }
    .empty h2 { font-size: 28px; }
    .result-title { font-size: 22px; }
    .paper { padding: 18px 16px; }
    .brand-version { display: none; }
}

@media (prefers-reduced-motion: reduce) {
    .run-btn.is-busy, .progress span { animation: none; }
}

[hidden] { display: none !important; }
