/* ═══════════════════════════════════════════════════════════
   TCS Daily — isolated-article stylesheet
   Reuses bzy.moe CSS variable system + pixel grid background
   ═══════════════════════════════════════════════════════════ */

/* ── Theme variables (same as main site) ── */
:root {
    --pink: #F0A0B0;
    --mint: #B8E6D3;
    --cream: #FFF8DC;
    --white: #ffffff;
    --black: #1a1a1a;
    --soft-cream: #DDD6BA;
    --soft-white: #f8f8f8;
    --border-white: #e8e8e8;

    /* Light (default) */
    --primary: var(--pink);
    --secondary: var(--mint);
    --accent: var(--cream);
    --text: var(--white);
    --border: var(--border-white);
    --shadow: rgba(255, 255, 255, 0.1);
    --px: 8px;

    /* Layout */
    --content-width: 860px;
    --aside-width: 220px;
    --aside-gap: 32px;
}

[data-theme="dark"] {
    --primary: var(--black);
    --secondary: var(--mint);
    --accent: var(--soft-cream);
    --text: var(--pink);
    --border: var(--pink);
    --shadow: rgba(240, 160, 176, 0.1);
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; width: 100%; }

::selection { background: var(--secondary); color: var(--primary); }

body {
    background: var(--primary);
    color: var(--text);
    font-family: 'Inter', system-ui, -apple-system, Segoe UI, Arial, sans-serif;
    letter-spacing: 0.02em;
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
    transition: background-color 0.6s ease, color 0.6s ease;
}

/* ── Pixel grid (identical to main site) ── */
.bg-grid {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    background-image:
        repeating-linear-gradient(0deg, rgba(255,255,255,0.05) 0, rgba(255,255,255,0.05) 1px, transparent 1px, transparent var(--px)),
        repeating-linear-gradient(90deg, rgba(255,255,255,0.05) 0, rgba(255,255,255,0.05) 1px, transparent 1px, transparent var(--px));
}

/* ── SVG icons (shared with main site) ── */
.icon {
    width: 24px;
    height: 24px;
    color: var(--text);
    display: inline-block;
    transition: color 0.6s ease, fill 0.6s ease;
}
.icon.small { width: 16px; height: 16px; }
svg, svg * { transition: fill 0.6s ease, stroke 0.6s ease; }

/* ── Top controls (index btn + theme btn) ── */
.top-controls {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 100;
    display: flex;
    gap: 8px;
    align-items: center;
}

/* Reuses main site .theme-btn styling */
.ctrl-btn {
    color: var(--text);
    background: transparent;
    border: 2px solid var(--text);
    padding: 8px;
    cursor: pointer;
    transition: all 0.6s ease;
    font-family: 'Press Start 2P', 'Courier New', monospace;
    font-size: 10px;
    position: relative;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
}
.ctrl-btn:hover {
    background: var(--text);
    color: var(--primary);
    border-color: var(--text);
    transform: scale(1.05);
}
.ctrl-btn:hover .icon { color: var(--primary); }
.ctrl-btn .icon { color: var(--text); transition: color 0.6s ease; }
.ctrl-btn:active { transform: scale(0.95); }

/* ── Container ── */
.container {
    position: relative;
    z-index: 1;
    max-width: var(--content-width);
    margin: 0 auto;
    padding: 60px 24px 40px;
}

/* ── Loading ── */
.loading {
    text-align: center;
    padding: 120px 0;
}
.loading-text {
    font-family: 'Press Start 2P', monospace;
    font-size: 12px;
    color: var(--text);
    opacity: 0.6;
    animation: blink 1.2s ease-in-out infinite;
    transition: color 0.6s ease;
}
@keyframes blink { 0%,100%{ opacity:0.6; } 50%{ opacity:0.2; } }

/* ═══════════════════════════════════════════════════════════
   Pixel badge (blog tag style, with clip-path corner)
   ═══════════════════════════════════════════════════════════ */

.pixel-badge {
    display: inline-block;
    padding: clamp(2px, 1vw, 4px) clamp(4px, 2vw, 8px);
    background: var(--secondary);
    color: var(--accent);
    font-family: 'Press Start 2P', monospace;
    font-size: clamp(6px, 2vw, 8px);
    text-transform: uppercase;
    margin: 2px;
    clip-path: polygon(0 0, calc(100% - 4px) 0, 100% 4px, 100% 100%, 4px 100%, 0 calc(100% - 4px));
    transition: all 0.3s ease;
    white-space: nowrap;
    text-decoration: none;
    cursor: pointer;
    border-bottom: none !important;
}
a.pixel-badge:hover {
    filter: brightness(1.3);
    transform: scale(1.08);
}

/* Tag filter pill in index — same filled style, with active/dim states */
.tag-filter {
    opacity: 0.55;
    transition: all 0.3s ease;
}
.tag-filter:hover {
    opacity: 0.85;
    filter: brightness(1.2);
    transform: scale(1.08);
}
.tag-filter.active {
    opacity: 1;
    filter: brightness(1.1);
    box-shadow: 0 0 8px var(--tag-color, var(--secondary));
}
.tag-filter.clear-btn {
    background: transparent !important;
    border: 1px solid var(--border);
    color: var(--text);
    clip-path: none;
    opacity: 0.5;
    align-self: flex-start;
}
.tag-filter.clear-btn:hover {
    opacity: 0.8;
    border-color: var(--accent);
}

/* ═══════════════════════════════════════════════════════════
   Article view
   ═══════════════════════════════════════════════════════════ */

.article {
    max-width: var(--content-width);
    margin: 0 auto;
    position: relative;
}

/* Header: enlarged centered blog-title style */
.article-header {
    text-align: center;
    margin-bottom: 40px;
    padding-bottom: 24px;
    position: relative;
}
/* Pixel L-corner decorations (same as main site .section) */
.article-header::before,
.article-header::after {
    content: '';
    position: absolute;
    width: 12px;
    height: 12px;
    background: var(--text);
    pointer-events: none;
    clip-path: polygon(0 0, 100% 0, 100% 4px, 4px 4px, 4px 100%, 0 100%);
    transition: background-color 0.6s ease;
}
.article-header::before {
    bottom: -2px;
    left: -2px;
    transform: rotate(270deg);
}
.article-header::after {
    bottom: -2px;
    right: -2px;
    transform: rotate(180deg);
}

.article-title {
    font-family: 'Press Start 2P', 'Courier New', monospace;
    font-size: clamp(16px, 3.5vw, 28px);
    color: var(--text);
    line-height: 1.5;
    margin-bottom: 16px;
    word-wrap: break-word;
    font-weight: 400;
    transition: color 0.6s ease;
}

.article-meta {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
}

.article-date,
.article-issue {
    font-family: 'Press Start 2P', monospace;
    font-size: 10px;
    color: var(--accent);
    transition: color 0.6s ease;
}

/* Prev / next triangle navigation arrows */
.nav-arrow {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--text);
    text-decoration: none;
    opacity: 0.5;
    transition: opacity 0.3s ease, transform 0.3s ease, color 0.6s ease;
    cursor: pointer;
}
.nav-arrow .icon { color: var(--text); transform: rotate(180deg); }
.nav-arrow-next .icon { transform: none; }
.nav-arrow:hover { opacity: 1; }
.nav-arrow.disabled { opacity: 0.15; cursor: default; pointer-events: none; }

.article-tags {
    display: flex;
    gap: 6px;
    justify-content: center;
    flex-wrap: wrap;
    margin-top: 18px;
}


/* ── Article body (markdown content) ── */
.article-body {
    position: relative;
    line-height: 1.7;
}

/* Sidenote anchor: invisible inline marker */
.sidenote-anchor { display: inline; }

/* Links */
.article-body a {
    color: var(--accent);
    text-decoration: none;
    border-bottom: 1px dashed var(--accent);
    transition: all 0.3s ease;
}
.article-body a:hover {
    color: var(--text);
    text-shadow: 0 0 8px var(--secondary);
}
.sidenote-column a {
    color: var(--accent);
    text-decoration: none;
    border-bottom: 1px dashed var(--accent);
    transition: all 0.3s ease;
}
.sidenote-column a:hover {
    color: var(--text);
    text-shadow: 0 0 8px var(--secondary);
}
/* Headings */
.article-body h2 {
    font-family: sans-serif;
    font-size: clamp(20px, 4vw, 28px);
    color: var(--text);
    margin: 32px 0 16px;
    font-weight: 400;
    line-height: 1.4;
    transition: color 0.6s ease;
}
.issue-content h2:hover {
    color: var(--accent);
}

.article-body h3 {
    font-family: sans-serif;
    font-size: clamp(17px, 3.5vw, 22px);
    color: var(--text);
    margin: 28px 0 12px;
    font-weight: 400;
    line-height: 1.4;
    transition: color 0.6s ease;
}

.article-body h4, .article-body h5, .article-body h6 {
    font-family: sans-serif;
    font-size: clamp(14px, 3vw, 17px);
    color: var(--text);
    margin: 20px 0 8px;
    font-weight: 500;
    transition: color 0.6s ease;
}

/* Paragraphs */
.article-body p {
    font-size: clamp(16px, 3.5vw, 18px);
    line-height: 1.75;
    margin-bottom: 12px;
    color: var(--text);
    transition: color 0.6s ease;
}

/* Lists */
.article-body ul, .article-body ol {
    margin: 8px 0;
    padding-left: 24px;
}
.article-body li {
    font-size: clamp(16px, 3.5vw, 18px);
    line-height: 1.7;
    margin-bottom: 4px;
    transition: color 0.6s ease;
}

/* Strong / em */
.article-body strong {
    color: var(--accent);
    font-weight: 700;
    transition: color 0.6s ease;
}
.article-body em { font-style: italic; }

/* Code */
.article-body code {
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.9em;
    background: rgba(255,255,255,0.1);
    padding: 2px 6px;
    border-radius: 3px;
    transition: background-color 0.6s ease, color 0.6s ease;
}
.article-body pre {
    background: rgba(0,0,0,0.3);
    padding: 16px;
    border-radius: 4px;
    overflow-x: auto;
    margin: 12px 0;
    transition: background-color 0.6s ease;
}
.article-body pre code {
    background: none;
    padding: 0;
}

/* Blockquote */
.article-body blockquote {
    border-left: 3px solid var(--accent);
    padding: 8px 16px;
    margin: 12px 0;
    opacity: 0.85;
    transition: border-color 0.6s ease;
}

/* Table */
.article-body table {
    width: 100%;
    border-collapse: collapse;
    margin: 16px 0;
    font-size: 15px;
}
.article-body th, .article-body td {
    border: 1px solid var(--border);
    padding: 8px 12px;
    text-align: left;
    transition: border-color 0.6s ease, background-color 0.6s ease, color 0.6s ease;
}
.article-body th {
    font-weight: 600;
    background: rgba(255,255,255,0.05);
    transition: border-color 0.6s ease, background-color 0.6s ease, color 0.6s ease;
}

/* Horizontal rule */
.article-body hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 24px 0;
    transition: border-color 0.6s ease;
}

/* Footnotes */
.article-body .footnotes {
    margin-top: 32px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
    font-size: 14px;
    opacity: 0.8;
    transition: border-color 0.6s ease;
}

/* ═══════════════════════════════════════════════════════════
   Issue Blocks (::::issue)
   Collapsible sections with hover-reveal gutter controls
   ═══════════════════════════════════════════════════════════ */

.article-body {
    counter-reset: issue-counter;
}

.issue-block {
    position: relative;
    counter-increment: issue-counter;
}

/* Invisible hover zone extending to the left so mouse can reach gutter */
.issue-block::before {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    right: 100%;
    width: 80px;
}

/* Gutter: triangle toggle + "Issue N" label, outside container on the left */
.issue-gutter {
    position: absolute;
    right: calc(100% + 32px);   /* 24px container padding + 8px gap */
    top: 4px;                   /* align with heading baseline */
    display: none;              /* hidden on narrow screens */
    align-items: center;
    gap: 6px;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
    white-space: nowrap;
    cursor: pointer;
}

@media (min-width: 1200px) {
    .issue-gutter {
        display: flex;
    }
}

.issue-block:hover .issue-gutter {
    opacity: 0.6;
    pointer-events: auto;
}
.issue-block:hover .issue-gutter:hover {
    opacity: 1;
}

/* When collapsed, gutter is always visible */
.issue-block.collapsed .issue-gutter {
    opacity: 0.6;
    pointer-events: auto;
}
.issue-block.collapsed .issue-gutter:hover {
    opacity: 1;
}

.issue-toggle {
    background: none;
    border: none;
    cursor: pointer;
    padding: 2px;
    color: var(--text);
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;       /* let clicks fall through to .issue-gutter */
    transition: color 0.6s ease;
}

/* Triangle icon: bigger, expanded → pointing down (90deg), collapsed → right (0deg) */
.issue-toggle .icon {
    width: 20px;
    height: 20px;
    transition: transform 0.3s ease;
    transform: rotate(90deg);
}
.issue-block.collapsed .issue-toggle .icon {
    transform: rotate(0deg);
}

.issue-label {
    font-family: 'Press Start 2P', monospace;
    font-size: 10px;
    color: var(--accent);
    letter-spacing: 0.05em;
    transition: color 0.6s ease;
    pointer-events: none;       /* let clicks fall through to .issue-gutter */
}
.issue-label::after {
    content: "Issue " counter(issue-counter);
}

/* Collapsed state: hide everything, then show back the first h2 and issue-tags */
.issue-block.collapsed .issue-content > * {
    display: none;
}
.issue-block.collapsed .issue-content > h2:first-of-type {
    display: block;
    opacity: 0.6;
    cursor: pointer;
}
.issue-block.collapsed .issue-content > h2:first-of-type::after {
    content: " ···";
    font-family: 'Press Start 2P', monospace;
    font-size: 10px;
    color: var(--accent);
    opacity: 0.5;
}
/* Show tags even when collapsed (they're at the end of .issue-content) */
.issue-block.collapsed .issue-content > .issue-tags {
    display: flex;
    opacity: 0.5;
}
/* Hide inline sidenotes when their issue is collapsed */
.issue-block.collapsed .sidenote-inline {
    display: none;
}

/* Issue per-paper tags */
.issue-tags {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-top: 12px;
    padding-bottom: 8px;
}

/* ═══════════════════════════════════════════════════════════
   Sidenotes (:::aside)
   Wide screen: external column positioned absolutely
   Narrow screen: inline <details> inside article-body
   ═══════════════════════════════════════════════════════════ */

/* The external sidenote column lives outside .container */
.sidenote-column {
    display: none;              /* hidden on narrow screens by default */
}

@media (min-width: 1200px) {
    .sidenote-column {
        display: block;
        position: absolute;
        top: 0;
        /* Centered content has left edge at (50vw - content-width/2);
           sidenote starts content-width/2 + aside-gap to the right of center */
        left: calc(50% + var(--content-width) / 2 + var(--aside-gap));
        width: var(--aside-width);
        z-index: 1;
        pointer-events: auto;
    }

    .sidenote {
        position: absolute;
        width: var(--aside-width);
        font-size: 13px;
        line-height: 1.55;
        color: var(--text);
        opacity: 0.75;
        border-left: 2px solid var(--accent);
        padding-left: 12px;
        transition: opacity 0.3s ease, color 0.6s ease, border-color 0.6s ease;
    }
    .sidenote:hover { opacity: 1; }

    .sidenote-label {
        font-family: 'Roboto', monospace;
        font-size: 12px;
        color: var(--accent);
        display: block;
        margin-bottom: 6px;
        letter-spacing: 0.05em;
        transition: color 0.6s ease;
    }

    .sidenote p {
        font-size: 13px !important;
        line-height: 1.55 !important;
        margin-bottom: 6px !important;
    }

    /* Hide the inline fallback on wide screens */
    .sidenote-inline { display: none; }
}

/* Narrow screen: inline collapsible details */
@media (max-width: 1199px) {
    .sidenote-inline {
        margin: 12px 0;
        border: 1px solid var(--border);
        border-radius: 4px;
        padding: 0;
        font-size: 14px;
        transition: border-color 0.6s ease;
    }
    .sidenote-inline summary {
        font-family: 'Press Start 2P', monospace;
        font-size: 8px;
        color: var(--accent);
        cursor: pointer;
        padding: 8px 12px;
        user-select: none;
        transition: color 0.6s ease;
    }
    .sidenote-inline summary:hover { opacity: 0.8; }
    .sidenote-inline .sidenote-content {
        padding: 8px 12px 12px;
        line-height: 1.6;
    }
    .sidenote-inline .sidenote-content p {
        font-size: 14px !important;
        margin-bottom: 6px !important;
    }
}

/* ═══════════════════════════════════════════════════════════
   Index view — flat date-grouped list
   ═══════════════════════════════════════════════════════════ */

.index {
    max-width: 860px;
    margin: 0 auto;
}

.index-header {
    text-align: center;
    margin-bottom: 32px;
}

.index-title {
    font-family: 'Press Start 2P', monospace;
    font-size: clamp(20px, 4vw, 36px);
    color: var(--text);
    margin-bottom: 8px;
    font-weight: 400;
    transition: color 0.6s ease;
}

.index-subtitle {
    font-size: 14px;
    color: var(--text);
    opacity: 0.6;
    transition: color 0.6s ease;
}

/* Tag filter bar */
.index-tags {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 10px;
    align-items: start;
    margin-bottom: 32px;
}

.tag-category {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    border: 1px solid rgba(255,255,255,0.18);
    background: rgba(255,255,255,0.02);
    min-height: 108px;
    transition: border-color 0.3s ease, background-color 0.3s ease, transform 0.2s ease;
}

.tag-category:hover {
    background: color-mix(in srgb, var(--category-accent, var(--accent)) 10%, rgba(255,255,255,0.04));
    transform: translateY(-1px);
}

.tag-category.expanded {
    border-color: rgba(255,255,255,0.24);
    background: color-mix(in srgb, var(--category-accent, var(--accent)) 14%, rgba(255,255,255,0.05));
    grid-column: 1 / -1;
    min-height: 0;
}

.tag-category-toggle {
    width: 100%;
    background: transparent;
    border: none;
    color: var(--text);
    padding: 12px 14px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    text-align: left;
}

.tag-category-heading {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
    min-height: 38px;
}

.tag-category-toggle::after {
    content: "▸";
    font-size: 12px;
    opacity: 0.6;
    color: #fff;
    transition: transform 0.2s ease;
}

.tag-category.expanded .tag-category-toggle::after {
    transform: rotate(90deg);
}

.tag-category-name {
    font-family: 'Press Start 2P', monospace;
    font-size: 9px;
    color: #fff;
}

.tag-category-meta {
    font-size: 12px;
    opacity: 0.65;
}

[data-theme="dark"] .tag-category {
    background: rgba(255,255,255,0.04);
}

[data-theme="dark"] .tag-category:hover {
    background: color-mix(in srgb, var(--category-accent, var(--accent)) 12%, rgba(255,255,255,0.08));
}

[data-theme="dark"] .tag-category.expanded {
    background: color-mix(in srgb, var(--category-accent, var(--accent)) 16%, rgba(255,255,255,0.08));
}

[data-theme="dark"] .tag-category-toggle::after,
[data-theme="dark"] .tag-category-name {
    color: var(--category-accent, var(--accent));
}

.tag-category-preview {
    display: flex;
    flex-wrap: nowrap;
    gap: 5px;
    padding: 0 12px 12px;
    min-height: 22px;
    opacity: 0.75;
    overflow: hidden;
}

.tag-category.expanded .tag-category-preview {
    display: none;
}

.tag-preview-badge {
    font-size: 5px;
    padding: 2px 4px;
    opacity: 0.85;
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tag-category-tags {
    display: none;
    padding: 0 12px 12px;
}

.tag-category.expanded .tag-category-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

@media (max-width: 640px) {
    .index-tags {
        grid-template-columns: 1fr;
    }

    .tag-category.expanded {
        grid-column: auto;
    }
}

/* Date-grouped list */
.index-list {
    display: flex;
    flex-direction: column;
    gap: 0;
}

/* Each date group */
.date-group {
    transition: opacity 0.3s ease;
}
.date-group.hidden-by-filter {
    display: none;
}

/* Date row: date + day-level tags */
.date-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 0;
    cursor: pointer;
    text-decoration: none;
    color: var(--text);
    transition: opacity 0.3s ease, color 0.6s ease;
}
.date-row:hover {
    opacity: 0.8;
}

.date-row-date {
    font-family: 'Press Start 2P', monospace;
    font-size: 11px;
    color: var(--accent);
    min-width: 120px;
    flex-shrink: 0;
    transition: color 0.6s ease;
}

/* Paper row: indented, Issue N: title */
.paper-row {
    display: flex;
    align-items: baseline;
    padding: 6px 0 6px 32px;
    text-decoration: none;
    color: var(--text);
    transition: all 0.3s ease;
    gap: 8px;
}
.paper-row:hover {
    color: var(--accent);
}
.paper-row.hidden-by-filter {
    display: none;
}
/* Highlight matching tags when filter is active */
.paper-row .pixel-badge.tag-match {
    filter: brightness(1.35);
    transform: scale(1.15);
    box-shadow: 0 0 10px var(--tag-color, var(--secondary)),
               0 0 2px var(--tag-color, var(--secondary));
    outline: 1.5px solid var(--tag-color, var(--secondary));
    outline-offset: 1px;
}

.paper-row-index {
    font-family: 'Press Start 2P', monospace;
    font-size: 8px;
    color: var(--accent);
    opacity: 0.5;
    flex-shrink: 0;
    min-width: 72px;
    transition: color 0.6s ease;
}

.paper-row-title {
    font-size: 15px;
    line-height: 1.5;
    flex: 1;
    min-width: 0;
}

.paper-row-tags {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
    flex-shrink: 0;
}
.paper-row-tags .pixel-badge {
    font-size: 6px;
    padding: 2px 5px;
}

/* ── Footer ── */
.footer {
    text-align: center;
    padding: 24px;
    font-size: 12px;
    opacity: 0.4;
    position: relative;
    z-index: 1;
    transition: color 0.6s ease;
}
.footer a {
    color: var(--text);
    border: none;
    transition: color 0.6s ease;
}

/* ── Responsive ── */
@media (max-width: 600px) {
    .top-controls { top: 10px; right: 10px; gap: 6px; }
    .ctrl-btn { padding: 5px; border-width: 1px; }
    .container { padding: 48px 16px 24px; }
}
