/* Briefly — mobile-first, no framework. */

:root {
    --bg: #0d0d12;
    --surface: #17171f;
    --surface-2: #21212c;
    --text: #f4f4f7;
    --muted: #9c9cb0;
    --border: #2b2b38;
    --overlay: rgba(13, 13, 18, .72);
    --brand: linear-gradient(135deg, #ff7a3d 0%, #ff2d78 52%, #7b5cff 100%);
    --accent: #ff4f7b;
    --ok: #34d399;
    --warn: #fbbf24;
    --bad: #f87171;
    --radius: 22px;
    --header-h: 56px;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --font: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --font-display: ui-rounded, "SF Pro Rounded", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    color-scheme: dark;
}

:root[data-theme="light"] {
    --bg: #f5f4f0;
    --surface: #ffffff;
    --surface-2: #ecebe5;
    --text: #15151c;
    --muted: #686879;
    --border: #e0ded6;
    --overlay: rgba(245, 244, 240, .78);
    color-scheme: light;
}

@media (prefers-color-scheme: light) {
    :root:not([data-theme]) {
        --bg: #f5f4f0;
        --surface: #ffffff;
        --surface-2: #ecebe5;
        --text: #15151c;
        --muted: #686879;
        --border: #e0ded6;
        --overlay: rgba(245, 244, 240, .78);
        color-scheme: light;
    }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 16px/1.5 var(--font);
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
}
a { color: inherit; }
img { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.icon { width: 22px; height: 22px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.muted { color: var(--muted); }

/* ------------------------------------------------------------------ header */

.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    gap: 6px;
    height: calc(var(--header-h) + var(--safe-top));
    padding: var(--safe-top) 10px 0 16px;
    background: var(--overlay);
    backdrop-filter: saturate(160%) blur(16px);
    -webkit-backdrop-filter: saturate(160%) blur(16px);
    border-bottom: 1px solid color-mix(in srgb, var(--border) 60%, transparent);
}
.page-feed .topbar { position: fixed; inset: 0 0 auto 0; border-bottom: 0; background: linear-gradient(to bottom, var(--bg) 20%, transparent); backdrop-filter: none; -webkit-backdrop-filter: none; }
.logo {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin-right: auto;
    font: 800 1.3rem/1 var(--font-display);
    letter-spacing: -.03em;
    text-decoration: none;
}
.logo-mark { width: 26px; height: 26px; border-radius: 8px; background: var(--brand); display: grid; place-items: center; color: #fff; font-size: .95rem; }
.icon-btn {
    display: inline-grid;
    place-items: center;
    width: 44px;
    height: 44px;
    border: 0;
    border-radius: 14px;
    background: transparent;
    text-decoration: none;
    position: relative;
}
.icon-btn:hover { background: color-mix(in srgb, var(--surface-2) 70%, transparent); }
.icon-btn .dot { position: absolute; top: 9px; right: 9px; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }

/* -------------------------------------------------------------------- feed */

.page-feed { overflow: hidden; height: 100dvh; }
.feed {
    position: fixed;
    inset: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    scroll-snap-type: y mandatory;
    overflow-anchor: none;
    scrollbar-width: none;
    outline: none;
}
.feed::-webkit-scrollbar { display: none; }

.card {
    height: 100dvh;
    scroll-snap-align: start;
    scroll-snap-stop: always;
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding: calc(var(--header-h) + var(--safe-top) + 4px) 16px calc(16px + var(--safe-bottom));
}
@supports not (height: 100dvh) { .card, .page-feed { height: 100vh; } }

.card-media {
    position: relative;
    flex: 1 1 40%;
    max-height: 52%;
    min-height: 150px;
    border-radius: var(--radius);
    overflow: hidden;
    background: var(--surface-2);
    text-decoration: none;
}
.card-media img { width: 100%; height: 100%; object-fit: cover; }
.card-media::after { content: ""; position: absolute; inset: 55% 0 0; background: linear-gradient(transparent, rgba(0,0,0,.45)); pointer-events: none; }
.placeholder {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    padding: 24px;
    color: rgba(255,255,255,.95);
    font: 800 clamp(1.6rem, 8vw, 2.6rem)/1.05 var(--font-display);
    letter-spacing: -.03em;
    text-align: center;
    background: linear-gradient(135deg, hsl(var(--h) 75% 52%), hsl(calc(var(--h) + 50) 70% 38%));
}
.media-chips { position: absolute; left: 12px; bottom: 12px; z-index: 1; display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 28px;
    padding: 0 11px;
    border-radius: 999px;
    font-size: .78rem;
    font-weight: 650;
    white-space: nowrap;
    background: rgba(0,0,0,.5);
    color: #fff;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}
.chip-geo::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--geo, #aaa); }

[data-geo="us"] { --geo: #60a5fa; }
[data-geo="us-ne"] { --geo: #22d3ee; }
[data-geo="us-ny"] { --geo: #a78bfa; }
[data-geo="es"] { --geo: #f87171; }
[data-geo="es-vc"] { --geo: #fb923c; }
[data-geo="es-alc"] { --geo: #fbbf24; }
[data-geo="eu"] { --geo: #818cf8; }
[data-geo="uk"] { --geo: #34d399; }
[data-geo="europe"] { --geo: #2dd4bf; }
[data-geo="intl"] { --geo: #e879f9; }

.card-body { flex: 0 1 auto; min-height: 0; display: flex; flex-direction: column; gap: 10px; overflow: hidden; }
.card-source { display: flex; align-items: center; gap: 8px; font-size: .88rem; color: var(--muted); min-width: 0; white-space: nowrap; }
.card-source strong { flex: 0 1 auto; max-width: 60%; color: var(--text); font-weight: 700; overflow: hidden; text-overflow: ellipsis; }
.card-time { flex: 1 1 0; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.badge-initial {
    flex: none;
    width: 26px;
    height: 26px;
    border-radius: 8px;
    display: grid;
    place-items: center;
    font-size: .75rem;
    font-weight: 800;
    color: #fff;
    background: hsl(var(--h, 200) 65% 48%);
}
.card-title {
    margin: 0;
    font: 800 clamp(1.45rem, 5.9vw, 2rem)/1.13 var(--font-display);
    letter-spacing: -.022em;
    text-wrap: pretty;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 5;
    overflow: hidden;
}
.card-title a { text-decoration: none; }
.card-excerpt {
    margin: 0;
    color: var(--muted);
    font-size: 1rem;
    line-height: 1.45;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 4;
    overflow: hidden;
}
.card-cluster { font-size: .82rem; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; }
.card-cluster .icon { width: 16px; height: 16px; }

.card-actions { flex: 0 0 auto; display: flex; gap: 10px; align-items: center; }
.btn-save {
    flex: none;
    width: 56px;
    height: 56px;
    border-radius: 18px;
    border: 1px solid var(--border);
    background: var(--surface);
    display: grid;
    place-items: center;
    transition: transform .15s ease;
}
.btn-save:active { transform: scale(.9); }
.btn-save .icon { width: 24px; height: 24px; }
.btn-save[aria-pressed="true"] { border-color: transparent; background: var(--brand); color: #fff; }
.btn-save[aria-pressed="true"] .icon { fill: currentColor; }
.btn-read {
    flex: 1;
    min-width: 0;
    height: 56px;
    border-radius: 18px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 0 18px;
    background: var(--text);
    color: var(--bg);
    font-weight: 750;
    text-decoration: none;
    white-space: nowrap;
    overflow: hidden;
}
.btn-read span { overflow: hidden; text-overflow: ellipsis; }
.btn-read .icon { width: 18px; height: 18px; }

.card-status { align-items: center; justify-content: center; text-align: center; }
.card-status h2 { margin: 0; font: 800 1.6rem/1.2 var(--font-display); letter-spacing: -.02em; }
.card-status p { margin: 0; color: var(--muted); max-width: 30ch; }
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid var(--border); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-height: 700px) {
    .card { gap: 10px; }
    .card-media { flex-basis: 34%; max-height: 40%; }
    .card-title { -webkit-line-clamp: 4; font-size: clamp(1.3rem, 5.4vw, 1.75rem); }
    .card-excerpt { -webkit-line-clamp: 3; font-size: .95rem; }
    .btn-save, .btn-read { height: 50px; }
    .btn-save { width: 50px; }
}
@media (max-height: 560px) {
    .card-excerpt { display: none; }
}

@media (min-width: 760px) {
    .feed { background: radial-gradient(1200px 600px at 50% -10%, color-mix(in srgb, var(--accent) 12%, transparent), transparent); }
    .card { max-width: 520px; margin: 0 auto; }
}

.active-filters {
    position: fixed;
    z-index: 19;
    top: calc(var(--header-h) + var(--safe-top) - 6px);
    left: 0;
    right: 0;
    display: flex;
    justify-content: center;
    gap: 6px;
    padding: 0 12px;
    pointer-events: none;
}
.active-filters .pill { pointer-events: auto; }
.page-feed.has-filters .card { padding-top: calc(var(--header-h) + var(--safe-top) + 34px); }

.pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 30px;
    padding: 0 12px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--surface);
    font-size: .82rem;
    font-weight: 650;
    white-space: nowrap;
    max-width: 70vw;
    overflow: hidden;
    text-overflow: ellipsis;
}
button.pill .icon { width: 14px; height: 14px; }

/* ------------------------------------------------------------ sheets/menus */

dialog.sheet {
    width: min(560px, 100%);
    max-height: 88dvh;
    margin: auto auto 0;
    padding: 20px 18px calc(18px + var(--safe-bottom));
    border: 0;
    border-radius: 26px 26px 0 0;
    background: var(--surface);
    color: var(--text);
    overflow: auto;
}
dialog.sheet[open] { animation: sheet-in .22s ease-out; }
dialog::backdrop { background: rgba(0,0,0,.5); backdrop-filter: blur(2px); }
@keyframes sheet-in { from { transform: translateY(40px); opacity: 0; } }
@media (min-width: 760px) { dialog.sheet { margin: auto; border-radius: 26px; } }
.sheet h2 { margin: 0 0 14px; font: 800 1.35rem/1.2 var(--font-display); letter-spacing: -.02em; }
.sheet h3 { margin: 18px 0 8px; font-size: .8rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.sheet-grip { width: 40px; height: 5px; border-radius: 3px; background: var(--border); margin: -8px auto 14px; }
.sheet-actions { display: flex; gap: 10px; margin-top: 22px; }
.sheet-actions > * { flex: 1; }

.choice-grid { display: flex; flex-wrap: wrap; gap: 8px; }
.choice input { position: absolute; opacity: 0; pointer-events: none; }
.choice span {
    display: inline-flex;
    align-items: center;
    height: 40px;
    padding: 0 16px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--surface-2);
    font-weight: 600;
    font-size: .92rem;
    cursor: pointer;
}
.choice input:checked + span { background: var(--text); color: var(--bg); border-color: var(--text); }
.choice input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

.menu-user { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.menu-user .avatar { width: 44px; height: 44px; border-radius: 14px; background: var(--brand); color: #fff; display: grid; place-items: center; font-weight: 800; }
.menu-links { display: grid; gap: 4px; margin: 14px 0 0; }
.menu-links a, .menu-links button {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 13px 12px;
    border: 0;
    border-radius: 14px;
    background: transparent;
    text-decoration: none;
    font-weight: 600;
    text-align: left;
}
.menu-links a:hover, .menu-links button:hover { background: var(--surface-2); }
.segmented { display: flex; padding: 4px; border-radius: 14px; background: var(--surface-2); gap: 4px; }
.segmented button { flex: 1; height: 38px; border: 0; border-radius: 10px; background: transparent; font-weight: 600; font-size: .9rem; }
.segmented button[aria-pressed="true"] { background: var(--surface); box-shadow: 0 1px 3px rgba(0,0,0,.2); }

/* ------------------------------------------------------------------ forms */

.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field label, .label { font-size: .85rem; font-weight: 650; color: var(--muted); }
.input, select.input, textarea.input {
    width: 100%;
    min-height: 48px;
    padding: 12px 14px;
    border-radius: 14px;
    border: 1px solid var(--border);
    background: var(--surface-2);
    outline: none;
}
textarea.input { min-height: 110px; resize: vertical; }
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent); }
.hint { font-size: .82rem; color: var(--muted); margin: 6px 0 0; }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 48px;
    padding: 0 20px;
    border-radius: 14px;
    border: 1px solid var(--border);
    background: var(--surface-2);
    font-weight: 700;
    text-decoration: none;
    white-space: nowrap;
}
.btn-primary { border-color: transparent; background: var(--brand); color: #fff; }
.btn-small { min-height: 36px; padding: 0 12px; border-radius: 10px; font-size: .88rem; }
.btn-danger { color: var(--bad); }
.btn:disabled { opacity: .6; cursor: default; }

.alert { padding: 12px 14px; border-radius: 14px; background: var(--surface-2); border: 1px solid var(--border); margin: 0 0 16px; font-size: .92rem; }
.alert-error { border-color: color-mix(in srgb, var(--bad) 50%, transparent); color: var(--bad); }

/* ------------------------------------------------------------------- auth */

.auth-wrap { min-height: 100dvh; display: grid; place-items: center; padding: 24px 18px calc(24px + var(--safe-bottom)); }
.auth-card { width: min(420px, 100%); }
.auth-card .logo { font-size: 2rem; margin-bottom: 8px; }
.auth-card .logo-mark { width: 38px; height: 38px; border-radius: 12px; font-size: 1.3rem; }
.auth-card h1 { margin: 18px 0 4px; font: 800 1.6rem/1.2 var(--font-display); letter-spacing: -.02em; }
.auth-card > p { margin: 0 0 22px; color: var(--muted); }
.auth-card .btn { width: 100%; }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* ------------------------------------------------------------ page layout */

.page { width: min(960px, 100%); margin: 0 auto; padding: 18px 16px calc(40px + var(--safe-bottom)); }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin: 6px 0 18px; flex-wrap: wrap; }
.page-head h1 { margin: 0; font: 800 1.8rem/1.1 var(--font-display); letter-spacing: -.025em; }
.page-head p { margin: 4px 0 0; color: var(--muted); }

/* ------------------------------------------------------------------ saved */

.saved-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.saved-item {
    display: grid;
    grid-template-columns: 96px 1fr auto;
    gap: 12px;
    align-items: start;
    padding: 10px;
    border-radius: 18px;
    background: var(--surface);
    border: 1px solid var(--border);
    transition: opacity .2s;
}
.saved-item.is-unsaved { opacity: .5; }
.saved-thumb { position: relative; width: 96px; height: 96px; border-radius: 12px; overflow: hidden; background: var(--surface-2); }
.saved-thumb img { width: 100%; height: 100%; object-fit: cover; }
.saved-thumb .placeholder { font-size: 1.4rem; padding: 6px; }
.saved-item h2 { margin: 2px 0 6px; font-size: 1rem; line-height: 1.3; font-weight: 750; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; overflow: hidden; }
.saved-item h2 a { text-decoration: none; }
.saved-meta { font-size: .8rem; color: var(--muted); }
.saved-item .btn-save { width: 42px; height: 42px; border-radius: 12px; }
.saved-item .btn-save .icon { width: 20px; height: 20px; }
.empty { text-align: center; padding: 60px 20px; color: var(--muted); }
.empty h2 { color: var(--text); font: 800 1.4rem/1.2 var(--font-display); margin: 12px 0 6px; }

/* ------------------------------------------------------------------- seen */

.seen-list { display: grid; gap: 8px; }
.seen-item {
    display: block;
    padding: 12px 14px;
    border-radius: 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    text-decoration: none;
}
.seen-item h2 { margin: 0 0 4px; font-size: .95rem; line-height: 1.35; font-weight: 700; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; }
.seen-item:hover { background: var(--surface-2); }

/* ------------------------------------------------------------------ admin */

.tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 14px; scrollbar-width: none; }
.tabs a { flex: none; text-decoration: none; }
.tabs a[aria-current="page"] { background: var(--text); color: var(--bg); border-color: var(--text); }
.tabs .count { opacity: .6; font-weight: 600; }

.panel { background: var(--surface); border: 1px solid var(--border); border-radius: 18px; padding: 16px; margin-bottom: 14px; }
.panel h2 { margin: 0 0 12px; font-size: 1.05rem; }
.panel-grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.stats { display: flex; flex-wrap: wrap; gap: 18px; }
.stat b { display: block; font: 800 1.5rem/1.1 var(--font-display); }
.stat span { font-size: .8rem; color: var(--muted); }

.source-list { display: grid; gap: 8px; }
.source-row {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 4px 12px;
    padding: 12px 14px;
    border-radius: 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    text-decoration: none;
}
.source-row:hover { border-color: var(--muted); }
.source-row .name { font-weight: 700; display: flex; align-items: center; gap: 8px; min-width: 0; }
.source-row .meta { grid-column: 1 / -1; font-size: .8rem; color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px 12px; }
.status-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); flex: none; }
.status-dot.ok { background: var(--ok); }
.status-dot.warn { background: var(--warn); }
.status-dot.bad { background: var(--bad); }
.tag { display: inline-block; padding: 1px 8px; border-radius: 999px; background: var(--surface-2); font-size: .75rem; font-weight: 650; color: var(--muted); }

.form-grid { display: grid; gap: 0 12px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.actions-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.actions-row form { margin: 0; }

.coverage { display: grid; gap: 6px; }
.coverage-row { display: grid; grid-template-columns: 110px 1fr 70px; gap: 10px; align-items: center; font-size: .88rem; }
.bar { height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--brand); }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; font-size: .88rem; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.sample { display: grid; grid-template-columns: 64px 1fr; gap: 12px; padding: 10px 0; border-top: 1px solid var(--border); font-size: .88rem; }
.sample:first-of-type { border-top: 0; }
.sample img, .sample .noimg { width: 64px; height: 64px; object-fit: cover; border-radius: 10px; background: var(--surface-2); }
.sample .t { font-weight: 700; margin-bottom: 2px; }
.code { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .8rem; overflow-wrap: anywhere; background: var(--surface-2); padding: 8px 10px; border-radius: 10px; display: block; }
details summary { cursor: pointer; font-weight: 650; }

/* ------------------------------------------------------------------ toast */

.toast {
    position: fixed;
    left: 50%;
    bottom: calc(96px + var(--safe-bottom));
    z-index: 50;
    transform: translate(-50%, 20px);
    opacity: 0;
    padding: 10px 16px;
    border-radius: 999px;
    background: var(--text);
    color: var(--bg);
    font-weight: 650;
    font-size: .9rem;
    pointer-events: none;
    transition: opacity .2s, transform .2s;
    max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
