/* ============================================================================
   ANES 2024 Ideological Clusters - Site Styles
   ============================================================================ */

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

:root {
    --color-primary: #2563eb;
    --color-primary-dark: #1e40af;
    --color-secondary: #64748b;
    --color-bg: #f8fafc;
    --color-surface: #ffffff;
    --color-border: #e2e8f0;
    --color-text: #1e293b;
    --color-text-muted: #64748b;
    --color-success: #10b981;
    --color-warning: #f59e0b;
    --color-danger: #ef4444;
    --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --font-mono: "SF Mono", Monaco, "Cascadia Code", "Roboto Mono", Consolas, monospace;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}

body {
    font-family: var(--font-sans);
    background-color: var(--color-bg);
    color: var(--color-text);
    line-height: 1.6;
    font-size: 16px;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
}

/* ============================================================================
   HEADER
   ============================================================================ */

.site-header {
    background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-primary-dark) 100%);
    color: white;
    padding: 40px 20px;
    text-align: center;
    box-shadow: var(--shadow-md);
}

.site-header h1 {
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: 10px;
}

.site-header .subtitle {
    font-size: 1.2rem;
    opacity: 0.9;
    margin-bottom: 20px;
}

#replay-tour-btn {
    margin-top: 10px;
}

/* ============================================================================
   TABS NAVIGATION
   ============================================================================ */

.tabs-nav {
    background: var(--color-surface);
    border-bottom: 2px solid var(--color-border);
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow-sm);
}

.tabs-nav .container {
    display: flex;
    gap: 0;
    overflow-x: auto;
    padding: 0;
}

.tab-btn {
    flex: 1;
    min-width: 150px;
    background: none;
    border: none;
    padding: 16px 20px;
    font-size: 1rem;
    font-weight: 500;
    color: var(--color-text-muted);
    cursor: pointer;
    transition: all 0.2s;
    border-bottom: 3px solid transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.tab-btn:hover {
    background: var(--color-bg);
    color: var(--color-text);
}

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

.tab-icon {
    font-size: 1.2rem;
}

/* ============================================================================
   MAIN CONTENT & TAB PANELS
   ============================================================================ */

main {
    padding: 40px 20px;
    min-height: calc(100vh - 400px);
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
    animation: fadeIn 0.3s ease-in;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.tab-content h2 {
    font-size: 2rem;
    margin-bottom: 10px;
    color: var(--color-text);
}

.intro {
    font-size: 1.1rem;
    color: var(--color-text-muted);
    margin-bottom: 30px;
}

/* ============================================================================
   BUTTONS
   ============================================================================ */

.btn {
    display: inline-block;
    padding: 10px 20px;
    font-size: 1rem;
    font-weight: 500;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
}

.btn-primary {
    background: var(--color-primary);
    color: white;
}

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

.btn-secondary {
    background: var(--color-secondary);
    color: white;
}

.btn-secondary:hover {
    background: #475569;
}

.btn-outline {
    background: transparent;
    color: white;
    border: 2px solid white;
}

.btn-outline:hover {
    background: rgba(255, 255, 255, 0.1);
}

.btn-large {
    padding: 14px 28px;
    font-size: 1.1rem;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ============================================================================
   EXPLORE TAB - VISUALIZATIONS
   ============================================================================ */

.viz-explanation {
    background: #e3f2fd;
    border-left: 4px solid var(--color-primary);
    border-radius: 6px;
    padding: 20px;
    margin-bottom: 25px;
}

.viz-explanation p {
    margin-bottom: 10px;
    font-weight: 600;
}

.viz-explanation ul {
    margin-left: 20px;
    line-height: 1.8;
}

.viz-explanation li {
    margin-bottom: 8px;
}

.dimension-questions {
    margin-top: 20px;
    padding: 15px;
    background: var(--color-bg);
    border-radius: 6px;
    border: 1px solid var(--color-border);
}

.question-item {
    margin-bottom: 12px;
    line-height: 1.6;
    font-size: 0.9rem;
}

.question-item:last-child {
    margin-bottom: 0;
}

.question-item strong {
    color: var(--color-primary);
    display: block;
    margin-bottom: 4px;
}

.viz-controls {
    margin-bottom: 20px;
    display: flex;
    gap: 10px;
}

.viz-toggle {
    padding: 10px 20px;
    background: var(--color-surface);
    border: 2px solid var(--color-border);
    border-radius: 6px;
    cursor: pointer;
    font-weight: 500;
    transition: all 0.2s;
}

.viz-toggle:hover {
    border-color: var(--color-primary);
}

.viz-toggle.active {
    background: var(--color-primary);
    color: white;
    border-color: var(--color-primary);
}

.visualization-container {
    background: var(--color-surface);
    border-radius: 8px;
    padding: 20px;
    box-shadow: var(--shadow-md);
    margin-bottom: 30px;
}

.axis-selectors {
    display: flex;
    gap: 20px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.axis-selectors label {
    font-weight: 500;
}

.axis-selectors select {
    padding: 8px 12px;
    border: 1px solid var(--color-border);
    border-radius: 4px;
    font-size: 1rem;
}

.plot-container {
    width: 100%;
    height: 600px;
    min-height: 400px;
}

.viz-note {
    margin-top: 10px;
    font-size: 0.9rem;
    color: var(--color-text-muted);
    font-style: italic;
}

.cluster-legend {
    background: var(--color-surface);
    border-radius: 8px;
    padding: 20px;
    box-shadow: var(--shadow-md);
}

.cluster-legend h3 {
    margin-bottom: 15px;
}

.cluster-legend-item {
    padding: 10px;
    margin-bottom: 10px;
    border-left: 4px solid var(--color-primary);
    background: var(--color-bg);
    border-radius: 4px;
}

/* ============================================================================
   QUIZ TAB
   ============================================================================ */

#quiz-container {
    max-width: 700px;
    margin: 0 auto;
}

.quiz-question {
    background: var(--color-surface);
    border-radius: 8px;
    padding: 25px;
    margin-bottom: 25px;
    box-shadow: var(--shadow-md);
}

.quiz-question h3 {
    margin-bottom: 15px;
    font-size: 1.2rem;
}

.quiz-options {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.quiz-option {
    display: flex;
    align-items: center;
    padding: 12px;
    background: var(--color-bg);
    border: 2px solid var(--color-border);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
}

.quiz-option:hover {
    border-color: var(--color-primary);
    background: #eff6ff;
}

.quiz-option input[type="radio"] {
    margin-right: 12px;
}

#submit-quiz {
    display: block;
    margin: 30px auto;
}

.quiz-results {
    max-width: 800px;
    margin: 30px auto;
    background: var(--color-surface);
    border-radius: 8px;
    padding: 30px;
    box-shadow: var(--shadow-md);
}

.quiz-results h3 {
    margin-bottom: 20px;
    color: var(--color-primary);
}

.cluster-card {
    background: var(--color-bg);
    border-radius: 6px;
    padding: 20px;
    margin-bottom: 15px;
    border-left: 4px solid var(--color-primary);
}

.cluster-card h4 {
    margin-bottom: 10px;
}

.cluster-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
    margin-top: 15px;
}

.stat-item {
    background: white;
    padding: 12px;
    border-radius: 4px;
    box-shadow: var(--shadow-sm);
}

.stat-item strong {
    display: block;
    font-size: 0.9rem;
    color: var(--color-text-muted);
    margin-bottom: 4px;
}

.stat-item span {
    font-size: 1.3rem;
    font-weight: 600;
    color: var(--color-primary);
}

/* ============================================================================
   STORY MODE
   ============================================================================ */

.story-container {
    max-width: 800px;
    margin: 30px auto;
    background: var(--color-surface);
    border-radius: 8px;
    padding: 40px;
    box-shadow: var(--shadow-md);
    min-height: 400px;
}

.story-step {
    display: none;
}

.story-step.active {
    display: block;
    animation: fadeIn 0.4s ease-in;
}

.story-step h3 {
    font-size: 1.8rem;
    margin-bottom: 15px;
    color: var(--color-primary);
}

.story-step p {
    font-size: 1.1rem;
    line-height: 1.8;
    color: var(--color-text);
}

.story-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 800px;
    margin: 20px auto 0;
}

#story-step-indicator {
    font-weight: 500;
    color: var(--color-text-muted);
}

/* ============================================================================
   PERSONA CHAT
   ============================================================================ */

.persona-selector {
    margin-bottom: 20px;
}

.persona-selector label {
    font-weight: 500;
    margin-right: 10px;
}

.persona-selector select {
    padding: 10px 14px;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    font-size: 1rem;
    min-width: 250px;
}

.persona-info {
    background: var(--color-surface);
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: var(--shadow-md);
}

.persona-info h3 {
    margin-bottom: 10px;
    color: var(--color-primary);
}

.cluster-distributions {
    background: var(--color-surface);
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: var(--shadow-md);
}

.cluster-distributions h4 {
    margin-bottom: 10px;
    color: var(--color-primary);
}

.distribution-note {
    color: var(--color-text-muted);
    font-size: 14px;
    margin-bottom: 15px;
}

.topic-selector {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    margin-bottom: 20px;
    padding: 15px;
    background: var(--color-bg);
    border-radius: 6px;
}

.topic-selector label {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 14px;
    cursor: pointer;
    user-select: none;
}

.topic-checkbox {
    cursor: pointer;
}

.distribution-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 20px;
}

.distribution-item {
    background: var(--color-bg);
    border-radius: 6px;
    padding: 15px;
    border: 1px solid var(--color-border);
}

.distribution-item h5 {
    color: var(--color-primary);
    margin-bottom: 5px;
    font-size: 16px;
}

.distribution-question {
    font-size: 12px;
    color: var(--color-text-muted);
    margin-bottom: 15px;
    line-height: 1.4;
}

.distribution-bar {
    position: relative;
    margin-bottom: 10px;
}

.distribution-track {
    height: 30px;
    background: linear-gradient(to right, #3b82f6 0%, #9ca3af 50%, #ef4444 100%);
    border-radius: 4px;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 10px;
}

.track-label {
    font-size: 11px;
    font-weight: 600;
    color: white;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.distribution-marker {
    position: absolute;
    top: -5px;
    width: 3px;
    height: 40px;
    background: #000;
    transform: translateX(-50%);
    box-shadow: 0 0 4px rgba(0, 0, 0, 0.5);
}

.distribution-value {
    font-size: 13px;
    color: var(--color-text);
    margin-top: 8px;
}

.chat-container {
    background: var(--color-surface);
    border-radius: 8px;
    box-shadow: var(--shadow-md);
    overflow: hidden;
}

.chat-messages {
    height: 400px;
    overflow-y: auto;
    padding: 20px;
    background: var(--color-bg);
    border-bottom: 1px solid var(--color-border);
}

.chat-message {
    margin-bottom: 15px;
    display: flex;
    gap: 10px;
}

.chat-message.user {
    justify-content: flex-end;
}

.message-bubble {
    max-width: 70%;
    padding: 12px 16px;
    border-radius: 12px;
    line-height: 1.5;
}

.chat-message.user .message-bubble {
    background: var(--color-primary);
    color: white;
    border-bottom-right-radius: 4px;
}

.chat-message.assistant .message-bubble {
    background: white;
    border: 1px solid var(--color-border);
    border-bottom-left-radius: 4px;
}

.evidence-badge {
    display: inline-block;
    padding: 3px 8px;
    font-size: 0.75rem;
    font-weight: 600;
    border-radius: 12px;
    margin-left: 6px;
    cursor: help;
}

.evidence-badge.observed {
    background: #10b981;
    color: white;
}

.evidence-badge.inferred_by_ml {
    background: #f59e0b;
    color: white;
}

.evidence-badge.fictional_extrapolation {
    background: #64748b;
    color: white;
}

.show-numbers-btn {
    font-size: 0.85rem;
    padding: 4px 10px;
    margin-top: 8px;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: 4px;
    cursor: pointer;
}

.show-numbers-btn:hover {
    background: var(--color-border);
}

.stance-details {
    max-width: 100%;
    font-size: 13px;
    line-height: 1.4;
}

.stance-details.hidden {
    display: none;
}

.chat-input-container {
    display: flex;
    padding: 15px;
    background: var(--color-surface);
}

.chat-input {
    flex: 1;
    padding: 12px 16px;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    font-size: 1rem;
    font-family: var(--font-sans);
}

.chat-input:focus {
    outline: none;
    border-color: var(--color-primary);
}

#chat-send {
    margin-left: 10px;
}

.llm-toggle {
    margin-top: 20px;
    padding: 15px;
    background: var(--color-bg);
    border-radius: 6px;
    font-size: 0.9rem;
}

.llm-key-input {
    display: block;
    width: 100%;
    margin-top: 10px;
    padding: 8px 12px;
    border: 1px solid var(--color-border);
    border-radius: 4px;
    font-family: var(--font-mono);
}

.llm-note {
    margin-top: 10px;
    font-size: 0.85rem;
    color: var(--color-text-secondary);
    font-style: italic;
}

.persona-profile {
    margin-top: 20px;
    padding: 15px;
    background: var(--color-bg);
    border-radius: 6px;
    border: 1px solid var(--color-border);
}

.persona-profile h4 {
    margin-top: 15px;
    margin-bottom: 10px;
    color: var(--color-primary);
    font-size: 1rem;
}

.persona-profile h4:first-of-type {
    margin-top: 0;
}

.stance-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.stance-list li {
    padding: 8px 0;
    border-bottom: 1px solid var(--color-border);
    font-size: 0.9rem;
}

.stance-list li:last-child {
    border-bottom: none;
}

.profile-note {
    margin-top: 15px;
    font-size: 0.85rem;
    color: var(--color-text-secondary);
}

.persona-stances-section {
    margin-top: 20px;
}

#toggle-stances {
    width: 100%;
    text-align: left;
    padding: 12px 16px;
    font-size: 1rem;
}

#stances-toggle-icon {
    display: inline-block;
    transition: transform 0.3s ease;
    margin-right: 8px;
}

#stances-toggle-icon.rotated {
    transform: rotate(-90deg);
}

.persona-stances {
    margin-top: 15px;
    padding: 20px;
    background: var(--color-surface);
    border-radius: 8px;
    box-shadow: var(--shadow-md);
    max-height: 600px;
    overflow-y: auto;
}

.persona-stances h4 {
    margin-top: 15px;
    margin-bottom: 10px;
    color: var(--color-primary);
    font-size: 1rem;
}

.persona-stances h4:first-of-type {
    margin-top: 0;
}

/* ============================================================================
   WELCOME TOUR OVERLAY
   ============================================================================ */

.overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.overlay.hidden {
    display: none;
}

.tour-modal {
    background: var(--color-surface);
    border-radius: 12px;
    padding: 40px;
    max-width: 600px;
    width: 90%;
    box-shadow: var(--shadow-lg);
    position: relative;
    animation: slideUp 0.3s ease-out;
}

@keyframes slideUp {
    from { transform: translateY(30px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.tour-close {
    position: absolute;
    top: 15px;
    right: 15px;
    background: none;
    border: none;
    font-size: 2rem;
    cursor: pointer;
    color: var(--color-text-muted);
    line-height: 1;
}

.tour-close:hover {
    color: var(--color-text);
}

.tour-modal h2 {
    margin-bottom: 20px;
    color: var(--color-primary);
}

.tour-modal p {
    font-size: 1.1rem;
    line-height: 1.7;
    margin-bottom: 30px;
}

.tour-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.tour-checkbox {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.9rem;
    color: var(--color-text-muted);
}

/* ============================================================================
   FOOTER
   ============================================================================ */

.site-footer {
    background: var(--color-surface);
    border-top: 1px solid var(--color-border);
    padding: 30px 20px;
    margin-top: 60px;
    text-align: center;
    color: var(--color-text-muted);
}

.site-footer p {
    margin-bottom: 10px;
}

.site-footer a {
    color: var(--color-primary);
    text-decoration: none;
}

.site-footer a:hover {
    text-decoration: underline;
}

.disclaimer {
    font-size: 0.85rem;
    font-style: italic;
}

/* ============================================================================
   UTILITY CLASSES
   ============================================================================ */

.hidden {
    display: none !important;
}

.text-center {
    text-align: center;
}

.mt-1 { margin-top: 10px; }
.mt-2 { margin-top: 20px; }
.mt-3 { margin-top: 30px; }
.mb-1 { margin-bottom: 10px; }
.mb-2 { margin-bottom: 20px; }
.mb-3 { margin-bottom: 30px; }

/* ============================================================================
   RESPONSIVE
   ============================================================================ */

/* ============================================================================
   ABOUT TAB
   ============================================================================ */

.about-section {
    background: var(--color-surface);
    border-radius: 8px;
    padding: 25px;
    margin-bottom: 25px;
    box-shadow: var(--shadow-md);
}

.about-section h3 {
    font-size: 1.5rem;
    margin-bottom: 15px;
    color: var(--color-primary);
}

.about-section p {
    margin-bottom: 15px;
    line-height: 1.7;
}

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

.about-list {
    margin-left: 20px;
    line-height: 1.8;
}

.about-list li {
    margin-bottom: 10px;
}

.about-section .btn {
    margin-right: 10px;
    margin-bottom: 10px;
}

/* ============================================================================
   RESPONSIVE
   ============================================================================ */

@media (max-width: 768px) {
    .site-header h1 {
        font-size: 1.8rem;
    }

    .tabs-nav .container {
        flex-direction: column;
    }

    .tab-btn {
        min-width: 100%;
    }

    .axis-selectors {
        flex-direction: column;
    }

    .plot-container {
        height: 400px;
    }

    .cluster-stats {
        grid-template-columns: 1fr;
    }

    .tour-modal {
        padding: 25px;
    }
}
