:root {
    --festival-red: #d63031;
    --journey-blue: #0984e3;
    --home-orange: #fd79a8;
    --prosperity-gold: #fdcb6e;
    --text-primary: #2d3436;
    --text-secondary: #636e72;
    --bg-light: #fdfcfb;

    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.08);

    --font-family: "Noto Serif SC", "Outfit", serif;
    --font-mono: "JetBrains Mono", monospace;
    --font-title: "Ma Shan Zheng", cursive;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-family);
    background: linear-gradient(135deg, #ff6b6b 0%, #ee5a6f 50%, #c44569 100%);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
}

.app-container {
    width: 96vw;
    height: 92vh;
    max-width: 1800px;
    background: rgba(255, 255, 255, 0.98);
    backdrop-filter: blur(20px);
    border-radius: 20px;
    box-shadow: var(--shadow-md);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Header */
.main-header {
    padding: 1rem 2rem;
    background: linear-gradient(135deg, var(--festival-red) 0%, #c0392b 100%);
    border-bottom: 3px solid rgba(0, 0, 0, 0.1);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.header-content h1 {
    font-size: 1.6rem;
    color: white;
    margin-bottom: 4px;
}

.highlight {
    font-family: var(--font-title);
    font-size: 1.8rem;
}

.subtitle {
    font-size: 0.85rem;
    color: rgba(255, 255, 255, 0.9);
    font-style: italic;
}

.header-controls {
    display: flex;
    gap: 8px;
}

.mode-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.1);
    color: white;
    font-family: var(--font-family);
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.3s;
}

.mode-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: translateY(-2px);
}

.mode-btn.active {
    background: rgba(255, 255, 255, 0.3);
    border-color: rgba(255, 255, 255, 0.8);
}

/* Main Stage */
.main-stage {
    flex: 1;
    display: grid;
    grid-template-columns: 1fr 380px;
    overflow: hidden;
}

.visualization-area {
    display: flex;
    flex-direction: column;
    background: linear-gradient(135deg, #fdfcfb 0%, #f8f9fa 100%);
    overflow: hidden;
}

.graph-container {
    flex: 1;
    position: relative;
    padding: 20px;
}

#migrationCanvas {
    width: 100%;
    height: 100%;
    border-radius: 12px;
    background: white;
    box-shadow: var(--shadow-sm);
}

.graph-overlay {
    position: absolute;
    top: 30px;
    right: 30px;
    pointer-events: none;
}

.time-marker {
    background: rgba(255, 255, 255, 0.95);
    padding: 12px 16px;
    border-radius: 10px;
    box-shadow: var(--shadow-sm);
    border-left: 4px solid var(--festival-red);
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.marker-label,
.marker-value {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.marker-value {
    font-weight: 700;
    color: var(--festival-red);
    font-family: var(--font-mono);
}

.controls-panel {
    padding: 24px;
    background: white;
    border-top: 2px solid rgba(0, 0, 0, 0.05);
}

.slider-control {
    margin-bottom: 20px;
}

.slider-control label {
    display: flex;
    justify-content: space-between;
    margin-bottom: 12px;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.control-value {
    font-family: var(--font-mono);
    font-weight: 700;
    color: var(--festival-red);
}

input[type="range"] {
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: linear-gradient(to right, var(--journey-blue) 0%, var(--festival-red) 50%, var(--home-orange) 100%);
    outline: none;
    -webkit-appearance: none;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: white;
    border: 3px solid var(--festival-red);
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

input[type="range"]::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: white;
    border: 3px solid var(--festival-red);
    cursor: pointer;
}

.slider-marks {
    display: flex;
    justify-content: space-between;
    margin-top: 8px;
    font-size: 0.75rem;
    color: #999;
}

.function-display {
    display: flex;
    gap: 12px;
}

.function-card {
    flex: 1;
    padding: 16px;
    background: linear-gradient(135deg, #f8f9fa 0%, white 100%);
    border-radius: 12px;
    border-left: 4px solid;
    box-shadow: var(--shadow-sm);
}

.function-card.outbound {
    border-left-color: var(--journey-blue);
}

.function-card.inbound {
    border-left-color: var(--home-orange);
}

.function-card h4 {
    font-size: 0.95rem;
    margin-bottom: 8px;
    color: var(--text-primary);
}

.function-card .formula {
    font-family: var(--font-mono);
    font-size: 1.1rem;
    margin: 8px 0;
    padding: 8px;
    background: white;
    border-radius: 6px;
    text-align: center;
}

.function-card p {
    font-size: 0.85rem;
    color: var(--text-secondary);
    text-align: center;
}

/* Sidebar */
.sidebar {
    background: linear-gradient(180deg, #f8f9fa 0%, #e9ecef 100%);
    border-left: 2px solid rgba(0, 0, 0, 0.05);
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    overflow-y: auto;
}

.panel-section {
    background: white;
    padding: 18px;
    border-radius: 12px;
    box-shadow: var(--shadow-sm);
}

.panel-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 14px;
    padding-bottom: 10px;
    border-bottom: 2px solid #f0f0f0;
}

.panel-icon {
    font-size: 1.3rem;
}

.panel-header h3 {
    font-size: 1rem;
    color: var(--text-primary);
}

.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.stat-item {
    padding: 12px;
    background: #f8f9fa;
    border-radius: 8px;
    text-align: center;
}

.stat-item.highlight {
    grid-column: span 2;
    background: linear-gradient(135deg, rgba(214, 48, 49, 0.1) 0%, rgba(214, 48, 49, 0.05) 100%);
}

.stat-label {
    display: block;
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.stat-value {
    display: block;
    font-size: 1.1rem;
    font-weight: 700;
    font-family: var(--font-mono);
    color: var(--text-primary);
}

.operation-display {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.operation-box {
    padding: 12px;
    background: #f8f9fa;
    border-radius: 8px;
    border-left: 3px solid var(--journey-blue);
}

.operation-box h4 {
    font-size: 0.9rem;
    margin-bottom: 8px;
    color: var(--text-primary);
}

.formula-explanation {
    font-family: var(--font-mono);
    font-size: 0.95rem;
    margin: 6px 0;
    padding: 6px;
    background: white;
    border-radius: 4px;
    text-align: center;
}

.description {
    font-size: 0.8rem;
    color: var(--text-secondary);
    text-align: center;
    margin-top: 4px;
}

.insight-content {
    font-size: 0.9rem;
    line-height: 1.8;
}

.insight-content h4 {
    color: var(--festival-red);
    margin: 12px 0 6px 0;
    font-size: 0.95rem;
}

.insight-content h4:first-child {
    margin-top: 0;
}

.insight-content p {
    color: #555;
    margin-bottom: 10px;
}

.example-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.example-item {
    padding: 12px;
    background: #f8f9fa;
    border-radius: 8px;
    font-size: 0.85rem;
    line-height: 1.6;
}

.example-item strong {
    display: block;
    margin-bottom: 6px;
    color: var(--journey-blue);
}

.solution {
    margin-top: 6px;
    padding: 8px;
    background: white;
    border-radius: 4px;
    font-family: var(--font-mono);
    font-size: 0.9rem;
    border-left: 3px solid var(--festival-red);
}