:root {
    --bg: #000000;
    --panel-bg: rgba(0, 0, 0, 0.85);
    --border: #ffffff;
    --text-primary: #ffffff;
    --text-secondary: #cccccc;
    --font-mono: 'Share Tech Mono', 'Courier New', Courier, monospace;
    --neon-cyan: #55f6ff;
    --neon-amber: #ffc45c;
    --glass: rgba(5, 14, 22, 0.78);
}

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

body {
    font-family: var(--font-mono);
    background-color: var(--bg);
    color: var(--text-primary);
    overflow: hidden;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
}

#canvas-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 1;
    touch-action: none;
    overscroll-behavior: none;
}

#canvas-container canvas { touch-action: none; }

/* Tactical UI Panel */
#ui-panel {
    position: absolute;
    top: max(20px, env(safe-area-inset-top));
    left: max(20px, env(safe-area-inset-left));
    width: min(320px, calc(100vw - 40px - env(safe-area-inset-left) - env(safe-area-inset-right)));
    max-height: calc(100vh - 40px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    z-index: 10;
    background: var(--glass);
    border: 1px solid rgba(85, 246, 255, 0.48);
    box-shadow: 0 0 24px rgba(0, 229, 255, 0.12), inset 0 0 30px rgba(0, 125, 170, 0.05);
    backdrop-filter: blur(14px) saturate(125%);
    -webkit-backdrop-filter: blur(14px) saturate(125%);
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
}

#ui-panel.collapsed #panel-content {
    display: none;
}

/* Decorative Wireframe Header */
.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.drag-handle {
    font-size: var(--text-lg);
    font-weight: 400;
    text-transform: uppercase;
    letter-spacing: 2px;
    border-bottom: 1px solid var(--border);
    padding-bottom: 0.2rem;
    cursor: move;
    user-select: none;
}

.wireframe-box {
    width: 100%;
    height: 30px;
    margin-bottom: 1.5rem;
    margin-top: 1rem;
    border: 1px solid var(--border);
    background: repeating-linear-gradient(
        45deg,
        transparent,
        transparent 5px,
        rgba(255, 255, 255, 0.2) 5px,
        rgba(255, 255, 255, 0.2) 10px
    );
}

/* Toggle Button */
#toggle-panel {
    width: 44px;
    height: 44px;
    background: transparent;
    border: 1px solid var(--border);
    color: var(--border);
    font-family: var(--font-mono);
    cursor: pointer;
    margin: 0;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

#toggle-panel:hover {
    background: var(--border);
    color: var(--bg);
}

/* Forms */
.input-group {
    margin-bottom: 1.5rem;
    position: relative;
}

.row {
    display: flex;
    gap: 1rem;
}

label {
    display: block;
    font-size: var(--text-sm);
    color: var(--text-secondary);
    margin-bottom: 0.2rem;
    text-transform: uppercase;
    letter-spacing: 1px;
}

input {
    width: 100%;
    background: transparent;
    border: none;
    border-bottom: 2px solid var(--border);
    padding: 0.5rem 0;
    color: var(--text-primary);
    font-size: var(--text-lg);
    font-family: var(--font-mono);
    outline: none;
    transition: all 0.3s;
}

input:focus {
    border-bottom: 2px solid rgba(255, 255, 255, 0.5);
    background: rgba(255,255,255,0.05);
}

button {
    width: 100%;
    background: transparent;
    color: var(--border);
    border: 2px solid var(--border);
    padding: 1rem;
    font-size: var(--text-md);
    font-family: var(--font-mono);
    cursor: pointer;
    text-transform: uppercase;
    letter-spacing: 2px;
    margin-top: 1rem;
    transition: all 0.2s ease;
    position: relative;
    overflow: hidden;
}

button:hover {
    background: var(--border);
    color: var(--bg);
}

button:focus-visible, input:focus-visible, a:focus-visible {
    outline: 2px solid var(--neon-amber);
    outline-offset: 3px;
}

button:disabled {
    cursor: not-allowed;
    opacity: 0.35;
}

/* Results Section */
#results {
    margin-top: 2rem;
    border-top: 1px dashed var(--border);
    padding-top: 1.5rem;
    flex-grow: 1;
}

.hidden {
    display: none !important;
}

.error {
    color: #ff0000;
    background: rgba(255, 0, 0, 0.1);
    padding: 1rem;
    border: 1px solid #ff0000;
    font-size: var(--text-md);
}

h3 {
    font-size: var(--text-md);
    font-weight: 400;
    color: var(--neon-cyan);
    margin-bottom: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.mt-10 { margin-top: 1.5rem; }

p {
    font-size: var(--text-md);
    margin-bottom: 0.5rem;
    display: flex;
    justify-content: space-between;
}

.highlight {
    color: var(--text-primary);
    font-weight: bold;
}

/* Route telemetry and hop rail */
.route-summary {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.45rem;
}

.route-summary p {
    min-width: 0;
    padding: 0.55rem;
    flex-direction: column;
    gap: 0.2rem;
    border: 1px solid rgba(85, 246, 255, 0.2);
    background: rgba(0, 210, 255, 0.045);
}

.route-summary p span { color: var(--text-secondary); font-size: var(--text-sm); }
.route-summary strong { color: var(--neon-amber); font-weight: 400; }

.hop-controls {
    display: grid;
    grid-template-columns: 48px minmax(0, 1fr) 48px;
    align-items: stretch;
    gap: 0.5rem;
    margin-top: 0.9rem;
}

.hop-controls button {
    width: 48px;
    min-height: 48px;
    margin: 0;
    padding: 0;
    color: var(--neon-cyan);
    border-color: rgba(85, 246, 255, 0.65);
    font-size: 1.35rem;
}

.hop-status {
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border-block: 1px solid rgba(85, 246, 255, 0.28);
}

#hop-progress { color: var(--neon-amber); letter-spacing: 0.12em; }
#hop-current { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-secondary); font-size: var(--text-sm); }

#hop-list {
    list-style: none;
    font-size: var(--text-sm);
    max-height: 250px;
    overflow-y: auto;
    border: 1px solid rgba(255,255,255,0.2);
    padding: 0.5rem;
    touch-action: pan-y;
    overscroll-behavior: contain;
}

#hop-list::-webkit-scrollbar {
    width: 4px;
}
#hop-list::-webkit-scrollbar-thumb {
    background: var(--border);
}

#hop-list li {
    padding: 0;
    border-bottom: 1px dotted rgba(255,255,255,0.2);
}

.hop-button {
    width: 100%;
    min-height: 44px;
    margin: 0;
    padding: 0.55rem;
    border: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    text-align: left;
    font-size: var(--text-sm);
    letter-spacing: 0.04em;
}

.hop-button .hop-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hop-button .hop-distance { flex: none; color: var(--text-secondary); }
.hop-button[aria-current="step"] { color: #001014; background: var(--neon-cyan); box-shadow: 0 0 16px rgba(85, 246, 255, 0.35); }

#star-details {
    position: absolute;
    right: max(20px, env(safe-area-inset-right));
    top: max(80px, env(safe-area-inset-top));
    z-index: 12;
    width: min(280px, calc(100vw - 40px));
    padding: 0;
    background: rgba(14, 14, 20, 0.92);
    border: 1px solid var(--border-soft);
    border-radius: 6px;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.5), 0 0 1px rgba(85, 246, 255, 0.15);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    font-family: var(--font-mono);
}

#star-details .card-header {
    display: flex;
    align-items: center;
    padding: 0 0.9rem;
    border-bottom: 1px solid var(--border-soft);
    min-height: 2.625rem;
}
#star-details.card-collapsed .card-header { border-bottom: none; }

#star-details h2 {
    color: var(--neon-amber);
    font-size: var(--text-lg);
    font-weight: 400;
    margin: 0;
    padding: 0;
    letter-spacing: 1px;
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

#star-details .card-toggle {
    width: 26px; height: 26px;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
    margin: 0 0 0 0.5rem;
    background: transparent;
    border: 1px solid var(--border-soft);
    color: var(--text-dim);
    font-size: var(--text-md); line-height: 1;
    cursor: pointer; border-radius: 3px;
    font-family: var(--font-mono);
    padding: 0;
    transition: color 0.2s, border-color 0.2s;
}
#star-details .card-toggle:hover {
    color: var(--neon-cyan);
    border-color: var(--neon-cyan);
}

#star-details .card-body {
    padding: 0.6rem 0.9rem 0.75rem;
}

#star-details dl {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 0.3rem 1rem;
    margin: 0;
    font-size: var(--text-sm);
    line-height: 1.5;
}
#star-details dt {
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    white-space: nowrap;
}
#star-details dd {
    text-align: right;
    color: var(--text-primary);
    margin: 0;
    overflow-wrap: anywhere;
}

#star-details a {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    margin-top: 0.6rem;
    color: var(--neon-cyan);
    font-size: var(--text-sm);
    text-decoration: none;
    letter-spacing: 0.3px;
}
#star-details a:hover { text-decoration: underline; }

#star-details.card-collapsed .card-body { display: none; }

/* Autocomplete Combobox */
.combobox-wrapper {
    position: relative;
}

.autocomplete-listbox {
    position: absolute;
    top: 100%;
    left: 0;
    width: 100%;
    max-height: 200px;
    background: rgba(4, 12, 20, 0.95);
    border: 1px solid rgba(85, 246, 255, 0.48);
    border-top: none;
    box-shadow: 0 4px 16px rgba(0, 229, 255, 0.15);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    z-index: 100;
    list-style: none;
    overflow-y: auto;
    touch-action: pan-y;
    overscroll-behavior: contain;
}

.autocomplete-listbox::-webkit-scrollbar {
    width: 4px;
}
.autocomplete-listbox::-webkit-scrollbar-thumb {
    background: var(--neon-cyan);
}

.autocomplete-option {
    padding: 0.7rem 0.8rem;
    cursor: pointer;
    border-bottom: 1px dotted rgba(255,255,255,0.15);
    color: var(--text-primary);
    font-size: var(--text-md);
    transition: background 0.2s, color 0.2s;
}

.autocomplete-option:last-child {
    border-bottom: none;
}

.autocomplete-option:hover,
.autocomplete-option.active {
    background: rgba(85, 246, 255, 0.15);
    color: var(--neon-amber);
}

@media (max-width: 768px), (pointer: coarse) {
    .autocomplete-option {
        min-height: 44px;
        box-sizing: border-box;
        display: flex;
        align-items: center;
    }
}

/* Mobile Responsive UI */
@media (max-width: 768px) {
    #ui-panel {
        top: 0;
        bottom: auto;
        left: 0;
        width: 100vw;
        max-height: 55vh;
        border-left: none;
        border-right: none;
        border-top: none;
        border-bottom: 2px solid var(--border);
        padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) 12px max(12px, env(safe-area-inset-left));
    }

    #ui-panel.collapsed {
        max-height: auto;
        height: auto;
        padding: 0;
    }

    #ui-panel.collapsed #panel-content {
        display: none;
    }

    .panel-header {
        padding: 0.6rem 1rem;
    }

    .drag-handle {
        font-size: var(--text-lg);
        border-bottom: none;
        padding-bottom: 0;
    }

    #panel-content {
        padding: 0.6rem 1rem 1rem 1rem;
        overflow-y: auto;
        max-height: calc(50vh - 48px);
        -webkit-overflow-scrolling: touch;
        touch-action: pan-y;
        overscroll-behavior: contain;
    }

    .wireframe-box {
        display: none;
    }

    .input-group {
        margin-bottom: 0.8rem;
    }

    label {
        font-size: var(--text-sm);
    }

    input {
        font-size: var(--text-lg);
        padding: 0.4rem 0;
        min-height: 44px;
    }

    .row {
        flex-direction: column;
        gap: 0.5rem;
    }

    .row > div {
        width: 100%;
    }

    button {
        min-height: 48px;
        padding: 0.7rem;
        font-size: var(--text-md);
        margin-top: 0.5rem;
    }

    #results {
        margin-top: 1rem;
        padding-top: 0.8rem;
    }

    h3 {
        font-size: var(--text-md);
        margin-bottom: 0.5rem;
    }

    p {
        font-size: var(--text-md);
        margin-bottom: 0.3rem;
    }

    #hop-list {
        display: flex;
        flex-direction: row;
        overflow-x: auto;
        overflow-y: hidden;
        white-space: nowrap;
        gap: 0.5rem;
        padding: 0.3rem;
        max-height: 100px;
        touch-action: pan-x;
        overscroll-behavior: contain;
    }

    #hop-list li {
        border-bottom: none;
        border-right: 1px dotted rgba(255,255,255,0.2);
        padding-right: 0.8rem;
        min-width: 160px;
        font-size: var(--text-sm);
        padding: 0.3rem 0.8rem 0.3rem 0;
    }

    .hop-button { min-width: 160px; }

    #star-details {
        top: auto;
        bottom: max(12px, env(safe-area-inset-bottom));
        left: max(12px, env(safe-area-inset-left));
        right: max(12px, env(safe-area-inset-right));
        width: calc(100vw - 24px - env(safe-area-inset-left) - env(safe-area-inset-right));
    }

    .error {
        padding: 0.6rem;
        font-size: var(--text-md);
    }

    .autocomplete-listbox {
        top: auto;
        bottom: 100%;
        border-top: 1px solid rgba(85, 246, 255, 0.48);
        border-bottom: none;
        box-shadow: 0 -4px 16px rgba(0, 229, 255, 0.15);
    }
}

/* Map Only Mode Styles */
body.map-only-mode #ui-panel,
body.map-only-mode #star-details,
body.map-only-mode #star-labels-container {
    display: none !important;
}

#map-mode-controls {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 50;
}

#map-mode-controls:not(.hidden) {
    display: block;
}

.floating-btn {
    position: absolute;
    width: 44px;
    height: 44px;
    background: var(--glass);
    border: 1px solid var(--border);
    color: var(--border);
    font-family: var(--font-mono);
    cursor: pointer;
    text-transform: uppercase;
    display: flex;
    justify-content: center;
    align-items: center;
    pointer-events: auto;
    font-size: var(--text-lg);
    transition: all 0.2s ease;
}

.floating-btn:hover:not(:disabled) {
    background: var(--border);
    color: var(--bg);
}

.floating-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
    background: transparent;
    color: var(--border);
}

.floating-btn.left {
    top: 50%;
    left: max(20px, env(safe-area-inset-left));
    transform: translateY(-50%);
}

.floating-btn.right {
    top: 50%;
    right: max(20px, env(safe-area-inset-right));
    transform: translateY(-50%);
}

.floating-btn.bottom {
    bottom: max(20px, env(safe-area-inset-bottom));
    left: 50%;
    transform: translateX(-50%);
    width: auto;
    padding: 0 1rem;
    font-size: var(--text-md);
    height: 36px;
}

.floating-search-container {
    position: absolute;
    top: max(20px, env(safe-area-inset-top));
    left: 50%;
    transform: translateX(-50%);
    width: min(400px, calc(100vw - 40px - env(safe-area-inset-left) - env(safe-area-inset-right)));
    z-index: 100;
    background: var(--bg);
    border: 1px solid var(--border);
    pointer-events: auto;
    box-shadow: 0 4px 16px rgba(0, 229, 255, 0.1);
}

.floating-search-container input {
    width: 100%;
    background: transparent;
    border: none;
    padding: 12px 16px;
    color: var(--text);
    font-family: var(--font-mono);
    font-size: var(--text-lg);
    outline: none;
    box-sizing: border-box;
}

.floating-search-container input::placeholder {
    color: var(--dim);
}

.floating-search-container .autocomplete-listbox {
    top: 100%;
    bottom: auto;
    border-top: none;
    border-bottom: 1px solid rgba(85, 246, 255, 0.48);
}
