/* --- Design System --- */
:root {
    --brand-green: #059669;
    --brand-orange: #f59e0b;
    --phase-u: #3b82f6;
    --phase-v: #10b981;
    --phase-w: #ef4444;
    --bg-dark: #0f172a;
    --text-main: #334155;
    --text-light: #f8fafc;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
    font-family: 'Noto Sans JP', 'Outfit', sans-serif;
    background-color: #f1f5f9;
    color: var(--text-main);
    line-height: 1.6;
}

.container {
    max-width: 1280px;
    margin: 0 auto;
    padding: 20px;
}

/* --- Header --- */
.main-header {
    background-color: var(--brand-green);
    color: white;
    padding: 16px 0;
    box-shadow: var(--shadow-md);
    margin-bottom: 24px;
}

.main-header-inner {
    max-width: 1280px;
    margin: 0 auto;
    padding: 0 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

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

.brand-logo {
    font-size: 1.4rem;
    font-weight: 700;
}

.title-icon {
    width: 28px;
    height: 28px;
    flex-shrink: 0;
}

/* --- Usage Guide (Info Section) --- */
.info-section {
    background: white;
    border-radius: 12px;
    margin-bottom: 24px;
    padding: 0;
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    border: 1px solid #e2e8f0;
}

.info-header {
    padding: 16px 20px;
    background: #f8fafc;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: var(--transition);
}

.info-header:hover { background: #f1f5f9; }

.info-header h2 {
    margin: 0;
    font-size: 1rem;
    color: var(--brand-green);
    border: none;
    padding: 0;
    display: flex;
    align-items: center;
    gap: 10px;
}

.toggle-icon {
    width: 24px;
    height: 24px;
    transition: transform 0.3s ease;
    fill: #64748b;
}

.info-section.collapsed .info-content { display: none; }
.info-section.collapsed .toggle-icon { transform: rotate(-90deg); }

.info-content {
    padding: 20px;
    border-top: 1px solid #e2e8f0;
    font-size: 0.95rem;
    color: var(--text-main);
}

.btn-home {
    color: white;
    text-decoration: none;
    font-weight: 600;
    padding: 6px 16px;
    border: 1px solid rgba(255,255,255,0.4);
    border-radius: 20px;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: var(--transition);
}

.btn-home:hover {
    background: rgba(255,255,255,0.1);
}

/* --- Simulation Area (Main Layout) --- */
.card {
    background: white;
    border-radius: 16px;
    padding: 24px;
    box-shadow: var(--shadow-md);
    margin-bottom: 24px;
}

.card-header, .card-header-inline {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
    border-bottom: 2px solid #e2e8f0;
    padding-bottom: 12px;
}

.card h2 {
    margin: 0;
    font-size: 1.25rem;
    color: var(--brand-green);
    border: none;
    padding: 0;
    display: flex;
    align-items: center;
    gap: 12px;
}

.section-number {
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--brand-green);
    color: white;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    font-size: 0.9rem;
}

.canvas-wrapper {
    background-color: var(--bg-dark);
    border-radius: 12px;
    margin-bottom: 24px;
    box-shadow: inset 0 2px 10px rgba(0,0,0,0.5);
    overflow-x: auto;
    overflow-y: hidden;
    height: 640px;
}

/* New Split Layout */
.active-simulation-area {
    position: relative;
    display: flex;
    flex-direction: row;
    width: 100%;
    min-height: 640px;
    background-color: #0f172a;
}

.gen-container {
    flex: 0 0 320px;
    height: 640px;
    border-right: 1px solid rgba(255,255,255,0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    background: radial-gradient(circle at center, #1e293b 0%, #0f172a 100%);
}

.wave-container {
    flex: 1;
    position: relative;
    height: 640px;
    background-color: #0f172a;
}

canvas {
    display: block;
}

/* --- LaTeX Overlays & Axis --- */
.latex-axis-v {
    position: absolute;
    top: 8px;
    left: 8px;
    color: rgba(255,255,255,0.7);
    font-size: 0.9rem;
    pointer-events: none;
    z-index: 5;
}

.latex-axis-wt {
    position: absolute;
    bottom: 25px;
    right: 15px;
    color: rgba(255,255,255,0.7);
    font-size: 0.9rem;
    pointer-events: none;
    z-index: 5;
}

.latex-legend {
    position: absolute;
    right: 15px;
    background: rgba(255, 255, 255, 0.95);
    padding: 6px 12px;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    min-width: 160px;
    text-align: right;
    pointer-events: none;
    z-index: 10;
}

/* Legend Positions (160px panels) */
#latex-overlay-u { top: 10px; }
#latex-overlay-v { top: 170px; }
#latex-overlay-w { top: 330px; }
#latex-overlay-sum { top: 490px; }

/* --- Instant Value Overlays (near Y-axis) --- */
.instant-value-overlay {
    position: absolute;
    left: 55px; /* Vertical axis line X position */
    transform: translateX(-50%);
    font-size: 0.9rem;
    font-weight: 600;
    pointer-events: none;
    z-index: 10;
    white-space: nowrap;
}
.instant-value-overlay.u { top: 0px; color: var(--phase-u); }
.instant-value-overlay.v { top: 160px; color: var(--phase-v); }
.instant-value-overlay.w { top: 320px; color: var(--phase-w); }
.instant-value-overlay.sum { top: 480px; color: var(--brand-orange); }

.help-btn-inline {
    background: var(--brand-orange);
    color: white;
    border: none;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    cursor: pointer;
    font-weight: 700;
    font-size: 0.8rem;
    transition: var(--transition);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-left: 8px;
}
.help-btn-inline:hover { transform: scale(1.1); background: #d97706; }

/* --- Controls Section --- */
.controls-section {
    padding: 24px;
    background: #f8fafc;
    border-radius: 12px;
}

.controls-header {
    display: flex;
    align-items: center;
    margin-bottom: 20px;
}

.controls-title {
    color: var(--brand-green);
    font-weight: 700;
}

.help-btn {
    background: var(--brand-orange);
    color: white;
    border: none;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    cursor: pointer;
    font-weight: 700;
    transition: var(--transition);
}

.help-btn:hover { transform: scale(1.1); background: #d97706; }

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

@media (max-width: 900px) {
    .controls-grid {
        grid-template-columns: 1fr;
    }
}

.control-group {
    background: white;
    padding: 16px;
    border-radius: 12px;
    border: 1px solid #e2e8f0;
    box-shadow: var(--shadow-sm);
}

.input-group {
    margin-bottom: 12px;
}
.input-group label {
    display: block;
    font-size: 0.85rem;
    color: #64748b;
    margin-bottom: 6px;
    min-height: 1.2rem;
}

.slider-container {
    display: flex;
    align-items: center;
    gap: 12px;
}

input[type="range"] {
    flex: 1;
    accent-color: var(--brand-green);
}

.value-display {
    min-width: 40px;
    text-align: right;
    font-weight: 700;
    color: var(--brand-green);
}

.playback-actions {
    display: flex;
    justify-content: center;
    gap: 16px;
    margin: -10px auto 20px;
    padding: 12px 24px;
    background: rgba(255, 255, 255, 0.7);
    backdrop-filter: blur(8px);
    border-radius: 100px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.05);
    border: 1px solid rgba(255,255,255,0.8);
    width: max-content;
    position: relative;
    z-index: 10;
}

.play-btn, .btn-outline {
    font-family: inherit;
    font-size: 1rem;
    padding: 10px 32px;
    border-radius: 100px;
    cursor: pointer;
    font-weight: 700;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border: none;
    letter-spacing: 0.05em;
}

.play-btn {
    background: linear-gradient(135deg, var(--brand-green), #059669);
    color: white;
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
}

.play-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(16, 185, 129, 0.4);
}

.play-btn.paused {
    background: linear-gradient(135deg, var(--brand-orange), #d97706);
    box-shadow: 0 4px 12px rgba(249, 115, 22, 0.3);
}
.play-btn.paused:hover {
    box-shadow: 0 6px 16px rgba(249, 115, 22, 0.4);
}

.btn-outline {
    background: white;
    color: #475569;
    border: 2px solid #cbd5e1;
    padding: 8px 30px; /* Adjust for border */
}

.btn-outline:hover {
    background: #f8fafc;
    color: #0f172a;
    border-color: #94a3b8;
    transform: translateY(-2px);
}


/* --- Modal --- */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    inset: 0;
    background: rgba(15,23,42,0.6);
    backdrop-filter: blur(4px);
    align-items: center; justify-content: center;
}

.modal-content {
    background: white;
    border-radius: 16px;
    width: 90%;
    max-width: 600px;
    padding: 0;
    overflow: hidden;
    box-shadow: 0 25px 50px -12px rgba(0,0,0,0.5);
}

.modal-header {
    background: var(--brand-green);
    color: white;
    padding: 16px 24px;
    display: flex; justify-content: space-between; align-items: center;
}

.close-btn { font-size: 24px; cursor: pointer; }
.modal-body { padding: 24px; }
.formula-display {
    background: #f1f5f9;
    padding: 16px;
    border-radius: 8px;
    text-align: center;
    font-size: 1.25rem;
    margin-bottom: 20px;
}

.param-desc li { margin-bottom: 12px; font-size: 0.9rem; }

/* --- Responsiveness --- */
@media (max-width: 950px) {
    .active-simulation-area {
        flex-direction: column;
        min-height: auto;
    }
    .gen-container {
        flex: 1;
        height: 350px;
        border-right: none;
        border-bottom: 1px solid rgba(255,255,255,0.1);
    }
    .wave-container {
        height: 600px;
    }
    #latex-overlay-u { top: 10px; }
    #latex-overlay-v { top: 160px; }
    #latex-overlay-w { top: 310px; }
    #latex-overlay-sum { top: 460px; }
}
