:root {
    --bg: #f6f7f9;
    --surface: #ffffff;
    --surface-hover: #f0f3f7;
    --text: #1b1f24;
    --muted: #667085;
    --border: #e3e6eb;
    --accent: #2563eb;
    --accent-text: #ffffff;
    --danger: #c0392b;
    --ok-bg: #e8f6ee;
    --ok-text: #1e6b3d;
    --error-bg: #fdecec;
    --error-text: #a12a2a;
    --read: #8a94a3;
    --shadow: 0 1px 2px rgba(16, 24, 40, .06);
    color-scheme: light;
}

:root[data-theme="dark"] {
    --bg: #111418;
    --surface: #1a1e24;
    --surface-hover: #222831;
    --text: #e6e9ee;
    --muted: #8d97a5;
    --border: #2b313a;
    --accent: #5b8def;
    --accent-text: #0b1020;
    --danger: #e5675a;
    --ok-bg: #16301f;
    --ok-text: #8fd9a8;
    --error-bg: #3a1a1a;
    --error-text: #f2a7a7;
    --read: #6b7482;
    --shadow: none;
    color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
    :root[data-theme="system"] {
        --bg: #111418;
        --surface: #1a1e24;
        --surface-hover: #222831;
        --text: #e6e9ee;
        --muted: #8d97a5;
        --border: #2b313a;
        --accent: #5b8def;
        --accent-text: #0b1020;
        --danger: #e5675a;
        --ok-bg: #16301f;
        --ok-text: #8fd9a8;
        --error-bg: #3a1a1a;
        --error-text: #f2a7a7;
        --read: #6b7482;
        --shadow: none;
        color-scheme: dark;
    }
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

a { color: var(--accent); }

main {
    max-width: 920px;
    margin: 0 auto;
    padding: 24px 16px 64px;
}

h1 { font-size: 1.5rem; margin: 0; }
h2 { font-size: 1.1rem; margin: 0 0 12px; }

.muted { color: var(--muted); font-weight: normal; }
.small { font-size: .85rem; }

/* Top bar */
.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 12px 24px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}
.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 700; color: var(--text); text-decoration: none; font-size: 1.05rem; }
.brand img { display: block; border-radius: 6px; }
.topbar nav { display: flex; gap: 4px; }
.topbar nav a {
    color: var(--muted);
    text-decoration: none;
    padding: 6px 12px;
    border-radius: 8px;
}
.topbar nav a:hover { background: var(--surface-hover); color: var(--text); }
.topbar nav a.active { color: var(--text); background: var(--surface-hover); font-weight: 600; }

.logout-form { display: inline; margin: 0; }
.logout-form button {
    padding: 6px 12px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--muted);
    font: inherit;
    cursor: pointer;
}
.logout-form button:hover { background: var(--surface-hover); color: var(--text); }

/* Login */
.login-card {
    max-width: 380px;
    margin: 8vh auto 0;
}
.login-card h1 { margin-bottom: 6px; }
.login-card form { display: flex; flex-direction: column; gap: 12px; margin-top: 16px; }
.login-card input[type="password"] { width: 100%; }
.login-card .btn { justify-content: center; }
.password-form { display: flex; gap: 8px; flex-wrap: wrap; }
.password-form input { flex: 1 1 200px; }

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
}
.btn:hover:not(:disabled) { background: var(--surface-hover); }
.btn:disabled { opacity: .5; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn-primary:hover:not(:disabled) { background: var(--accent); filter: brightness(1.08); }
.btn-danger { color: var(--danger); }
.btn.is-busy::before {
    content: "";
    width: 12px;
    height: 12px;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Toolbar */
.toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 16px;
}
.toolbar-left, .toolbar-right { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.status { color: var(--muted); font-size: .9rem; }
.toggle { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); cursor: pointer; user-select: none; }

/* Filter bar */
.filterbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
}
.search {
    position: relative;
    flex: 1 1 280px;
    max-width: 480px;
    color: var(--muted);
}
.search svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); pointer-events: none; }
.search input {
    width: 100%;
    padding: 8px 36px 8px 34px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
    font: inherit;
}
.search input::-webkit-search-cancel-button { cursor: pointer; }
.search-hint {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    padding: 0 6px;
    border: 1px solid var(--border);
    border-radius: 4px;
    font: .75rem/1.5 ui-monospace, monospace;
    pointer-events: none;
}
.search input:focus ~ .search-hint,
.search input:not(:placeholder-shown) ~ .search-hint { display: none; }
#feed-filter {
    flex: 0 1 240px;
    min-width: 0;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
    font: inherit;
}
#feed-filter:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

/* Notices */
.notice { padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; }
.notice ul { margin: 6px 0 0; padding-left: 20px; }
.notice-ok { background: var(--ok-bg); color: var(--ok-text); }
.notice-error { background: var(--error-bg); color: var(--error-text); }

.empty { text-align: center; color: var(--muted); padding: 48px 0; }
.empty .btn { margin-top: 8px; }

/* Article list */
.day-heading {
    font-size: .8rem;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--muted);
    margin: 24px 0 8px;
}
.day-heading:first-child { margin-top: 0; }
.day-group {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: var(--shadow);
}

.item {
    display: flex;
    gap: 16px;
    padding: 16px;
    color: inherit;
    text-decoration: none;
    border-top: 1px solid var(--border);
    transition: background .1s;
}
.item:first-child { border-top: 0; }
.item:hover { background: var(--surface-hover); }
.item:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

.item-image {
    flex: 0 0 160px;
    height: 100px;
    border-radius: 8px;
    overflow: hidden;
    background: var(--surface-hover);
}
.item-image img { width: 100%; height: 100%; object-fit: cover; display: block; }

.item-body { flex: 1; min-width: 0; }
.item-meta { display: flex; gap: 8px; align-items: center; font-size: .8rem; color: var(--muted); margin-bottom: 2px; }
.item-feed { font-weight: 600; color: var(--accent); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-date { white-space: nowrap; }
.item-date::before { content: "·"; margin-right: 8px; }
.item-title { font-size: 1.05rem; line-height: 1.35; margin: 0 0 4px; }
.item-excerpt {
    margin: 0;
    color: var(--muted);
    font-size: .92rem;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.item:not(.is-read) .item-title::before {
    content: "";
    display: inline-block;
    width: 8px;
    height: 8px;
    margin-right: 8px;
    border-radius: 50%;
    background: var(--accent);
    vertical-align: middle;
    position: relative;
    top: -1px;
}
.item.is-read .item-title { color: var(--read); font-weight: 500; }
.item.is-read .item-image { opacity: .55; }
.item.is-read .item-feed { color: var(--read); }

/* View switcher */
.view-switch {
    display: inline-flex;
    padding: 2px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
}
.view-switch button {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--muted);
    font: inherit;
    font-size: .9rem;
    cursor: pointer;
}
.view-switch button:hover { color: var(--text); }
.view-switch button[aria-checked="true"] { background: var(--surface-hover); color: var(--text); font-weight: 600; }
.view-switch button:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

/* List view: compact single-line rows, no image or excerpt */
body[data-view="list"] .item { padding: 9px 16px; gap: 12px; align-items: center; }
body[data-view="list"] .item-image,
body[data-view="list"] .item-excerpt { display: none; }
body[data-view="list"] .item-body { display: flex; align-items: baseline; gap: 16px; }
body[data-view="list"] .item-title {
    order: 1;
    flex: 1;
    min-width: 0;
    margin: 0;
    font-size: .95rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
body[data-view="list"] .item-meta { order: 2; flex: 0 0 auto; max-width: 40%; margin: 0; }

/* Blocks view: responsive card grid, column count follows the screen width */
body.page-home[data-view="blocks"] main { max-width: 2400px; }
body[data-view="blocks"] .day-group {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 16px;
    background: none;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    overflow: visible;
}
body[data-view="blocks"] .item {
    flex-direction: column;
    gap: 0;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface);
    box-shadow: var(--shadow);
    overflow: hidden;
}
body[data-view="blocks"] .item:hover { background: var(--surface-hover); }
body[data-view="blocks"] .item:first-child { border-top: 1px solid var(--border); }
body[data-view="blocks"] .item-image {
    flex: none;
    height: auto;
    aspect-ratio: 16 / 9;
    border-radius: 0;
}
body[data-view="blocks"] .item-body { padding: 12px 14px 14px; }

/* Settings */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 20px;
    margin-top: 20px;
    box-shadow: var(--shadow);
}
.theme-form { display: flex; gap: 20px; flex-wrap: wrap; }
.general-form { display: flex; flex-direction: column; gap: 14px; max-width: 480px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field > span { font-weight: 600; font-size: .9rem; }
.field select {
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg);
    color: var(--text);
    font: inherit;
}
.card h3 { font-size: .95rem; margin: 18px 0 8px; }

.opml-actions { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; justify-content: space-between; }
.import-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.import-form input[type="file"] { color: var(--muted); font: inherit; font-size: .9rem; max-width: 100%; }
.import-form input[type="file"]::file-selector-button {
    margin-right: 10px;
    padding: 7px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface-hover);
    color: var(--text);
    font: inherit;
    cursor: pointer;
}
.btn[aria-disabled="true"] { opacity: .5; pointer-events: none; }
.radio { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }

input[type="url"], input[type="text"], input[type="password"] {
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg);
    color: var(--text);
    font: inherit;
}
input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.add-form { display: flex; gap: 8px; flex-wrap: wrap; }
.add-form input[type="url"] { flex: 2 1 280px; }
.add-form input[type="text"] { flex: 1 1 160px; }

.feed-list { list-style: none; margin: 0; padding: 0; }
.feed-list li {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 0;
    border-top: 1px solid var(--border);
}
.feed-list li:first-child { border-top: 0; }
.feed-info { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1; }
.feed-info .muted { font-size: .85rem; }
.rename-form input {
    width: 100%;
    font-weight: 600;
    background: transparent;
    border-color: transparent;
    padding: 2px 6px;
    margin-left: -6px;
}
.rename-form input:hover { border-color: var(--border); }
.feed-url { font-size: .85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.feed-error { color: var(--error-text); font-size: .85rem; }

@media (max-width: 640px) {
    .topbar { padding: 10px 16px; }
    body[data-view="row"] .item { flex-direction: column; gap: 10px; }
    body[data-view="row"] .item-image { flex-basis: auto; height: 180px; }
    body[data-view="list"] .item-body { flex-direction: column; gap: 0; }
    body[data-view="list"] .item-title { order: 2; white-space: normal; }
    body[data-view="list"] .item-meta { order: 1; max-width: 100%; }
    .view-switch { width: 100%; }
    .search { flex-basis: 100%; max-width: none; }
    .search-hint { display: none; }
    #feed-filter { flex: 1 1 auto; }
    .view-switch button { flex: 1; justify-content: center; }
    .toolbar-right { width: 100%; }
    .toolbar-right .btn { flex: 1; justify-content: center; }
}
