/* Premium 1D Wave Pulse Superposition Stylesheet */
:root {
    --bg-gradient: radial-gradient(circle at top left, #08090f, #101422 65%, #05060b);
    --panel-bg: rgba(18, 24, 40, 0.7);
    --panel-border: rgba(255, 255, 255, 0.18);
    --text: #f8fafc;
    --text-muted: #94a3b8;
    
    --primary: #00f2fe;
    --primary-hover: #00c6ff;
    --primary-glow: rgba(0, 242, 254, 0.35);
    
    --pulse-a: #f43f5e;
    --pulse-a-glow: rgba(244, 63, 94, 0.3);
    --pulse-b: #3b82f6;
    --pulse-b-glow: rgba(59, 130, 246, 0.3);
    --pulse-total: #a855f7;
    --pulse-total-glow: rgba(168, 85, 247, 0.4);
    
    --canvas-bg: #0b0d19;
}

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

body {
    background: var(--bg-gradient);
    color: var(--text);
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 16px;
    overflow: hidden;
}

.app-container {
    width: 100%;
    max-width: 1300px;
    height: 85vh;
    max-height: 850px;
    background: rgba(8, 10, 18, 0.4);
    border-radius: 24px;
    box-shadow: 0 30px 70px rgba(0, 0, 0, 0.8), 
                inset 0 1px 0 rgba(255, 255, 255, 0.05);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid var(--panel-border);
    backdrop-filter: blur(25px);
}

/* HEADER */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 24px;
    background: rgba(6, 8, 16, 0.6);
    border-bottom: 1px solid var(--panel-border);
    backdrop-filter: blur(10px);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo-icon {
    width: 28px;
    height: 28px;
    background: linear-gradient(135deg, #00f2fe, #4facfe);
    border-radius: 8px;
    box-shadow: 0 0 15px rgba(0, 242, 254, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    overflow: hidden;
}

.logo-icon::after {
    content: '';
    width: 100%;
    height: 2px;
    background: rgba(255, 255, 255, 0.8);
    box-shadow: 0 0 6px #fff;
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    animation: waveLogo 2s infinite ease-in-out;
}

@keyframes waveLogo {
    0%, 100% { transform: translateY(-50%) skewY(-15deg) translateY(-3px); }
    50% { transform: translateY(-50%) skewY(15deg) translateY(3px); }
}

h1 {
    font-family: 'Outfit', sans-serif;
    font-size: 1.25rem;
    font-weight: 700;
    background: linear-gradient(to right, #ffffff, #cbd5e1);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: -0.5px;
}

.nav-btn {
    background: rgba(255, 255, 255, 0.03);
    color: var(--text);
    border: 1px solid var(--panel-border);
    padding: 6px 12px;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.8rem;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.nav-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.15);
    transform: translateY(-1px);
}

.nav-btn svg {
    stroke-width: 2.5;
}

.nav-btn.info {
    background: rgba(0, 242, 254, 0.08);
    color: #38bdf8;
    border-color: rgba(0, 242, 254, 0.15);
}

.nav-btn.info:hover {
    background: rgba(0, 242, 254, 0.15);
    border-color: rgba(0, 242, 254, 0.35);
    box-shadow: 0 0 15px rgba(0, 242, 254, 0.2);
}

/* MAIN LAYOUT */
.sim-wrapper {
    flex: 1;
    display: grid;
    grid-template-columns: 1.55fr 1.45fr;
    gap: 12px;
    padding: 12px;
    height: 0; /* allows grid children to constrain height */
    overflow: hidden;
}

/* CANVAS SIMULATION SCREEN */
.sim-container {
    background: var(--canvas-bg);
    border-radius: 20px;
    border: 1px solid var(--panel-border);
    position: relative;
    overflow: hidden;
    box-shadow: inset 0 0 50px rgba(0, 0, 0, 0.8),
                0 15px 30px rgba(0, 0, 0, 0.4);
    height: 100%;
}

canvas#simCanvas {
    width: 100%;
    height: 100%;
    display: block;
}

.sim-overlay {
    position: absolute;
    top: 16px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(8, 10, 20, 0.85);
    padding: 6px 16px;
    border-radius: 30px;
    font-size: 0.78rem;
    font-weight: 500;
    color: var(--text-muted);
    backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.08);
    pointer-events: none;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.4);
    display: flex;
    align-items: center;
    gap: 8px;
    z-index: 5;
    white-space: nowrap;
}

.sim-overlay::before {
    content: '';
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: #a855f7;
    box-shadow: 0 0 8px #a855f7;
}

/* RIGHT COLUMN - NO SCROLL */
.right-column {
    display: flex;
    flex-direction: column;
    gap: 12px;
    height: 100%;
    overflow: hidden;
}

/* CONTROLS PANEL */
.controls-panel {
    background: var(--panel-bg);
    border-radius: 20px;
    border: 1px solid var(--panel-border);
    padding: 12px 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    overflow-y: auto; /* Prevent hard clipping, scroll on super-small views */
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    backdrop-filter: blur(20px);
}

/* Custom Scrollbar for Controls Panel */
.controls-panel::-webkit-scrollbar {
    width: 5px;
}
.controls-panel::-webkit-scrollbar-track {
    background: transparent;
}
.controls-panel::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 3px;
}
.controls-panel::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.12);
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1.5px solid rgba(255, 255, 255, 0.15);
    padding-bottom: 6px;
    margin-bottom: 2px;
}

.btn-toggle-panel {
    display: none;
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.15);
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-toggle-panel:hover {
    background: rgba(255, 255, 255, 0.15);
}

@media (max-width: 900px) {
    .btn-toggle-panel {
        display: block;
    }
    
    .controls-panel.collapsed {
        height: auto !important;
        max-height: none !important;
        padding-bottom: 12px;
    }
    
    .controls-panel.collapsed > *:not(.panel-header):not(.actions) {
        display: none !important;
    }
}

.panel-header h2 {
    font-family: 'Outfit', sans-serif;
    font-size: 1.05rem;
    font-weight: 600;
    color: #fff;
}

.badge {
    background: rgba(168, 85, 247, 0.1);
    color: #c084fc;
    padding: 2px 8px;
    border-radius: 6px;
    font-size: 0.7rem;
    font-weight: 700;
    border: 1px solid rgba(168, 85, 247, 0.2);
    letter-spacing: 0.5px;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.control-group-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.control-group-row label {
    font-size: 0.78rem;
    color: var(--text-muted);
    font-weight: 600;
}

.slider-label-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

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

.val-display {
    color: #fff;
    font-weight: 700;
    font-family: 'Outfit', sans-serif;
    font-size: 0.9rem;
    display: flex;
    align-items: baseline;
}

.unit {
    margin-left: 2px;
    font-size: 0.7rem;
    color: var(--text-muted);
    font-weight: 500;
}

/* Pulses Side-by-Side Wrapper */
.pulses-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

/* 1D Pulse UI Sub-panels */
.pulse-settings {
    background: rgba(0, 0, 0, 0.25);
    padding: 8px 12px;
    border-radius: 12px;
    border-left: 4px solid transparent;
    display: flex;
    flex-direction: column;
    gap: 5px;
    border: 1.5px solid rgba(255, 255, 255, 0.15);
    border-left-width: 4px;
}

.pulse-settings h3 {
    font-family: 'Outfit', sans-serif;
    font-size: 0.8rem;
    font-weight: 700;
    margin-bottom: 2px;
}

.pulse-settings.obj1-border {
    border-left-color: var(--pulse-a);
    box-shadow: inset 8px 0 16px rgba(244, 63, 94, 0.03);
}
.pulse-settings.obj1-border h3 {
    color: var(--pulse-a);
}

.pulse-settings.obj2-border {
    border-left-color: var(--pulse-b);
    box-shadow: inset 8px 0 16px rgba(59, 130, 246, 0.03);
}
.pulse-settings.obj2-border h3 {
    color: var(--pulse-b);
}

.mb-4 {
    margin-bottom: 4px;
}

/* Radio buttons styled as a button toggle */
.radio-group {
    display: flex;
    background: rgba(0, 0, 0, 0.4);
    padding: 2px;
    border-radius: 8px;
    border: 1.5px solid rgba(255, 255, 255, 0.15);
}

.radio-btn {
    background: transparent;
    color: var(--text-muted);
    border: none;
    padding: 4px 8px;
    border-radius: 6px;
    font-size: 0.72rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
}

.radio-btn:hover {
    color: #fff;
}

.radio-btn.active {
    background: rgba(255, 255, 255, 0.08);
    color: #00f2fe;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

/* Range Sliders */
input[type=range] {
    -webkit-appearance: none;
    width: 100%;
    background: transparent;
    touch-action: none;
}

input[type=range]:focus {
    outline: none;
}

input[type=range]::-webkit-slider-runnable-track {
    width: 100%;
    height: 4px;
    cursor: pointer;
    background: rgba(255, 255, 255, 0.06);
    border-radius: 2px;
}

input[type=range]::-webkit-slider-thumb {
    -webkit-appearance: none;
    height: 14px;
    width: 14px;
    border-radius: 50%;
    background: #ffffff;
    cursor: pointer;
    margin-top: -5px;
    border: 3px solid #00f2fe;
    transition: transform 0.1s ease;
}

input[type=range]::-webkit-slider-thumb:hover {
    transform: scale(1.2);
}

/* Specific thumb colors */
#amp-a-slider::-webkit-slider-thumb, #width-a-slider::-webkit-slider-thumb {
    border-color: var(--pulse-a);
}
#amp-b-slider::-webkit-slider-thumb, #width-b-slider::-webkit-slider-thumb {
    border-color: var(--pulse-b);
}

/* BUTTONS AND ACTIONS */
.actions {
    display: flex;
    gap: 6px;
    margin-top: 2px;
}

.action-btn {
    flex: 1;
    padding: 8px 10px;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.78rem;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 4px;
    font-family: 'Inter', sans-serif;
}

.action-btn.play {
    background: linear-gradient(135deg, #00f2fe, #00c6ff);
    color: #050811;
    font-weight: 700;
    box-shadow: 0 4px 10px var(--primary-glow);
}

.action-btn.play:hover {
    background: linear-gradient(135deg, #00c6ff, #0072ff);
    transform: translateY(-1px);
}

.action-btn.play.paused {
    background: linear-gradient(135deg, #f59e0b, #d97706);
    color: white;
    box-shadow: 0 4px 10px rgba(245, 158, 11, 0.25);
}

.action-btn.reset {
    background: rgba(255, 255, 255, 0.03);
    color: var(--text);
    border: 1px solid var(--panel-border);
}

.action-btn.reset:hover {
    background: rgba(255, 255, 255, 0.07);
    border-color: rgba(255, 255, 255, 0.12);
}

/* ANALYSIS CONTAINER */
.chart-container {
    background: var(--panel-bg);
    border-radius: 20px;
    border: 1px solid var(--panel-border);
    padding: 10px 16px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    overflow: hidden;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    backdrop-filter: blur(20px);
}

.chart-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    padding-bottom: 4px;
}

.chart-header h3 {
    font-family: 'Outfit', sans-serif;
    font-size: 0.8rem;
    font-weight: 600;
    color: #fff;
}

.analysis-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
}

.val-card {
    background: rgba(0, 0, 0, 0.25);
    border: 1.5px solid rgba(255, 255, 255, 0.15);
    border-radius: 10px;
    padding: 6px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    gap: 1px;
}

.val-card.card-a { border-top: 3.5px solid var(--pulse-a); }
.val-card.card-b { border-top: 3.5px solid var(--pulse-b); }
.val-card.card-total { border-top: 3.5px solid var(--pulse-total); }

.card-label {
    font-size: 0.58rem;
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    white-space: nowrap;
}

.card-val {
    font-family: 'Outfit', sans-serif;
    font-size: 0.95rem;
    font-weight: 700;
    color: #fff;
}

.card-val .unit {
    font-size: 0.65rem;
    font-weight: 500;
}

.val-card.card-a .card-val { color: #fecdd3; text-shadow: 0 0 8px var(--pulse-a-glow); }
.val-card.card-b .card-val { color: #bfdbfe; text-shadow: 0 0 8px var(--pulse-b-glow); }
.val-card.card-total .card-val { color: #f5d0fe; text-shadow: 0 0 10px var(--pulse-total-glow); }

.stats-box.single-col {
    display: flex;
    justify-content: center;
    background: rgba(0, 0, 0, 0.15);
    border: 1.5px solid rgba(255, 255, 255, 0.15);
    border-radius: 10px;
    padding: 6px 12px;
}

.stat-banner {
    display: flex;
    align-items: center;
    gap: 8px;
}

.stat-banner .stat-label {
    font-size: 0.68rem;
    color: var(--text-muted);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stat-banner .stat-value {
    font-family: 'Outfit', sans-serif;
    font-size: 0.9rem;
    font-weight: 700;
    color: #fff;
}

/* INFO MODAL */
.modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(3, 4, 8, 0.75);
    backdrop-filter: blur(8px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    opacity: 1;
    transition: opacity 0.25s ease;
}

.modal-backdrop.hidden {
    opacity: 0;
    pointer-events: none;
}

.modal-content {
    background: rgba(15, 20, 35, 0.96);
    border: 1.5px solid rgba(255, 255, 255, 0.18);
    border-radius: 20px;
    width: 90%;
    max-width: 480px;
    padding: 20px 24px;
    box-shadow: 0 30px 60px rgba(0, 0, 0, 0.7);
    transform: translateY(0) scale(1);
    transition: transform 0.25s ease;
    backdrop-filter: blur(10px);
}

.modal-backdrop.hidden .modal-content {
    transform: translateY(20px) scale(0.96);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 14px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    padding-bottom: 8px;
}

.modal-header h2 {
    font-family: 'Outfit', sans-serif;
    font-size: 1.15rem;
    font-weight: 700;
    color: #fff;
}

.close-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 1.25rem;
    cursor: pointer;
    line-height: 1;
}

.close-btn:hover {
    color: #fff;
}

.modal-body {
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-height: 50vh;
    overflow-y: auto;
}

.modal-body h3 {
    font-family: 'Outfit', sans-serif;
    color: #38bdf8;
    font-size: 0.95rem;
    margin-bottom: 2px;
    font-weight: 600;
}

.modal-body p {
    color: var(--text-muted);
    font-size: 0.8rem;
    line-height: 1.5;
}

.modal-body hr {
    border: 0;
    height: 1px;
    background: rgba(255, 255, 255, 0.06);
}

.modal-body code {
    background: rgba(0, 0, 0, 0.3);
    padding: 1px 4px;
    border-radius: 3px;
    font-family: monospace;
    color: #00f2fe;
    font-size: 0.8rem;
}

/* RESPONSIVE SCALING */
@media (max-width: 900px) {
    body {
        overflow-y: auto;
        padding: 8px;
    }
    
    .app-container {
        height: auto;
        max-height: none;
    }
    
    .sim-wrapper {
        grid-template-columns: 1fr;
        grid-template-rows: auto auto;
        height: auto;
        padding: 8px;
        gap: 8px;
    }
    
    .sim-container {
        height: 280px;
    }
    
    .right-column {
        height: auto;
    }
    
    .controls-panel {
        max-height: none;
    }
    
    .pulses-container {
        grid-template-columns: 1fr; /* Stack vertically on small mobile views */
    }
    .sim-overlay {
        display: none !important;
    }
}

@media (max-width: 600px) {
    header {
        flex-wrap: wrap;
        gap: 8px;
        padding: 8px 12px;
    }
    .header-left {
        width: 100%;
        justify-content: space-between;
    }
    .nav-btn.info {
        width: 100%;
        justify-content: center;
        margin-top: 4px;
    }
    .modal-content {
        max-height: 85vh;
        display: flex;
        flex-direction: column;
        padding: 16px 20px;
    }
    .modal-body {
        overflow-y: auto;
        padding-right: 4px;
    }
}

@media (max-width: 480px) {
    .control-group-row {
        flex-direction: column;
        align-items: stretch;
        gap: 6px;
    }
    .radio-group {
        width: 100%;
        display: flex;
    }
    .radio-btn {
        flex: 1;
        text-align: center;
        padding: 6px 2px;
        font-size: 0.7rem;
    }
}

