:root {
    --bg:              #F8F7F2;
    --text:            #111111;
    --text-secondary:  #555555;
    --border:          #e2e2e2;
    --accent:          #000000;
    --hover:           #f0efe9;
    --code-bg:         #f6f6f6;
    --card-bg:         #ffffff;
    --header-bg:       #F8F7F2;
    --search-bottom-bg: rgba(248, 247, 242, 0.92);
}

[data-theme="dark"] {
    --bg:              #262624;
    --text:            #e0e0e0;
    --text-secondary:  #a0a0a0;
    --border:          #333333;
    --accent:          #ffffff;
    --hover:           #2d2d2b;
    --code-bg:         rgba(255, 255, 255, 0.08);
    --card-bg:         #2d2d2b;
    --header-bg:       #262624;
    --search-bottom-bg: rgba(38, 38, 36, 0.92);
}

/* ── Base ─────────────────────────────────────────────── */
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    margin: 0;
    background: var(--bg);
    color: var(--text);
}

/* ── Header ───────────────────────────────────────────── */
header {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1.25rem;
    background: var(--header-bg);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}

.logo { height: 36px; cursor: pointer; flex-shrink: 0; }

.header-right { display: flex; align-items: center; gap: 0.5rem; margin-left: auto; }

.theme-toggle {
    background: none;
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    cursor: pointer;
    padding: 5px 7px;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 0;
    transition: background 0.15s;
}
.theme-toggle:hover { background: var(--hover); }

/* Landing state: hide header, show full-page hero */
body.body--landing header { display: none; }
body.body--landing #search-top-container { height: 100vh; align-items: flex-start; padding-top: 35vh; }
body.body--landing #search-top-container input[type="text"] { border-radius: 24px; }

/* ── Hero logo (landing state) ────────────────────────── */
.hero-logo {
    height: 36px;
    cursor: pointer;
    display: block;
    margin: 0 auto 2rem;
}

/* ── Content fade transition ──────────────────────────── */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

#main-content.fade-in {
    animation: fadeIn 0.22s ease both;
}

/* ── Empty state ──────────────────────────────────────── */
.empty-state {
    text-align: center;
    padding: 3rem 1rem 0.5rem;
    color: var(--text-secondary);
    font-size: 1.1rem;
    letter-spacing: 0.02em;
}

.empty-state__hint {
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.85rem;
    margin-top: 0.4rem;
    opacity: 0.75;
}

.empty-state__hint code {
    background: var(--hover);
    border-radius: 3px;
    padding: 1px 4px;
    font-size: 0.82rem;
}

/* ── Search – top hero ────────────────────────────────── */
#search-top-container {
    height: 80vh;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    padding: 0 1rem;
    transition: height 0.5s ease, opacity 0.5s ease;
}

#search-top-container.collapsed {
    height: 0;
    opacity: 0;
    pointer-events: none;
}

.search-box {
    text-align: center;
    width: 90%;
    max-width: 500px;
}

.search-box h1 {
    font-size: clamp(1.4rem, 5vw, 2.2rem);
    margin-bottom: 1.25rem;
    line-height: 1.2;
}

.search-input-wrap {
    position: relative;
    width: 100%;
}

.search-icon {
    position: absolute;
    left: 16px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-secondary);
    pointer-events: none;
}

.search-actions {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    align-items: center;
    gap: 2px;
}

.search-action-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 4px 6px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    transition: color 0.15s, background 0.15s;
}

.search-action-btn:hover {
    color: var(--text);
    background: var(--hover);
}

input[type="text"] {
    width: 100%;
    box-sizing: border-box;
    padding: 14px 22px 14px 44px;
    border-radius: 6px;
    border: 1px solid var(--border);
    font-size: 1rem;
    outline: none;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
    background: var(--card-bg);
    color: var(--text);
}

/* Bottom bar input needs extra right padding for the action buttons */
#search-bottom { padding-right: 110px; }

/* ── Search – bottom bar ──────────────────────────────── */
#search-bottom-container {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 10px 1rem;
    background: var(--search-bottom-bg);
    backdrop-filter: blur(10px);
    border-top: 1px solid var(--border);
}

.search-bar-inner {
    max-width: 800px;
    margin: 0 auto;
}

/* ── Main content ─────────────────────────────────────── */
.hidden { display: none !important; }

#main-content {
    max-width: 800px;
    margin: 20px auto 100px;
    padding: 0 1rem;
}

/* ── Post card (compact mode) ─────────────────────────── */
.post-card {
    background: var(--card-bg);
    padding: 1.25rem;
    border-radius: 6px;
    margin-bottom: 20px;
    border: 1px solid var(--border);
    display: flex;
    align-items: flex-start;
    gap: 1rem;
}

.post-card__body {
    flex: 1;
    min-width: 0;
    padding-bottom: 0.25rem;
}

.post-card__thumb {
    flex-shrink: 0;
    width: 140px;
    aspect-ratio: 16 / 9;
    object-fit: cover;
    border-radius: 8px;
    display: block;
    cursor: pointer;
    transition: opacity 0.2s, transform 0.2s;
}

.post-card__thumb:hover {
    opacity: 0.85;
    transform: scale(1.03);
}

.post-card__title {
    cursor: pointer;
    transition: opacity 0.2s;
}

.post-card__title:hover {
    opacity: 0.65;
}

/* ── Stats bar ────────────────────────────────────────── */
.stats-bar {
    display: flex;
    gap: 20px;
    margin-top: 20px;
    padding-top: 15px;
    border-top: 1px solid var(--border);
    align-items: center;
    flex-wrap: wrap;
}

.stat-item { cursor: pointer; display: flex; align-items: center; gap: 5px; color: var(--text-secondary); }
.stat-item:hover { color: var(--text); }

/* ── Toast ────────────────────────────────────────────── */
.toast {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--accent);
    color: var(--bg);
    padding: 8px 18px;
    border-radius: 20px;
    font-size: 0.875rem;
    z-index: 200;
    white-space: nowrap;
    animation: fade-toast 2s ease forwards;
    pointer-events: none;
}

@keyframes fade-toast {
    0%   { opacity: 0; transform: translateX(-50%) translateY(6px); }
    15%  { opacity: 1; transform: translateX(-50%) translateY(0); }
    75%  { opacity: 1; }
    100% { opacity: 0; }
}

/* ── Article preview ──────────────────────────────────── */
.preview-full { padding-bottom: 2rem; }

.post-date {
    display: block;
    font-size: 0.78rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.07em;
    margin-bottom: 0.5rem;
}

.post-title {
    font-size: clamp(1.8rem, 6vw, 2.8rem);
    font-weight: 800;
    line-height: 1.1;
    letter-spacing: -0.02em;
    margin: 0 0 1.5rem;
    overflow-wrap: break-word;
    word-break: break-word;
}

.post-video {
    width: 100%;
    aspect-ratio: 16 / 9;
    background: var(--hover);
    border: 1px solid var(--border);
    overflow: hidden;
    margin-bottom: 1.75rem;
    border-radius: 4px;
}

.post-video iframe {
    width: 100%;
    height: 100%;
    border: none;
    display: block;
}

.post-body {
    font-size: 1.1rem;
    line-height: 1.75;
    color: var(--text);
}

.post-body a {
    color: var(--accent);
    text-decoration: underline;
    text-decoration-color: var(--border);
    text-underline-offset: 3px;
    transition: text-decoration-color 0.2s;
}
.post-body a:hover { text-decoration-color: var(--accent); }

.post-body p  { margin-bottom: 1.1em; }
.post-body h2 { font-size: 1.4rem; font-weight: 700; margin: 2rem 0 0.75rem; }
.post-body h3 { font-size: 1.15rem; font-weight: 700; margin: 1.5rem 0 0.5rem; }
.post-body ul, .post-body ol { padding-left: 1.4em; margin-bottom: 1em; }
.post-body li { margin-bottom: 0.35em; }
.post-body strong { font-weight: 700; }
.post-body blockquote {
    border-left: 3px solid var(--accent);
    margin: 1.25rem 0;
    padding: 0.5rem 1rem;
    color: var(--text-secondary);
    font-style: italic;
}

/* ── Code blocks ──────────────────────────────────────── */
code, pre {
    background: var(--code-bg);
    color: var(--text);
    border-radius: 4px;
    font-family: "SF Mono", "Fira Code", Consolas, monospace;
    font-size: 0.875em;
}
code { padding: 2px 6px; }
pre  { padding: 1rem; overflow-x: auto; }

/* ── Keyword pills ────────────────────────────────────── */
.quick-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    margin-top: 14px;
}

/* ── Browse by Tag panel (landing only) ──────────────── */
.tag-browse {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    justify-content: center;
    margin-top: 18px;
    min-height: 0;
}

.tag-browse:empty {
    display: none;
}

.tag-browse__pill {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border);
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.78rem;
    cursor: pointer;
    transition: color 0.2s, border-color 0.2s;
    user-select: none;
}

.tag-browse__pill:hover {
    color: #16a34a;
    border-color: #16a34a;
}

[data-theme="dark"] .tag-browse__pill:hover {
    color: #4ade80;
    border-color: #4ade80;
}

.tag-browse__count {
    background: var(--hover);
    border-radius: 99px;
    padding: 0 5px;
    font-size: 0.72rem;
    color: var(--text-secondary);
    min-width: 16px;
    text-align: center;
}

.suggestion-chip {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border);
    padding: 5px 12px;
    border-radius: 20px;
    font-size: 0.8rem;
    cursor: pointer;
    transition: color 0.2s, border-color 0.2s;
    user-select: none;
}

.suggestion-chip:hover {
    color: var(--text);
    border-color: var(--text-secondary);
}

.tag-cloud {
    display: flex;
    flex-wrap: wrap;
    gap: 3px;
    margin: 15px 0;
}

.tag {
    background: var(--hover);
    color: var(--text);
    border: 1px solid var(--border);
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: background 0.2s, opacity 0.2s;
}

.tag:hover {
    background: var(--hover);
    opacity: 0.7;
    border-color: var(--border);
}

.tag--curated {
    border-color: #16a34a55;
    color: #16a34a;
}

[data-theme="dark"] .tag--curated {
    border-color: #4ade8088;
    color: #4ade80;
}

/* ── Mobile overrides (<600px) ────────────────────────── */
@media (max-width: 600px) {
    header { padding: 0.6rem 1rem; }

    .search-box { width: 95%; }

.post-card { padding: 1rem; flex-direction: column; }

    .post-card__thumb { width: 100%; aspect-ratio: 16 / 9; }

    .stats-bar { gap: 12px; }
}

/* ── Option-key editing ──────────────────────────────────────────────── */
.edit-btn {
    display: none;
    margin-top: 0.75rem;
    padding: 4px 10px;
    font-size: 0.78rem;
    background: var(--card-bg);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 4px;
    cursor: pointer;
}
.alt-held .edit-btn { display: inline-block; }
.delete-btn {
    display: none;
    margin-top: 0.75rem;
    margin-left: 0.4rem;
    padding: 4px 10px;
    font-size: 0.78rem;
    background: var(--card-bg);
    border: 1px solid rgba(220, 38, 38, 0.5);
    color: #dc2626;
    border-radius: 4px;
    cursor: pointer;
}
.alt-held .delete-btn { display: inline-block; }
.delete-btn:hover { background: rgba(220, 38, 38, 0.08); }

.edit-textarea {
    width: 100%;
    min-height: 420px;
    padding: 0.75rem;
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.9rem;
    line-height: 1.5;
    border: 1px solid var(--border, #ccc);
    border-radius: 4px;
    resize: vertical;
    box-sizing: border-box;
    background: var(--bg, #fff);
    color: var(--text, #111);
}
.edit-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.5rem;
}
.edit-actions button {
    padding: 6px 14px;
    font-size: 0.85rem;
    border-radius: 4px;
    cursor: pointer;
    border: 1px solid var(--border);
}
#saveEditBtn { background: #0070f3; color: #fff; border-color: #0070f3; }
#saveEditBtn:disabled { opacity: 0.6; cursor: not-allowed; }
#cancelEditBtn { background: transparent; }

/* ── Calendar Discovery ───────────────────────────────── */
/* top is set dynamically in toggleCalendar() via getBoundingClientRect.
   calFadeIn carries translateX(-50%) in both keyframes so it isn't
   overwritten by the shared fadeIn animation. */
@keyframes calFadeIn {
    from { opacity: 0; transform: translateX(-50%) translateY(6px); }
    to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

#calendar-overlay {
    position: fixed;
    left: 50%;
    transform: translateX(-50%);
    z-index: 200;
    background: #1e1e1c;
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: 12px;
    padding: 0.75rem 0.875rem 0.875rem;
    width: 90%;
    max-width: 320px;
    animation: calFadeIn 0.18s ease both;
    box-shadow: 0 8px 32px rgba(0,0,0,0.45);
}

.cal-header {
    text-align: center;
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: #c0c0bc;
    margin-bottom: 0.6rem;
}

.cal-weekdays {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 2px;
    margin-bottom: 3px;
}

.cal-weekday {
    text-align: center;
    font-size: 0.6rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: #555550;
    padding: 1px 0;
}

.cal-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 2px;
}

.cal-day {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 28px;
    border-radius: 5px;
    font-size: 0.72rem;
    color: #c0c0bc;
    cursor: pointer;
    position: relative;
    transition: background 0.12s ease, color 0.12s ease;
}

.cal-day:not(.cal-day--empty):hover {
    background: rgba(255,255,255,0.1);
    color: #ffffff;
}

.cal-day--empty {
    cursor: default;
    pointer-events: none;
}

.cal-day--today {
    border: 1.5px solid rgba(255,255,255,0.5);
    color: #ffffff;
    font-weight: 600;
}

.cal-day--has-post::after {
    content: '';
    position: absolute;
    bottom: 3px;
    width: 3px;
    height: 3px;
    border-radius: 50%;
    background: #8ba8f0;
}

@media (max-width: 400px) {
    #calendar-overlay { padding: 0.625rem; max-width: 280px; }
    .cal-day { height: 26px; font-size: 0.68rem; }
}
