/* ==========================================================================
   Design Tokens
   ========================================================================== */

:root {
    --bg: #f5f5f5;
    --secondary: #2b2b2b;
    --accent: #a1b9ed;

    /* Heatmap colors — green default, overridden by settings.js */
    --level-0: #e2e2da;
    --level-1: #9be9a8;
    --level-2: #40c463;
    --level-3: #30a14e;
    --level-4: #216e39;

    --cell-size: 13px;
    --cell-gap: 3px;
    --radius: 3px;
    --font: 'Inter', sans-serif;
}

/* ==========================================================================
   Reset & Base
   ========================================================================== */

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

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--secondary);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 64px 24px;
    -webkit-font-smoothing: antialiased;
}

#app {
    width: 100%;
    margin: auto 0;
    display: flex;
    flex-direction: column;
    align-items: center;
}

code {
    font-family: var(--font);
    background: var(--level-0);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.9em;
}

/* ==========================================================================
   Visibility
   ========================================================================== */

.hidden {
    display: none !important;
}

/* ==========================================================================
   Header
   ========================================================================== */

#header {
    text-align: center;
    margin-bottom: 48px;
}

#header h1 {
    font-size: 1.75rem;
    font-weight: 700;
    letter-spacing: -0.03em;
    margin-bottom: 8px;
}

.subtitle {
    font-size: 0.95rem;
    color: var(--secondary);
    opacity: 0.6;
}

/* ==========================================================================
   Upload Zone
   ========================================================================== */

#upload-section {
    width: 100%;
    max-width: 480px;
}

#drop-zone {
    border: 2px dashed var(--secondary);
    border-radius: 16px;
    padding: 56px 32px;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.2s ease, background 0.2s ease;
    opacity: 0.7;
}

#drop-zone:hover,
#drop-zone.drag-over {
    opacity: 1;
    border-color: var(--accent);
}

.drop-icon {
    margin-bottom: 16px;
    opacity: 0.5;
}

.drop-text {
    font-size: 1rem;
    font-weight: 500;
    margin-bottom: 6px;
}

.drop-hint {
    font-size: 0.82rem;
    opacity: 0.45;
}

/* ==========================================================================
   Loading
   ========================================================================== */

#loading-section {
    text-align: center;
    padding: 64px 0;
}

.spinner {
    width: 28px;
    height: 28px;
    border: 2.5px solid var(--level-0);
    border-top-color: var(--secondary);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    margin: 0 auto 16px;
}

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

.loading-text {
    font-size: 0.9rem;
    opacity: 0.5;
}

/* ==========================================================================
   FAQ Section
   ========================================================================== */

#faq-section {
    width: 100%;
    max-width: 640px;
    margin: 64px auto 0;
}

.faq-title {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 24px;
    text-align: center;
    letter-spacing: -0.02em;
}

.faq-accordion {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.faq-item {
    border: 1px solid rgba(43, 43, 43, 0.08);
    border-radius: 12px;
    background: rgba(43, 43, 43, 0.02);
    overflow: hidden;
    transition: background 0.2s ease;
}

.faq-item:hover {
    background: rgba(43, 43, 43, 0.04);
}

.faq-question {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 20px;
    background: transparent;
    border: none;
    cursor: pointer;
    font-family: var(--font);
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--secondary);
    text-align: left;
}

.faq-icon {
    opacity: 0.3;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.2s ease;
}

.faq-item.active .faq-icon {
    transform: rotate(180deg);
    opacity: 1;
}

.faq-answer {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s cubic-bezier(0.4, 0, 0.2, 1), padding 0.3s ease;
    padding: 0 20px;
    font-size: 0.9rem;
    line-height: 1.6;
    opacity: 0.7;
}

.faq-item.active .faq-answer {
    max-height: 500px;
    padding-bottom: 20px;
}

.faq-answer ol {
    margin-top: 12px;
    margin-left: 18px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.faq-answer a {
    color: var(--accent);
    text-decoration: underline;
    text-underline-offset: 2px;
}

/* ==========================================================================
   Error
   ========================================================================== */

#error-section {
    text-align: center;
    padding: 48px 0;
    max-width: 420px;
}

#error-message {
    font-size: 0.92rem;
    margin-bottom: 20px;
    line-height: 1.6;
    opacity: 0.75;
}

#retry-btn,
#reset-btn {
    font-family: var(--font);
    font-size: 0.85rem;
    font-weight: 500;
    padding: 10px 24px;
    border: 1.5px solid var(--secondary);
    border-radius: 8px;
    background: transparent;
    color: var(--secondary);
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
}

#retry-btn:hover,
#reset-btn:hover {
    background: var(--secondary);
    color: var(--bg);
}

/* ==========================================================================
   Result Section
   ========================================================================== */

#result-section {
    width: 100%;
    max-width: 1040px;
    animation: fadeIn 0.4s ease;
}

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

/* ==========================================================================
   Stats
   ========================================================================== */

#stats-container {
    display: flex;
    justify-content: center;
    gap: 40px;
    margin-top: 32px;
    margin-bottom: 32px;
    flex-wrap: wrap;
}

.stat {
    text-align: center;
}

.stat-value {
    display: block;
    font-size: 1.6rem;
    font-weight: 700;
    letter-spacing: -0.03em;
    line-height: 1.2;
}

.stat-label {
    display: block;
    font-size: 0.78rem;
    opacity: 0.45;
    margin-top: 2px;
}

/* ==========================================================================
   Tab Bar
   ========================================================================== */

#tab-bar {
    display: flex;
    align-items: center;
    gap: 4px;
    margin: 0 auto 20px; /* Centered */
    max-width: 880px;    /* Constrain the tab bar to trace the bounds of the heatmap */
    border-bottom: 1.5px solid rgba(43, 43, 43, 0.1);
    padding-bottom: 0;
}

.tab-btn {
    font-family: var(--font);
    font-size: 0.82rem;
    font-weight: 500;
    padding: 10px 20px;
    border: none;
    background: transparent;
    color: var(--secondary);
    opacity: 0.45;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: opacity 0.15s ease, border-color 0.15s ease;
    margin-bottom: -1.5px;
}

.tab-btn:hover {
    opacity: 0.7;
}

.tab-btn.active {
    opacity: 1;
    border-bottom-color: var(--secondary);
}

.icon-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 8px;
    border-radius: 6px;
    color: var(--secondary);
    opacity: 0.4;
    transition: opacity 0.15s ease, background 0.15s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-left: auto;
}

.icon-btn:hover {
    opacity: 0.8;
    background: rgba(43, 43, 43, 0.06);
}

/* ==========================================================================
   Tab Panels
   ========================================================================== */

.tab-panel {
    min-height: 160px;
}

/* ==========================================================================
   Prompts
   ========================================================================== */

.prompts-layout {
    display: flex;
    gap: 32px;
    width: 100%;
}

.prompts-viz-container {
    flex: 1;
    min-width: 0;
    background: var(--bg);
    border: 1.5px solid rgba(43, 43, 43, 0.08);
    border-radius: 12px;
    padding: 24px;
    min-height: 480px; /* Force minimum height for chart */
}

.prompts-list-container {
    flex: 1;
    min-width: 0;
    background: var(--bg);
    border: 1.5px solid rgba(43, 43, 43, 0.08);
    border-radius: 12px;
    padding: 24px;
    display: flex;
    flex-direction: column;
    max-height: 480px;
}

.prompts-title {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 20px;
    letter-spacing: -0.02em;
}

#prompts-list {
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding-right: 8px;
}

#prompts-list::-webkit-scrollbar {
    width: 6px;
}
#prompts-list::-webkit-scrollbar-thumb {
    background: rgba(43, 43, 43, 0.15);
    border-radius: 4px;
}
#prompts-list::-webkit-scrollbar-track {
    background: transparent;
}

.prompt-item {
    font-size: 0.85rem;
    line-height: 1.4;
    padding: 12px;
    background: rgba(43, 43, 43, 0.04);
    border-radius: 8px;
    color: var(--secondary);
}

/* ==========================================================================
   Heatmap
   ========================================================================== */

#heatmap-container {
    display: flex;
    justify-content: center;
    overflow: visible;
    margin-bottom: 16px;
    padding: 12px 0;
}

.heatmap-wrapper {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    width: fit-content;
    margin: 0 auto;
}

.heatmap-months {
    display: flex;
    margin-bottom: 6px;
}

.month-labels {
    position: relative;
    height: 18px;
}

.month-label {
    position: absolute;
    font-size: 0.72rem;
    font-weight: 500;
    opacity: 0.5;
    white-space: nowrap;
}

.heatmap-body {
    display: flex;
    gap: 6px;
}

.day-labels {
    display: grid;
    grid-template-rows: repeat(7, var(--cell-size));
    gap: var(--cell-gap);
    align-items: center;
    width: 30px;
    flex-shrink: 0;
}

.day-label {
    font-size: 0.68rem;
    font-weight: 500;
    opacity: 0.4;
    line-height: var(--cell-size);
    text-align: right;
    padding-right: 4px;
}

.heatmap-grid {
    display: grid;
    grid-template-rows: repeat(7, var(--cell-size));
    grid-auto-flow: column;
    grid-auto-columns: var(--cell-size);
    gap: var(--cell-gap);
}

/* Cell */
.cell {
    width: var(--cell-size);
    height: var(--cell-size);
    border-radius: var(--radius);
    position: relative;
    cursor: crosshair;
    transition: outline 0.1s ease;
}

.cell:hover {
    outline: 1.5px solid var(--secondary);
    outline-offset: -1px;
}

.level-0 { background: var(--level-0); }
.level-1 { background: var(--level-1); }
.level-2 { background: var(--level-2); }
.level-3 { background: var(--level-3); }
.level-4 { background: var(--level-4); }

/* Tooltip */
.cell::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    background: var(--secondary);
    color: var(--bg);
    padding: 5px 10px;
    border-radius: 6px;
    font-size: 0.72rem;
    font-weight: 500;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.12s ease;
    z-index: 10;
}

.cell:hover::after {
    opacity: 1;
}

/* ==========================================================================
   Legend
   ========================================================================== */

#legend-container {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 32px;
}

.legend {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.72rem;
    opacity: 0.5;
}

.legend .cell {
    cursor: default;
}

.legend .cell:hover {
    outline: none;
}

.legend .cell::after {
    display: none;
}

.legend-label {
    margin: 0 4px;
}

/* ==========================================================================
   3D View
   ========================================================================== */

#three-container {
    width: 100%;
    height: 480px;
    border-radius: 12px;
    overflow: hidden;
    margin-bottom: 32px;
    border: 1.5px solid rgba(43, 43, 43, 0.08);
}

#three-container canvas {
    display: block;
    width: 100% !important;
    height: 100% !important;
}

#three-tooltip {
    position: absolute;
    background: var(--secondary);
    color: var(--bg);
    padding: 5px 10px;
    border-radius: 6px;
    font-size: 0.72rem;
    font-weight: 500;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.12s ease;
    z-index: 200;
    white-space: nowrap;
}

/* ==========================================================================
   Settings Modal
   ========================================================================== */

#settings-overlay {
    position: fixed;
    inset: 0;
    background: rgba(43, 43, 43, 0.25);
    z-index: 100;
}

#settings-panel {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--bg);
    border: 1.5px solid rgba(43, 43, 43, 0.12);
    border-radius: 16px;
    padding: 28px 32px;
    z-index: 101;
    min-width: 320px;
    box-shadow: 0 12px 40px rgba(43, 43, 43, 0.12);
}

.settings-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
}

.settings-row {
    margin-bottom: 24px;
}

.settings-title {
    font-size: 1.1rem;
    font-weight: 600;
    letter-spacing: -0.02em;
}

.settings-section-label {
    font-size: 0.78rem;
    font-weight: 500;
    opacity: 0.5;
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.settings-select {
    width: 100%;
    padding: 8px 12px;
    font-family: var(--font);
    font-size: 0.9rem;
    border: 1.5px solid rgba(43, 43, 43, 0.2);
    border-radius: 8px;
    background: var(--bg);
    color: var(--secondary);
    cursor: pointer;
    outline: none;
    transition: border-color 0.15s ease;
}

.settings-select:hover {
    border-color: rgba(43, 43, 43, 0.4);
}

.settings-select:focus {
    border-color: var(--secondary);
}

#swatches-container {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.swatch-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

.color-swatch {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    border: 2.5px solid transparent;
    cursor: pointer;
    transition: border-color 0.15s ease, transform 0.15s ease;
}

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

.color-swatch.active {
    border-color: var(--secondary);
}

.swatch-label {
    font-size: 0.68rem;
    font-weight: 500;
    opacity: 0.5;
}

/* ==========================================================================
   Responsive
   ========================================================================== */

@media (max-width: 600px) {
    body {
        padding: 40px 16px;
    }

    #header h1 {
        font-size: 1.35rem;
    }

    #stats-container {
        gap: 24px;
    }

    .stat-value {
        font-size: 1.3rem;
    }

    #drop-zone {
        padding: 40px 20px;
    }

    #three-container {
        height: 320px;
    }

    #settings-panel {
        min-width: 0;
        width: calc(100% - 32px);
        padding: 24px;
    }

    .prompts-layout {
        flex-direction: column;
    }
}

.github-star-btn:hover {
    opacity: 1 !important;
    background: rgba(43,43,43,0.05) !important;
}
