/* ============================================================
   RSS Preview — Design System
   Monochrome tech aesthetic, inspired by grid-border layouts
   ============================================================ */

/* --- Design Tokens --- */
:root {
    --bg-primary:     #fafafa;
    --bg-secondary:   #f2f2f2;
    --bg-code:        #f0f0f0;
    --text-primary:   #111111;
    --text-secondary: #555555;
    --text-muted:     #999999;
    --border-color:   #d4d4d4;
    --border-hover:   #a0a0a0;
    --accent:         #111111;

    --font-display: "Playfair Display", Georgia, "Noto Serif SC", serif;
    --font-body:    "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", sans-serif;
    --font-mono:    "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;

    --max-width: 860px;
    --spacing-sm: 12px;
    --spacing-md: 24px;
    --spacing-lg: 40px;
    --spacing-xl: 56px;
}

/* --- Reset & Base --- */
*, *::before, *::after {
    box-sizing: border-box;
}

body {
    margin: 0;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    font-family: var(--font-body);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Noise texture overlay */
body::before {
    content: '';
    position: fixed;
    inset: 0;
    opacity: 0.028;
    pointer-events: none;
    z-index: 9999;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
    background-repeat: repeat;
    background-size: 200px 200px;
}

/* --- Container --- */
.container {
    max-width: var(--max-width);
    margin: 0 auto;
    border-left: 1px solid var(--border-color);
    border-right: 1px solid var(--border-color);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

main {
    flex: 1;
}

/* ============================================================
   Header — Grid-divided search bar
   ============================================================ */
header {
    display: grid;
    grid-template-columns: auto 1fr auto;
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--bg-primary);
}

.header-brand {
    font-family: var(--font-display);
    font-size: 22px;
    font-weight: 900;
    letter-spacing: 0.04em;
    padding: 20px 28px;
    border-right: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    user-select: none;
}

.header-input {
    padding: 0 var(--spacing-md);
    display: flex;
    align-items: center;
}

.header-input input {
    width: 100%;
    background: transparent;
    border: none;
    outline: none;
    font-family: var(--font-mono);
    font-size: 13px;
    color: var(--text-primary);
    letter-spacing: 0.04em;
}

.header-input input::placeholder {
    color: var(--text-muted);
    letter-spacing: 0.08em;
}

#previewBtn {
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 500;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    padding: 20px 28px;
    border: none;
    border-left: 1px solid var(--border-color);
    background: var(--accent);
    color: #fff;
    cursor: pointer;
    transition: opacity 0.15s ease;
    white-space: nowrap;
}

#previewBtn:hover {
    opacity: 0.8;
}

#previewBtn:active {
    opacity: 0.6;
}

/* ============================================================
   Loading & Error States
   ============================================================ */
#loading {
    padding: var(--spacing-xl) var(--spacing-lg);
    text-align: center;
}

.loading-text {
    font-family: var(--font-mono);
    font-size: 12px;
    letter-spacing: 0.2em;
    color: var(--text-muted);
    animation: pulse 1.8s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 0.4; }
    50% { opacity: 1; }
}

#error {
    padding: var(--spacing-md) var(--spacing-lg);
    font-family: var(--font-mono);
    font-size: 13px;
    color: #b91c1c;
    background: #fef2f2;
    border-left: 3px solid #ef4444;
    border-bottom: 1px solid var(--border-color);
}

/* ============================================================
   Feed Header
   ============================================================ */
#feedContent {
    display: flex;
    flex-direction: column;
}

#feedHeader {
    display: grid;
    grid-template-columns: 140px 1fr;
    gap: var(--spacing-md) 32px;
    padding: var(--spacing-lg);
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-secondary);
    align-items: start;
}

/* When no image, span full width */
#feedHeader.no-image {
    grid-template-columns: 1fr;
}

#feedImage {
    width: 140px;
    height: 140px;
    object-fit: cover;
    border: 1px solid var(--border-color);
    display: block;
}

.feed-info {
    min-width: 0;
}

#feedTitle {
    font-family: var(--font-display);
    font-size: 28px;
    font-weight: 700;
    letter-spacing: -0.02em;
    line-height: 1.2;
    margin: 0 0 12px 0;
    color: var(--text-primary);
}

.feed-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    margin-bottom: 12px;
}

.feed-meta-author {
    font-family: var(--font-mono);
    font-size: 11px;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--text-muted);
}

.feed-meta-tag {
    font-family: var(--font-mono);
    font-size: 10px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    padding: 2px 8px;
    line-height: 1.4;
}

.feed-info .description {
    font-size: 14px;
    color: var(--text-secondary);
    line-height: 1.6;
    margin: 0;
}

/* ============================================================
   RSS Items — Stacked, line-divided
   ============================================================ */
.rss-item {
    padding: var(--spacing-lg);
    border-bottom: 1px solid var(--border-color);
    transition: background-color 0.15s ease;
}

.rss-item:hover {
    background-color: var(--bg-secondary);
}

.item-meta {
    font-family: var(--font-mono);
    font-size: 11px;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: var(--spacing-sm);
}

.rss-item h3 {
    font-family: var(--font-display);
    font-size: 20px;
    font-weight: 700;
    letter-spacing: -0.01em;
    line-height: 1.3;
    margin: 0 0 16px 0;
}

.rss-item h3 a {
    text-decoration: none;
    color: inherit;
    transition: opacity 0.15s ease;
}

.rss-item h3 a:hover {
    opacity: 0.6;
}

/* Cover image */
.item-cover {
    width: 100%;
    max-height: 360px;
    object-fit: cover;
    border: 1px solid var(--border-color);
    margin-bottom: var(--spacing-md);
    display: block;
}

/* ============================================================
   Item Content — Overflow protection (critical fix)
   ============================================================ */
.item-content {
    font-size: 15px;
    color: var(--text-secondary);
    line-height: 1.7;
    overflow: hidden;
    word-break: break-word;
    overflow-wrap: break-word;
}

.item-content img {
    max-width: 100%;
    height: auto;
    display: block;
    margin: 16px 0;
    border: 1px solid var(--border-color);
}

.item-content h1,
.item-content h2,
.item-content h3,
.item-content h4,
.item-content h5,
.item-content h6 {
    font-family: var(--font-display);
    color: var(--text-primary);
    overflow-wrap: break-word;
    word-break: break-word;
    margin: 24px 0 12px 0;
    line-height: 1.3;
}

.item-content h1 { font-size: 22px; }
.item-content h2 { font-size: 19px; }
.item-content h3 { font-size: 17px; }
.item-content h4,
.item-content h5,
.item-content h6 { font-size: 15px; }

.item-content p {
    margin: 0 0 16px 0;
}

.item-content a {
    color: var(--text-primary);
    text-decoration: underline;
    text-underline-offset: 2px;
}

.item-content a:hover {
    opacity: 0.6;
}

.item-content pre,
.item-content code {
    font-family: var(--font-mono);
    font-size: 13px;
}

.item-content pre {
    background: var(--bg-code);
    border: 1px solid var(--border-color);
    padding: 16px;
    overflow-x: auto;
    margin: 16px 0;
}

.item-content code {
    background: var(--bg-code);
    padding: 2px 6px;
}

.item-content blockquote {
    border-left: 3px solid var(--border-color);
    margin: 16px 0;
    padding: 4px 0 4px 20px;
    color: var(--text-muted);
}

.item-content audio,
.item-content video,
.item-content iframe,
.item-content embed,
.item-content object,
.item-content table {
    max-width: 100%;
}

.item-content figure {
    margin: 16px 0;
    max-width: 100%;
}

.item-content figure img {
    margin: 0;
}

.item-content figure figcaption {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 8px;
    text-align: center;
}

/* ============================================================
   Podcast Layout
   ============================================================ */
.podcast-item {
    display: grid;
    grid-template-columns: 120px 1fr;
    gap: 28px;
}

.podcast-item .item-left {
    grid-column: 1;
}

.podcast-item .item-right {
    grid-column: 2;
    min-width: 0;
}

.podcast-item .item-cover {
    width: 120px;
    height: 120px;
    max-height: none;
    margin-bottom: 0;
}

.podcast-item .item-content {
    max-height: 72px;
    overflow: hidden;
    mask-image: linear-gradient(to bottom, black 30%, transparent 100%);
    -webkit-mask-image: linear-gradient(to bottom, black 30%, transparent 100%);
    margin-bottom: var(--spacing-sm);
}

.podcast-item .item-content.expanded {
    max-height: none;
    mask-image: none;
    -webkit-mask-image: none;
}

/* ============================================================
   Custom Audio Player — Monochrome
   ============================================================ */
.custom-audio-wrapper {
    background: var(--bg-code);
    border: 1px solid var(--border-color);
    padding: 10px 16px;
    display: flex;
    align-items: center;
    gap: 14px;
    margin-top: 14px;
    max-width: 100%;
}

.play-btn {
    background: transparent;
    border: none;
    color: var(--text-primary);
    cursor: pointer;
    padding: 0;
    display: flex;
    align-items: center;
    flex-shrink: 0;
    transition: opacity 0.15s ease;
}

.play-btn:hover {
    opacity: 0.5;
}

.audio-progress {
    flex-grow: 1;
    height: 2px;
    background: var(--border-color);
    position: relative;
    cursor: pointer;
    min-width: 0;
}

.audio-progress-fill {
    height: 100%;
    background: var(--accent);
    width: 0%;
    transition: width 0.1s linear;
}

.audio-time {
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-muted);
    letter-spacing: 0.02em;
    white-space: nowrap;
    flex-shrink: 0;
}

.volume-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0;
    display: flex;
    align-items: center;
    flex-shrink: 0;
    transition: color 0.15s ease;
}

.volume-btn:hover {
    color: var(--text-primary);
}

.volume-slider {
    width: 60px;
    height: 2px;
    -webkit-appearance: none;
    appearance: none;
    background: var(--border-color);
    outline: none;
    flex-shrink: 0;
    cursor: pointer;
}

.volume-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
}

.volume-slider::-moz-range-thumb {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--accent);
    border: none;
    cursor: pointer;
}

.toggle-content {
    font-family: var(--font-mono);
    font-size: 11px;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--text-primary);
    text-decoration: underline;
    text-underline-offset: 3px;
    cursor: pointer;
    background: none;
    border: none;
    padding: 0;
    margin-top: 10px;
    transition: opacity 0.15s ease;
}

.toggle-content:hover {
    opacity: 0.5;
}

/* ============================================================
   Footer
   ============================================================ */
footer {
    padding: var(--spacing-md) var(--spacing-lg);
    border-top: 1px solid var(--border-color);
    text-align: center;
}

footer span {
    font-family: var(--font-mono);
    font-size: 10px;
    letter-spacing: 0.2em;
    text-transform: uppercase;
    color: var(--text-muted);
}

/* ============================================================
   Utilities
   ============================================================ */
.hidden {
    display: none !important;
}

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 860px) {
    .container {
        border-left: none;
        border-right: none;
    }
}

@media (max-width: 600px) {
    header {
        grid-template-columns: 1fr auto;
    }

    .header-brand {
        display: none;
    }

    .header-input {
        padding: 0 16px;
    }

    #previewBtn {
        padding: 16px 20px;
    }

    #feedHeader {
        grid-template-columns: 80px 1fr;
        gap: 16px;
        padding: var(--spacing-md);
    }

    #feedImage {
        width: 80px;
        height: 80px;
    }

    #feedTitle {
        font-size: 22px;
    }

    .rss-item {
        padding: var(--spacing-md);
    }

    .podcast-item {
        grid-template-columns: 72px 1fr;
        gap: 16px;
    }

    .podcast-item .item-cover {
        width: 72px;
        height: 72px;
    }

    .item-cover {
        max-height: 240px;
    }

    footer {
        padding: 16px;
    }
}
