/* ===== Design Tokens ===== */
:root {
    --bg: #0F0F23;
    --bg-card: rgba(21, 21, 48, 0.7);
    --bg-card-hover: rgba(30, 30, 60, 0.8);
    --bg-input: rgba(15, 15, 40, 0.9);
    --text: #E6E6FA;
    --text-secondary: #8E8EA0;
    --text-muted: #5C5C7A;
    --primary: #8B5CF6;
    --primary-glow: rgba(139, 92, 246, 0.2);
    --secondary: #A78BFA;
    --accent: #C4B5FD;
    --green: #34D399;
    --green-soft: rgba(52, 211, 153, 0.12);
    --red: #F87171;
    --red-soft: rgba(248, 113, 113, 0.12);
    --orange: #FBBF24;
    --border: rgba(139, 92, 246, 0.1);
    --border-focus: rgba(139, 92, 246, 0.5);
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
    --radius: 14px;
    --radius-sm: 10px;
    --radius-xs: 6px;
    --font: 'Inter', system-ui, -apple-system, sans-serif;
    --mono: 'JetBrains Mono', 'Fira Code', monospace;
    --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

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

html {
    -webkit-font-smoothing: antialiased;
    scroll-behavior: smooth;
}

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
}

/* ===== Header ===== */
.header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: rgba(15, 15, 35, 0.85);
    backdrop-filter: blur(20px) saturate(1.6);
    border-bottom: 1px solid var(--border);
}

.header-inner {
    max-width: 1440px;
    margin: 0 auto;
    padding: 0.75rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.logo-icon {
    width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    border-radius: var(--radius-sm);
    font-size: 1.1rem;
}

.logo h1 {
    font-size: 1.15rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    background: linear-gradient(135deg, var(--text) 0%, var(--primary) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* ===== Buttons ===== */
.btn-secondary {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem 1rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-family: var(--font);
    font-size: 0.82rem;
    cursor: pointer;
    transition: var(--transition);
}

.btn-secondary:hover {
    border-color: var(--primary);
    color: var(--text);
}

.btn-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition);
}

.btn-icon:hover {
    border-color: var(--primary);
    color: var(--text);
}

/* ===== Main Layout ===== */
.main {
    max-width: 1440px;
    margin: 0 auto;
    padding: 1.25rem;
    display: grid;
    grid-template-columns: 1fr 380px;
    gap: 1.25rem;
    align-items: start;
}

/* ===== Glass Card ===== */
.glass-card {
    background: var(--bg-card);
    backdrop-filter: blur(12px);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    transition: var(--transition);
}

.glass-card:hover {
    border-color: rgba(139, 92, 246, 0.2);
}

.section-title {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 1rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* ===== Expression Card ===== */
.expression-card {
    margin-bottom: 1.25rem;
}

.expr-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 0.5rem;
    display: block;
}

.expr-row {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

.expr-input {
    flex: 1;
    padding: 0.75rem 1rem;
    background: var(--bg-input);
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--primary);
    font-family: var(--mono);
    font-size: 1.5rem;
    font-weight: 600;
    text-align: center;
    outline: none;
    transition: var(--transition);
    letter-spacing: 0.05em;
}

.expr-input:focus {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 4px var(--primary-glow);
}

.expr-human {
    font-size: 0.95rem;
    color: var(--accent);
    font-weight: 500;
}

.expr-valid {
    font-size: 0.78rem;
    margin-top: 0.3rem;
}

.expr-valid.valid {
    color: var(--green);
}

.expr-valid.invalid {
    color: var(--red);
}

/* ===== Pickers ===== */
.pickers-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 0.75rem;
    margin-bottom: 1.25rem;
}

.picker-card {
    padding: 1rem;
}

.picker-title {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 0.25rem;
}

.picker-field-val {
    font-family: var(--mono);
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 0.6rem;
}

.picker-type-tabs {
    display: flex;
    gap: 2px;
    margin-bottom: 0.75rem;
    background: var(--bg-input);
    border-radius: var(--radius-xs);
    padding: 2px;
}

.ptab {
    flex: 1;
    padding: 0.3rem 0.4rem;
    background: none;
    border: none;
    border-radius: 4px;
    font-family: var(--font);
    font-size: 0.68rem;
    color: var(--text-muted);
    cursor: pointer;
    transition: var(--transition);
}

.ptab:hover {
    color: var(--text-secondary);
}

.ptab.active {
    background: var(--primary);
    color: #fff;
    font-weight: 600;
}

.picker-body {
    min-height: 60px;
}

.picker-hint {
    font-size: 0.78rem;
    color: var(--text-muted);
}

.picker-grid-nums {
    display: flex;
    flex-wrap: wrap;
    gap: 3px;
}

.picker-num {
    width: 30px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    border: 1px solid transparent;
    background: var(--bg-input);
    font-family: var(--mono);
    font-size: 0.7rem;
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition);
}

.picker-num:hover {
    border-color: var(--primary);
    color: var(--text);
}

.picker-num.selected {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
    font-weight: 600;
}

.picker-range-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.picker-range-row label {
    font-size: 0.72rem;
    color: var(--text-muted);
    min-width: 35px;
}

.picker-range-input {
    width: 60px;
    padding: 0.3rem 0.5rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text);
    font-family: var(--mono);
    font-size: 0.8rem;
    outline: none;
}

.picker-range-input:focus {
    border-color: var(--border-focus);
}

.picker-step-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.picker-step-row span {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* ===== Presets ===== */
.presets-card {
    margin-bottom: 1.25rem;
}

.presets-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 0.5rem;
}

.preset-btn {
    padding: 0.6rem 0.75rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-xs);
    cursor: pointer;
    transition: var(--transition);
    text-align: left;
}

.preset-btn:hover {
    border-color: var(--primary);
    background: var(--primary-glow);
}

.preset-name {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 2px;
}

.preset-expr {
    font-family: var(--mono);
    font-size: 0.72rem;
    color: var(--primary);
}

/* ===== Results Panel ===== */
.results-panel {
    position: sticky;
    top: 70px;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

/* Next Runs */
.tz-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

.tz-row label {
    font-size: 0.78rem;
    color: var(--text-muted);
}

.tz-select {
    flex: 1;
    padding: 0.35rem 0.5rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-xs);
    color: var(--text);
    font-family: var(--font);
    font-size: 0.8rem;
    outline: none;
}

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

.runs-list {
    list-style: none;
    counter-reset: run;
}

.run-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0;
    border-bottom: 1px solid rgba(139, 92, 246, 0.06);
    font-size: 0.82rem;
}

.run-item:last-child {
    border-bottom: none;
}

.run-num {
    color: var(--text-muted);
    font-size: 0.7rem;
    min-width: 24px;
}

.run-date {
    color: var(--text);
    font-weight: 500;
    font-family: var(--mono);
    font-size: 0.78rem;
}

.run-rel {
    color: var(--text-muted);
    font-size: 0.72rem;
}

/* ===== Heatmap ===== */
.heatmap-grid {
    display: grid;
    grid-template-columns: repeat(24, 1fr);
    gap: 2px;
    margin-bottom: 0.75rem;
}

.heatmap-cell {
    aspect-ratio: 1;
    border-radius: 3px;
    position: relative;
    cursor: default;
}

.heatmap-cell[title]:hover {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}

.heatmap-row-label {
    grid-column: 1 / -1;
    font-size: 0.65rem;
    color: var(--text-muted);
    padding: 2px 0;
}

.heatmap-legend {
    display: flex;
    align-items: center;
    gap: 4px;
    justify-content: flex-end;
}

.heat-label {
    font-size: 0.65rem;
    color: var(--text-muted);
}

.heat-box {
    width: 14px;
    height: 14px;
    border-radius: 3px;
}

.h0 {
    background: rgba(139, 92, 246, 0.05);
}

.h1 {
    background: rgba(139, 92, 246, 0.2);
}

.h2 {
    background: rgba(139, 92, 246, 0.4);
}

.h3 {
    background: rgba(139, 92, 246, 0.65);
}

.h4 {
    background: var(--primary);
}

/* ===== Export ===== */
.export-tabs {
    display: flex;
    gap: 2px;
    margin-bottom: 0.75rem;
    background: var(--bg-input);
    border-radius: var(--radius-xs);
    padding: 2px;
}

.etab {
    flex: 1;
    padding: 0.4rem;
    background: none;
    border: none;
    border-radius: 4px;
    font-family: var(--font);
    font-size: 0.78rem;
    color: var(--text-muted);
    cursor: pointer;
    transition: var(--transition);
}

.etab:hover {
    color: var(--text-secondary);
}

.etab.active {
    background: var(--primary);
    color: #fff;
    font-weight: 600;
}

.export-output {
    padding: 1rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-xs);
    font-family: var(--mono);
    font-size: 0.78rem;
    color: var(--green);
    overflow-x: auto;
    white-space: pre-wrap;
    line-height: 1.6;
    max-height: 200px;
    overflow-y: auto;
}

/* ===== Compare ===== */
.compare-row {
    display: flex;
    gap: 0.75rem;
    align-items: flex-start;
}

.compare-col {
    flex: 1;
}

.compare-col label {
    font-size: 0.72rem;
    color: var(--text-muted);
    display: block;
    margin-bottom: 0.3rem;
}

.compare-input {
    width: 100%;
    padding: 0.5rem 0.6rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-xs);
    color: var(--primary);
    font-family: var(--mono);
    font-size: 0.85rem;
    font-weight: 600;
    outline: none;
    transition: var(--transition);
}

.compare-input:focus {
    border-color: var(--border-focus);
}

.compare-vs {
    font-size: 0.75rem;
    color: var(--text-muted);
    padding-top: 1.5rem;
    font-weight: 600;
}

.compare-desc {
    font-size: 0.75rem;
    color: var(--accent);
    margin-top: 0.35rem;
}

/* ===== Toast ===== */
.toast-container {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    z-index: 500;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.toast {
    padding: 0.6rem 1rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.82rem;
    color: var(--text);
    box-shadow: var(--shadow);
    animation: toastIn 0.3s ease, toastOut 0.3s ease 2s forwards;
}

@keyframes toastIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes toastOut {
    from {
        opacity: 1;
    }

    to {
        opacity: 0;
        transform: translateY(-10px);
    }
}

/* ===== Responsive ===== */
@media (max-width: 900px) {
    .main {
        grid-template-columns: 1fr;
    }

    .results-panel {
        position: static;
    }
}

@media (max-width: 640px) {
    .header-inner {
        padding: 0.6rem 1rem;
    }

    .logo h1 {
        font-size: 1rem;
    }

    .main {
        padding: 0.75rem;
    }

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

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