/* UI and HUD Styles */

/* HUD Container */
#hud {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 10;
    font-size: 16px;
}

/* Top HUD Bar */
#top-hud {
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 40px;
    background: var(--hud-bg);
    padding: 15px 30px;
    border-radius: 8px;
    backdrop-filter: blur(10px);
    border: 2px solid rgba(255, 255, 255, 0.1);
}

body.perf-mode #top-hud,
body.perf-mode #engine-status,
body.perf-mode #status-text,
body.perf-mode #controls {
    backdrop-filter: none;
}

body.perf-mode .hud-value {
    text-shadow: none;
}

body.perf-mode #status-text {
    animation: none;
}

.hud-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
}

.hud-label {
    font-size: 12px;
    color: rgba(255, 255, 255, 0.7);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.hud-value {
    font-size: 28px;
    font-weight: bold;
    color: var(--text-color);
    text-shadow: 0 0 10px rgba(0, 172, 230, 0.5);
    font-family: 'Courier New', monospace;
}

/* Engine Status */
#engine-status {
    position: absolute;
    top: 20px;
    right: 20px;
    background: var(--hud-bg);
    padding: 12px 24px;
    border-radius: 8px;
    backdrop-filter: blur(10px);
    border: 2px solid rgba(255, 255, 255, 0.1);
    font-size: 14px;
    font-weight: bold;
    letter-spacing: 1px;
}

/* Crosshair */
#crosshair {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 40px;
    height: 40px;
    pointer-events: none;
    display: none;
}

#crosshair::before,
#crosshair::after {
    content: '';
    position: absolute;
    background: rgba(255, 255, 255, 0.8);
}

#crosshair::before {
    top: 50%;
    left: 0;
    width: 100%;
    height: 2px;
    transform: translateY(-50%);
}

#crosshair::after {
    top: 0;
    left: 50%;
    width: 2px;
    height: 100%;
    transform: translateX(-50%);
}

/* Center dot */
#crosshair>.dot {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 6px;
    height: 6px;
    background: var(--danger-color);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    box-shadow: 0 0 10px var(--danger-color);
}

/* Status Text */
#status-text {
    position: absolute;
    bottom: 150px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--hud-bg);
    padding: 15px 40px;
    border-radius: 8px;
    backdrop-filter: blur(10px);
    border: 2px solid var(--warning-color);
    font-size: 18px;
    text-align: center;
    animation: pulse 2s ease-in-out infinite;
    max-width: 600px;
}

/* Controls Panel */
#controls {
    position: absolute;
    bottom: 20px;
    left: 20px;
    background: var(--hud-bg);
    padding: 20px;
    border-radius: 8px;
    backdrop-filter: blur(10px);
    border: 2px solid rgba(255, 255, 255, 0.1);
    font-size: 12px;
    line-height: 1.8;
}

#controls h3 {
    margin-bottom: 10px;
    color: var(--primary-color);
    font-size: 14px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

#controls .control-row {
    display: flex;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 5px;
}

#controls .key {
    background: rgba(255, 255, 255, 0.1);
    padding: 2px 8px;
    border-radius: 4px;
    font-weight: bold;
    color: var(--warning-color);
}

#controls .action {
    color: rgba(255, 255, 255, 0.8);
}

/* Mini Map (Future Enhancement) */
#minimap {
    position: absolute;
    bottom: 20px;
    right: 20px;
    width: 200px;
    height: 200px;
    background: var(--hud-bg);
    border-radius: 8px;
    backdrop-filter: blur(10px);
    border: 2px solid rgba(255, 255, 255, 0.1);
    display: none;
    /* Hidden for now */
}

/* Responsive Design */
@media (max-width: 768px) {
    #top-hud {
        gap: 20px;
        padding: 10px 20px;
    }

    .hud-value {
        font-size: 20px;
    }

    #controls {
        font-size: 10px;
        padding: 15px;
    }

    #status-text {
        font-size: 14px;
        padding: 10px 20px;
    }
}

/* Name Gate Overlay */
#name-gate {
    position: fixed;
    inset: 0;
    z-index: 900;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    font-family: 'Space Grotesk', 'Trebuchet MS', sans-serif;
}

#name-gate::before,
#name-gate::after {
    content: '';
    position: absolute;
    inset: 0;
    pointer-events: none;
}

#name-gate::before {
    background:
        radial-gradient(circle at 20% 20%, rgba(24, 140, 255, 0.25), transparent 45%),
        radial-gradient(circle at 80% 10%, rgba(255, 180, 70, 0.2), transparent 40%),
        radial-gradient(circle at 50% 80%, rgba(90, 255, 210, 0.2), transparent 45%),
        linear-gradient(160deg, rgba(6, 10, 18, 0.92), rgba(3, 6, 12, 0.98));
}

#name-gate::after {
    background-image: linear-gradient(120deg, rgba(255, 255, 255, 0.06) 0%, transparent 40%);
    opacity: 0.7;
}

#name-gate.is-hidden {
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.35s ease;
}

.gate-card {
    position: relative;
    width: min(92vw, 480px);
    padding: 28px 28px 24px;
    border-radius: 18px;
    background: linear-gradient(160deg, rgba(12, 20, 32, 0.95), rgba(12, 20, 32, 0.75));
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow:
        0 24px 60px rgba(0, 0, 0, 0.55),
        inset 0 0 0 1px rgba(255, 255, 255, 0.05);
    backdrop-filter: blur(14px);
    animation: gateRise 0.6s ease both;
    color: #eaf2ff;
}

.gate-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: 999px;
    font-size: 11px;
    letter-spacing: 2px;
    text-transform: uppercase;
    color: #9bd7ff;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.12);
    margin-bottom: 16px;
}

.gate-title {
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 8px;
}

.gate-subtitle {
    font-size: 14px;
    line-height: 1.6;
    color: rgba(234, 242, 255, 0.75);
    margin-bottom: 20px;
}

.gate-stack {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.gate-label {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 1.6px;
    color: rgba(154, 208, 255, 0.9);
}

.gate-input {
    width: 100%;
    padding: 12px 14px;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    background: rgba(240, 246, 255, 0.08);
    color: #f5faff;
    font-size: 16px;
    font-family: 'JetBrains Mono', 'Courier New', monospace;
}

.gate-input:focus {
    border-color: rgba(139, 224, 255, 0.9);
    box-shadow: 0 0 0 3px rgba(139, 224, 255, 0.25);
}

.gate-input::placeholder {
    color: rgba(245, 250, 255, 0.45);
}

#gate-link-input {
    text-transform: uppercase;
    letter-spacing: 1px;
}

.gate-help {
    font-size: 12px;
    color: rgba(186, 214, 255, 0.7);
    margin-top: -6px;
}

.gate-error {
    min-height: 18px;
    font-size: 12px;
    color: #ff9e7c;
}

.gate-button {
    width: 100%;
    padding: 12px 16px;
    border-radius: 10px;
    font-size: 15px;
    font-weight: 600;
    border: none;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.gate-button:hover:not(:disabled) {
    transform: translateY(-1px);
}

.gate-button:active {
    transform: translateY(1px);
}

.gate-primary {
    color: #08121f;
    background: linear-gradient(135deg, #8be0ff, #68ffca);
    box-shadow: 0 12px 24px rgba(104, 255, 202, 0.25);
}

.gate-primary:disabled {
    cursor: not-allowed;
    color: rgba(8, 18, 31, 0.5);
    background: linear-gradient(135deg, rgba(139, 224, 255, 0.3), rgba(104, 255, 202, 0.3));
    box-shadow: none;
}

.gate-ghost {
    background: transparent;
    color: #b7c9ff;
    border: 1px solid rgba(183, 201, 255, 0.3);
}

.gate-continue-text {
    font-size: 16px;
    color: rgba(234, 242, 255, 0.8);
}

#gate-display-name {
    color: #ffffff;
    font-weight: 700;
}

.gate-footer {
    margin-top: 18px;
    font-size: 12px;
    color: rgba(234, 242, 255, 0.55);
}

.link-overlay {
    position: fixed;
    inset: 0;
    z-index: 920;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: rgba(5, 10, 18, 0.7);
    backdrop-filter: blur(6px);
    font-family: 'Space Grotesk', 'Trebuchet MS', sans-serif;
}

.link-card {
    width: min(90vw, 420px);
    padding: 24px;
    border-radius: 16px;
    background: linear-gradient(160deg, rgba(12, 20, 32, 0.96), rgba(12, 20, 32, 0.8));
    border: 1px solid rgba(255, 255, 255, 0.12);
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
    color: #eaf2ff;
}

.link-title {
    font-size: 20px;
    font-weight: 700;
    margin-bottom: 12px;
}

.link-code-value {
    font-family: 'JetBrains Mono', 'Courier New', monospace;
    font-size: 22px;
    letter-spacing: 2px;
    padding: 12px;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.12);
    text-align: center;
    margin-bottom: 10px;
}

.link-desc {
    font-size: 13px;
    line-height: 1.5;
    color: rgba(234, 242, 255, 0.75);
    margin-bottom: 16px;
}

.link-actions {
    display: flex;
    gap: 10px;
}

.link-actions .gate-button {
    flex: 1;
}

@keyframes gateRise {
    from {
        opacity: 0;
        transform: translateY(18px) scale(0.98);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@media (max-width: 600px) {
    .gate-card {
        padding: 22px 20px;
    }

    .gate-title {
        font-size: 22px;
    }
}

@media (max-width: 480px) {
    .link-actions {
        flex-direction: column;
    }
}

/* Touch Controls */
body.touch-controls-on {
    --touch-base: clamp(96px, 18vw, 160px);
    --touch-knob: calc(var(--touch-base) * 0.45);
    --touch-button: clamp(56px, 12vw, 90px);
    --touch-gap: clamp(10px, 3vw, 18px);
}

#touch-controls {
    position: fixed;
    inset: 0;
    z-index: 12;
    pointer-events: none;
    display: none;
    touch-action: none;
    font-family: 'Space Grotesk', 'Trebuchet MS', sans-serif;
    user-select: none;
}

body.touch-controls-on #touch-controls {
    display: block;
}

body.touch-controls-on #controls {
    display: none;
}

body.touch-controls-on #status-text {
    bottom: calc(env(safe-area-inset-bottom) + var(--touch-base) + 120px);
}

.touch-stick {
    position: absolute;
    width: var(--touch-base);
    height: var(--touch-base);
    pointer-events: auto;
    touch-action: none;
}

.touch-stick.left {
    left: calc(env(safe-area-inset-left) + var(--touch-gap));
    bottom: calc(env(safe-area-inset-bottom) + var(--touch-gap));
}

.touch-stick.right {
    right: calc(env(safe-area-inset-right) + var(--touch-gap));
    bottom: calc(env(safe-area-inset-bottom) + var(--touch-gap));
}

.touch-stick .stick-base {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    background: radial-gradient(circle at 30% 30%, rgba(255, 255, 255, 0.18), rgba(0, 0, 0, 0.4));
    border: 2px solid rgba(255, 255, 255, 0.2);
    box-shadow: inset 0 0 12px rgba(0, 0, 0, 0.35);
}

.touch-stick .stick-knob {
    position: absolute;
    left: 50%;
    top: 50%;
    width: var(--touch-knob);
    height: var(--touch-knob);
    transform: translate(-50%, -50%);
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.22);
    border: 2px solid rgba(255, 255, 255, 0.3);
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.35);
}

.touch-buttons {
    position: absolute;
    right: calc(env(safe-area-inset-right) + var(--touch-gap));
    bottom: calc(env(safe-area-inset-bottom) + var(--touch-base) + var(--touch-gap));
    display: flex;
    flex-direction: column;
    gap: var(--touch-gap);
    pointer-events: auto;
}

.touch-button {
    width: var(--touch-button);
    height: var(--touch-button);
    border-radius: 999px;
    border: 2px solid rgba(255, 255, 255, 0.2);
    background: rgba(10, 20, 28, 0.7);
    color: #eaf2ff;
    font-size: 12px;
    letter-spacing: 1px;
    text-transform: uppercase;
    font-weight: 700;
    cursor: pointer;
    touch-action: none;
    transition: transform 0.1s ease, box-shadow 0.1s ease, background 0.1s ease;
}

.touch-button.is-active {
    transform: scale(0.96);
    box-shadow: 0 0 16px rgba(0, 255, 180, 0.4);
}

.touch-button.fire {
    background: rgba(60, 18, 18, 0.75);
    color: #ffd2d2;
    border-color: rgba(255, 120, 120, 0.4);
}

.touch-button.fire.is-active {
    box-shadow: 0 0 18px rgba(255, 80, 80, 0.55);
}

.touch-button.accel {
    background: rgba(15, 36, 28, 0.75);
    color: #ccffe8;
    border-color: rgba(120, 255, 210, 0.4);
}

@media (max-width: 480px) {
    body.touch-controls-on #status-text {
        bottom: calc(env(safe-area-inset-bottom) + var(--touch-base) + 90px);
        font-size: 14px;
    }
}
