* {
    padding: 0;
    margin: 0;
    border: none;
    box-sizing: border-box;
    font-family: Helvetica, Arial, sans-serif;
}

:root {
    --bg-primary:    #0d0d0d;
    --bg-card:       rgba(20, 20, 20, 0.92);
    --bg-overlay:    rgba(0, 0, 0, 0.75);
    --bg-pill:       rgba(255, 255, 255, 0.07);
    --bg-pill-on:    rgba(255, 255, 255, 0.18);
    --txt-primary:   #f0f0f0;
    --txt-secondary: #888;
    --txt-muted:     #555;
    --accent:        #4a9eff;
    --danger:        #c0392b;
    --border:        rgba(255, 255, 255, 0.07);
}

html, body {
    background-color: var(--bg-primary);
    color: var(--txt-primary);
    min-height: 100vh;
    width: 100%;
    overscroll-behavior: none;
}

/* ─── Header ─────────────────────────────────────────────── */

#header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
    background: rgba(13, 13, 13, 0.95);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border);
    padding: 10px 16px 8px;
}

#header-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}

#app-title {
    font-size: 1.1em;
    font-weight: 600;
    letter-spacing: 0.02em;
}

#btn-settings {
    background: var(--bg-pill);
    color: var(--txt-secondary);
    font-size: 1.1em;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
}

#btn-settings:hover {
    background: var(--bg-pill-on);
    color: var(--txt-primary);
}

/* ─── Filter Pills ────────────────────────────────────────── */

nav#topic-filters,
nav#lang-filters {
    display: flex;
    gap: 6px;
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
    padding-bottom: 2px;
}

nav#topic-filters::-webkit-scrollbar,
nav#lang-filters::-webkit-scrollbar {
    display: none;
}

nav#lang-filters {
    margin-top: 6px;
}

.filter-pill {
    flex-shrink: 0;
    background: var(--bg-pill);
    color: var(--txt-secondary);
    font-size: 0.72em;
    padding: 4px 10px;
    border-radius: 999px;
    cursor: pointer;
    border: 1px solid transparent;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
    user-select: none;
}

.filter-pill.active {
    background: var(--bg-pill-on);
    color: var(--txt-primary);
    border-color: rgba(255, 255, 255, 0.15);
}

.filter-pill:hover {
    color: var(--txt-primary);
}

/* ─── Feed ────────────────────────────────────────────────── */

#feed {
    max-width: 680px;
    margin: 0 auto;
    /* padding-top set dynamically by JS after measuring header */
    padding-right: 12px;
    padding-bottom: 80px;
    padding-left: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

#loading {
    text-align: center;
    color: var(--txt-muted);
    padding: 40px 0;
    font-size: 0.9em;
}

/* ─── Article Card ────────────────────────────────────────── */

article.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px 14px;
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-rows: auto auto auto;
    gap: 4px 10px;
    cursor: pointer;
    transition: background 0.12s;
    color: inherit;
}

article.card:hover {
    background: rgba(30, 30, 30, 0.95);
}

article.card .card-meta {
    grid-column: 1;
    grid-row: 1;
    font-size: 0.68em;
    color: var(--txt-muted);
    display: flex;
    align-items: center;
    gap: 6px;
}

article.card .card-meta .source {
    color: var(--txt-secondary);
    font-weight: 500;
}

article.card .card-meta .topic-badge {
    background: var(--bg-pill);
    padding: 1px 7px;
    border-radius: 999px;
    color: var(--txt-muted);
}

article.card .card-title {
    grid-column: 1;
    grid-row: 2;
    font-size: 0.95em;
    font-weight: 600;
    color: var(--txt-primary);
    line-height: 1.35;
}

article.card .card-summary {
    grid-column: 1;
    grid-row: 3;
    font-size: 0.78em;
    color: var(--txt-secondary);
    line-height: 1.45;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

article.card .card-actions {
    grid-column: 2;
    grid-row: 1 / 4;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    justify-content: space-between;
    gap: 8px;
    min-width: 28px;
}

article.card .card-time {
    font-size: 0.65em;
    color: var(--txt-muted);
    white-space: nowrap;
}

/* ─── Dismiss Button ──────────────────────────────────────── */

button.btn-dismiss {
    background: none;
    color: var(--txt-muted);
    font-size: 1em;
    width: 26px;
    height: 26px;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.12s, background 0.12s;
    flex-shrink: 0;
}

button.btn-dismiss:hover {
    color: var(--danger);
    background: rgba(192, 57, 43, 0.12);
}

/* ─── Load More ───────────────────────────────────────────── */

#btn-load-more {
    display: block;
    margin: 0 auto 32px;
    background: var(--bg-pill);
    color: var(--txt-secondary);
    font-size: 0.85em;
    padding: 10px 28px;
    border-radius: 999px;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

#btn-load-more:hover {
    background: var(--bg-pill-on);
    color: var(--txt-primary);
}

#btn-load-more[hidden] {
    display: none;
}

/* ─── Settings Panel ──────────────────────────────────────── */

#settings-panel {
    position: fixed;
    inset: 0;
    z-index: 200;
    background: var(--bg-overlay);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    animation: fade-in 0.15s ease;
}

#settings-panel[hidden] {
    display: none;
}

@keyframes fade-in {
    from { opacity: 0; }
    to   { opacity: 1; }
}

#settings-inner {
    background: #161616;
    border: 1px solid var(--border);
    border-radius: 14px;
    width: 100%;
    max-width: 560px;
    max-height: min(75vh, 640px);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: slide-up 0.2s ease;
}

@keyframes slide-up {
    from { transform: translateY(16px); opacity: 0; }
    to   { transform: translateY(0);    opacity: 1; }
}

#settings-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 18px 12px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

#settings-header h2 {
    font-size: 1em;
    font-weight: 600;
}

#btn-settings-close {
    background: var(--bg-pill);
    color: var(--txt-secondary);
    font-size: 0.85em;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
}

#btn-settings-close:hover {
    background: var(--bg-pill-on);
    color: var(--txt-primary);
}

#settings-body {
    overflow-y: auto;
    flex: 1;
    min-height: 0;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
    padding-bottom: 24px;
}

/* ─── Settings Sections ───────────────────────────────────── */

.section-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px 8px;
    font-size: 0.72em;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--txt-muted);
    border-bottom: 1px solid var(--border);
}

/* ─── Sources List ────────────────────────────────────────── */

#sources-list {
    list-style: none;
}

#sources-list li {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 18px;
    border-bottom: 1px solid var(--border);
    transition: background 0.1s;
}

#sources-list li:last-child {
    border-bottom: none;
}

#sources-list li:hover {
    background: rgba(255, 255, 255, 0.03);
}

.source-flag {
    font-size: 1.2em;
    flex-shrink: 0;
}

.source-info {
    flex: 1;
    min-width: 0;
}

.source-name {
    font-size: 0.88em;
    font-weight: 500;
    color: var(--txt-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.source-meta {
    font-size: 0.7em;
    color: var(--txt-muted);
    margin-top: 1px;
}

.source-meta span {
    display: inline-block;
    background: var(--bg-pill);
    padding: 1px 6px;
    border-radius: 999px;
    margin-right: 4px;
}

/* ─── Toggle Switch ───────────────────────────────────────── */

.toggle {
    position: relative;
    width: 38px;
    height: 22px;
    flex-shrink: 0;
}

.toggle input {
    opacity: 0;
    width: 0;
    height: 0;
    position: absolute;
}

.toggle-track {
    position: absolute;
    inset: 0;
    background: var(--txt-muted);
    border-radius: 999px;
    cursor: pointer;
    transition: background 0.2s;
}

.toggle input:checked + .toggle-track {
    background: var(--accent);
}

.toggle-thumb {
    position: absolute;
    top: 3px;
    left: 3px;
    width: 16px;
    height: 16px;
    background: #fff;
    border-radius: 50%;
    pointer-events: none;
    transition: transform 0.2s;
}

.toggle input:checked ~ .toggle-thumb {
    transform: translateX(16px);
}

/* ─── Keywords List ───────────────────────────────────────── */

#btn-add-keyword {
    background: var(--bg-pill);
    color: var(--txt-secondary);
    font-size: 0.8em;
    padding: 3px 10px;
    border-radius: 999px;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

#btn-add-keyword:hover {
    background: var(--bg-pill-on);
    color: var(--txt-primary);
}

#keywords-list {
    list-style: none;
}

#keywords-list li {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 18px;
    border-bottom: 1px solid var(--border);
}

#keywords-list li:last-child {
    border-bottom: none;
}

.keyword-text {
    font-size: 0.85em;
    color: var(--txt-secondary);
    font-family: monospace;
}

#keyword-input-row {
    display: flex;
    gap: 8px;
    padding: 10px 18px;
    border-bottom: 1px solid var(--border);
}

#keyword-input {
    flex: 1;
    background: var(--bg-pill);
    color: var(--txt-primary);
    font-size: 0.85em;
    padding: 6px 10px;
    border-radius: 6px;
    outline: none;
    border: 1px solid transparent;
    transition: border-color 0.15s;
}

#keyword-input:focus {
    border-color: var(--accent);
}

#btn-keyword-confirm {
    background: var(--accent);
    color: #fff;
    font-size: 0.82em;
    padding: 6px 14px;
    border-radius: 6px;
    cursor: pointer;
    transition: opacity 0.15s;
}

#btn-keyword-confirm:hover {
    opacity: 0.85;
}

/* ─── Reddit Card ─────────────────────────────────────────── */

article.reddit-card {
    grid-template-columns: auto 1fr auto;
}

article.reddit-card .card-meta {
    grid-column: 1 / 3;
}

article.reddit-card .card-title {
    grid-column: 1 / 3;
    min-width: 0;
    max-width: 90%;
    word-break: break-word;
}

article.reddit-card .card-actions {
    grid-row: 1 / 3;
}

article.reddit-card.has-thumb .card-meta {
    grid-column: 2;
}

article.reddit-card.has-thumb .card-title {
    grid-column: 2;
}

.reddit-thumb {
    grid-column: 1;
    grid-row: 1 / 3;
    width: 72px;
    height: 72px;
    object-fit: cover;
    border-radius: 6px;
    flex-shrink: 0;
    align-self: center;
}

.reddit-comments {
    font-size: 0.7em;
    color: var(--txt-muted);
    text-decoration: none;
    white-space: nowrap;
    transition: color 0.12s;
}

.reddit-comments:hover {
    color: var(--txt-secondary);
}

/* ─── Reader Drawer ───────────────────────────────────────── */

#reader-drawer {
    position: fixed;
    inset: 0;
    z-index: 200;
    background: var(--bg-overlay);
    display: flex;
    align-items: flex-end;
    animation: fade-in 0.15s ease;
}

#reader-drawer[hidden] {
    display: none;
}

#reader-inner {
    background: #111;
    border-top: 1px solid var(--border);
    border-radius: 14px 14px 0 0;
    width: 100%;
    max-width: 740px;
    height: 88vh;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: slide-up 0.25s ease;
}

#reader-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    gap: 12px;
}

#reader-source {
    font-size: 0.75em;
    color: var(--txt-muted);
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#reader-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

#reader-original {
    font-size: 0.75em;
    color: var(--accent);
    text-decoration: none;
    padding: 4px 10px;
    border-radius: 999px;
    background: rgba(74, 158, 255, 0.1);
    transition: background 0.15s;
    white-space: nowrap;
}

#reader-original:hover {
    background: rgba(74, 158, 255, 0.2);
}

#btn-reader-close {
    background: var(--bg-pill);
    color: var(--txt-secondary);
    font-size: 0.85em;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
    flex-shrink: 0;
}

#btn-reader-close:hover {
    background: var(--bg-pill-on);
    color: var(--txt-primary);
}

#reader-body {
    overflow-y: auto;
    flex: 1;
    min-height: 0;
    padding: 24px 24px 48px;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}

#reader-title {
    font-size: 1.35em;
    font-weight: 700;
    line-height: 1.3;
    color: var(--txt-primary);
    margin-bottom: 20px;
}

#reader-content {
    font-size: 0.95em;
    line-height: 1.7;
    color: #ccc;
}

#reader-content p {
    margin-bottom: 1em;
}

#reader-content h1,
#reader-content h2,
#reader-content h3,
#reader-content h4 {
    color: var(--txt-primary);
    font-weight: 600;
    line-height: 1.3;
    margin: 1.4em 0 0.5em;
}

#reader-content h1 { font-size: 1.2em; }
#reader-content h2 { font-size: 1.1em; }
#reader-content h3 { font-size: 1em; }
#reader-content h4 { font-size: 0.95em; }

#reader-content a {
    color: var(--accent);
    text-decoration: none;
}

#reader-content a:hover {
    text-decoration: underline;
}

#reader-content img {
    max-width: 100%;
    height: auto;
    border-radius: 6px;
    margin: 0.5em 0;
    display: block;
}

#reader-content ul,
#reader-content ol {
    padding-left: 1.4em;
    margin-bottom: 1em;
}

#reader-content li {
    margin-bottom: 0.3em;
}

#reader-content blockquote {
    border-left: 3px solid var(--border);
    padding-left: 1em;
    margin: 1em 0;
    color: var(--txt-secondary);
    font-style: italic;
}

#reader-loading {
    text-align: center;
    color: var(--txt-muted);
    padding: 60px 0;
    font-size: 0.9em;
}

#reader-error {
    text-align: center;
    color: var(--txt-muted);
    padding: 60px 20px;
    font-size: 0.9em;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

#reader-error a {
    color: var(--accent);
    font-size: 0.9em;
}

button.btn-read {
    background: none;
    color: var(--txt-muted);
    font-size: 1em;
    width: 26px;
    height: 26px;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.12s, background 0.12s;
    flex-shrink: 0;
}

button.btn-read:hover {
    color: var(--accent);
    background: rgba(74, 158, 255, 0.1);
}

@media (max-width: 480px) {
    #reader-body {
        padding: 16px 16px 40px;
    }

    #reader-title {
        font-size: 1.15em;
    }
}

/* ─── Token Prompt ────────────────────────────────────────── */

#token-prompt {
    position: fixed;
    inset: 0;
    z-index: 300;
    background: var(--bg-overlay);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    animation: fade-in 0.15s ease;
}

#token-prompt-box {
    background: #161616;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 24px 20px 20px;
    width: 100%;
    max-width: 320px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    animation: slide-up 0.2s ease;
}

#token-prompt-box p {
    font-size: 0.88em;
    color: var(--txt-secondary);
    text-align: center;
}

#token-input {
    background: var(--bg-pill);
    color: var(--txt-primary);
    font-size: 0.9em;
    padding: 8px 12px;
    border-radius: 8px;
    outline: none;
    border: 1px solid transparent;
    transition: border-color 0.15s;
    width: 100%;
}

#token-input:focus {
    border-color: var(--accent);
}

#token-prompt-actions {
    display: flex;
    gap: 8px;
}

#btn-token-cancel {
    flex: 1;
    background: var(--bg-pill);
    color: var(--txt-secondary);
    font-size: 0.85em;
    padding: 8px;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

#btn-token-cancel:hover {
    background: var(--bg-pill-on);
    color: var(--txt-primary);
}

#btn-token-confirm {
    flex: 2;
    background: var(--accent);
    color: #fff;
    font-size: 0.85em;
    padding: 8px;
    border-radius: 8px;
    cursor: pointer;
    transition: opacity 0.15s;
}

#btn-token-confirm:hover {
    opacity: 0.85;
}

#token-error {
    font-size: 0.78em;
    color: var(--danger);
    text-align: center;
    margin-top: -4px;
}

#token-error[hidden] {
    display: none;
}

/* ─── Responsive ──────────────────────────────────────────── */

@media (max-width: 480px) {
    article.card .card-title {
        font-size: 0.9em;
    }
}
