:root {
    --bg: #0f1115;
    --surface: #171a21;
    --surface-2: #1e222b;
    --border: #2a2f3a;
    --text: #e6e8ec;
    --muted: #9aa3b2;
    --accent: #6ea8fe;
    --accent-soft: rgba(110, 168, 254, 0.14);
    --success: #58c98a;
    --danger: #f2777a;
    --warn: #e5b567;
    --radius: 10px;
}

@media (prefers-color-scheme: light) {
    :root {
        --bg: #f6f7f9;
        --surface: #ffffff;
        --surface-2: #f0f2f6;
        --border: #dde1e8;
        --text: #1a1d23;
        --muted: #5f6875;
        --accent: #2563eb;
        --accent-soft: rgba(37, 99, 235, 0.1);
        --success: #17864b;
        --danger: #c02b30;
        --warn: #9a6b12;
    }
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------------------------------------------------------------- chrome */

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 14px 24px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
    position: sticky;
    top: 0;
    z-index: 10;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 600;
    color: var(--text);
    font-size: 16px;
}
.brand:hover { text-decoration: none; }
.brand-mark { font-size: 20px; }

.topbar nav { display: flex; gap: 6px; }
.topbar nav a {
    padding: 6px 12px;
    border-radius: 7px;
    color: var(--muted);
    font-size: 14px;
}
.topbar nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }

.nav-toggle { display: none; font-size: 18px; line-height: 1; padding: 6px 11px; }

main {
    max-width: 900px;
    margin: 0 auto;
    padding: 28px 24px 80px;
}

.footer {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 6px 24px;
    font-size: 12px;
    color: var(--muted);
    background: var(--surface);
    border-top: 1px solid var(--border);
}

/* ---------------------------------------------------------------- shared */

h1 { font-size: 24px; margin: 0 0 4px; letter-spacing: -0.01em; }
h2 { font-size: 17px; margin: 28px 0 12px; }
h3 { font-size: 15px; margin: 0 0 4px; }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.loading { color: var(--muted); padding: 40px 0; text-align: center; }

.notice {
    padding: 10px 14px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--surface);
    margin-bottom: 16px;
    font-size: 14px;
}
.notice.error { border-color: var(--danger); color: var(--danger); }
.notice.warn { border-color: var(--warn); color: var(--warn); }

button {
    font: inherit;
    cursor: pointer;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text);
    padding: 8px 14px;
    transition: background 0.15s, border-color 0.15s;
}
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: 0.5; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover:not(:disabled) { filter: brightness(1.1); }
button.danger:hover:not(:disabled) { border-color: var(--danger); color: var(--danger); }
button.small { padding: 5px 10px; font-size: 13px; }

button.toggle-btn { font-size: 13px; padding: 6px 12px; }
button.toggle-btn.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

button.fav-btn {
    background: none;
    border: none;
    padding: 4px;
    font-size: 22px;
    line-height: 1;
    color: var(--border);
    flex-shrink: 0;
}
button.fav-btn:hover:not(:disabled) { color: var(--warn); border-color: transparent; }
button.fav-btn.active { color: var(--warn); }

.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spread { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; }

/* ---------------------------------------------------------------- search */

.searchbar { display: flex; gap: 10px; margin-bottom: 22px; }
.searchbar input {
    flex: 1;
    font: inherit;
    padding: 11px 14px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
}
.searchbar input:focus { outline: none; border-color: var(--accent); }

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

.card {
    display: flex;
    gap: 14px;
    padding: 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: border-color 0.15s, transform 0.1s;
    text-align: left;
    width: 100%;
    align-items: flex-start;
}
.card:hover { border-color: var(--accent); }
.card:active { transform: translateY(1px); }

.art {
    width: 68px;
    height: 68px;
    border-radius: 8px;
    object-fit: cover;
    background: var(--surface-2);
    flex-shrink: 0;
}
.art.lg { width: 96px; height: 96px; }

.card-body { min-width: 0; flex: 1; }
.card-title { font-weight: 600; margin-bottom: 2px; }
.card-sub { color: var(--muted); font-size: 13px; }
.card-desc {
    color: var(--muted);
    font-size: 13px;
    margin-top: 6px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.badges { display: flex; gap: 5px; flex-wrap: wrap; margin-top: 7px; }
.badge {
    font-size: 11px;
    padding: 2px 7px;
    border-radius: 20px;
    background: var(--accent-soft);
    color: var(--accent);
    border: 1px solid transparent;
    white-space: nowrap;
}
.badge.neutral { background: var(--surface-2); color: var(--muted); }
.badge.done { background: rgba(88, 201, 138, 0.14); color: var(--success); }
.badge.warn { background: rgba(229, 181, 103, 0.16); color: var(--warn); }

.card[data-status="not_summarized"] { cursor: default; }

/* -------------------------------------------------------------- episodes */

.episode {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 14px;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
}
.episode + .episode { margin-top: 8px; }
.episode-main { min-width: 0; flex: 1; }
.episode-title { font-weight: 500; margin-bottom: 3px; }
.ep-audio { display: block; width: 100%; max-width: 360px; height: 32px; margin-top: 6px; }

.show-header { display: flex; gap: 18px; margin-bottom: 8px; align-items: flex-start; }

/* ------------------------------------------------------------------ job */

.progress-wrap { margin: 20px 0 8px; }
.progress {
    height: 8px;
    border-radius: 20px;
    background: var(--surface-2);
    overflow: hidden;
    border: 1px solid var(--border);
}
.progress-bar {
    height: 100%;
    width: 0;
    background: var(--accent);
    border-radius: 20px;
    transition: width 0.4s ease;
}
.progress-bar.done { background: var(--success); }
.progress-bar.failed { background: var(--danger); }

.stages { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 14px; }
.stage {
    font-size: 12px;
    padding: 4px 10px;
    border-radius: 20px;
    background: var(--surface-2);
    color: var(--muted);
    border: 1px solid transparent;
}
.stage.active { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }
.stage.complete { color: var(--success); }

/* -------------------------------------------------------------- summary */

.tldr {
    font-size: 16px;
    line-height: 1.6;
    padding: 16px 18px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-left: 3px solid var(--accent);
    border-radius: var(--radius);
}

.chapter {
    display: flex;
    gap: 14px;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
}
.chapter:last-child { border-bottom: none; }
.ts {
    font-variant-numeric: tabular-nums;
    color: var(--accent);
    font-size: 13px;
    min-width: 58px;
    padding-top: 1px;
}

ul.points { margin: 0; padding-left: 20px; }
ul.points li { margin-bottom: 7px; }

.quote {
    padding: 12px 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-style: italic;
}
.quote + .quote { margin-top: 8px; }
.quote-meta { font-style: normal; color: var(--muted); font-size: 12px; margin-top: 6px; }

.terms { display: grid; gap: 8px; }
.term { padding: 10px 14px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.term-name { font-weight: 600; font-size: 14px; }
.term-note { color: var(--muted); font-size: 13px; }

.meta-line { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }

.transcript-text {
    margin-top: 20px;
    padding: 20px 24px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 15px;
    line-height: 1.75;
}
.transcript-text p { margin: 0 0 14px; }
.transcript-text p:last-child { margin-bottom: 0; }

/* --------------------------------------------------------------- compare */

.compare-grid {
    display: grid;
    gap: 20px;
    align-items: start;
    margin-top: 20px;
    overflow-x: auto;
}
.compare-col {
    min-width: 0;
    padding: 16px 18px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
.compare-col .tldr { font-size: 14px; padding: 12px 14px; }
.compare-col h4 {
    font-size: 12px;
    margin: 20px 0 8px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

/* ----------------------------------------------------------------- login */

.login-wrap { max-width: 340px; margin: 90px auto 0; }
.login-wrap h1 { text-align: center; margin-bottom: 24px; }
.login-wrap input {
    display: block;
    width: 100%;
    font: inherit;
    padding: 11px 14px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    margin-bottom: 12px;
}
.login-wrap input:focus { outline: none; border-color: var(--accent); }
.login-wrap button { width: 100%; }

/* --------------------------------------------------------------- account */

.key-row {
    padding: 14px 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 12px;
}
.key-row input {
    flex: 1;
    min-width: 0;
    font: inherit;
    padding: 9px 12px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
}
.key-row input:focus { outline: none; border-color: var(--accent); }

/* ----------------------------------------------------------------- mobile */
/* .spread and .episode assume side-by-side space for a title and a button
   cluster; below this width that cluster has nowhere to go and either wraps
   into the title or overflows the viewport, so both stack instead. */

@media (max-width: 640px) {
    main { padding: 20px 14px 90px; }
    .topbar { padding: 10px 14px; }

    .nav-toggle { display: inline-flex; align-items: center; justify-content: center; }
    .topbar nav {
        display: none;
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        flex-direction: column;
        gap: 2px;
        padding: 6px 14px 12px;
        background: var(--surface);
        border-bottom: 1px solid var(--border);
        box-shadow: 0 8px 16px rgba(0, 0, 0, 0.08);
    }
    .topbar nav.open { display: flex; }
    .topbar nav a { padding: 9px 10px; font-size: 15px; }

    h1 { font-size: 20px; }

    .spread { flex-direction: column; align-items: stretch; }
    .episode { flex-direction: column; align-items: stretch; }

    /* The Library card's Transcript/Delete row competing for space alongside
       the thumbnail and title squeezes card-body to ~130px, wrapping titles
       5-6 lines deep and stacking badges one per line. Push it to its own
       full-width line instead — flex-wrap rather than restructuring the
       markup, since .card is shared with the search-results and podcast-list
       cards, which only end in one small favorite-star button and are fine
       as they are. */
    .card { flex-wrap: wrap; }
    .card > .row { flex-basis: 100%; justify-content: flex-end; }
}
