:root {
    --bg-app: #0f172a;
    --bg-card: #1e293b;
    --bg-input: #334155;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --accent-primary: #10b981;
    /* Emerald */
    --accent-secondary: #6366f1;
    /* Indigo */
    --accent-glow: rgba(16, 185, 129, 0.2);
    --border-color: #334155;

    --color-pi: #10b981;
    --color-tax: #3b82f6;
    --color-ins: #f59e0b;
    --color-hoa: #ef4444;
    --color-pmi: #8b5cf6;

    --font-family: 'Inter', sans-serif;
    --radius-lg: 16px;
    --radius-md: 8px;
    --radius-sm: 4px;
}

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

body {
    font-family: var(--font-family);
    background-color: var(--bg-app);
    color: var(--text-main);
    -webkit-font-smoothing: antialiased;
    padding-bottom: 40px;
    /* Space for scrolling */
}

/* Typography */
h1 {
    font-size: 1.25rem;
    font-weight: 600;
}

h2 {
    font-size: 1rem;
    font-weight: 500;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 1rem;
}

/* Layout */
.app-container {
    max-width: 600px;
    /* Mobile focused, constrained on desktop */
    margin: 0 auto;
    padding: 1rem;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

/* Main Output */
.main-output {
    background: var(--bg-card);
    padding: 1.5rem;
    border-radius: var(--radius-lg);
    text-align: center;
    margin-bottom: 1.5rem;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    position: sticky;
    top: 1rem;
    z-index: 100;
    backdrop-filter: blur(10px);
    /* For nice effect if we make bg transparent later */
}

.output-sublabel {
    color: var(--text-muted);
    font-size: 0.875rem;
}

.output-value-large {
    font-size: 3rem;
    font-weight: 700;
    color: var(--text-main);
    margin: 0.5rem 0;
    font-variant-numeric: tabular-nums;
}

/* Breakdown Bar */
.payment-breakdown-bar {
    display: flex;
    height: 8px;
    border-radius: 4px;
    overflow: hidden;
    margin: 1rem 0;
    background: var(--bg-input);
}

.bar-segment {
    height: 100%;
    transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

.segment-pi {
    background-color: var(--color-pi);
}

.segment-tax {
    background-color: var(--color-tax);
}

.segment-ins {
    background-color: var(--color-ins);
}

.segment-hoa {
    background-color: var(--color-hoa);
}

.segment-pmi {
    background-color: var(--color-pmi);
}

.segment-extra {
    background-color: var(--color-extra, #8b5cf6);
}

.breakdown-legend {
    display: flex;
    justify-content: center;
    gap: 1rem;
    flex-wrap: wrap;
    font-size: 0.75rem;
    color: var(--text-muted);
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 4px;
}

.dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.dot-pi {
    background-color: var(--color-pi);
}

.dot-tax {
    background-color: var(--color-tax);
}

.dot-ins {
    background-color: var(--color-ins);
}

.dot-pmi {
    background-color: var(--color-pmi);
}

/* Inputs */
.controls-section {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.card {
    background: var(--bg-card);
    padding: 1.5rem;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
}

.input-group {
    margin-bottom: 1.5rem;
}

.input-group:last-child {
    margin-bottom: 0;
}

.input-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-size: 0.875rem;
    color: var(--text-muted);
}

.label-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}

.input-wrapper {
    background: var(--bg-input);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    padding: 0 1rem;
    height: 48px;
    transition: 0.2s;
    border: 1px solid transparent;
}

.input-wrapper:focus-within {
    border-color: var(--accent-secondary);
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.2);
}

.input-wrapper input {
    background: transparent;
    border: none;
    color: var(--text-main);
    font-size: 1.125rem;
    font-family: inherit;
    width: 100%;
    outline: none;
}

.prefix,
.suffix {
    color: var(--text-muted);
}

.prefix {
    margin-right: 0.5rem;
}

.suffix {
    margin-left: 0.5rem;
}

/* Range Slider */
input[type=range] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    background: transparent;
    margin-top: 0.75rem;
}

input[type=range]::-webkit-slider-thumb {
    -webkit-appearance: none;
    height: 20px;
    width: 20px;
    border-radius: 50%;
    background: var(--text-main);
    cursor: pointer;
    margin-top: -8px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

input[type=range]::-webkit-slider-runnable-track {
    width: 100%;
    height: 4px;
    cursor: pointer;
    background: var(--bg-input);
    border-radius: 3px;
}

/* Input Validation Warning */
@keyframes flash-red {

    0%,
    100% {
        border-color: var(--border-color);
    }

    50% {
        border-color: var(--color-hoa);
        box-shadow: 0 0 0 2px rgba(239, 68, 68, 0.2);
    }
}

.input-warn {
    animation: flash-red 0.5s ease-in-out;
}

/* Firefox styles omitted for brevity but should be added for prod */

/* Mode Toggle */
.mode-selector {
    display: flex;
    background: var(--bg-card);
    padding: 4px;
    border-radius: var(--radius-lg);
    gap: 4px;
}

.mode-btn {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-muted);
    padding: 0.75rem 0.5rem;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    transition: 0.2s;
}

.mode-btn.active {
    background: var(--bg-input);
    color: var(--text-main);
}

/* Pills */
.toggle-pill {
    background: var(--bg-input);
    border-radius: var(--radius-sm);
    padding: 2px;
    display: flex;
}

.pill-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    padding: 2px 8px;
    border-radius: 2px;
    font-size: 0.75rem;
    cursor: pointer;
}

.pill-btn.active {
    background: var(--bg-card);
    color: var(--text-main);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

/* Radio Cards */
.term-options {
    display: flex;
    gap: 0.5rem;
}

.radio-card {
    flex: 1;
    position: relative;
    cursor: pointer;
}

.radio-card input {
    position: absolute;
    opacity: 0;
    cursor: pointer;
}

.radio-card span {
    display: block;
    text-align: center;
    padding: 0.75rem;
    background: var(--bg-input);
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    font-weight: 500;
    border: 1px solid transparent;
    transition: 0.2s;
}

.radio-card input:checked+span {
    background: var(--accent-secondary);
    color: white;
}

/* Helpers */
.hidden {
    display: none !important;
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
    margin-top: 1rem;
}

.stat-item {
    background: var(--bg-card);
    padding: 1rem;
    border-radius: var(--radius-lg);
    text-align: center;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.stat-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.stat-value {
    font-size: 0.875rem;
    font-weight: 600;
}

/* Chart */
.chart-container {
    padding: 1rem 0;
    transition: 0.3s;
    height: 300px;
    /* Specific height for Canvas */
    position: relative;
    width: 100%;
}

.chart-controls {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
}

.control-row {
    display: flex;
    justify-content: space-between;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
    flex-wrap: wrap;
}

/* Playground */
.playground-section {
    margin-top: 1.5rem;
    border-top: 4px solid var(--accent-secondary);
}

.playground-group {
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.playground-stats {
    display: flex;
    justify-content: space-between;
    margin-top: 1rem;
    background: var(--bg-input);
    padding: 0.75rem;
    border-radius: var(--radius-md);
    gap: 0.5rem;
}

.stat-compare {
    display: flex;
    flex-direction: column;
    text-align: center;
    flex: 1;
}

.stat-compare .muted {
    font-size: 0.7rem;
    color: var(--text-muted);
}

.stat-compare .highlight {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-main);
}

.stat-compare .positive {
    color: var(--accent-primary);
}

.playground-details summary {
    cursor: pointer;
    font-weight: 500;
    margin-bottom: 1rem;
    color: var(--accent-secondary);
}

.details-content {
    padding-left: 1rem;
    border-left: 2px solid var(--border-color);
}

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

.disabled {
    opacity: 0.5;
    pointer-events: none;
}

/* Help Text */
.mode-explainer {
    font-size: 0.8rem;
    color: var(--accent-secondary);
    margin-top: 0.5rem;
    padding: 0 0.5rem;
    text-align: center;
    min-height: 1.25em;
    /* Prevent jump */
}

.help-text-block {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 1rem;
    line-height: 1.4;
    font-style: italic;
}

/* Heatmap */
.heatmap-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    /* 6 cols for Down Payment steps */
    gap: 2px;
    margin-top: 1rem;
    overflow: hidden;
    /* Prevent scrollbars */
}

.heatmap-cell {
    background: var(--bg-input);
    padding: 8px 4px;
    text-align: center;
    font-size: 0.7rem;
    border-radius: 2px;
    cursor: pointer;
    transition: 0.2s;
    color: #fff;
    min-width: 50px;
}

.heatmap-cell:hover {
    transform: scale(1.1);
    z-index: 10;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.5);
}

.heatmap-legend {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-top: 0.5rem;
    font-size: 0.75rem;
    color: var(--text-muted);
}

.gradient-bar {
    flex: 1;
    height: 6px;
    background: linear-gradient(to right, #10b981, #f59e0b, #ef4444);
    border-radius: 3px;
}

/* Desktop Layout (Flex Columns) */
@media (min-width: 1024px) {
    .app-container {
        max-width: 1600px;
        /* FlexRow of 3 Columns */
    }

    .controls-section {
        display: flex;
        flex-direction: row;
        gap: 2rem;
        align-items: flex-start;
        /* Important so they don't stretch to max height */
    }

    /* Columns */
    .col-inputs,
    .col-results,
    .col-tools {
        flex: 1;
        display: flex;
        flex-direction: column;
        gap: 2rem;
    }

    /* Column 2 Specifics */
    /* .col-results { } - Removed empty block */

    .main-output {
        position: sticky;
        top: 2rem;
        z-index: 10;
        margin-bottom: 0;
        /* Ensure it doesn't push others down if we aren't careful, 
           but here it's just the top item in the flex col. 
        */
    }

    /* Adjustments for Density */
    .output-value-large {
        font-size: 2.5rem;
    }
}
