/* Foil Physics Simulator - Mobile-First CSS */

:root {
    --primary: #0066cc;
    --primary-dark: #004d99;
    --primary-light: #3399ff;
    --secondary: #00ccaa;
    --accent: #ff6b35;
    --background: #0a1628;
    --surface: #1a2a44;
    --surface-light: #2a3a54;
    --text: #ffffff;
    --text-secondary: #a0b0c0;
    --success: #00cc66;
    --warning: #ffaa00;
    --danger: #ff4444;
    --border-radius: 12px;
    --transition: 0.3s ease;
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

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

html {
    font-size: 16px;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: var(--background);
    color: var(--text);
    min-height: 100vh;
    min-height: 100dvh;
    overflow-x: hidden;
    line-height: 1.5;
}

/* App Container */
.app-container {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    min-height: 100dvh;
}

/* Header */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: linear-gradient(135deg, var(--surface) 0%, var(--surface-light) 100%);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    position: sticky;
    top: 0;
    z-index: 100;
}

.app-header h1 {
    font-size: 1.25rem;
    font-weight: 600;
    background: linear-gradient(135deg, var(--primary-light) 0%, var(--secondary) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.menu-btn {
    display: flex;
    flex-direction: column;
    gap: 5px;
    padding: 8px;
    background: transparent;
    border: none;
    cursor: pointer;
}

.menu-btn span {
    display: block;
    width: 24px;
    height: 2px;
    background: var(--text);
    border-radius: 2px;
    transition: var(--transition);
}

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

/* Simulation View */
.simulation-view {
    position: relative;
    width: 100%;
    height: 40vh;
    min-height: 250px;
    max-height: 400px;
    background: linear-gradient(180deg,
        #1a3a5c 0%,
        #0d2847 30%,
        #041525 60%,
        #020a10 100%
    );
    overflow: hidden;
}

#simulationCanvas {
    width: 100%;
    height: 100%;
    display: block;
}

.simulation-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    padding: 16px;
    display: flex;
    justify-content: space-between;
    pointer-events: none;
}

.speed-indicator, .height-indicator {
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(10px);
    padding: 8px 16px;
    border-radius: var(--border-radius);
    display: flex;
    align-items: baseline;
    gap: 4px;
}

.speed-indicator .value, .height-indicator .value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary-light);
}

.speed-indicator .unit, .height-indicator .unit {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.height-indicator {
    flex-direction: column;
    align-items: flex-end;
}

.height-indicator .label {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.play-btn {
    position: absolute;
    bottom: 16px;
    right: 16px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    border: none;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow);
    transition: transform var(--transition), box-shadow var(--transition);
}

.play-btn:active {
    transform: scale(0.95);
}

.play-btn svg {
    width: 24px;
    height: 24px;
}

/* Controls Panel */
.controls-panel {
    background: var(--surface);
    border-radius: var(--border-radius) var(--border-radius) 0 0;
    margin-top: -12px;
    position: relative;
    z-index: 10;
}

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

.panel-header h2 {
    font-size: 1rem;
    font-weight: 600;
}

.collapse-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px;
    transition: transform var(--transition);
}

.controls-panel.collapsed .collapse-btn {
    transform: rotate(180deg);
}

.controls-panel.collapsed .controls-content {
    display: none;
}

.controls-content {
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* Control Groups */
.control-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

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

.label-text {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.label-value {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--primary-light);
}

/* Range Sliders */
input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 8px;
    background: var(--surface-light);
    border-radius: 4px;
    outline: none;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 24px;
    height: 24px;
    background: linear-gradient(135deg, var(--primary-light) 0%, var(--primary) 100%);
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0, 102, 204, 0.4);
}

input[type="range"]::-moz-range-thumb {
    width: 24px;
    height: 24px;
    background: linear-gradient(135deg, var(--primary-light) 0%, var(--primary) 100%);
    border-radius: 50%;
    cursor: pointer;
    border: none;
    box-shadow: 0 2px 8px rgba(0, 102, 204, 0.4);
}

/* Profile Select Dropdown */
.profile-select {
    width: 100%;
    padding: 10px 12px;
    background: var(--surface-light);
    border: 2px solid transparent;
    border-radius: 8px;
    color: var(--text);
    font-size: 0.875rem;
    cursor: pointer;
    transition: all 0.2s ease;
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23667' stroke-width='2'%3E%3Cpolyline points='6,9 12,15 18,9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
}

.profile-select:hover {
    border-color: var(--primary);
}

.profile-select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(0, 102, 204, 0.2);
}

.profile-select option {
    background: var(--surface);
    color: var(--text);
    padding: 8px;
}

/* Preset Buttons */
.presets .label-text {
    margin-bottom: 4px;
}

.preset-buttons {
    display: flex;
    gap: 8px;
}

.preset-btn {
    flex: 1;
    padding: 10px 12px;
    background: var(--surface-light);
    border: 2px solid transparent;
    border-radius: 8px;
    color: var(--text-secondary);
    font-size: 0.8125rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
}

.preset-btn.active {
    background: rgba(0, 102, 204, 0.2);
    border-color: var(--primary);
    color: var(--primary-light);
}

.preset-btn:not(.active):active {
    transform: scale(0.98);
}

/* Data Panel */
.data-panel {
    padding: 16px;
    background: var(--background);
}

.data-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
}

.data-card {
    background: var(--surface);
    border-radius: var(--border-radius);
    padding: 16px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.data-icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.data-card.lift .data-icon {
    background: rgba(0, 204, 102, 0.2);
    color: var(--success);
}

.data-card.drag .data-icon {
    background: rgba(255, 68, 68, 0.2);
    color: var(--danger);
}

.data-card.efficiency .data-icon {
    background: rgba(0, 204, 170, 0.2);
    color: var(--secondary);
}

.data-card.status .data-icon {
    background: rgba(0, 102, 204, 0.2);
    color: var(--primary-light);
}

.data-info {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.data-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.data-value {
    font-size: 1rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.status-text {
    color: var(--warning);
}

.status-text.flying {
    color: var(--success);
}

.status-text.stalled {
    color: var(--danger);
}

/* Side Menu */
.side-menu {
    position: fixed;
    top: 0;
    left: -280px;
    width: 280px;
    height: 100%;
    background: var(--surface);
    z-index: 200;
    transition: transform var(--transition);
    box-shadow: var(--shadow);
}

.side-menu.open {
    transform: translateX(280px);
}

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

.menu-header h2 {
    font-size: 1.125rem;
    font-weight: 600;
}

.close-btn {
    width: 32px;
    height: 32px;
    background: var(--surface-light);
    border: none;
    border-radius: 50%;
    color: var(--text);
    font-size: 1.5rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.menu-list {
    list-style: none;
    padding: 8px 0;
}

.menu-list li a {
    display: block;
    padding: 16px;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 1rem;
    transition: var(--transition);
}

.menu-list li a:hover,
.menu-list li a.active {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text);
}

.menu-list li a.active {
    border-left: 3px solid var(--primary);
}

.menu-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 150;
    opacity: 0;
    visibility: hidden;
    transition: var(--transition);
}

.menu-overlay.active {
    opacity: 1;
    visibility: visible;
}

/* Pumping Controls */
.pumping-controls {
    padding: 16px;
    background: var(--surface);
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.pump-btn {
    width: 100%;
    padding: 16px;
    background: linear-gradient(135deg, var(--accent) 0%, #e55a2b 100%);
    border: none;
    border-radius: var(--border-radius);
    color: white;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform var(--transition);
    touch-action: manipulation;
}

.pump-btn:active {
    transform: scale(0.98);
}

.pump-btn.pumping {
    animation: pump-pulse 0.15s ease-out;
}

.pump-btn .pump-text {
    display: block;
    font-size: 1.25rem;
    letter-spacing: 2px;
}

.pump-btn .pump-hint {
    display: block;
    font-size: 0.75rem;
    font-weight: 400;
    opacity: 0.7;
    margin-top: 4px;
}

@keyframes pump-pulse {
    0% { transform: scale(1); }
    50% { transform: scale(0.95); }
    100% { transform: scale(1); }
}

/* Responsive - Tablet and up */
@media (min-width: 768px) {
    .main-content {
        flex-direction: row;
        flex-wrap: wrap;
    }

    .simulation-view {
        width: 60%;
        height: auto;
        min-height: 400px;
        max-height: none;
    }

    .controls-panel {
        width: 40%;
        margin-top: 0;
        border-radius: 0;
        max-height: calc(100vh - 60px);
        overflow-y: auto;
    }

    .data-panel {
        width: 100%;
    }

    .pumping-controls {
        width: 100%;
    }

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

/* Responsive - Desktop */
@media (min-width: 1024px) {
    .simulation-view {
        width: 65%;
        min-height: 500px;
    }

    .controls-panel {
        width: 35%;
    }

    .speed-indicator .value,
    .height-indicator .value {
        font-size: 2rem;
    }

    .play-btn {
        width: 64px;
        height: 64px;
    }

    .play-btn svg {
        width: 28px;
        height: 28px;
    }
}

/* Landscape mobile */
@media (max-height: 500px) and (orientation: landscape) {
    .simulation-view {
        aspect-ratio: auto;
        height: 60vh;
    }

    .controls-panel {
        max-height: 40vh;
        overflow-y: auto;
    }
}

/* Dark mode adjustments for PWA */
@media (prefers-color-scheme: dark) {
    :root {
        color-scheme: dark;
    }
}

/* Safe area insets for notched devices */
@supports (padding: max(0px)) {
    .app-header {
        padding-top: max(12px, env(safe-area-inset-top));
        padding-left: max(16px, env(safe-area-inset-left));
        padding-right: max(16px, env(safe-area-inset-right));
    }

    .data-panel {
        padding-bottom: max(16px, env(safe-area-inset-bottom));
    }
}

/* Touch feedback */
@media (hover: none) {
    .preset-btn:active,
    .play-btn:active,
    .menu-btn:active {
        opacity: 0.8;
    }
}

/* Reduce motion for accessibility */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Mode Toggle */
.mode-toggle {
    margin-bottom: 8px;
}

.toggle-buttons {
    display: flex;
    gap: 8px;
}

.toggle-btn {
    flex: 1;
    padding: 10px 16px;
    background: var(--surface-light);
    border: 2px solid transparent;
    border-radius: 8px;
    color: var(--text-secondary);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
}

.toggle-btn.active {
    background: rgba(0, 102, 204, 0.2);
    border-color: var(--primary);
    color: var(--primary-light);
}

.toggle-btn:not(.active):hover {
    background: var(--surface);
}

.mode-hint {
    display: block;
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 8px;
    font-style: italic;
}

/* Advanced Settings Toggle */
.advanced-toggle {
    width: 100%;
    padding: 12px 16px;
    background: var(--surface-light);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    color: var(--text-secondary);
    font-size: 0.875rem;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: var(--transition);
}

.advanced-toggle:hover {
    background: var(--surface);
    color: var(--text);
}

.advanced-toggle svg {
    transition: transform var(--transition);
}

.advanced-toggle.open svg {
    transform: rotate(180deg);
}

/* Advanced Settings Panel */
.advanced-settings {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 8px;
    padding: 16px;
    margin-top: 8px;
}

.advanced-settings h3 {
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 16px;
    padding-bottom: 8px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.advanced-settings h3:not(:first-child) {
    margin-top: 20px;
}

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

.advanced-settings .control-group:last-child {
    margin-bottom: 0;
}

/* Power Overlay */
.power-overlay {
    position: absolute;
    bottom: 16px;
    left: 16px;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(10px);
    padding: 8px 16px;
    border-radius: var(--border-radius);
    display: flex;
    align-items: baseline;
    gap: 4px;
    pointer-events: none;
}

.power-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--accent);
}

.power-unit {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

/* Telemetry Debug Overlay */
.telemetry-overlay {
    position: absolute;
    top: 8px;
    left: 8px;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(8px);
    padding: 10px 14px;
    border-radius: 6px;
    font-family: 'SF Mono', 'Monaco', 'Consolas', monospace;
    font-size: 11px;
    line-height: 1.5;
    color: #e0e0e0;
    pointer-events: none;
    z-index: 100;
    min-width: 200px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.telemetry-header {
    font-weight: 600;
    color: #00ccff;
    margin-bottom: 6px;
    padding-bottom: 4px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
    font-size: 12px;
}

.telemetry-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 8px;
}

.telemetry-label {
    color: #a0a0a0;
    flex-shrink: 0;
}

.telemetry-value {
    color: #ffffff;
    font-weight: 500;
    text-align: right;
}

.telemetry-unit {
    color: #808080;
    font-size: 10px;
    min-width: 28px;
}

.telemetry-divider {
    height: 1px;
    background: rgba(255, 255, 255, 0.1);
    margin: 6px 0;
}

/* Highlight values that are out of normal range */
.telemetry-value.warning {
    color: #ffaa00;
}

.telemetry-value.danger {
    color: #ff4444;
}

.telemetry-value.good {
    color: #44ff88;
}

/* Power data card */
.data-card.power .data-icon {
    background: rgba(255, 107, 53, 0.2);
    color: var(--accent);
}
