/* ===== CSS Variables & Reset ===== */
:root {
    --bg-primary: #f0f4f8;
    --bg-secondary: #ffffff;
    --bg-tertiary: #e8eef4;
    --text-primary: #1a1a2e;
    --text-secondary: #5a6270;
    --border-color: #d0d8e0;
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.08);

    /* State Colors */
    --solid-color: #3498db;
    --liquid-color: #2ecc71;
    --gas-color: #e74c3c;

    --radius: 12px;
    --transition: all 0.3s ease;
}

[data-theme="dark"] {
    --bg-primary: #0f0f1a;
    --bg-secondary: #1a1a2e;
    --bg-tertiary: #252540;
    --text-primary: #f0f4f8;
    --text-secondary: #a0a8b8;
    --border-color: #2a2a45;
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    transition: var(--transition);
}

/* ===== App Container ===== */
.app-container {
    max-width: 1800px;
    margin: 0 auto;
    padding: 15px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ===== Header ===== */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 25px;
    background: var(--bg-secondary);
    border-radius: var(--radius);
    margin-bottom: 15px;
    box-shadow: var(--shadow);
}

.header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: #4f883d;
}

.header-controls {
    display: flex;
    gap: 10px;
}

.control-btn {
    width: 42px;
    height: 42px;
    border: 2px solid var(--border-color);
    border-radius: 50%;
    background: var(--bg-primary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.control-btn:hover {
    border-color: var(--liquid-color);
    transform: scale(1.05);
}

.control-btn svg {
    width: 20px;
    height: 20px;
    color: var(--text-primary);
}

.moon-icon {
    display: none;
}

[data-theme="dark"] .sun-icon {
    display: none;
}

[data-theme="dark"] .moon-icon {
    display: block;
}

.compress-icon {
    display: none;
}

.fullscreen-active .expand-icon {
    display: none;
}

.fullscreen-active .compress-icon {
    display: block;
}

/* ===== Main Content ===== */
.main-content {
    display: grid;
    grid-template-columns: 240px 1fr 280px;
    gap: 15px;
    flex: 1;
}

/* ===== Controls Panel ===== */
.controls-panel {
    background: var(--bg-secondary);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.controls-panel h2 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
}

.control-section h3 {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 10px;
    text-transform: uppercase;
}

/* Substance Grid */
.substance-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.substance-btn {
    padding: 10px 8px;
    background: var(--bg-tertiary);
    border: 2px solid transparent;
    border-radius: 8px;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-primary);
    cursor: pointer;
    transition: var(--transition);
}

.substance-btn:hover {
    border-color: var(--liquid-color);
}

.substance-btn.active {
    background: var(--liquid-color);
    color: white;
    border-color: var(--liquid-color);
}

/* Temperature Display */
.temp-display {
    text-align: center;
    padding: 15px;
    background: linear-gradient(135deg, var(--solid-color), var(--gas-color));
    border-radius: 12px;
    color: white;
}

.temp-value {
    font-size: 2.5rem;
    font-weight: 800;
}

.temp-unit {
    font-size: 1.2rem;
    font-weight: 600;
}

.temp-celsius {
    text-align: center;
    font-size: 1rem;
    color: var(--text-secondary);
    margin-top: 5px;
}

/* Temperature Slider */
.temp-slider {
    width: 100%;
    height: 12px;
    border-radius: 6px;
    background: linear-gradient(to right, #3498db, #2ecc71, #f1c40f, #e74c3c);
    -webkit-appearance: none;
    margin: 15px 0;
}

.temp-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: white;
    border: 3px solid var(--text-primary);
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

/* Unit Toggle */
.unit-toggle {
    display: flex;
    gap: 5px;
}

.unit-btn {
    flex: 1;
    padding: 8px;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-tertiary);
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition);
}

.unit-btn.active {
    background: var(--text-primary);
    color: var(--bg-primary);
    border-color: var(--text-primary);
}

/* Preset Buttons */
.preset-buttons {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.preset-btn {
    padding: 10px;
    background: var(--bg-tertiary);
    border: 2px solid transparent;
    border-radius: 8px;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-primary);
    cursor: pointer;
    transition: var(--transition);
    text-align: left;
}

.preset-btn:hover {
    border-color: var(--liquid-color);
    transform: translateX(5px);
}

/* Slider Row */
.slider-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.slider-row input[type="range"] {
    flex: 1;
    height: 6px;
    border-radius: 3px;
    background: var(--bg-tertiary);
    -webkit-appearance: none;
}

.slider-row input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--liquid-color);
    cursor: pointer;
}

.slider-row span {
    min-width: 30px;
    font-weight: 600;
}

/* ===== Simulation Container ===== */
.simulation-container {
    background: var(--bg-secondary);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.simulation-header {
    text-align: center;
    padding: 10px 15px;
    background: linear-gradient(135deg, rgba(79, 136, 61, 0.1), rgba(46, 204, 113, 0.1));
    border-radius: 10px;
    border-left: 4px solid #4f883d;
}

.simulation-header h2 {
    font-size: 1.1rem;
    font-weight: 700;
    color: #4f883d;
    margin-bottom: 6px;
}

.simulation-header p {
    font-size: 0.8rem;
    color: var(--text-secondary);
    line-height: 1.5;
    max-width: 600px;
    margin: 0 auto;
}

.simulation-box {
    flex: 1;
    position: relative;
    background: linear-gradient(135deg, rgba(52, 152, 219, 0.1), rgba(46, 204, 113, 0.1));
    border-radius: 12px;
    overflow: hidden;
    min-height: 400px;
    border: 3px solid var(--border-color);
}

#particleCanvas {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
}

.state-indicator {
    position: absolute;
    top: 15px;
    left: 15px;
    background: var(--bg-secondary);
    padding: 10px 20px;
    border-radius: 25px;
    display: flex;
    align-items: center;
    gap: 8px;
    box-shadow: var(--shadow);
    z-index: 10;
}

.state-indicator .state-icon {
    font-size: 1.5rem;
}

.state-indicator .state-name {
    font-weight: 700;
    font-size: 1rem;
}

/* Temperature Bar */
.temp-bar-container {
    padding: 10px 0;
}

.temp-bar {
    height: 20px;
    background: linear-gradient(to right, #3498db 0%, #2ecc71 50%, #e74c3c 100%);
    border-radius: 10px;
    position: relative;
}

.temp-marker {
    position: absolute;
    top: -5px;
    width: 4px;
    height: 30px;
    background: var(--text-primary);
    border-radius: 2px;
}

.temp-marker.melting {
    left: 30%;
}

.temp-marker.boiling {
    left: 60%;
}

.temp-current {
    position: absolute;
    top: -8px;
    width: 16px;
    height: 36px;
    background: white;
    border: 3px solid var(--text-primary);
    border-radius: 8px;
    left: 50%;
    transform: translateX(-50%);
    transition: left 0.3s ease;
}

.temp-bar-labels {
    display: flex;
    justify-content: space-between;
    margin-top: 8px;
    font-size: 0.7rem;
    color: var(--text-secondary);
}

/* ===== Info Panel ===== */
.info-panel {
    background: var(--bg-secondary);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    gap: 15px;
    overflow-y: auto;
}

.info-panel h2 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
}

/* State Info Card */
.state-info-card {
    background: var(--bg-tertiary);
    border-radius: 12px;
    padding: 15px;
}

.state-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 10px;
}

.state-icon-large {
    font-size: 2.5rem;
}

.state-header h3 {
    font-size: 1.1rem;
    margin-bottom: 2px;
}

.state-header p {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.state-description {
    font-size: 0.85rem;
    line-height: 1.5;
    color: var(--text-secondary);
}

/* Properties Grid */
.properties-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.property-item {
    background: var(--bg-tertiary);
    padding: 10px;
    border-radius: 8px;
    text-align: center;
}

.property-label {
    display: block;
    font-size: 0.65rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    margin-bottom: 4px;
}

.property-value {
    font-size: 0.85rem;
    font-weight: 700;
}

/* Energy Section */
.energy-section h3 {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.energy-bar {
    height: 12px;
    background: var(--bg-tertiary);
    border-radius: 6px;
    overflow: hidden;
}

.energy-fill {
    height: 100%;
    width: 20%;
    background: linear-gradient(to right, var(--solid-color), var(--gas-color));
    border-radius: 6px;
    transition: width 0.5s ease;
}

.energy-value {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 5px;
}

.energy-value span {
    font-weight: 700;
    color: var(--text-primary);
}

/* Substance Info */
.substance-info h3 {
    font-size: 0.9rem;
    margin-bottom: 10px;
}

.phase-points {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.phase-point {
    display: flex;
    justify-content: space-between;
    font-size: 0.8rem;
}

.phase-label {
    color: var(--text-secondary);
}

.phase-value {
    font-weight: 600;
}

/* Explanation Box */
.explanation-box {
    background: linear-gradient(135deg, rgba(46, 204, 113, 0.1), rgba(39, 174, 96, 0.1));
    border-left: 4px solid var(--liquid-color);
    padding: 15px;
    border-radius: 10px;
}

.explanation-box h3 {
    font-size: 0.85rem;
    margin-bottom: 8px;
}

.explanation-box p {
    font-size: 0.8rem;
    line-height: 1.5;
    color: var(--text-secondary);
}

/* ===== Responsive ===== */
@media (max-width: 1200px) {
    .main-content {
        grid-template-columns: 200px 1fr 240px;
    }
}

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

    .controls-panel {
        order: 1;
    }

    .simulation-container {
        order: 2;
        min-height: 350px;
    }

    .info-panel {
        order: 3;
    }

    .substance-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}