/* The Daily Unhinged - Premium Dark Theme with Enhanced UX */

@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;500;600;700&family=Inter:wght@400;500;600&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
    --bg-primary: #0a0a12;
    --bg-secondary: #12121f;
    --bg-tertiary: #1a1a2e;
    --bg-card: #151524;
    --bg-glass: rgba(26, 26, 46, 0.7);
    --accent-primary: #ff6b6b;
    --accent-secondary: #4ecdc4;
    --accent-tertiary: #ffe66d;
    --accent-purple: #a855f7;
    --accent-blue: #3b82f6;
    --accent-green: #22c55e;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --border: rgba(255, 255, 255, 0.08);
    --border-glow: rgba(255, 107, 107, 0.3);
    --gradient-1: linear-gradient(135deg, #ff6b6b 0%, #feca57 100%);
    --gradient-2: linear-gradient(135deg, #a855f7 0%, #3b82f6 100%);
    --gradient-3: linear-gradient(135deg, #4ecdc4 0%, #44a08d 100%);
    --shadow-glow: 0 0 40px rgba(255, 107, 107, 0.12);
    --shadow-card: 0 4px 24px rgba(0, 0, 0, 0.4);
    --glass-blur: blur(12px);
}

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

html {
    scroll-behavior: smooth;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.75;
    min-height: 100vh;
    background-image:
        radial-gradient(ellipse at 0% 0%, rgba(255, 107, 107, 0.06) 0%, transparent 50%),
        radial-gradient(ellipse at 100% 100%, rgba(78, 205, 196, 0.06) 0%, transparent 50%);
    background-attachment: fixed;
}

/* ========================================
   HEADER
   ======================================== */
header {
    background: var(--bg-glass);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    padding: 2rem;
    text-align: center;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}

header::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--gradient-1);
}

.header-content {
    max-width: 1400px;
    margin: 0 auto;
}

header h1 {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 2.25rem;
    font-weight: 700;
    background: var(--gradient-1);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: -0.02em;
}

.tagline {
    color: var(--text-secondary);
    font-size: 0.95rem;
    margin-top: 0.25rem;
    font-weight: 400;
}

/* ========================================
   MAIN LAYOUT
   ======================================== */
main {
    display: flex;
    max-width: 1600px;
    margin: 0 auto;
    min-height: calc(100vh - 120px);
}

/* ========================================
   STICKY SIDEBAR
   ======================================== */
.calendar-sidebar {
    width: 320px;
    flex-shrink: 0;
    padding: 1.5rem;
    border-right: 1px solid var(--border);
    background: var(--bg-secondary);
    position: sticky;
    top: 80px;
    height: calc(100vh - 80px);
    overflow-y: auto;
}

.calendar-sidebar::-webkit-scrollbar {
    width: 4px;
}

.calendar-sidebar::-webkit-scrollbar-track {
    background: transparent;
}

.calendar-sidebar::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 2px;
}

.calendar-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.25rem;
    padding: 0.5rem;
    background: var(--bg-tertiary);
    border-radius: 10px;
    border: 1px solid var(--border);
}

.calendar-nav button {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 1.25rem;
    cursor: pointer;
    padding: 0.5rem 0.75rem;
    border-radius: 6px;
    transition: all 0.2s ease;
}

.calendar-nav button:hover {
    background: var(--bg-card);
    color: var(--accent-primary);
}

#current-month {
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 600;
    color: var(--text-primary);
    font-size: 1rem;
}

/* Calendar Grid */
.calendar {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 4px;
    margin-bottom: 2rem;
}

.calendar .day-header {
    text-align: center;
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-muted);
    padding: 0.5rem 0;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.calendar .day {
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    border-radius: 8px;
    cursor: default;
    color: var(--text-muted);
    transition: all 0.2s ease;
    font-weight: 500;
}

.calendar .day.has-digest {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    cursor: pointer;
    border: 1px solid var(--border);
}

.calendar .day.has-digest:hover {
    background: var(--accent-primary);
    color: white;
    transform: scale(1.05);
    border-color: var(--accent-primary);
}

.calendar .day.today {
    border: 2px solid var(--accent-secondary);
}

.calendar .day.selected {
    background: var(--gradient-1) !important;
    color: white !important;
    font-weight: 600;
    box-shadow: 0 4px 12px rgba(255, 107, 107, 0.3);
}

/* Available Dates List */
.available-dates {
    margin-top: 1.5rem;
}

.available-dates h3 {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 1rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.available-dates h3::before {
    content: '';
    display: block;
    width: 10px;
    height: 10px;
    background: var(--gradient-1);
    border-radius: 3px;
}

#date-list {
    list-style: none;
    max-height: 300px;
    overflow-y: auto;
}

#date-list::-webkit-scrollbar {
    width: 3px;
}

#date-list::-webkit-scrollbar-thumb {
    background: var(--accent-primary);
    border-radius: 2px;
}

#date-list li {
    padding: 0.75rem 1rem;
    margin-bottom: 0.5rem;
    background: var(--bg-tertiary);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 0.9rem;
    font-weight: 500;
    border: 1px solid var(--border);
    position: relative;
    overflow: hidden;
}

#date-list li::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: var(--accent-primary);
    opacity: 0;
    transition: opacity 0.2s ease;
}

#date-list li:hover {
    background: var(--bg-card);
    transform: translateX(4px);
}

#date-list li:hover::before {
    opacity: 1;
}

#date-list li.active {
    background: var(--gradient-1);
    color: white;
    border-color: transparent;
}

#date-list li.active::before {
    opacity: 0;
}

/* ========================================
   DIGEST CONTENT
   ======================================== */
.digest-content {
    flex: 1;
    padding: 2.5rem 3rem;
    max-width: 900px;
    min-width: 0;
}

.loading, .no-digest {
    text-align: center;
    padding: 5rem 2rem;
    color: var(--text-secondary);
}

.spinner {
    width: 48px;
    height: 48px;
    border: 3px solid var(--border);
    border-top-color: var(--accent-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 1.5rem;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.no-digest h2 {
    font-family: 'Space Grotesk', sans-serif;
    color: var(--text-primary);
    margin-bottom: 0.75rem;
}

/* ========================================
   DIGEST TYPOGRAPHY
   ======================================== */
.digest h1 {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 2.25rem;
    font-weight: 700;
    margin-bottom: 0.25rem;
    background: var(--gradient-1);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.digest h2 {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 1.5rem;
    font-weight: 600;
    margin: 3rem 0 1.5rem;
    padding-bottom: 0.75rem;
    color: var(--text-primary);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 80px;
    background: var(--bg-primary);
    z-index: 10;
    padding-top: 1rem;
    margin-top: 2rem;
}

.digest h2::after {
    content: '';
    position: absolute;
    bottom: -1px;
    left: 0;
    width: 50px;
    height: 2px;
    background: var(--gradient-1);
}

/* Story Cards (h3) */
.digest h3 {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 1.2rem;
    font-weight: 600;
    margin: 2.5rem 0 1rem;
    color: var(--accent-tertiary);
    line-height: 1.4;
}

.digest p {
    margin-bottom: 1.25rem;
    color: var(--text-primary);
    font-size: 1rem;
    line-height: 1.8;
}

.digest em {
    color: var(--text-secondary);
    font-style: italic;
}

.digest strong {
    color: var(--accent-primary);
    font-weight: 600;
}

.digest a {
    color: var(--accent-secondary);
    text-decoration: none;
    transition: all 0.2s ease;
    border-bottom: 1px solid transparent;
}

.digest a:hover {
    color: var(--accent-tertiary);
    border-bottom-color: var(--accent-tertiary);
}

/* Story Card Container */
.digest h3 + p,
.digest h3 ~ p:first-of-type {
    background: var(--bg-glass);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border: 1px solid var(--border);
    padding: 1.25rem 1.5rem;
    border-radius: 12px;
    margin-bottom: 1rem;
}

/* Commentary Blockquotes - Glassmorphism */
.digest blockquote {
    background: var(--bg-glass);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border: 1px solid var(--border);
    border-left: 3px solid var(--accent-primary);
    padding: 1.5rem 2rem;
    margin: 1.25rem 0;
    border-radius: 0 12px 12px 0;
    position: relative;
    box-shadow: var(--shadow-card);
}

.digest blockquote::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, rgba(255, 107, 107, 0.03) 0%, transparent 50%);
    border-radius: 0 12px 12px 0;
    pointer-events: none;
}

.digest blockquote p {
    margin: 0;
    font-size: 1.05rem;
    line-height: 1.85;
    color: var(--text-primary);
    position: relative;
    z-index: 1;
}

/* Market Call & Theory - Styled Chips */
.digest p:has(strong:first-child) {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

/* Category Headlines List */
.digest ul, .digest ol {
    margin: 1.25rem 0;
    padding-left: 0;
    list-style: none;
}

.digest > ul > li {
    background: var(--bg-card);
    padding: 1rem 1.25rem;
    margin-bottom: 0.6rem;
    border-radius: 10px;
    border: 1px solid var(--border);
    transition: all 0.25s ease;
    position: relative;
    overflow: hidden;
}

.digest > ul > li::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: var(--accent-secondary);
    opacity: 0;
    transition: opacity 0.2s ease;
}

.digest > ul > li:hover {
    border-color: var(--accent-secondary);
    transform: translateX(6px);
    box-shadow: 0 4px 16px rgba(78, 205, 196, 0.1);
}

.digest > ul > li:hover::before {
    opacity: 1;
}

.digest > ul > li a {
    font-weight: 500;
    color: var(--text-primary);
}

.digest > ul > li em {
    font-size: 0.8rem;
    color: var(--text-muted);
    display: block;
    margin-top: 0.25rem;
}

.digest hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 2.5rem 0;
}

/* Source Links */
.digest p > a:only-child {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: var(--bg-tertiary);
    border-radius: 8px;
    font-size: 0.9rem;
    border: 1px solid var(--border);
    transition: all 0.2s ease;
}

.digest p > a:only-child:hover {
    background: var(--bg-card);
    border-color: var(--accent-secondary);
}

/* ========================================
   THEORY LINKS WITH TOOLTIPS
   ======================================== */
.theory-link {
    color: var(--accent-purple) !important;
    font-weight: 600;
    text-decoration: none;
    border-bottom: 1px dashed var(--accent-purple);
    cursor: help;
    position: relative;
    transition: all 0.2s ease;
}

.theory-link:hover {
    color: var(--accent-tertiary) !important;
    border-bottom-color: var(--accent-tertiary);
}

.theory-link::after {
    content: attr(title);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-secondary);
    border: 1px solid var(--accent-purple);
    color: var(--text-primary);
    padding: 0.75rem 1rem;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 400;
    font-style: normal;
    white-space: normal;
    width: 260px;
    max-width: 90vw;
    text-align: left;
    opacity: 0;
    visibility: hidden;
    transition: all 0.2s ease;
    z-index: 100;
    box-shadow: 0 8px 32px rgba(168, 85, 247, 0.2);
    pointer-events: none;
}

.theory-link:hover::after {
    opacity: 1;
    visibility: visible;
    bottom: calc(100% + 10px);
}

/* ========================================
   KATEX MATH STYLING
   ======================================== */
.katex {
    font-size: 1.05em;
    color: var(--accent-secondary);
}

.katex-display {
    margin: 1.5rem 0;
    padding: 1.25rem;
    background: var(--bg-tertiary);
    border-radius: 10px;
    border: 1px solid var(--border);
    overflow-x: auto;
}

.katex-display > .katex {
    color: var(--accent-tertiary);
}

.digest p .katex,
.digest blockquote .katex {
    background: rgba(78, 205, 196, 0.1);
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
    font-size: 0.95em;
}

/* ========================================
   BACK TO TOP BUTTON
   ======================================== */
.back-to-top {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    width: 48px;
    height: 48px;
    background: var(--gradient-1);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    z-index: 1000;
    box-shadow: 0 4px 20px rgba(255, 107, 107, 0.4);
}

.back-to-top.visible {
    opacity: 1;
    visibility: visible;
}

.back-to-top:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 30px rgba(255, 107, 107, 0.5);
}

.back-to-top svg {
    width: 24px;
    height: 24px;
    fill: white;
}

/* ========================================
   CATEGORY CHIPS / TAGS
   ======================================== */
.category-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.25rem 0.75rem;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    margin-right: 0.5rem;
    margin-bottom: 0.5rem;
}

.category-chip.india { background: rgba(255, 153, 51, 0.2); color: #ff9933; }
.category-chip.us { background: rgba(59, 130, 246, 0.2); color: #3b82f6; }
.category-chip.china { background: rgba(239, 68, 68, 0.2); color: #ef4444; }
.category-chip.world { background: rgba(34, 197, 94, 0.2); color: #22c55e; }
.category-chip.tech { background: rgba(168, 85, 247, 0.2); color: #a855f7; }
.category-chip.market { background: rgba(78, 205, 196, 0.2); color: #4ecdc4; }
.category-chip.policy { background: rgba(255, 230, 109, 0.2); color: #ffe66d; }

/* ========================================
   FOOTER
   ======================================== */
footer {
    background: var(--bg-secondary);
    padding: 1.5rem 2rem;
    text-align: center;
    border-top: 1px solid var(--border);
    color: var(--text-secondary);
    font-size: 0.85rem;
}

footer a {
    color: var(--accent-primary);
    text-decoration: none;
    font-weight: 500;
    transition: color 0.2s ease;
}

footer a:hover {
    color: var(--accent-secondary);
}

.disclaimer {
    margin-top: 0.5rem;
    font-style: italic;
    color: var(--text-muted);
    font-size: 0.8rem;
}

/* ========================================
   SCROLLBARS
   ======================================== */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
    background: var(--bg-tertiary);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--accent-primary);
}

/* ========================================
   RESPONSIVE - TABLET
   ======================================== */
@media (max-width: 1200px) {
    .calendar-sidebar {
        width: 280px;
    }

    .digest-content {
        padding: 2rem;
    }
}

/* ========================================
   RESPONSIVE - MOBILE
   ======================================== */
@media (max-width: 900px) {
    header {
        position: relative;
        padding: 1.5rem 1rem;
    }

    header h1 {
        font-size: 1.75rem;
    }

    main {
        flex-direction: column;
    }

    .calendar-sidebar {
        width: 100%;
        position: relative;
        top: 0;
        height: auto;
        max-height: none;
        border-right: none;
        border-bottom: 1px solid var(--border);
        padding: 1rem;
    }

    .calendar {
        margin-bottom: 1rem;
    }

    .available-dates {
        display: none;
    }

    .digest-content {
        padding: 1.5rem;
    }

    .digest h1 {
        font-size: 1.75rem;
    }

    .digest h2 {
        font-size: 1.25rem;
        position: relative;
        top: 0;
    }

    .digest h3 {
        font-size: 1.1rem;
    }

    .digest blockquote {
        padding: 1rem 1.25rem;
        margin: 1rem 0;
    }

    .back-to-top {
        bottom: 1.5rem;
        right: 1.5rem;
        width: 44px;
        height: 44px;
    }

    .theory-link::after {
        left: 0;
        transform: translateX(0);
        width: calc(100vw - 3rem);
    }
}

@media (max-width: 600px) {
    header {
        padding: 1rem;
    }

    header h1 {
        font-size: 1.5rem;
    }

    .tagline {
        font-size: 0.85rem;
    }

    .digest-content {
        padding: 1rem;
    }

    .digest h1 {
        font-size: 1.5rem;
    }

    .digest h2 {
        font-size: 1.15rem;
    }

    .digest blockquote {
        padding: 0.875rem 1rem;
    }

    .calendar .day {
        font-size: 0.75rem;
    }
}

/* ========================================
   ANIMATIONS
   ======================================== */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(16px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.digest > * {
    animation: fadeInUp 0.35s ease forwards;
}

.digest > *:nth-child(1) { animation-delay: 0.03s; }
.digest > *:nth-child(2) { animation-delay: 0.06s; }
.digest > *:nth-child(3) { animation-delay: 0.09s; }
.digest > *:nth-child(4) { animation-delay: 0.12s; }
.digest > *:nth-child(5) { animation-delay: 0.15s; }
.digest > *:nth-child(6) { animation-delay: 0.18s; }
.digest > *:nth-child(7) { animation-delay: 0.21s; }
.digest > *:nth-child(8) { animation-delay: 0.24s; }
.digest > *:nth-child(9) { animation-delay: 0.27s; }
.digest > *:nth-child(10) { animation-delay: 0.30s; }

/* Reduced motion preference */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}
