body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    margin: 0;
    color: #e0e0e0;
    display: flex;
    flex-direction: column;
    align-items: center;
    height: 100vh;
    overflow: hidden;
    background: linear-gradient(to bottom, #1c2a3e, #0a0f15);
}

header {
    width: 100%;
    padding: 10px 20px;
    background-color: rgba(10, 15, 21, 0.85);
    border-bottom: 1px solid #333;
    z-index: 10;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-sizing: border-box;
}

.header-links {
    display: flex;
    align-items: center;
    gap: 12px;
}

.header-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border-radius: 6px;
    background: rgba(35, 52, 78, 0.55);
    color: #dbe8ff;
    text-decoration: none;
    font-size: 13px;
    letter-spacing: 0.2px;
    transition: background 0.25s ease, transform 0.25s ease;
    border: 1px solid rgba(80, 120, 190, 0.55);
}

.header-link:hover {
    background: rgba(60, 110, 185, 0.65);
    transform: translateY(-1px);
}

.header-link--primary {
    background: linear-gradient(120deg, rgba(79, 160, 255, 0.85), rgba(35, 80, 210, 0.8));
    border-color: rgba(120, 185, 255, 0.85);
    color: #ffffff;
}

.header-link--primary:hover {
    background: linear-gradient(120deg, rgba(105, 200, 255, 0.95), rgba(45, 110, 255, 0.9));
}

h1 {
    margin: 0;
    font-weight: 300;
    letter-spacing: 1px;
    font-size: 22px;
}

#main-display {
    display: flex;
    gap: 18px;
    align-items: center;
    background: transparent;
    padding: 8px 12px;
    border-radius: 6px;
}

.display-item {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.display-label {
    font-size: 11px;
    color: #a0a0a0;
}

.display-value {
    font-family: monospace;
    font-size: 18px;
    font-weight: 700;
    color: #33ccff;
}

.display-value.secondary {
    color: #ffae42;
}

.display-unit {
    font-size: 13px;
    color: #a0a0a0;
    margin-left: 6px;
}

#main-container {
    display: flex;
    width: 100%;
    height: calc(100vh - 67px);
}

#controls-container {
    width: 36%;
    max-width: 600px;
    min-width: 380px;
    padding: 18px;
    background-color: rgba(35, 40, 48, 0.88);
    border-right: 1px solid #333;
    overflow-y: auto;
    z-index: 10;
    display: flex;
    flex-direction: column;
}

#dual-controls {
    display: flex;
    gap: 18px;
}

.control-column {
    flex: 1;
    padding: 14px;
    border: 1px solid #444;
    border-radius: 6px;
    background: rgba(10, 15, 21, 0.3);
}

.control-column h2 {
    margin: 0 0 8px 0;
    font-size: 16px;
    color: #33ccff;
    text-align: center;
}

.control-group {
    margin-bottom: 16px;
}

label {
    display: block;
    margin-bottom: 6px;
    color: #a0a0a0;
    font-weight: 500;
    font-size: 13px;
}

input[type="range"],
select {
    width: 100%;
    background: #333942;
    border: 1px solid #555;
    color: #e0e0e0;
    border-radius: 4px;
    padding: 6px;
    box-sizing: border-box;
}

.numeric-input {
    background: #1c2230;
    border: 1px solid #555;
    color: #e0e0e0;
    border-radius: 4px;
    padding: 6px 8px;
    box-sizing: border-box;
    font-family: monospace;
    font-size: 13px;
}

.numeric-input:focus {
    outline: none;
    border-color: rgba(120, 180, 255, 0.7);
    box-shadow: 0 0 6px rgba(72, 140, 255, 0.25);
}

.value-display {
    display: inline-block;
    margin-left: 10px;
    font-weight: 700;
    color: #fff;
}

.slider-input-row {
    display: flex;
    gap: 10px;
    align-items: center;
}

.slider-input-row input[type="range"] {
    flex: 1;
    margin: 0;
}

.slider-input-row .numeric-input {
    width: 88px;
    text-align: right;
    flex: 0 0 88px;
}

.slider-with-action {
    display: flex;
    gap: 10px;
    align-items: center;
}

.slider-with-action input[type="range"] {
    flex: 1;
    margin: 0;
}

.slider-with-action .numeric-input {
    width: 88px;
    text-align: right;
    flex: 0 0 88px;
}

.inline-button {
    padding: 6px 10px;
    border-radius: 4px;
    border: 1px solid rgba(80, 110, 140, 0.6);
    background: linear-gradient(145deg, rgba(40, 60, 80, 0.8), rgba(20, 30, 44, 0.95));
    color: #d8e7ff;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.inline-button:hover {
    border-color: rgba(120, 180, 255, 0.8);
    color: #ffffff;
    box-shadow: 0 0 8px rgba(72, 140, 255, 0.35);
}

.inline-button:active {
    transform: translateY(1px);
    box-shadow: 0 0 4px rgba(72, 140, 255, 0.4);
}

.reset-button {
    width: 100%;
    margin-top: 6px;
    letter-spacing: 0.6px;
}

.flow-mode-row {
    display: flex;
    gap: 8px;
    margin-top: 8px;
    flex-wrap: wrap;
}

.flow-mode-row .inline-button {
    flex: 1 1 calc(50% - 4px);
    text-transform: none;
    letter-spacing: 0.2px;
    font-size: 12px;
}

.geometry-row {
    display: flex;
    margin-top: 6px;
}

.geometry-row .inline-button {
    flex: 1;
    text-transform: none;
    letter-spacing: 0.2px;
    font-size: 12px;
}

.inline-button.toggle-button {
    background: linear-gradient(145deg, rgba(48, 72, 98, 0.85), rgba(18, 28, 42, 0.95));
    border-color: rgba(90, 130, 170, 0.65);
}

.inline-button.toggle-button.active {
    border-color: rgba(120, 210, 255, 0.9);
    color: #ffffff;
    box-shadow: 0 0 10px rgba(90, 200, 255, 0.45), inset 0 0 10px rgba(120, 210, 255, 0.2);
    background: linear-gradient(145deg, rgba(70, 120, 180, 0.95), rgba(30, 50, 80, 0.98));
}

#dual-properties-container {
    display: flex;
    gap: 18px;
    margin-top: 12px;
}

.gas-properties-display {
    flex: 1;
    padding: 12px;
    border: 1px solid #555;
    background: rgba(10, 15, 21, 0.6);
    border-radius: 6px;
    box-shadow: 0 0 12px rgba(0, 0, 0, 0.25);
    transition: border-color 0.4s ease, box-shadow 0.4s ease, background 0.6s ease;
}

.gas-properties-display h4 {
    margin: 0 0 10px 0;
    color: #fff;
    font-size: 15px;
    text-align: center;
}

.prop-grid {
    display: grid;
    grid-template-columns: auto auto;
    gap: 8px 12px;
    font-size: 13px;
}

.prop-grid span:nth-child(odd) {
    color: #a0a0a0;
}

.prop-grid span:nth-child(even) {
    font-weight: 700;
    text-align: right;
    font-family: monospace;
    color: #fff;
}

.phase-display {
    font-family: monospace;
    font-weight: 700;
    text-align: right;
    color: #7de9ff;
    transition: color 0.3s ease;
}

.phase-liquid {
    color: #7df5b9;
}

.phase-boiling {
    color: #ffae42;
    animation: pulsePhase 1.4s ease-in-out infinite;
}

.phase-unknown {
    color: #c0c9d6;
}

@keyframes pulsePhase {
    0%, 100% {
        opacity: 0.7;
    }
    50% {
        opacity: 1;
    }
}

#plot-container {
    margin-top: 18px;
}

.pressure-plot {
    width: 100%;
    height: 195px;
    background-color: #0a0f15;
    border-radius: 6px;
    border: 1px solid #333;
    box-shadow: inset 0 0 18px rgba(0, 0, 0, 0.35);
}

#simulation-container {
    flex-grow: 1;
    height: 100%;
    position: relative;
}

#legend-container {
    position: absolute;
    bottom: 20px;
    left: 20px;
    width: 220px;
    padding: 12px;
    background: rgba(35, 40, 48, 0.92);
    border-radius: 8px;
    border: 1px solid rgba(140, 152, 166, 0.35);
    color: #e0e0e0;
    z-index: 10;
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.35);
}

.legend-title {
    font-weight: bold;
    margin-bottom: 8px;
    text-align: center;
    font-size: 13px;
    letter-spacing: 0.3px;
}

.legend-gradient {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.legend-row {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.legend-row-header {
    font-size: 12px;
    color: #b6c2d1;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.legend-bar {
    width: 100%;
    height: 16px;
    border-radius: 4px;
    border: 1px solid rgba(255, 255, 255, 0.18);
    box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.35);
    display: block;
}

.legend-bar-labels {
    display: flex;
    justify-content: space-between;
    font-size: 10px;
    color: #8d99aa;
    text-transform: uppercase;
    letter-spacing: 0.4px;
}

.legend-labels {
    display: none;
}

#explanation-box {
    margin-top: 18px;
    padding-top: 12px;
    border-top: 1px solid #555;
}

#explanation-box h4 {
    margin-top: 0;
    color: #fff;
}

#explanation-box p {
    font-size: 13px;
    line-height: 1.45;
    color: #a0a0a0;
}

.small-note {
    font-size: 12px;
    color: #99aabb;
    margin-top: 6px;
}

.marker-checkbox {
    margin-bottom: 8px;
}

.marker-slider {
    margin-bottom: 8px;
}

@media (max-width: 1280px) {
    #controls-container {
        width: 40%;
        min-width: 320px;
    }
}

/* iPad and tablet-specific styles */
@media (min-width: 768px) and (max-width: 1366px) {
    /* iPad landscape and portrait */
    #controls-container {
        width: 45%;
        min-width: 350px;
        max-width: 500px;
        padding: 15px;
    }
    
    .control-group {
        margin-bottom: 15px;
    }
    
    /* Touch-friendly controls */
    input[type="range"] {
        height: 8px;
        -webkit-appearance: none;
    }
    
    input[type="range"]::-webkit-slider-thumb {
        height: 20px;
        width: 20px;
        -webkit-appearance: none;
    }
    
    button {
        min-height: 44px;
        padding: 12px 18px;
        font-size: 16px;
    }
    
    select {
        min-height: 44px;
        font-size: 16px;
        padding: 8px 12px;
    }
}

/* iPad portrait mode */
@media (max-width: 1024px) and (orientation: portrait) {
    #main-container {
        flex-direction: column;
    }
    
    #controls-container {
        width: 100%;
        max-width: none;
        height: auto;
        flex: none;
        border-right: none;
        border-bottom: 2px solid #333;
        overflow-y: auto;
        max-height: 40vh;
    }
    
    #simulation-container {
        width: 100%;
        height: 60vh;
        flex: 1;
    }
    
    /* Compact control layout for portrait */
    .control-group {
        margin-bottom: 10px;
    }
    
    .control-row {
        display: flex;
        gap: 10px;
        align-items: center;
        flex-wrap: wrap;
    }
}

/* Fine pointer detection for desktop vs touch */
@media (pointer: coarse) {
    /* Touch devices - larger touch targets */
    button, select, input[type="range"] {
        min-height: 44px;
        min-width: 44px;
    }
    
    .header-link {
        padding: 12px 16px;
        font-size: 14px;
    }
}

@media (max-width: 1080px) {
    #main-container {
        flex-direction: column;
    }

    #controls-container {
        width: 100%;
        max-width: none;
        border-right: none;
        border-bottom: 1px solid #333;
        height: auto;
        flex: none;
    }

    #simulation-container {
        width: 100%;
        height: 60vh;
    }
}
