:root {
    --bg: #f6f6ef;
    --bg-card: #ffffff;
    --bg-card-hover: #fdf2f2;
    --bg-header: #fafafa;
    --bg-period: #f5f5f5;
    --bg-period-hover: #ececec;
    --bg-btn: #e0e0e0;
    --bg-btn-hover: #d0d0d0;
    --text: #333;
    --text-heading: #2c3e50;
    --text-secondary: #666;
    --text-muted: #888;
    --text-faint: #999;
    --text-link: #1a1a1a;
    --text-btn: #555;
    --text-period: #444;
    --text-domain: #aaa;
    --text-visited: #8e44ad;
    --text-permalink: #ccc;
    --border: #ddd;
    --border-light: #eee;
    --border-cell: #f2f2f2;
    --border-header: #e0e0e0;
    --accent: #882222;
    --accent-hover: #6b1a1a;
    --tl-tick: #d0d0d0;
    --tl-tick-year: #aaa;
    --tl-year-text: #999;
    --tooltip-bg: rgba(50,50,50,0.9);
    --shadow: rgba(0,0,0,0.2);
    --shadow-hover: rgba(0,0,0,0.25);
    --bg-fab-light: rgba(0, 0, 0, 0.06);
}
[data-theme="dark"] {
    --bg: #1a1a1a;
    --bg-card: #252525;
    --bg-card-hover: #2d2020;
    --bg-header: #2a2a2a;
    --bg-period: #2a2a2a;
    --bg-period-hover: #333;
    --bg-btn: #3a3a3a;
    --bg-btn-hover: #4a4a4a;
    --text: #e0e0e0;
    --text-heading: #f0f0f0;
    --text-secondary: #aaa;
    --text-muted: #888;
    --text-faint: #777;
    --text-link: #f0f0f0;
    --text-btn: #ddd;
    --text-period: #ccc;
    --text-domain: #777;
    --text-visited: #b86fdb;
    --text-permalink: #555;
    --border: #3a3a3a;
    --border-light: #333;
    --border-cell: #2d2d2d;
    --border-header: #3a3a3a;
    --accent: #bb4444;
    --accent-hover: #cc5555;
    --tl-tick: #555;
    --tl-tick-year: #777;
    --tl-year-text: #888;
    --tooltip-bg: rgba(30,30,30,0.95);
    --shadow: rgba(0,0,0,0.4);
    --shadow-hover: rgba(0,0,0,0.5);
    --bg-fab-light: rgba(255, 255, 255, 0.08);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 40px 80px 16px;
    color: var(--text);
    line-height: 1.4;
    background-color: var(--bg);
}

/* Title bar */
.title-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px 16px;
    margin-bottom: 8px;
    background: var(--bg-header);
    border-bottom: 1px solid var(--border-header);
}
.title-bar h1 {
    font-size: 20px;
    color: var(--text-heading);
    font-weight: 700;
    margin: 0;
}

/* Header */
.header {
    text-align: center;
    margin-bottom: 28px;
    padding-bottom: 20px;
    border-bottom: 2px solid var(--border-header);
}
.home-link {
    color: inherit;
    text-decoration: none;
}
.home-link:hover {
    color: var(--accent);
}
.title-sep {
    font-weight: 400;
    color: var(--text);
    font-size: 14px;
}
.title-subtitle {
    font-weight: 400;
    color: var(--text);
    font-size: 14px;
}
.theme-toggle {
    position: fixed;
    top: 12px;
    right: 12px;
    z-index: 1000;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    cursor: pointer;
    padding: 4px 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    transition: all 0.15s;
}
.theme-toggle:hover {
    border-color: var(--accent);
    color: var(--accent);
}
.theme-toggle svg {
    width: 16px;
    height: 16px;
}
[data-theme="light"] .icon-moon,
[data-theme="dark"] .icon-sun {
    display: none;
}
[data-theme="light"] .icon-sun,
[data-theme="dark"] .icon-moon {
    display: block;
}
.nav-link {
    font-size: 13px;
    font-weight: 500;
    color: var(--accent);
    text-decoration: none;
    padding: 5px 14px;
    background: var(--bg-btn);
    border-radius: 6px;
}
.nav-link:hover {
    background: var(--bg-btn-hover);
    text-decoration: none;
}
.last-updated {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 8px;
}

/* Controls */
.controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 24px;
    flex-wrap: wrap;
}
.control-group {
    display: flex;
    align-items: center;
    gap: 6px;
}
.control-group label {
    font-size: 13px;
    color: var(--text-secondary);
    font-weight: 500;
    margin-right: 2px;
}
.control-group button {
    background-color: var(--bg-btn);
    color: var(--text-btn);
    border: none;
    border-radius: 16px;
    padding: 5px 14px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.15s ease;
}
.control-group button:hover {
    background-color: var(--bg-btn-hover);
}
.control-group button.active {
    background-color: var(--accent);
    color: white;
}

/* Year sections */
.year-section {
    margin-bottom: 16px;
}
.year-section > details {
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg-card);
}
.year-section > details > summary {
    background: transparent;
    padding: 10px 14px;
    font-weight: 600;
    font-size: 15px;
    cursor: pointer;
    list-style: none;
    display: flex;
    align-items: center;
    gap: 8px;
    user-select: none;
    touch-action: manipulation;
}
.year-section > details > summary::-webkit-details-marker { display: none; }
.year-section > details > summary .year-label {
    background: var(--accent);
    color: white;
    padding: 4px 12px;
    border-radius: 4px;
    display: inline-block;
}
.year-section > details > summary::before {
    content: '\25B6';
    font-size: 10px;
    color: var(--accent);
    transition: transform 0.2s ease;
    display: inline-block;
}
.year-section > details[open] > summary::before {
    transform: rotate(90deg);
}
.year-section > details > summary:hover .year-label {
    background: var(--accent-hover);
}

/* Period sections */
.period-section {
    margin: 8px 10px;
}
.period-section > details {
    border: 1px solid var(--border-light);
    border-radius: 5px;
}
.period-section > details > summary {
    background: var(--bg-period);
    padding: 8px 12px;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-period);
    cursor: pointer;
    list-style: none;
    display: flex;
    align-items: center;
    gap: 8px;
    user-select: none;
    touch-action: manipulation;
}
.period-section > details > summary::-webkit-details-marker { display: none; }
.period-section > details > summary::before {
    content: '\25B6';
    font-size: 9px;
    color: var(--accent);
    transition: transform 0.2s ease;
    display: inline-block;
}
.period-section > details[open] > summary::before {
    transform: rotate(90deg);
}
.period-section > details > summary:hover {
    background: var(--bg-period-hover);
}

/* Tables */
table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}
thead th {
    background: var(--bg-header);
    padding: 6px 8px;
    text-align: left;
    font-weight: 500;
    color: var(--text-muted);
    font-size: 11px;
    letter-spacing: 0.3px;
    border-bottom: 1px solid var(--border-light);
    white-space: nowrap;
}
thead th .open-all {
    font-size: 10px;
    color: var(--text-faint);
    text-transform: none;
    letter-spacing: 0;
    cursor: pointer;
    margin-left: 4px;
    font-weight: normal;
}
thead th .open-all:hover {
    color: var(--accent);
    text-decoration: underline;
}
thead th.sortable {
    cursor: pointer;
    user-select: none;
}
thead th.sortable:hover {
    color: var(--accent);
}
thead th.sort-active {
    color: var(--accent);
}
thead th .th-label {
    cursor: pointer;
}
tbody td {
    padding: 5px 8px;
    border-bottom: 1px solid var(--border-cell);
    vertical-align: top;
}
tbody tr:last-child td {
    border-bottom: none;
}
tbody tr:hover {
    background: var(--bg-card-hover);
}
.col-score {
    width: 55px;
    text-align: right;
    font-variant-numeric: tabular-nums;
    color: var(--text-secondary);
    font-weight: 500;
}
.col-comments {
    width: 70px;
    font-variant-numeric: tabular-nums;
}
.col-comments a {
    color: var(--accent);
    text-decoration: none;
}
.col-comments a:hover {
    text-decoration: underline;
}
.col-title a {
    color: var(--text-link);
    text-decoration: none;
}
.col-title a:hover {
    text-decoration: underline;
}
.col-title a.visited {
    color: var(--text-visited);
}
.col-archived a.visited {
    color: var(--text-visited);
}
.col-comments a.visited {
    color: var(--text-visited);
}
.col-archived {
    width: 65px;
}
.col-archived a {
    color: var(--text-faint);
    text-decoration: none;
    font-size: 12px;
}
.col-archived a:hover {
    color: var(--accent);
}
.col-user {
    width: 90px;
    font-size: 12px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 90px;
}
.col-user a {
    color: var(--text-secondary);
    text-decoration: none;
}
.col-user a:hover {
    color: var(--accent);
}
.col-date {
    width: 80px;
    font-size: 12px;
    color: var(--text-muted);
    white-space: nowrap;
}
.col-title .domain {
    color: var(--text-domain);
    font-size: 11px;
    margin-left: 4px;
}

/* Tag Filters */
.tag-filters {
    padding: 12px 0;
    margin-top: 8px;
}
.tag-search-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}
.tag-search-bar label {
    font-size: 13px;
    color: var(--text-secondary);
    font-weight: 500;
    flex-shrink: 0;
}
.tag-search-input {
    flex: 1;
    padding: 6px 10px;
    font-size: 13px;
    font-family: inherit;
    color: var(--text);
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 6px;
    outline: none;
    transition: border-color 0.15s;
}
.tag-search-input:focus {
    border-color: var(--accent);
}
.tag-search-input::placeholder {
    color: var(--text-faint);
    font-size: 12px;
}
.tag-go-btn {
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 6px;
    padding: 6px 14px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s;
    flex-shrink: 0;
}
.tag-go-btn:hover {
    background: var(--accent-hover);
}
.tag-error {
    font-size: 12px;
    color: var(--accent);
    flex-shrink: 0;
}
.tag-suggestions {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-wrap: wrap;
}
.tag-filter-btn {
    background: var(--bg-btn);
    color: var(--text-btn);
    border: none;
    border-radius: 16px;
    padding: 4px 10px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 500;
    transition: all 0.15s ease;
    white-space: nowrap;
}
.tag-filter-btn:hover {
    background: var(--bg-btn-hover);
}
.tag-filter-btn .tag-count {
    font-size: 10px;
    opacity: 0.7;
    margin-left: 2px;
}
.tag-filter-btn.clear-tags {
    background: transparent;
    color: var(--text-muted);
    text-decoration: underline;
    padding: 4px 6px;
    font-size: 11px;
}
.tag-filter-btn.clear-tags:hover {
    color: var(--accent);
}

/* Tags */
.tag-pill {
    display: inline-block;
    background: var(--bg-btn);
    color: var(--text-secondary);
    padding: 1px 6px;
    border-radius: 10px;
    font-size: 10px;
    margin-right: 2px;
    text-decoration: none;
    white-space: nowrap;
}
.tag-pill:hover {
    background: var(--accent);
    color: white;
}

/* Timeline sidebar */
#timeline {
    position: fixed;
    right: 18px;
    top: 50%;
    transform: translateY(-50%);
    z-index: 999;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    max-height: 85vh;
    overflow-y: auto;
    overflow-x: visible;
    padding: 4px 0;
    scrollbar-width: none;
}
#timeline::-webkit-scrollbar {
    display: none;
}
.tl-item {
    position: relative;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding: 1px 0;
}
#timeline.tl-yearly .tl-item {
    padding: 4px 0;
}
#timeline.tl-yearly .tl-year-text {
    font-size: 11px;
}
#timeline.tl-yearly .tl-tick {
    width: 16px;
    height: 3px;
}
.tl-tick {
    width: 12px;
    height: 2px;
    border-radius: 1px;
    background: var(--tl-tick);
    transition: all 0.15s ease;
    flex-shrink: 0;
}
.tl-item.tl-year-start .tl-tick {
    width: 18px;
    height: 2px;
    background: var(--tl-tick-year);
}
.tl-item:hover .tl-tick {
    background: var(--accent);
    width: 20px;
    height: 3px;
}
.tl-item.active .tl-tick {
    background: var(--accent);
    width: 18px;
    height: 3px;
}
.tl-year-text {
    font-size: 10px;
    font-weight: 600;
    color: var(--tl-year-text);
    white-space: nowrap;
    user-select: none;
    margin-right: 4px;
}
.tl-item.active .tl-year-text {
    color: var(--accent);
}
#tl-tooltip {
    position: fixed;
    background: var(--tooltip-bg);
    color: white;
    padding: 3px 8px;
    border-radius: 3px;
    font-size: 11px;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.12s ease;
    user-select: none;
    backdrop-filter: blur(4px);
    z-index: 1000;
}
#tl-tooltip.visible {
    opacity: 1;
}
#tl-tooltip::after {
    content: '';
    position: absolute;
    right: -4px;
    top: 50%;
    transform: translateY(-50%);
    border-left: 4px solid var(--tooltip-bg);
    border-top: 4px solid transparent;
    border-bottom: 4px solid transparent;
}

/* FAB - Floating Action Button */
.fab {
    position: fixed;
    bottom: 24px;
    right: 56px;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--accent);
    color: white;
    border: none;
    cursor: pointer;
    box-shadow: 0 2px 8px var(--shadow);
    font-size: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    z-index: 1000;
}
.back-to-top {
    position: fixed;
    bottom: 24px;
    right: 112px;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--bg-fab-light);
    color: var(--text-secondary);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s ease;
    z-index: 1000;
}
.back-to-top:hover {
    color: var(--accent);
}
.back-to-top svg {
    width: 24px;
    height: 24px;
    fill: currentColor;
}
.fab:hover {
    background: var(--accent-hover);
    box-shadow: 0 4px 12px var(--shadow-hover);
    transform: scale(1.05);
}
.fab svg {
    width: 22px;
    height: 22px;
    fill: white;
}

/* Tooltip */
.tooltip {
    position: fixed;
    background: var(--tooltip-bg);
    color: white;
    padding: 6px 10px;
    border-radius: 4px;
    font-size: 12px;
    pointer-events: none;
    z-index: 1001;
    opacity: 0;
    transition: opacity 0.2s;
}
.tooltip.show { opacity: 1; }

/* Permalink */
.permalink {
    opacity: 0;
    transition: opacity 0.15s;
    font-size: 11px;
    color: var(--text-permalink);
    cursor: pointer;
    margin-left: 6px;
}
summary:hover .permalink {
    opacity: 1;
}
.permalink:hover {
    color: var(--accent);
}

/* Loading indicator */
#loading {
    text-align: center;
    padding: 80px 20px;
    color: var(--text-muted);
    font-size: 16px;
}

/* "When" column (today.html only) */
.col-when {
    width: 65px;
    font-size: 12px;
    color: var(--text-muted);
    white-space: nowrap;
}

/* Mobile-actions (hidden on desktop) */
.mobile-actions {
    display: none;
}

/* Responsive — Mobile Card Layout */
@media (max-width: 768px) {

    .title-bar { position: sticky; top: 0; z-index: 100; background: var(--bg-header); }
    .controls { gap: 12px; }
    body { padding: 0 12px 80px 12px; }

    /* --- Hide timeline on mobile --- */
    #timeline { display: none !important; }
    #tl-tooltip { display: none !important; }

    /* --- FAB & back-to-top --- */
    .fab { bottom: 16px; right: 16px; width: 44px; height: 44px; }
    .back-to-top { bottom: 16px; right: 68px; width: 44px; height: 44px; }

    /* --- Mobile-actions pill buttons --- */
    .mobile-actions {
        display: flex;
        gap: 8px;
        padding: 8px 4px;
        flex-wrap: wrap;
    }
    .mobile-actions button {
        background: var(--bg-btn);
        color: var(--text-btn);
        border: none;
        border-radius: 16px;
        padding: 5px 14px;
        font-size: 12px;
        font-weight: 500;
        cursor: pointer;
        transition: all 0.15s ease;
    }
    .mobile-actions button:hover,
    .mobile-actions button:active {
        background: var(--bg-btn-hover);
    }

    /* --- Hide table header --- */
    thead { display: none; }

    /* --- Table to block layout --- */
    table { display: block; font-size: 14px; }
    tbody { display: block; }

    /* --- Card rows --- */
    .post-row {
        display: flex;
        flex-wrap: wrap;
        align-items: baseline;
        padding: 12px 14px;
        margin: 8px 0;
        background: var(--bg-card);
        border: 1px solid var(--border-light);
        border-radius: 8px;
        box-shadow: 0 1px 3px rgba(0,0,0,0.04);
    }
    .post-row:hover {
        background: var(--bg-card-hover);
    }

    /* Reset td defaults for card */
    .post-row td {
        display: inline;
        padding: 0;
        border: none;
        width: auto;
        max-width: none;
        vertical-align: baseline;
    }

    /* --- Line 1: Title (full width) --- */
    .post-row .col-title {
        display: block;
        width: 100%;
        order: 1;
        font-size: 15px;
        line-height: 1.4;
        margin-bottom: 6px;
    }
    .post-row .col-title a {
        font-weight: 500;
    }
    .post-row .col-title .domain {
        font-size: 12px;
    }

    /* --- Line 2: Score pts · Comments · Date --- */
    .post-row .col-score {
        order: 2;
        font-size: 12px;
        color: var(--text-muted);
        text-align: left;
        width: auto;
        font-weight: 500;
    }
    .post-row .col-score::after {
        content: ' pts \00b7 ';
        font-weight: 400;
        color: var(--text-muted);
    }

    .post-row .col-comments {
        order: 3;
        font-size: 12px;
        width: auto;
    }
    .post-row .col-comments a {
        color: var(--accent);
        text-decoration: none;
    }
    .post-row .col-comments::after {
        content: ' comments \00b7 ';
        color: var(--text-muted);
        font-size: 12px;
    }

    .post-row .col-date {
        order: 4;
        font-size: 12px;
        color: var(--text-muted);
        width: auto;
        white-space: nowrap;
    }
    .post-row .col-date::after {
        content: ' \00b7 ';
        color: var(--text-muted);
    }

    /* --- Line 2 continued: "when" column (today.html) --- */
    .post-row .col-when {
        order: 5;
        font-size: 12px;
        color: var(--text-muted);
        width: auto;
    }
    .post-row .col-when::after {
        content: ' \00b7 ';
        color: var(--text-muted);
    }

    /* --- Line 2 continued: Username (inline after date) --- */
    .post-row .col-user {
        order: 6;
        font-size: 12px;
        color: var(--text-muted);
        overflow: visible;
        white-space: normal;
        max-width: none;
    }
    .post-row .col-user:not(:empty)::after {
        content: ' \00b7 ';
        color: var(--text-muted);
    }

    /* --- [archived] inline after user --- */
    .post-row .col-archived {
        order: 7;
        font-size: 12px;
        width: auto;
    }
    .post-row .col-archived a {
        font-size: 12px;
        color: var(--text-faint);
    }

    /* --- Sections spacing --- */
    .period-section { margin: 4px 6px; }
    .year-section { margin-bottom: 12px; }

    /* --- Fix iOS Safari double-tap on details/summary --- */
    .permalink {
        display: none;
    }

    /* --- Fix collapsed <details> showing empty space --- */
    details:not([open]) > table,
    details:not([open]) > .mobile-actions {
        display: none;
    }

    /* --- Tags wrap on mobile --- */
    .tag-pill {
        margin-bottom: 2px;
    }
}

[data-theme="dark"] .post-row {
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
