*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg: #0f1118;
    --bg-card: #181a25;
    --bg-hover: #1f2233;
    --surface: #1c1e2d;
    --border: #2a2d40;
    --text: #e4e6f0;
    --text-dim: #7a7e96;
    --text-link: #5b9cf5;
    --accent: #5b8bf5;
    --accent-glow: rgba(91, 139, 245, 0.15);
    --rt-color: #2dba6e;
    --quote-bg: #13141e;
    --quote-border: #2a2d40;
    --radius: 16px;
    --radius-sm: 10px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Hiragino Sans', 'Noto Sans JP', sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    -webkit-tap-highlight-color: transparent;
}

/* ── Header ── */
header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: rgba(15, 17, 24, 0.88);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border);
}

.header-inner {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px 8px;
    max-width: 680px;
    margin: 0 auto;
}

header h1 {
    font-size: 18px;
    font-weight: 700;
}

#last-update {
    font-size: 12px;
    color: var(--text-dim);
}

/* ── Filter ── */
#user-filter {
    display: flex;
    gap: 6px;
    padding: 4px 16px 10px;
    max-width: 680px;
    margin: 0 auto;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}

#user-filter::-webkit-scrollbar {
    display: none;
}

.filter-btn {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text-dim);
    padding: 5px 14px;
    border-radius: 20px;
    font-size: 13px;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.15s;
    flex-shrink: 0;
}

.filter-btn.active {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.filter-btn:not(.active):hover {
    background: var(--bg-hover);
    color: var(--text);
}

/* ── Main ── */
main {
    max-width: 680px;
    margin: 0 auto;
    padding: 0 0 80px 0;
}

/* ── Loading ── */
#loading {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-dim);
}

.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 16px;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* ── Date Separator ── */
.date-sep {
    padding: 20px 16px 8px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-dim);
    display: flex;
    align-items: center;
    gap: 10px;
}

.date-sep::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border);
}

/* ── Tweet Card ── */
.tweet {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    transition: background 0.15s;
}

.tweet:hover {
    background: var(--bg-hover);
}

.tweet-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 6px;
}

.tweet-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    background: var(--surface);
}

.tweet-author {
    flex: 1;
    min-width: 0;
}

.tweet-name {
    font-size: 14px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tweet-handle {
    font-size: 13px;
    color: var(--text-dim);
}

.tweet-time {
    font-size: 12px;
    color: var(--text-dim);
    white-space: nowrap;
    flex-shrink: 0;
}

.tweet-time a {
    color: var(--text-dim);
    text-decoration: none;
}

.tweet-time a:hover {
    color: var(--text-link);
    text-decoration: underline;
}

/* RT indicator */
.rt-label {
    font-size: 12px;
    color: var(--rt-color);
    margin-bottom: 4px;
    padding-left: 50px;
}

.rt-label::before {
    content: '🔁 ';
}

/* Tweet body */
.tweet-text {
    font-size: 15px;
    line-height: 1.55;
    word-break: break-word;
    padding-left: 50px;
    white-space: pre-wrap;
}

.tweet-text a {
    color: var(--text-link);
    text-decoration: none;
}

.tweet-text a:hover {
    text-decoration: underline;
}

/* Media */
.tweet-media {
    margin-top: 10px;
    padding-left: 50px;
    display: grid;
    gap: 4px;
}

.tweet-media.count-1 {
    grid-template-columns: 1fr;
}

.tweet-media.count-2 {
    grid-template-columns: 1fr 1fr;
}

.tweet-media.count-3,
.tweet-media.count-4 {
    grid-template-columns: 1fr 1fr;
}

.tweet-media img {
    width: 100%;
    border-radius: var(--radius-sm);
    object-fit: cover;
    max-height: 300px;
    cursor: pointer;
    transition: opacity 0.15s;
}

.tweet-media img:hover {
    opacity: 0.85;
}

/* Quote tweet */
.tweet-quote {
    margin-top: 10px;
    margin-left: 50px;
    padding: 10px 12px;
    background: var(--quote-bg);
    border: 1px solid var(--quote-border);
    border-radius: var(--radius-sm);
}

.tweet-quote .quote-header {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 4px;
}

.tweet-quote .quote-avatar {
    width: 18px;
    height: 18px;
    border-radius: 50%;
}

.tweet-quote .quote-name {
    font-size: 13px;
    font-weight: 600;
}

.tweet-quote .quote-handle {
    font-size: 12px;
    color: var(--text-dim);
}

.tweet-quote .quote-text {
    font-size: 14px;
    line-height: 1.45;
    color: var(--text);
}

/* URLs */
.tweet-urls {
    margin-top: 6px;
    padding-left: 50px;
}

.tweet-urls a {
    display: inline-block;
    font-size: 13px;
    color: var(--text-link);
    text-decoration: none;
    margin-right: 12px;
}

.tweet-urls a:hover {
    text-decoration: underline;
}

/* Metrics */
.tweet-metrics {
    display: flex;
    gap: 18px;
    margin-top: 8px;
    padding-left: 50px;
    font-size: 13px;
    color: var(--text-dim);
}

.tweet-metrics span {
    display: flex;
    align-items: center;
    gap: 4px;
}

/* ── Empty ── */
#empty {
    text-align: center;
    padding: 80px 20px;
    color: var(--text-dim);
}

#empty>div {
    font-size: 56px;
    margin-bottom: 16px;
}

#empty .sub {
    font-size: 13px;
    margin-top: 8px;
}

.hidden {
    display: none !important;
}

/* ── Image Lightbox ── */
#img-lightbox {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.9);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

#img-lightbox.hidden {
    display: none !important;
}

#img-lightbox img {
    max-width: 95%;
    max-height: 95%;
    object-fit: contain;
    border-radius: 8px;
}

/* ── Responsive ── */
@media (max-width: 480px) {
    .tweet-avatar {
        width: 34px;
        height: 34px;
    }

    .tweet-text,
    .tweet-media,
    .tweet-quote,
    .tweet-urls,
    .tweet-metrics {
        padding-left: 44px;
    }

    .rt-label {
        padding-left: 44px;
    }

    .tweet-quote {
        margin-left: 44px;
    }
}