/* ==========================================================================
   TWITTER DIGEST - STYLES
   A scalable, variable-driven stylesheet for the Twitter Digest app
   ========================================================================== */

/* ==========================================================================
   FONTS
   Chirp - Twitter/X's official typeface
   ========================================================================== */

@font-face {
    font-family: 'Chirp';
    src: url('assets/Chirp-Regular.woff') format('woff');
    font-weight: 400;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'Chirp';
    src: url('assets/Chirp-Medium.woff') format('woff');
    font-weight: 500;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'Chirp';
    src: url('assets/Chirp-Bold.woff') format('woff');
    font-weight: 700;
    font-style: normal;
    font-display: swap;
}

/* ==========================================================================
   CSS VARIABLES
   Centralized design tokens for consistent theming
   ========================================================================== */

:root {
    /* -------------------------------------------------------------------------
       COLORS - Light Theme (Default)
       ------------------------------------------------------------------------- */

    /* Base colors */
    --color-white: #ffffff;
    --color-black: #000000;

    /* Gray scale */
    --color-gray-50: #fafafa;
    --color-gray-100: #f8f8f8;
    --color-gray-150: #f5f5f5;
    --color-gray-200: #f0f0f0;
    --color-gray-300: #e5e5e5;
    --color-gray-400: #cccccc;
    --color-gray-500: #bbbbbb;
    --color-gray-600: #999999;
    --color-gray-700: #888888;
    --color-gray-800: #666666;
    --color-gray-900: #555555;
    --color-gray-950: #333333;

    /* Dark palette - Twitter "Dim" theme colors */
    --color-dark-bg: #0d1117;           /* Darker page background */
    --color-dark-card: #15202b;         /* Twitter Dim - matches embeds */
    --color-dark-elevated: #1e2d3d;     /* Elevated surfaces */
    --color-dark-hover: #22303c;        /* Hover state */
    --color-dark-border: #38444d;       /* Twitter Dim border */
    --color-dark-border-strong: #536471; /* Stronger border */

    /* Semantic colors - these get remapped in dark mode */
    --color-text-primary: #1a1a1a;
    --color-text-secondary: var(--color-gray-900);
    --color-text-tertiary: var(--color-gray-700);
    --color-text-muted: var(--color-gray-600);
    --color-text-subtle: var(--color-gray-500);

    --color-bg-page: var(--color-gray-100);
    --color-bg-card: var(--color-white);
    --color-bg-hover: var(--color-gray-50);
    --color-bg-button: var(--color-gray-150);
    --color-bg-button-hover: var(--color-gray-200);

    --color-border: var(--color-gray-200);
    --color-border-strong: var(--color-gray-300);

    /* Brand colors */
    --color-twitter: #1d9bf0;
    --color-twitter-light: #e8f5fd;

    /* Tag colors (light mode) */
    --color-tag-bg: #eff3f4;
    --color-tag-text: #536471;

    /* -------------------------------------------------------------------------
       TYPOGRAPHY
       ------------------------------------------------------------------------- */

    --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Chirp', sans-serif;

    /* Font sizes */
    --font-size-xs: 11px;
    --font-size-sm: 13px;
    --font-size-md: 14px;
    --font-size-base: 15px;
    --font-size-lg: 16px;
    --font-size-xl: 18px;
    --font-size-2xl: 20px;
    --font-size-3xl: 22px;
    --font-size-4xl: 24px;

    /* Component-specific sizes */
    --font-size-narrative: 19px;
    --font-size-section-title: var(--font-size-3xl);
    --font-size-tag: 15px;
    --font-size-feedback: 19px;

    /* Font weights */
    --font-weight-normal: 400;
    --font-weight-medium: 500;
    --font-weight-semibold: 600;

    /* Line heights */
    --line-height-tight: 1.3;
    --line-height-normal: 1.5;
    --line-height-relaxed: 1.7;
    --line-height-loose: 1.8;

    /* Letter spacing */
    --letter-spacing-tight: -0.02em;
    --letter-spacing-normal: 0;
    --letter-spacing-wide: 0.02em;

    /* -------------------------------------------------------------------------
       SPACING
       ------------------------------------------------------------------------- */

    --space-1: 2px;
    --space-2: 4px;
    --space-3: 6px;
    --space-4: 8px;
    --space-5: 10px;
    --space-6: 12px;
    --space-7: 14px;
    --space-8: 16px;
    --space-10: 20px;
    --space-12: 24px;
    --space-14: 28px;
    --space-16: 32px;
    --space-20: 40px;
    --space-24: 48px;

    /* Section spacing */
    --section-gap: var(--space-20);
    --section-gap-sm: var(--space-16);

    /* -------------------------------------------------------------------------
       LAYOUT
       ------------------------------------------------------------------------- */

    --container-max-width: 600px;
    --card-padding: 60px;
    --card-padding-mobile: 24px;

    /* -------------------------------------------------------------------------
       BORDERS & RADIUS
       ------------------------------------------------------------------------- */

    --radius-sm: 4px;
    --radius-md: 6px;
    --radius-lg: 8px;
    --radius-xl: 10px;
    --radius-2xl: 12px;
    --radius-3xl: 16px;
    --radius-full: 100px;

    /* -------------------------------------------------------------------------
       SHADOWS
       ------------------------------------------------------------------------- */

    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.04);
    --shadow-md: 0 3px 8px rgba(0, 0, 0, 0.04);
    --shadow-lg: 0 4px 12px rgba(0, 0, 0, 0.06);

    /* -------------------------------------------------------------------------
       TRANSITIONS & ANIMATIONS
       ------------------------------------------------------------------------- */

    --duration-fast: 0.15s;
    --duration-normal: 0.3s;
    --duration-slow: 0.4s;
    --duration-slower: 0.5s;

    --ease-default: ease;
    --ease-smooth: cubic-bezier(0.4, 0, 0.2, 1);
    --ease-bounce: cubic-bezier(0.34, 1.56, 0.64, 1);

    /* Animation system */
    --animation-distance: 16px;
    --animation-blur: 8px;
    --animation-base-delay: 0.1s;
    --animation-stagger: 0.06s;
}


/* ==========================================================================
   DARK THEME
   Remaps semantic tokens to dark palette values
   ========================================================================== */

[data-theme="dark"] {
    /* Text colors - Twitter Dim palette */
    --color-text-primary: #f7f9f9;      /* Twitter primary text */
    --color-text-secondary: #e7e9ea;    /* Twitter secondary text */
    --color-text-tertiary: #8b98a5;     /* Twitter muted text */
    --color-text-muted: #6e767d;        /* Twitter subtle text */
    --color-text-subtle: #536471;       /* Twitter very subtle */

    /* Background colors - layered dark theme */
    --color-bg-page: var(--color-dark-bg);      /* Darkest - page background */
    --color-bg-card: var(--color-dark-card);    /* Card - matches Twitter embeds */
    --color-bg-hover: var(--color-dark-hover);
    --color-bg-button: var(--color-dark-elevated);
    --color-bg-button-hover: var(--color-dark-hover);

    /* Border colors - Twitter Dim */
    --color-border: var(--color-dark-border);
    --color-border-strong: var(--color-dark-border-strong);

    /* Tag colors - dark mode */
    --color-tag-bg: #263340;
    --color-tag-text: #8b98a5;

    /* Shadows - more blur and spread for dark mode */
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.5);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.5);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.6);
}

/* Dark mode button overrides */
[data-theme="dark"] .btn--primary {
    background: var(--color-white);
    color: var(--color-dark-card);
}

[data-theme="dark"] .btn--primary:hover {
    background: var(--color-gray-200);
}

/* Dark mode main card - soft elevated shadow */
[data-theme="dark"] .main-card {
    box-shadow: 0 8px 48px rgba(0, 0, 0, 0.25),
                0 2px 12px rgba(0, 0, 0, 0.12);
}


/* ==========================================================================
   BASE STYLES
   Reset and foundational styles
   ========================================================================== */

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

html {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-family);
    font-size: var(--font-size-lg);
    font-weight: var(--font-weight-normal);
    line-height: var(--line-height-relaxed);
    letter-spacing: var(--letter-spacing-tight);
    color: var(--color-text-primary);
    background: var(--color-bg-page);
    padding: 60px var(--space-6);
    min-height: 100vh;
    transition: background-color var(--duration-normal) var(--ease-smooth),
                color var(--duration-normal) var(--ease-smooth);
}

/* Smooth theme transitions for all components */
.main-card,
.feedback__trigger,
.feedback__content,
.feedback__textarea,
.btn {
    transition: background-color var(--duration-normal) var(--ease-smooth),
                border-color var(--duration-normal) var(--ease-smooth),
                color var(--duration-normal) var(--ease-smooth),
                box-shadow var(--duration-fast) var(--ease-smooth);
}


/* ==========================================================================
   LAYOUT
   Container and main card structure
   ========================================================================== */

.container {
    max-width: var(--container-max-width);
    margin: 0 auto;
}

.main-card {
    background: var(--color-bg-card);
    border-radius: var(--radius-3xl);
    padding: var(--card-padding);
    box-shadow: var(--shadow-sm);
}


/* ==========================================================================
   DIGEST HEADER
   Logo, title, and date
   ========================================================================== */

.digest-header {
    display: flex;
    align-items: center;
    gap: var(--space-8);
    margin-bottom: var(--space-16);
    padding-bottom: var(--space-12);
    border-bottom: 1px solid var(--color-border);
}

.digest-header__logo {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-2xl);
    flex-shrink: 0;
}

.digest-header__text {
    flex: 1;
}

.digest-header__title {
    font-size: var(--font-size-2xl);
    font-weight: var(--font-weight-semibold);
    color: var(--color-text-primary);
    line-height: var(--line-height-tight);
}

.digest-header__date {
    font-size: var(--font-size-base);
    color: var(--color-text-tertiary);
    margin-top: var(--space-1);
}

[data-theme="dark"] .digest-header__date {
    color: var(--color-white);
}


/* ==========================================================================
   TOPIC SECTIONS
   Section headers with icons and labels
   ========================================================================== */

.topic-header {
    display: flex;
    align-items: center;
    gap: var(--space-6);
    margin-top: var(--section-gap);
    margin-bottom: var(--space-5);
}

/* First topic after header - no top margin */
.digest-header + .topic-header {
    margin-top: 0;
}

.topic-header__icon {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
}

.topic-header__label {
    font-size: var(--font-size-section-title);
    font-weight: var(--font-weight-semibold);
    color: var(--color-text-primary);
}

/* Topic tags (pill badges) */
.topic-tags {
    display: flex;
    gap: var(--space-3);
    flex-wrap: wrap;
    margin-bottom: var(--space-8);
}

.topic-tag {
    display: inline-block;
    padding: var(--space-2) var(--space-5);
    background: var(--color-tag-bg);
    border: none;
    border-radius: var(--radius-full);
    font-size: var(--font-size-tag);
    color: var(--color-tag-text);
    text-decoration: none;
}


/* ==========================================================================
   NARRATIVE TEXT
   Editorial content between tweets
   ========================================================================== */

.narrative {
    margin-bottom: var(--space-10);
}

.narrative--closing {
    margin-top: var(--space-16);
    margin-bottom: var(--space-8);
}

.narrative p {
    font-size: var(--font-size-narrative);
    line-height: var(--line-height-loose);
    color: var(--color-text-secondary);
    margin-bottom: var(--space-8);
}

.narrative p:last-child {
    margin-bottom: 0;
}

.narrative strong {
    font-weight: var(--font-weight-semibold);
    color: var(--color-text-primary);
}

.narrative em {
    font-style: italic;
}

/* Links in narrative */
.narrative a {
    color: var(--color-twitter);
    text-decoration: none;
    border-bottom: 1px solid transparent;
    transition: border-color var(--duration-fast) var(--ease-default);
}

.narrative a:hover {
    border-bottom-color: var(--color-twitter);
}


/* ==========================================================================
   TWEET EMBEDS
   Container for Twitter embeds
   ========================================================================== */

.tweet-container {
    margin: var(--space-10) 0;
}

/* Center Twitter widget */
.twitter-tweet {
    margin: 0 auto !important;
}

/* Twitter widget iframe styling (when loaded) */
.twitter-tweet-rendered {
    margin: 0 auto !important;
}


/* ==========================================================================
   FEEDBACK BOX
   Expandable feedback form
   ========================================================================== */

.feedback {
    margin-top: var(--section-gap);
}

.feedback__trigger {
    display: block;
    width: 100%;
    padding: var(--space-7) var(--space-8);
    background: var(--color-bg-button);
    border: none;
    border-radius: var(--radius-xl);
    font-family: inherit;
    font-size: var(--font-size-feedback);
    letter-spacing: var(--letter-spacing-tight);
    color: var(--color-text-tertiary);
    text-align: center;
    cursor: pointer;
    transition: all var(--duration-normal) var(--ease-smooth);
}

.feedback__trigger:hover {
    background: var(--color-bg-button-hover);
    color: var(--color-text-muted);
}

.feedback__trigger.is-expanded {
    background: var(--color-bg-hover);
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
}

.feedback__content {
    max-height: 0;
    overflow: hidden;
    background: var(--color-bg-hover);
    border-radius: 0 0 var(--radius-xl) var(--radius-xl);
    opacity: 0;
    transition: max-height var(--duration-slow) var(--ease-smooth),
                padding var(--duration-slow) var(--ease-smooth),
                opacity var(--duration-normal) var(--ease-default);
}

.feedback__content.is-open {
    max-height: 300px;
    padding: 0 var(--space-10) var(--space-10);
    opacity: 1;
}

.feedback__textarea {
    width: 100%;
    min-height: 90px;
    padding: var(--space-6) var(--space-7);
    border: 1px solid var(--color-border-strong);
    border-radius: var(--radius-lg);
    background: var(--color-bg-card);
    font-family: inherit;
    font-size: var(--font-size-base);
    line-height: var(--line-height-normal);
    letter-spacing: var(--letter-spacing-tight);
    color: var(--color-text-primary);
    resize: vertical;
    transition: border-color var(--duration-normal) var(--ease-smooth),
                box-shadow var(--duration-normal) var(--ease-smooth);
}

.feedback__textarea:focus {
    outline: none;
    border-color: var(--color-twitter);
    box-shadow: 0 0 0 3px rgba(29, 155, 240, 0.15);
}

.feedback__textarea::placeholder {
    color: var(--color-text-subtle);
}

.feedback__actions {
    display: flex;
    justify-content: flex-end;
    gap: var(--space-4);
    margin-top: var(--space-6);
    opacity: 0;
    transform: translateY(-8px);
    transition: opacity var(--duration-normal) var(--ease-default) 0.1s,
                transform var(--duration-normal) var(--ease-default) 0.1s;
}

.feedback__content.is-open .feedback__actions {
    opacity: 1;
    transform: translateY(0);
}


/* ==========================================================================
   BUTTONS
   Reusable button styles
   ========================================================================== */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-4) var(--space-7);
    border: none;
    border-radius: var(--radius-md);
    font-family: inherit;
    font-size: var(--font-size-md);
    font-weight: var(--font-weight-normal);
    letter-spacing: var(--letter-spacing-tight);
    cursor: pointer;
    transition: all var(--duration-fast) var(--ease-default);
}

.btn--secondary {
    background: transparent;
    color: var(--color-text-tertiary);
}

.btn--secondary:hover {
    background: var(--color-bg-button-hover);
    color: var(--color-text-muted);
}

.btn--primary {
    padding-left: var(--space-8);
    padding-right: var(--space-8);
    background: var(--color-text-primary);
    color: var(--color-white);
    font-weight: var(--font-weight-medium);
}

.btn--primary:hover {
    background: var(--color-gray-950);
}


/* ==========================================================================
   ANIMATIONS
   Keyframes and animation utilities
   ========================================================================== */

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(var(--animation-distance));
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

@keyframes blurIn {
    from {
        opacity: 0;
        filter: blur(var(--animation-blur));
    }
    to {
        opacity: 1;
        filter: blur(0);
    }
}

/* Content item animation system */
.content-item {
    --animation-index: 0;
    opacity: 0;
    animation: fadeInUp var(--duration-slow) var(--ease-smooth) both;
    animation-delay: calc(var(--animation-base-delay) + var(--animation-index) * var(--animation-stagger));
}

/* Modifier: featured items use blur animation */
.content-item--featured {
    animation-name: blurIn;
    animation-duration: var(--duration-slower);
}

/* Modifier: fast animation */
.content-item--fast {
    animation-duration: var(--duration-normal);
}

/* Modifier: no delay */
.content-item--no-delay {
    animation-delay: 0s;
}

/* Tweet containers use fade only (to avoid transform conflicts) */
.tweet-container.content-item {
    animation-name: fadeIn;
}


/* ==========================================================================
   UTILITY CLASSES
   Helper classes for common patterns
   ========================================================================== */

/* Visually hidden (for accessibility) */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Text utilities */
.text-center { text-align: center; }
.text-muted { color: var(--color-text-muted); }
.text-subtle { color: var(--color-text-subtle); }

/* Spacing utilities */
.mt-0 { margin-top: 0; }
.mb-0 { margin-bottom: 0; }


/* ==========================================================================
   RESPONSIVE STYLES
   Mobile-first adjustments
   ========================================================================== */

/* Tablet and below */
@media (max-width: 768px) {
    :root {
        --card-padding: 40px;
        --section-gap: var(--space-16);
    }

    body {
        padding: 32px var(--space-4);
    }

    .main-card {
        border-radius: var(--radius-2xl);
    }

    .digest-header {
        gap: var(--space-6);
    }

    .digest-header__logo {
        width: 44px;
        height: 44px;
    }

    .digest-header__title {
        font-size: var(--font-size-xl);
    }
}

/* Mobile phones */
@media (max-width: 480px) {
    :root {
        --card-padding: 24px;
        --section-gap: var(--space-14);
    }

    body {
        padding: 16px var(--space-3);
    }

    .main-card {
        border-radius: var(--radius-xl);
    }

    .digest-header {
        gap: var(--space-5);
        margin-bottom: var(--space-12);
        padding-bottom: var(--space-10);
    }

    .digest-header__logo {
        width: 40px;
        height: 40px;
        border-radius: var(--radius-lg);
    }

    .digest-header__title {
        font-size: var(--font-size-lg);
    }

    .digest-header__date {
        font-size: var(--font-size-sm);
    }

    /* Topic sections */
    .topic-header {
        gap: var(--space-4);
    }

    .topic-header__label {
        font-size: var(--font-size-base);
    }

    .topic-tags {
        gap: var(--space-2);
    }

    .topic-tag {
        padding: var(--space-1) var(--space-4);
        font-size: var(--font-size-xs);
    }

    /* Narrative */
    .narrative p {
        font-size: var(--font-size-sm);
    }

    /* Feedback */
    .feedback__trigger {
        padding: var(--space-5) var(--space-6);
        font-size: var(--font-size-sm);
    }

    .feedback__content.is-open {
        padding: 0 var(--space-6) var(--space-6);
    }

    .feedback__textarea {
        min-height: 80px;
        padding: var(--space-5) var(--space-6);
        font-size: var(--font-size-sm);
    }

    .btn {
        padding: var(--space-3) var(--space-5);
        font-size: var(--font-size-sm);
    }

    .btn--primary {
        padding-left: var(--space-6);
        padding-right: var(--space-6);
    }
}

/* Extra small phones */
@media (max-width: 360px) {
    :root {
        --card-padding: 20px;
    }

    body {
        padding: 12px var(--space-2);
    }

    .main-card {
        border-radius: var(--radius-lg);
    }
}
