/* ═══════════════════════════════════════════
   DESIGN TOKENS
   ═══════════════════════════════════════════ */
:root {
    --bg-space: #0a0e1a;
    --bg-panel: rgba(15, 23, 42, 0.82);
    --glass-border: rgba(148, 163, 184, 0.18);
    --glass-shadow: 0 8px 32px rgba(0, 0, 0, 0.45);
    --accent: #38bdf8;
    --accent-glow: rgba(56, 189, 248, 0.35);
    --danger: #f43f5e;
    --success: #34d399;
    --warning: #fbbf24;
    --text: #e2e8f0;
    --text-dim: #94a3b8;
    --radius: 14px;
    --radius-sm: 8px;
    --font: 'Outfit', system-ui, sans-serif;
    --transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ═══════════════════════════════════════════
   RESET & BASE
   ═══════════════════════════════════════════ */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html,
body {
    height: 100%;
    width: 100%;
    overflow: hidden;
    font-family: var(--font);
    background: var(--bg-space);
    color: var(--text);
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

/* ═══════════════════════════════════════════
   GLASS PANEL
   ═══════════════════════════════════════════ */
.glass-panel {
    background: var(--bg-panel);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius);
    box-shadow: var(--glass-shadow);
}

/* ═══════════════════════════════════════════
   TAB BAR
   ═══════════════════════════════════════════ */
#tab-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
    display: flex;
    gap: 4px;
    padding: 8px 12px;
    background: rgba(10, 14, 26, 0.92);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--glass-border);
}

.tab-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 16px;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-dim);
    font-family: var(--font);
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

.tab-btn:hover {
    background: rgba(56, 189, 248, 0.08);
    color: var(--text);
}

.tab-btn.active {
    background: rgba(56, 189, 248, 0.15);
    color: var(--accent);
    box-shadow: inset 0 -2px 0 var(--accent);
}

.tab-icon {
    font-size: 1.2rem;
}

/* ═══════════════════════════════════════════
   TAB CONTENT
   ═══════════════════════════════════════════ */
.tab-content {
    position: absolute;
    top: 56px;
    left: 0;
    right: 0;
    bottom: 0;
    display: none;
}

.tab-content.active {
    display: flex;
}

/* ═══════════════════════════════════════════
   TAB 1 – ORBIT
   ═══════════════════════════════════════════ */
#orbit-wrapper {
    position: relative;
    flex: 1;
    overflow: hidden;
}

#orbit-canvas {
    width: 100%;
    height: 100%;
    display: block;
    background: var(--bg-space);
    touch-action: none;
    /* Prevents scrolling while panning */
}

#orbit-controls {
    position: absolute;
    top: 16px;
    left: 16px;
    width: 280px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    z-index: 10;
}

#orbit-controls h2 {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--accent);
    margin-bottom: 4px;
}

/* Slider group */
.slider-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.slider-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.slider-value {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--accent);
    text-align: right;
}

/* Range input styling */
input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: rgba(148, 163, 184, 0.2);
    outline: none;
    cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--accent);
    box-shadow: 0 0 8px var(--accent-glow);
    cursor: grab;
}

input[type="range"]::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border: none;
    border-radius: 50%;
    background: var(--accent);
    box-shadow: 0 0 8px var(--accent-glow);
    cursor: grab;
}

/* Buttons */
.btn-primary {
    padding: 12px;
    border: none;
    border-radius: var(--radius-sm);
    background: linear-gradient(135deg, #38bdf8, #818cf8);
    color: #fff;
    font-family: var(--font);
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    transition: var(--transition);
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 20px var(--accent-glow);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-secondary {
    padding: 8px 12px;
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-sm);
    background: rgba(148, 163, 184, 0.08);
    color: var(--text-dim);
    font-family: var(--font);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

.btn-secondary:hover {
    background: rgba(148, 163, 184, 0.18);
    color: var(--text);
}

.btn-danger {
    padding: 12px;
    border: none;
    border-radius: var(--radius-sm);
    background: linear-gradient(135deg, #f43f5e, #e11d48);
    color: #fff;
    font-family: var(--font);
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    transition: var(--transition);
}

.btn-danger:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 20px rgba(244, 63, 94, 0.4);
}

.btn-danger:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.btn-floating {
    position: absolute;
    bottom: 20px;
    right: 20px;
    padding: 12px 20px;
    border: none;
    color: var(--text);
    font-family: var(--font);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    z-index: 10;
    transition: var(--transition);
}

.btn-floating:hover {
    background: rgba(56, 189, 248, 0.15);
}

.btn-icon {
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 50%;
    background: rgba(148, 163, 184, 0.15);
    color: var(--text);
    font-size: 1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.btn-icon:hover {
    background: rgba(244, 63, 94, 0.3);
}

/* Info box */
.info-box {
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    background: rgba(56, 189, 248, 0.08);
    border: 1px solid rgba(56, 189, 248, 0.15);
    font-size: 0.85rem;
    color: var(--accent);
    text-align: center;
}

/* Circular orbit velocity reference */
.orbit-ref-speed {
    font-size: 0.78rem;
    color: var(--text-dim);
    text-align: right;
    padding: 2px 0;
    opacity: 0.85;
}

.orbit-ref-speed span {
    color: var(--success);
    font-weight: 600;
}

/* ═══════════════════════════════════════════
   ISS INTERIOR PANEL
   ═══════════════════════════════════════════ */
#iss-interior {
    width: 0;
    min-width: 0;
    max-height: 100%;
    overflow: hidden;
    background: var(--bg-space);
    border-left: 1px solid var(--glass-border);
    transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1),
        min-width 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
}

#iss-interior.open {
    width: 420px;
    min-width: 420px;
}

.interior-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-radius: 0;
    border-bottom: 1px solid var(--glass-border);
}

.interior-header h3 {
    font-size: 1rem;
    font-weight: 700;
    color: var(--accent);
}

#iss-canvas {
    flex: 1;
    width: 100%;
    max-height: 500px;
    display: block;
}

.info-badge {
    padding: 8px 16px;
    border-radius: 0;
    border-top: 1px solid var(--glass-border);
    text-align: center;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--success);
}

/* ═══════════════════════════════════════════
   TAB 2 – EQUIVALENCE
   ═══════════════════════════════════════════ */
#equiv-wrapper {
    flex: 1;
    display: flex;
    gap: 0;
    min-width: 0;
    overflow: hidden;
}

.equiv-half {
    flex: 1 1 0;
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
    min-width: 0;
}

.equiv-half:first-child {
    border-right: 1px solid var(--glass-border);
}

.equiv-title {
    position: absolute;
    top: 12px;
    left: 50%;
    transform: translateX(-50%);
    padding: 6px 20px;
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--accent);
    z-index: 10;
    white-space: nowrap;
    border-radius: 20px;
}

#elevator-canvas,
#rocket-canvas {
    flex: 1 1 0;
    width: 100%;
    min-height: 0;
    display: block;
}

.equiv-controls {
    padding: 14px 16px;
    border-radius: 0;
    display: flex;
    flex-direction: column;
    gap: 10px;
    border-top: 1px solid var(--glass-border);
}

/* G display */
.g-display {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    background: rgba(56, 189, 248, 0.06);
    border: 1px solid rgba(56, 189, 248, 0.12);
}

.g-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-dim);
}

.g-value {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--accent);
    font-variant-numeric: tabular-nums;
}

/* Direction pad */
#direction-pad {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.dpad-row {
    display: flex;
    gap: 4px;
}

.dpad-btn {
    width: 44px;
    height: 44px;
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-sm);
    background: rgba(148, 163, 184, 0.08);
    color: var(--text);
    font-size: 1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
    -webkit-user-select: none;
    user-select: none;
}

.dpad-btn:hover {
    background: rgba(56, 189, 248, 0.15);
}

.dpad-btn.active {
    background: var(--accent);
    color: #0a0e1a;
}

.dpad-center {
    border-radius: 50%;
}

/* ═══════════════════════════════════════════
   RESPONSIVE – TABLET
   ═══════════════════════════════════════════ */
@media (max-width: 1024px) {
    #orbit-controls {
        width: 240px;
        padding: 14px;
    }

    #iss-interior.open {
        width: 320px;
        min-width: 320px;
    }
}

@media (max-width: 768px) {
    .tab-label {
        font-size: 0.8rem;
    }

    .tab-icon {
        font-size: 1rem;
    }

    /* Tab 1 */
    #tab1 {
        flex-direction: column;
    }

    #orbit-controls {
        position: relative;
        top: 0;
        left: 0;
        width: 100%;
        border-radius: 0;
        padding: 12px 16px;
        flex-direction: row;
        flex-wrap: wrap;
        align-items: center;
    }

    #orbit-controls h2 {
        width: 100%;
        font-size: 1rem;
    }

    #orbit-controls .slider-group {
        flex: 1;
        min-width: 120px;
    }

    #orbit-controls .btn-primary,
    #orbit-controls .btn-secondary {
        flex: 0;
    }

    #iss-interior.open {
        position: absolute;
        top: 0;
        right: 0;
        bottom: 0;
        width: 80vw;
        min-width: 280px;
        z-index: 50;
    }

    .btn-floating {
        bottom: 12px;
        right: 12px;
        padding: 10px 14px;
        font-size: 0.8rem;
    }

    /* Tab 2 */
    #equiv-wrapper {
        flex-direction: column;
    }

    .equiv-half:first-child {
        border-right: none;
        border-bottom: 1px solid var(--glass-border);
    }

    .equiv-controls {
        flex-direction: row;
        flex-wrap: wrap;
        align-items: center;
        gap: 8px;
    }

    .equiv-controls .slider-group {
        flex: 1;
        min-width: 120px;
    }

    #direction-pad {
        flex-direction: row;
        gap: 2px;
    }

    #direction-pad .dpad-row {
        gap: 2px;
    }

    .dpad-btn {
        width: 38px;
        height: 38px;
        font-size: 0.85rem;
    }
}

/* ═══════════════════════════════════════════
   ANIMATIONS
   ═══════════════════════════════════════════ */
@keyframes pulse-glow {

    0%,
    100% {
        box-shadow: 0 0 8px var(--accent-glow);
    }

    50% {
        box-shadow: 0 0 20px var(--accent-glow);
    }
}

@keyframes float {

    40%,
    60% {
        transform: translate3d(4px, 0, 0);
    }
}

/* ═══════════════════════════════════════════
   KEYPAD OVERLAY
   ═══════════════════════════════════════════ */
#keypad-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(10, 14, 26, 0.95);
    backdrop-filter: blur(12px);
    z-index: 1000;
    /* High z-index to ensure visibility */
    display: none;
    align-items: center;
    justify-content: center;
    animation: fade-in 0.3s ease-out;
}

#keypad-overlay.active {
    display: flex;
}

.keypad-box {
    width: 320px;
    padding: 24px;
    background: var(--bg-panel);
    border: 1px solid var(--accent);
    box-shadow: 0 0 50px rgba(0, 0, 0, 0.8), 0 0 15px var(--accent-glow);
    border-radius: var(--radius);
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.keypad-box h3 {
    text-align: center;
    color: var(--accent);
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.keypad-box p {
    text-align: center;
    color: var(--text-dim);
    font-size: 0.9rem;
}

#keypad-display {
    background: rgba(10, 14, 26, 0.8);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-sm);
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    font-weight: 700;
    letter-spacing: 8px;
    color: var(--text);
    margin-bottom: 8px;
    box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.5);
}

#keypad-display.error {
    animation: shake 0.4s cubic-bezier(.36, .07, .19, .97) both;
    border-color: var(--danger);
    color: var(--danger);
    box-shadow: 0 0 10px rgba(244, 63, 94, 0.4);
}

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

.key-btn {
    aspect-ratio: 1;
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-sm);
    background: rgba(148, 163, 184, 0.08);
    color: var(--text);
    font-size: 1.4rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
}

.key-btn:hover {
    background: rgba(56, 189, 248, 0.15);
    border-color: rgba(56, 189, 248, 0.5);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

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

.key-clear {
    background: rgba(244, 63, 94, 0.15);
    color: var(--danger);
    font-size: 1.1rem;
    font-weight: 700;
}

.key-clear:hover {
    background: rgba(244, 63, 94, 0.3);
    border-color: var(--danger);
}

.key-enter {
    background: rgba(52, 211, 153, 0.15);
    color: var(--success);
    font-size: 1.5rem;
}

.key-enter:hover {
    background: rgba(52, 211, 153, 0.3);
    border-color: var(--success);
}

@keyframes fade-in {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes shake {

    10%,
    90% {
        transform: translate3d(-1px, 0, 0);
    }

    20%,
    80% {
        transform: translate3d(2px, 0, 0);
    }

    30%,
    50%,
    70% {
        transform: translate3d(-4px, 0, 0);
    }

    40%,
    60% {
        transform: translate3d(4px, 0, 0);
    }
}