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

:root {
    --primary-color: #E1306C;
    --primary-hover: #C13584;
    --secondary-color: #833AB4;
    --background: #fafafa;
    --card-bg: #ffffff;
    --text-primary: #262626;
    --text-secondary: #8e8e8e;
    --border-color: #dbdbdb;
    --error-color: #ed4956;
    --success-color: #00ba34;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    --shadow-hover: 0 4px 16px rgba(0, 0, 0, 0.15);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    padding: 20px;
    color: var(--text-primary);
}

.container {
    max-width: 900px;
    margin: 0 auto;
}

header {
    text-align: center;
    margin-bottom: 40px;
    color: white;
}

.logo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 15px;
    margin-bottom: 10px;
}

.logo svg {
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.2));
}

h1 {
    font-size: 2.5rem;
    font-weight: 700;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.subtitle {
    font-size: 1.1rem;
    opacity: 0.95;
    margin-top: 10px;
}

main {
    background: var(--card-bg);
    border-radius: 16px;
    padding: 40px;
    box-shadow: var(--shadow);
    margin-bottom: 20px;
}

.search-section {
    margin-bottom: 30px;
}

.input-wrapper {
    display: flex;
    gap: 12px;
    margin-bottom: 10px;
}

#urlInput {
    flex: 1;
    padding: 16px 20px;
    font-size: 16px;
    border: 2px solid var(--border-color);
    border-radius: 12px;
    outline: none;
    transition: all 0.3s ease;
    font-family: inherit;
}

#urlInput:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(225, 48, 108, 0.1);
}

#fetchBtn {
    padding: 16px 32px;
    font-size: 16px;
    font-weight: 600;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: white;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 140px;
    justify-content: center;
}

#fetchBtn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(225, 48, 108, 0.3);
}

#fetchBtn:active {
    transform: translateY(0);
}

#fetchBtn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

.spinner {
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

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

.helper-text {
    color: var(--text-secondary);
    font-size: 14px;
    margin-left: 4px;
}

.error-message {
    background: #fee;
    border: 1px solid var(--error-color);
    color: #c00;
    padding: 16px 20px;
    border-radius: 12px;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.error-message::before {
    content: "⚠️";
    font-size: 20px;
}

.loading-message {
    text-align: center;
    padding: 40px;
    color: var(--text-secondary);
}

.loading-spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 20px;
}

.results {
    margin-top: 30px;
}

.results h2 {
    font-size: 1.8rem;
    margin-bottom: 20px;
    color: var(--text-primary);
    padding-bottom: 12px;
    border-bottom: 2px solid var(--border-color);
}

.post-card {
    border: 1px solid var(--border-color);
    border-radius: 12px;
    overflow: hidden;
    margin-bottom: 20px;
}

.carousel-container {
    position: relative;
    width: 100%;
    background: #000;
    overflow: hidden;
}

.carousel-images {
    position: relative;
    width: 100%;
    height: 600px;
    display: block;
}

.carousel-image {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
    object-position: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.5s ease-in-out, visibility 0.5s ease-in-out;
    z-index: 1;
}

.carousel-image.active {
    opacity: 1;
    visibility: visible;
    z-index: 2;
}

.carousel-btn {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(0, 0, 0, 0.5);
    color: white;
    border: none;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    font-size: 30px;
    cursor: pointer;
    z-index: 10;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

.carousel-btn:hover {
    background: rgba(0, 0, 0, 0.8);
    transform: translateY(-50%) scale(1.1);
}

.carousel-btn.prev {
    left: 15px;
}

.carousel-btn.next {
    right: 15px;
}

.carousel-dots {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 10px;
    z-index: 10;
}

.dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.5);
    cursor: pointer;
    transition: all 0.3s ease;
    border: 2px solid rgba(255, 255, 255, 0.8);
}

.dot.active {
    background: white;
    transform: scale(1.2);
}

.dot:hover {
    background: rgba(255, 255, 255, 0.8);
}

.post-info {
    padding: 20px;
}

.post-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
}

.profile-pic {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
}

.username {
    font-weight: 600;
    font-size: 16px;
}

.post-caption {
    margin: 16px 0;
    line-height: 1.6;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.post-likes {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 16px 0;
    padding: 12px 0;
    font-size: 16px;
    font-weight: 600;
}

.likes-icon {
    font-size: 20px;
}

.likes-count {
    color: var(--text-primary);
}

.post-url {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 12px 0;
    padding: 12px;
    background: var(--background);
    border-radius: 8px;
    font-size: 14px;
}

.url-label {
    font-size: 18px;
}

.post-url a {
    color: var(--primary-color);
    text-decoration: none;
    word-break: break-all;
    font-weight: 500;
}

.post-url a:hover {
    text-decoration: underline;
}

.post-meta {
    margin-top: 16px;
    font-size: 14px;
    color: var(--text-secondary);
}

.meta-item {
    margin: 8px 0;
    padding: 8px 12px;
    background: var(--background);
    border-radius: 8px;
}

.meta-label {
    font-weight: 600;
    margin-right: 8px;
}

.json-data {
    margin-top: 20px;
}

.json-data summary {
    cursor: pointer;
    padding: 12px 16px;
    background: var(--background);
    border-radius: 8px;
    font-weight: 600;
    user-select: none;
}

.json-data summary:hover {
    background: #f0f0f0;
}

.json-content {
    margin-top: 12px;
    padding: 20px;
    background: #f5f5f5;
    border-radius: 8px;
    overflow-x: auto;
}

.json-content pre {
    margin: 0;
    font-family: 'Courier New', monospace;
    font-size: 13px;
    line-height: 1.6;
}

footer {
    text-align: center;
    color: white;
    opacity: 0.9;
    font-size: 14px;
}

footer a {
    color: white;
    text-decoration: none;
    font-weight: 600;
    border-bottom: 1px solid rgba(255, 255, 255, 0.3);
    transition: border-color 0.3s ease;
}

footer a:hover {
    border-bottom-color: white;
}

/* Navigation Tabs */
.nav-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 30px;
    border-bottom: 2px solid var(--border-color);
}

.tab-btn {
    padding: 12px 24px;
    background: none;
    border: none;
    border-bottom: 3px solid transparent;
    color: var(--text-secondary);
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    margin-bottom: -2px;
}

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

.tab-btn.active {
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* Options Row */
.options-row {
    margin-top: 12px;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 14px;
}

.checkbox-label input[type="checkbox"] {
    cursor: pointer;
}

/* Analyze Button */
.analyze-btn {
    width: 100%;
    padding: 16px 32px;
    margin: 20px 0;
    font-size: 18px;
    font-weight: 600;
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.analyze-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

.analyze-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

/* Analysis Results */
.analysis-results {
    margin-top: 30px;
}

.analysis-results h2 {
    font-size: 1.8rem;
    margin-bottom: 20px;
    color: var(--text-primary);
    padding-bottom: 12px;
    border-bottom: 2px solid var(--border-color);
}

/* Aggregate Analysis */
.aggregate-analysis {
    background: linear-gradient(135deg, #667eea15, #764ba215);
    border: 2px solid var(--primary-color);
    border-radius: 16px;
    padding: 32px;
    margin-bottom: 40px;
}

.aggregate-header {
    text-align: center;
    margin-bottom: 30px;
}

.aggregate-header h3 {
    font-size: 1.8rem;
    color: var(--primary-color);
    margin-bottom: 8px;
}

.aggregate-subtitle {
    color: var(--text-secondary);
    font-size: 1rem;
}

.aggregate-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 20px;
    margin-bottom: 24px;
}

.aggregate-card {
    background: white;
    padding: 20px;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    transition: transform 0.2s ease;
}

.aggregate-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
}

.aggregate-card h4 {
    font-size: 1rem;
    margin-bottom: 12px;
    color: var(--primary-color);
}

.aggregate-card p {
    color: var(--text-primary);
    line-height: 1.6;
    font-size: 0.95rem;
}

.key-takeaways {
    background: white;
    padding: 24px;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.key-takeaways h4 {
    font-size: 1.2rem;
    margin-bottom: 16px;
    color: var(--primary-color);
}

.key-takeaways ul {
    list-style: none;
    padding: 0;
}

.key-takeaways li {
    padding: 12px 0;
    padding-left: 30px;
    position: relative;
    line-height: 1.6;
    color: var(--text-primary);
    border-bottom: 1px solid var(--border-color);
}

.key-takeaways li:last-child {
    border-bottom: none;
}

.key-takeaways li::before {
    content: "✓";
    position: absolute;
    left: 0;
    color: var(--success-color);
    font-weight: bold;
    font-size: 18px;
}

.section-divider {
    text-align: center;
    margin: 40px 0 30px;
    position: relative;
}

.section-divider h3 {
    display: inline-block;
    background: var(--card-bg);
    padding: 0 20px;
    font-size: 1.4rem;
    color: var(--text-secondary);
    position: relative;
    z-index: 1;
}

.section-divider::before {
    content: "";
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    height: 1px;
    background: var(--border-color);
    z-index: 0;
}

.analysis-card {
    background: var(--background);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 24px;
    margin-bottom: 20px;
}

.analysis-header h3 {
    font-size: 1.4rem;
    color: var(--primary-color);
    margin-bottom: 20px;
}

.analysis-section {
    margin-bottom: 20px;
}

.analysis-section h4 {
    font-size: 1.1rem;
    margin-bottom: 12px;
    color: var(--text-primary);
}

.transcription {
    background: white;
    padding: 16px;
    border-radius: 8px;
    border-left: 4px solid var(--primary-color);
    white-space: pre-wrap;
    font-family: 'Courier New', monospace;
    font-size: 14px;
    line-height: 1.6;
}

.visual-description {
    line-height: 1.7;
    color: var(--text-primary);
}

.color-palette {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.color-swatch {
    width: 80px;
    height: 80px;
    border-radius: 8px;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    cursor: pointer;
    transition: transform 0.2s ease;
}

.color-swatch:hover {
    transform: scale(1.1);
}

.color-code {
    background: rgba(255, 255, 255, 0.9);
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
    color: #333;
}

.tag-list {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.tag {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    padding: 6px 12px;
    border-radius: 16px;
    font-size: 14px;
    color: var(--text-primary);
}

.tag.highlight {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: white;
    border: none;
}

/* Library Section */
.library-header {
    margin-bottom: 30px;
}

.library-header h2 {
    font-size: 2rem;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.library-subtitle {
    color: var(--text-secondary);
    font-size: 1.1rem;
}

.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-secondary);
}

.empty-state p:first-child {
    font-size: 3rem;
    margin-bottom: 16px;
}

.empty-subtitle {
    font-size: 1.1rem;
}

.library-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 24px;
    margin-top: 20px;
}

.library-card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    overflow: hidden;
    cursor: pointer;
    transition: all 0.3s ease;
}

.library-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-hover);
}

.library-card-image {
    position: relative;
    height: 200px;
    overflow: hidden;
    background: var(--background);
}

.library-card-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.image-count {
    position: absolute;
    top: 12px;
    right: 12px;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 6px 12px;
    border-radius: 16px;
    font-size: 13px;
    font-weight: 600;
}

.library-card-content {
    padding: 16px;
    position: relative;
}

.library-card-user {
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 8px;
    font-size: 15px;
}

.library-card-caption {
    color: var(--text-secondary);
    font-size: 14px;
    line-height: 1.4;
    margin-bottom: 12px;
    min-height: 40px;
}

.library-card-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 13px;
    color: var(--text-secondary);
}

.library-card-likes {
    font-weight: 600;
}

.library-card-date {
    font-size: 12px;
}

.analyzed-badge {
    position: absolute;
    top: 16px;
    right: 16px;
    background: var(--success-color);
    color: white;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
}

@media (max-width: 768px) {
    body {
        padding: 10px;
    }

    main {
        padding: 24px;
    }

    h1 {
        font-size: 2rem;
    }

    .logo {
        flex-direction: column;
        gap: 10px;
    }

    .input-wrapper {
        flex-direction: column;
    }

    #fetchBtn {
        width: 100%;
    }

    .carousel-btn {
        width: 40px;
        height: 40px;
        font-size: 24px;
    }

    .carousel-btn.prev {
        left: 10px;
    }

    .carousel-btn.next {
        right: 10px;
    }

    .carousel-images {
        height: 400px;
    }

    .carousel-dots {
        bottom: 10px;
    }

    .dot {
        width: 10px;
        height: 10px;
    }

    .library-grid {
        grid-template-columns: 1fr;
    }

    .nav-tabs {
        gap: 4px;
    }

    .tab-btn {
        padding: 10px 16px;
        font-size: 14px;
    }
}

