:root {
    --bg-color: #f8f9fa;
    --panel-bg-color: #ffffff;
    --text-color: #212529;
    --text-muted: #6c757d;
    --primary-color: #4A81B3;
    --secondary-color: #6c757d;
    --border-color: #dee2e6;
    --shadow: 0 2px 4px rgba(0,0,0,0.05);
    --shadow-lg: 0 4px 12px rgba(0,0,0,0.1);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    margin: 0;
    background-color: var(--bg-color);
    color: var(--text-color);
    line-height: 1.5;
}

/* ===========================================
   PAGE HEADER - Title Section
   =========================================== */
.page-header {
    text-align: center;
    padding: 1.5rem 1rem 1rem;
    background-color: var(--panel-bg-color);
    border-bottom: 1px solid var(--border-color);
}

.page-header h1 {
    margin: 0 0 0.25rem;
    font-size: 1.75rem;
    font-weight: 600;
    color: var(--text-color);
}

.page-header .subtitle {
    margin: 0;
    font-size: 0.9rem;
    color: var(--text-muted);
    line-height: 1.5;
}

.page-header .subtitle a {
    color: var(--primary-color);
    text-decoration: none;
}

.page-header .subtitle a:hover {
    text-decoration: underline;
}

/* ===========================================
   MAIN LAYOUT - Two Column
   =========================================== */
.main-container {
    display: flex;
    flex-wrap: wrap;
    padding: 1rem;
    gap: 1rem;
    max-width: 1200px;
    margin: 0 auto;
}

.left-column {
    flex: 1;
    min-width: 340px;
    max-width: 550px;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.right-column {
    flex: 1;
    min-width: 300px;
    max-width: 450px;
    position: sticky;
    top: 1rem;
    height: calc(100vh - 8rem);
    min-height: 300px; /* Ensure usable minimum */
    background-color: var(--panel-bg-color);
    border-radius: 12px;
    box-shadow: var(--shadow);
    display: none; /* Hidden on mobile */
    overflow: hidden; /* Prevent content overflow on small screens */
}

@media (min-width: 900px) {
    .right-column {
        display: block;
    }
    .visualization-panel-mobile {
        display: none !important;
    }
}

/* ===========================================
   UNIFIED LEFT PANEL
   =========================================== */
.unified-panel {
    background-color: var(--panel-bg-color);
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    padding: 1rem;
}

.panel-section {
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--border-color);
}

.panel-section:first-child {
    padding-top: 0;
}

.panel-section:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

.panel-section-compact {
    padding: 0.4rem 0;
    border-bottom: none;
}

/* ===========================================
   MOBILE VISUALIZATION
   =========================================== */
.visualization-panel-mobile {
    display: block;
    height: 280px;
    margin: 0 1rem 1rem;
    background-color: var(--panel-bg-color);
    border-radius: 12px;
    box-shadow: var(--shadow);
}

@media (min-width: 900px) {
    .visualization-panel-mobile {
        display: none;
    }
}

/* ===========================================
   THREE-PACK RECOMMENDATIONS
   =========================================== */
.three-pack-container {
    display: grid;
    grid-template-columns: 1fr 1.2fr 1fr;
    gap: 0.75rem;
    text-align: center;
    padding: 0.25rem 0.25rem 0.5rem;
    align-items: end;
}

.pack-option {
    display: flex;
    flex-direction: column;
    align-items: center;
    cursor: pointer;
    min-width: 0; /* Allows grid item to shrink below content size */
    padding: 8px; /* Space for bezel overflow */
}

/* The TV screen - 16:9 aspect ratio */
.pack-tv {
    position: relative;
    background: linear-gradient(to bottom, #1a1a1a 0%, #0d0d0d 100%);
    border-radius: 4px;
    transition: width 0.3s ease, height 0.3s ease, transform 0.3s ease;
    box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.5);
    overflow: hidden;
    aspect-ratio: 16 / 9;
}

/* Screen reflection */
.pack-tv::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 40%;
    background: linear-gradient(
        180deg,
        rgba(255, 255, 255, 0.15) 0%,
        rgba(255, 255, 255, 0.05) 50%,
        rgba(255, 255, 255, 0) 100%
    );
    pointer-events: none;
}

/* TV bezel */
.pack-tv-bezel {
    position: absolute;
    top: -5px;
    left: -5px;
    right: -5px;
    bottom: -5px;
    background: linear-gradient(to bottom, #3a3a3a 0%, #1a1a1a 50%, #0a0a0a 100%);
    border-radius: 6px;
    z-index: -1;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

/* Size displayed on the TV screen */
.pack-size {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 1.5rem;
    font-weight: 700;
    color: white;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.6);
    z-index: 1;
}

/* Label below the TV */
.pack-label {
    margin-top: 0.5rem;
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Hover state */
.pack-option:hover .pack-tv-bezel {
    background: linear-gradient(to bottom, #4a4a4a 0%, #2a2a2a 50%, #1a1a1a 100%);
}

/* Recommended styling - visually dominant */
.pack-option.recommended .pack-tv-bezel {
    background: linear-gradient(to bottom,
        hsl(211, 70%, 45%) 0%,
        hsl(211, 70%, 30%) 50%,
        hsl(211, 70%, 20%) 100%
    );
    box-shadow:
        0 0 0 2px hsl(211, 100%, 65%),
        0 0 20px rgba(0, 123, 255, 0.4),
        0 4px 16px rgba(0, 123, 255, 0.3);
    border-top: 1px solid hsl(211, 100%, 70%);
}

.pack-option.recommended .pack-tv {
    box-shadow:
        inset 0 0 10px rgba(0, 0, 0, 0.5),
        0 0 15px rgba(0, 123, 255, 0.2);
}

.pack-option.recommended .pack-label {
    color: var(--primary-color);
    font-weight: 700;
    font-size: 0.85rem;
}

/* Flash effect */
.pack-option.recommended.changed .pack-tv {
    background: linear-gradient(to bottom, #2a4a6a 0%, #1a3a5a 100%);
}

/* Selected state */
.pack-option.selected .pack-tv-bezel {
    background: linear-gradient(to bottom,
        hsl(211, 50%, 40%) 0%,
        hsl(211, 50%, 30%) 50%,
        hsl(211, 50%, 20%) 100%
    );
    box-shadow:
        0 0 0 2px hsl(211, 80%, 55%),
        0 4px 12px rgba(0, 123, 255, 0.25);
}

/* Max Size state - when bigger option equals recommended (98" ceiling) */
.pack-option.state-maxed .pack-label,
.pack-option.state-minned .pack-label {
    color: #d97706;
    font-weight: 600;
}

.pack-option.state-maxed .pack-tv-bezel,
.pack-option.state-minned .pack-tv-bezel {
    opacity: 0.7;
}

/* Hidden state - collapsed range (all sizes identical) */
.pack-option.state-hidden {
    visibility: hidden;
    pointer-events: none;
}

/* Only size state - when there's just one valid size */
.pack-option.state-only .pack-label {
    color: #d97706;
    font-weight: 600;
}


/* ===========================================
   CONTROLS
   =========================================== */
.control-row {
    margin-bottom: 0.75rem;
}

.control-row:last-child {
    margin-bottom: 0;
}

.distance-group {
    margin-bottom: 0;
    margin-top: 0.35rem;
}

.distance-group > label {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 0.35rem;
    display: block;
}

.distance-controls {
    display: flex;
    align-items: center;
    gap: 1rem;
}

#distance-slider {
    flex-grow: 1;
}

/* Mode Selector - Card Style */
.control-label {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 0.35rem;
    display: block;
    font-weight: 500;
}

.mode-caption {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-align: center;
    margin: 0.35rem 0 0;
}

/* Progressive reveal */
.progressive-hide {
    opacity: 0;
    transform: translateY(6px);
    pointer-events: none;
    transition: opacity 0.4s ease, transform 0.4s ease;
}
.progressive-hide.revealed {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

/* Mode section — tighter to slider */
#mode-section {
    padding-top: 0;
}

/* Mode selector — pill-style buttons (matches priorities page) */
.mode-selector {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    justify-content: center;
}

.mode-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: #f0f1f3;
    border: 1px solid #d5d7db;
    color: #2D2D2D;
    padding: 0.28rem 0.8rem;
    border-radius: 6px;
    font-size: 0.9rem;
    font-weight: 600;
    min-height: 2.6rem;
    cursor: pointer;
    user-select: none;
    text-align: center;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.mode-btn:hover {
    background: #e6e7ea;
    border-color: #c8cad0;
}

.mode-btn:focus-visible {
    outline: 3px solid #4A81B3;
    outline-offset: 2px;
}

.mode-btn.active {
    background: #4A81B3;
    border-color: #4A81B3;
    color: #fff;
}

/* Gaming Sub-options */
.submode-row {
    margin-top: 0.4rem;
    text-align: center;
}

.submode-selector {
    display: inline-flex;
    gap: 1px;
    background: #ccc;
    border-radius: 5px;
    padding: 2px;
    border: 1px solid #bbb;
}

.submode-btn {
    flex: 0 0 auto;
    padding: 0.2rem 0.65rem;
    border: none;
    border-radius: 3px;
    background-color: #e5e7eb;
    color: #555;
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
    text-align: center;
}

.submode-btn:hover {
    color: #2D2D2D;
    background-color: #ddd;
}

.submode-btn:focus-visible {
    outline: 3px solid #4A81B3;
    outline-offset: 2px;
}

.submode-btn.active {
    background: #4A81B3;
    color: #fff;
}

/* Units Toggle */
.units-toggle {
    display: flex;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    overflow: hidden;
    cursor: pointer;
    flex-shrink: 0;
}

.unit-option {
    padding: 0.25rem 0.6rem;
    font-size: 0.8rem;
    background-color: #e9ecef;
    color: var(--secondary-color);
    transition: all 0.2s ease-in-out;
    border: none;
    cursor: pointer;
    font-family: inherit;
    line-height: inherit;
}

.unit-option:focus-visible {
    outline: 3px solid #4A81B3;
    outline-offset: 2px;
}

.unit-option.active {
    background-color: var(--primary-color);
    color: white;
    font-weight: bold;
}

/* ===========================================
   EXPLANATION
   =========================================== */
#explanation-content {
    margin: 0;
}

#explanation-short {
    margin: 0 0 0.5rem;
    font-size: 0.95rem;
    color: var(--text-color);
    line-height: 1.5;
}

#explanation-bullets {
    padding-left: 1.1rem;
    margin: 0 0 0.25rem;
}

#explanation-bullets li {
    font-size: 0.85rem;
    margin-bottom: 0.2rem;
    color: var(--text-muted);
    line-height: 1.4;
}

.calculation-link {
    margin: 0.15rem 0 0;
    padding-left: 1.1rem;
    font-size: 0.8rem;
    color: var(--text-muted);
    text-align: left;
}

.link-button {
    background: none;
    border: none;
    color: var(--primary-color);
    text-decoration: underline;
    cursor: pointer;
    padding: 0;
    font-size: inherit;
}

/* ===========================================
   NOTES & INSPECTOR
   =========================================== */
/* Notes section inside unified panel */
#notes-container details {
    border: none;
    padding: 0;
}

#notes-container summary {
    font-weight: 500;
    cursor: pointer;
    font-size: 0.9rem;
    color: var(--text-muted);
    padding: 0.25rem 0;
}

#notes-container summary:hover {
    color: var(--text-color);
}

#notes-content ul {
    padding-left: 1.25rem;
    margin: 0.5rem 0 0;
}

#notes-content li {
    font-size: 0.85rem;
    margin-bottom: 0.5rem;
}

/* ===========================================
   NoUiSlider Customizations
   =========================================== */
.noUi-horizontal {
    height: 14px;
}

.noUi-handle {
    height: 22px;
    width: 22px;
    top: -5px;
    right: -11px;
    border-radius: 11px;
    background: var(--primary-color);
    box-shadow: none;
    border: none;
}

.noUi-connect {
    background: var(--primary-color);
}

.noUi-tooltip {
    bottom: 150%;
    transform: translate(-50%, 0);
    padding: 4px 10px;
    border-radius: 6px;
    background: var(--primary-color);
    color: white;
    font-size: 0.9rem;
    font-weight: 500;
}

/* ===========================================
   MODAL
   =========================================== */
.modal {
    position: fixed;
    z-index: 100;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0,0,0,0.4);
}

.modal-content {
    background-color: #fefefe;
    margin: 5% auto;
    padding: 1.5rem;
    border: 1px solid #888;
    width: 90%;
    max-width: 550px;
    border-radius: 8px;
    position: relative;
    max-height: 85vh;
    overflow-y: auto;
}

.modal-content h2 {
    margin: 0 0 1rem;
    font-size: 1.1rem;
    color: var(--text-color);
    padding-right: 2rem;
}

.modal-section {
    margin-bottom: 1rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.modal-section:last-child {
    margin-bottom: 0;
    padding-bottom: 0;
    border-bottom: none;
}

.modal-section h3 {
    margin: 0 0 0.5rem;
    font-size: 0.9rem;
    color: var(--primary-color);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.modal-section p {
    margin: 0.25rem 0;
    font-size: 0.9rem;
    line-height: 1.5;
}

.modal-formula {
    font-family: monospace;
    background: #f5f5f5;
    padding: 0.5rem;
    border-radius: 4px;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.modal-note {
    font-size: 0.85rem;
    color: var(--text-muted);
    font-style: italic;
}

.modal-close {
    color: #aaa;
    position: absolute;
    top: 10px;
    right: 20px;
    font-size: 28px;
    font-weight: bold;
    background: none;
    border: none;
    cursor: pointer;
}


/* ===========================================
   VISUALIZATION COMPONENT
   =========================================== */
.viz-wrapper {
    width: 100%;
    height: 100%;
    box-sizing: border-box;
    position: relative;
    padding: 1rem;
}

.viz-person, .viz-tv {
    position: absolute;
    display: flex;
    justify-content: center;
    align-items: center;
}

.viz-person {
    z-index: 1;
    top: 1rem;
    left: 50%;
    transform: translateX(-50%);
    /* Slightly transparent to read as reference, not competing object */
    opacity: 0.75;
}

.viz-person img {
    height: 100%;
    width: auto;
    /* Subtle filter to differentiate from TV's dark values */
    filter: brightness(0.9) contrast(0.95);
}

/* SVG fallback silhouette */
.viz-person-fallback {
    background: linear-gradient(to bottom, #666 0%, #666 20%, #888 20%, #888 25%, #666 25%, #666 100%);
    border-radius: 50% 50% 5% 5% / 20% 20% 5% 5%;
    opacity: 0.7;
}

/* TV Shell - outer wrapper with thin modern bezel */
.viz-tv-shell {
    position: absolute;
    z-index: 2;
    left: 50%;
    transform: translateX(-50%);
    transition: all 0.3s ease-in-out;
    /* Modern thin bezel - dark matte */
    background: linear-gradient(
        to bottom,
        #3a3a3a 0%,
        #2a2a2a 50%,
        #222222 100%
    );
    border-radius: 3px; /* Near-square, modern TV look */
    padding: 4px; /* Thin bezel */
    box-sizing: border-box;
    /* Subtle warm glow for separation from silhouette */
    box-shadow:
        /* Warm ambient glow - gentle separation */
        0 0 20px rgba(255, 200, 120, 0.12),
        0 0 40px rgba(255, 180, 100, 0.06),
        /* Light drop shadow */
        0 4px 12px rgba(0, 0, 0, 0.25);
    /* Subtle edge definition */
    border: 1px solid rgba(255, 255, 255, 0.08);
}

/* TV Screen - inner display area */
.viz-tv-screen {
    position: relative;
    width: 100%;
    height: 100%;
    /* Clean dark screen */
    background:
        /* Subtle vignette */
        radial-gradient(
            ellipse at center,
            transparent 0%,
            transparent 60%,
            rgba(0, 0, 0, 0.3) 100%
        ),
        /* Base screen - near black */
        linear-gradient(
            165deg,
            #1a1a1c 0%,
            #121214 50%,
            #0a0a0c 100%
        );
    border-radius: 2px;
    /* Subtle inner shadow */
    box-shadow:
        inset 0 0 20px rgba(0, 0, 0, 0.4),
        inset 0 1px 3px rgba(0, 0, 0, 0.6);
    overflow: hidden;
}

/* Subtle screen reflection */
.viz-tv-screen::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 50%;
    background: linear-gradient(
        to bottom,
        rgba(255, 255, 255, 0.06) 0%,
        rgba(255, 255, 255, 0.02) 30%,
        transparent 100%
    );
    pointer-events: none;
    z-index: 1;
}

.viz-tv-label {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: white;
    font-size: 4rem;
    font-weight: 700;
    /* Enhanced text shadow for better readability */
    text-shadow:
        0 2px 8px rgba(0, 0, 0, 0.9),
        0 0 20px rgba(0, 0, 0, 0.5);
    pointer-events: none;
    letter-spacing: -1px;
    z-index: 2; /* Above screen reflections */
}

/* ===========================================
   RESPONSIVE - Tablet
   =========================================== */
@media (max-width: 768px) {
    .three-pack-container {
        gap: 0.5rem;
    }

    .pack-tv {
        transform: scale(0.85);
        transform-origin: bottom center;
    }

    .pack-size {
        font-size: 1.35rem;
    }
}

/* ===========================================
   RESPONSIVE - Mobile
   =========================================== */
@media (max-width: 600px) {
    .page-header {
        padding: 0.75rem 1rem;
    }

    .page-header h1 {
        font-size: 1.3rem;
    }

    .page-header .subtitle {
        font-size: 0.8rem;
    }

    .main-container {
        padding: 0.5rem;
    }

    .unified-panel {
        padding: 0.5rem;
    }

    .panel-section {
        padding: 0.4rem 0;
    }

    .panel-section-compact {
        padding: 0.25rem 0;
    }

    .left-column {
        min-width: 100%;
        max-width: 100%;
    }

    .three-pack-container {
        gap: 0.25rem;
        padding: 0.1rem 0.25rem 0.35rem;
    }

    .pack-option {
        padding: 3px;
    }

    .pack-tv {
        transform: scale(0.7);
        transform-origin: bottom center;
    }

    .pack-size {
        font-size: 1.25rem;
    }

    .pack-option.recommended .pack-size {
        font-size: 1.5rem;
    }

    .distance-group > label {
        font-size: 0.75rem;
        margin-bottom: 0.25rem;
    }

    .mode-selector {
        gap: 0.35rem;
    }

    .mode-btn {
        padding: 0.25rem 0.6rem;
        font-size: 0.82rem;
        min-height: 2.2rem;
    }

    .submode-row {
        margin-top: 0.3rem;
    }

    .pack-label {
        font-size: 0.7rem;
        margin-top: 0.5rem;
    }

    .mode-controls {
        flex-direction: column;
        gap: 0.5rem;
    }

    #submode-group.hidden {
        display: none;
    }
}

/* ===========================================
   RESPONSIVE - Extra Small
   =========================================== */
@media (max-width: 380px) {
    .three-pack-container {
        gap: 0.125rem;
        padding: 0.5rem 0;
    }

    .pack-tv {
        transform: scale(0.55);
    }

    .pack-size {
        font-size: 1.1rem;
    }

    .pack-label {
        font-size: 0.65rem;
    }
}

/* General form elements */
.input-group {
    margin-bottom: 1rem;
}

.input-group label {
    display: block;
    font-weight: 500;
    margin-bottom: 0.5rem;
}

select {
    padding: 0.4rem 0.5rem;
}

details {
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 0.5rem;
}

summary {
    font-weight: 500;
    cursor: pointer;
}
