:root {
    --gold-main: #D4AF37;
    --gold-light: #F4CF57;
    --bg-color: #050505;
    --panel-bg: #000000;
    --border-color: #333333;
    --grid-color: rgba(212, 175, 55, 0.08);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background-color: var(--bg-color);
    color: #fff;
    font-family: "Audiowide", sans-serif;
    background-image:
        linear-gradient(var(--grid-color) 1px, transparent 1px),
        linear-gradient(90deg, var(--grid-color) 1px, transparent 1px);
    background-size: 50px 50px;
    height: 100vh;
    overflow: hidden;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

.fascinate-font {
    font-family: "Fascinate Inline", system-ui;
}

.audiowide-font {
    font-family: "Audiowide", sans-serif;
}

#app-shell {
    --search-width: min(360px, 70vw);
    --sheet-height: min(42vh, 420px);
    height: 100vh;
    position: relative;
}

#main-panel {
    --preview-width: 46vw;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 0;
    height: 100vh;
    transition: grid-template-columns 0.25s ease;
}

#main-panel.preview-open {
    grid-template-columns: minmax(0, 1fr) minmax(320px, var(--preview-width));
}

#content-area {
    position: relative;
    min-width: 0;
    min-height: 0;
}

#scene-host {
    position: absolute;
    inset: 0;
    overflow: hidden;
    z-index: 1;
}

#scene-container {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 0;
    height: 0;
    overflow: visible;
}

#connections {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    will-change: transform;
}

.node-link {
    position: absolute;
    transform-style: preserve-3d;
    text-decoration: none;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 8px;
    will-change: transform, opacity;
}

.node-dot {
    width: 6px;
    height: 6px;
    background-color: var(--gold-main);
    box-shadow: 0 0 10px var(--gold-main);
    border-radius: 50%;
    margin-bottom: 8px;
    transition: all 0.2s;
}

.node-text {
    color: var(--gold-main);
    font-size: 12px;
    letter-spacing: 1px;
    opacity: 0.85;
    white-space: nowrap;
}

.node-link:hover .node-dot,
.node-link.is-active .node-dot {
    background-color: #FFF;
    transform: scale(2);
    box-shadow: 0 0 20px var(--gold-main);
}

.node-link.is-match .node-dot {
    transform: scale(1.55);
    box-shadow: 0 0 16px rgba(244, 207, 87, 0.95);
    background-color: var(--gold-light);
}

.node-link.is-match .node-text {
    color: #FFF;
    opacity: 0.95;
}

.node-link:hover .node-text,
.node-link.is-active .node-text {
    color: #FFF;
    opacity: 1;
}

#hud-layer {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 50;
}

.hud-title {
    position: absolute;
    top: 14px;
    left: 16px;
    margin: 0;
    font-size: 2rem;
    color: rgba(212, 175, 55, 0.88);
    letter-spacing: 1.8px;
    text-shadow: 0 0 18px rgba(212, 175, 55, 0.18);
}

.hud-chip {
    pointer-events: auto;
    position: fixed;
    width: auto;
    min-width: 90px;
    background: rgba(0, 0, 0, 0.75);
    border: 1px solid var(--border-color);
    color: var(--gold-main);
    font-family: "Audiowide", sans-serif;
    font-size: 0.75rem;
    padding: 9px 12px;
    cursor: pointer;
    text-transform: uppercase;
    letter-spacing: 1px;
    transition: all 0.2s;
    backdrop-filter: blur(2px);
}

#chip-search {
    top: 16px;
    right: 16px;
}

#chip-mode {
    top: 16px;
    right: 120px;
}

#chip-motion {
    top: 16px;
    right: 224px;
}

.hud-chip:hover,
.hud-chip[aria-pressed="true"],
.hud-chip[aria-expanded="true"] {
    background: var(--gold-main);
    color: #000;
}

.hud-popover {
    position: fixed;
    top: 58px;
    right: 16px;
    width: var(--search-width);
    max-width: 80vw;
    min-width: 240px;
    background: rgba(0, 0, 0, 0.85);
    border: 1px solid var(--border-color);
    padding: 14px 12px 12px;
    z-index: 55;
    backdrop-filter: blur(4px);
    transform: translateY(-8px);
    opacity: 0;
    pointer-events: none;
    transition: all 0.18s ease;
}

#search-resize-handle {
    position: absolute;
    right: 2px;
    bottom: 2px;
    width: 14px;
    height: 14px;
    cursor: nwse-resize;
    border-right: 1px solid rgba(212, 175, 55, 0.45);
    border-bottom: 1px solid rgba(212, 175, 55, 0.45);
}

.hud-popover.active {
    transform: translateY(0);
    opacity: 1;
    pointer-events: auto;
}

#search-input {
    width: 100%;
    background: #111;
    border: 1px solid var(--border-color);
    color: var(--gold-main);
    padding: 12px;
    font-family: "Audiowide", sans-serif;
    font-size: 0.9rem;
    text-transform: uppercase;
    outline: none;
}

#search-input:focus,
#search-input:focus-visible {
    background: #000;
    border-color: var(--gold-light);
    box-shadow: inset 0 0 10px rgba(212, 175, 55, 0.2);
}

#list-sheet {
    position: fixed;
    left: 12px;
    right: 12px;
    bottom: 12px;
    height: var(--sheet-height);
    min-height: 220px;
    max-height: 80vh;
    background: rgba(0, 0, 0, 0.92);
    border: 1px solid var(--border-color);
    box-shadow: 0 -14px 40px rgba(0, 0, 0, 0.5);
    z-index: 90;
    transform: translateY(calc(100% + 14px));
    transition: transform 0.24s ease;
    display: flex;
    flex-direction: column;
}

#sheet-resize-handle {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 12px;
    cursor: ns-resize;
    z-index: 2;
}

#list-sheet.active {
    transform: translateY(0);
}

.sheet-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 14px;
    border-bottom: 1px solid var(--border-color);
    color: var(--gold-main);
}

.sheet-close {
    width: auto;
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--gold-main);
    font-family: "Audiowide", sans-serif;
    font-size: 0.68rem;
    padding: 6px 10px;
}

#project-list {
    margin: 0;
    padding: 10px;
    list-style: none;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 10px;
    overflow: auto;
}

.list-item {
    border: 1px solid var(--border-color);
    background: #0b0b0b;
    color: var(--gold-main);
    padding: 12px;
    min-height: 60px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    transition: transform 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}

.list-item:hover,
.list-item.is-selected {
    border-color: var(--gold-main);
    background: #141414;
    transform: translateY(-1px);
}

.list-item-text {
    font-size: 0.82rem;
    color: var(--gold-main);
}

.list-item-arrow {
    color: #76663b;
    font-size: 0.66rem;
    margin-left: 10px;
}

.list-item.is-hidden {
    display: none;
}

#preview-sidebar {
    position: relative;
    width: 100%;
    min-width: 0;
    border-left: 2px solid var(--border-color);
    background: #000;
    z-index: 120;
    display: flex;
    flex-direction: column;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.18s ease;
}

#main-panel.preview-open #preview-sidebar {
    opacity: 1;
    pointer-events: auto;
}

#resize-handle {
    position: absolute;
    left: 0;
    top: 0;
    width: 10px;
    height: 100%;
    cursor: col-resize;
    z-index: 20;
}

.preview-header {
    background: var(--gold-main);
    padding: 14px 20px 14px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

#preview-title {
    color: #000;
    margin: 0;
    font-size: 0.95rem;
    line-height: 1.3;
}

.preview-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.preview-btn {
    border: 1px solid #000;
    color: #000;
    background: transparent;
    padding: 6px 10px;
    font-size: 0.66rem;
    font-weight: bold;
    text-decoration: none;
    white-space: nowrap;
}

.preview-btn:hover {
    background: #000;
    color: var(--gold-main);
}

.preview-btn.is-disabled {
    opacity: 0.5;
    pointer-events: none;
}

#preview-sidebar:fullscreen {
    width: 100vw;
    height: 100vh;
    border: none;
}

#preview-sidebar:fullscreen #resize-handle {
    display: none;
}

.preview-content {
    position: relative;
    flex: 1;
    background: #111;
    overflow: hidden;
}

#preview-frame {
    width: 100%;
    height: 100%;
    border: none;
    background: #fff;
    opacity: 0;
    transition: opacity 0.22s ease;
}

.preview-content.is-loaded #preview-frame {
    opacity: 1;
}

.iframe-loader {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: var(--gold-main);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    z-index: 10;
    pointer-events: none;
    opacity: 1;
    transition: opacity 0.2s ease;
    text-align: center;
}

.preview-content.is-loaded .iframe-loader {
    opacity: 0;
}

.preview-content.is-error .iframe-loader {
    opacity: 1;
}

.preview-content.is-error .spinner {
    animation: none;
    border-color: #662222;
    border-top-color: #FF6B6B;
}

.preview-content.is-error .iframe-loader span::before {
    content: 'Unable to load preview. ';
    color: #FF6B6B;
}

.spinner {
    width: 28px;
    height: 28px;
    border: 2px solid #333;
    border-top-color: var(--gold-main);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.hud-hint {
    position: fixed;
    left: 16px;
    bottom: 16px;
    color: rgba(160, 160, 160, 0.72);
    font-size: 0.6rem;
    letter-spacing: 1px;
    z-index: 60;
    pointer-events: none;
}

#kao-corner-banner {
    position: fixed;
    right: 12px;
    bottom: 12px;
    width: min(320px, 42vw);
    z-index: 8;
    opacity: 0.72;
    filter: saturate(0.9);
    pointer-events: none;
}

#kao-corner-banner>* {
    pointer-events: auto;
}

#kao-corner-banner:hover {
    opacity: 0.9;
}

#drag-shield {
    position: fixed;
    inset: 0;
    z-index: 5000;
    pointer-events: none;
    cursor: inherit;
}

body.resizing-preview #main-panel {
    transition: none;
}

body.resizing-search .hud-popover,
body.resizing-sheet #list-sheet {
    transition: none;
}

body.dragging-resize #drag-shield {
    pointer-events: auto;
}

body.dragging-resize #preview-frame {
    pointer-events: none;
}

button:focus-visible,
#search-input:focus-visible,
.list-item:focus-visible,
#preview-link:focus-visible,
#close-preview:focus-visible,
.node-link:focus-visible,
.hud-chip:focus-visible {
    outline: 2px solid var(--gold-main);
    outline-offset: 2px;
}

@media (max-width: 980px) {
    .hud-title {
        font-size: 1.5rem;
        top: 12px;
        left: 12px;
    }

    .hud-chip {
        font-size: 0.68rem;
        min-width: 78px;
        padding: 8px 10px;
    }

    #chip-search {
        right: 10px;
    }

    #chip-mode {
        right: 98px;
    }

    #chip-motion {
        right: 186px;
    }

    .hud-popover {
        right: 10px;
        width: min(330px, calc(100vw - 20px));
    }

    #main-panel {
        grid-template-columns: 1fr;
        grid-template-rows: minmax(0, 1fr) 0;
        height: 100vh;
    }

    #main-panel.preview-open {
        grid-template-columns: 1fr;
        grid-template-rows: minmax(0, 1fr) minmax(320px, 54vh);
    }

    #preview-sidebar {
        border-left: none;
        border-top: 2px solid var(--border-color);
    }

    #resize-handle {
        display: none;
    }

    #list-sheet {
        left: 8px;
        right: 8px;
        bottom: 8px;
        height: min(48vh, 460px);
    }

    #search-resize-handle,
    #sheet-resize-handle {
        display: none;
    }

    #project-list {
        grid-template-columns: 1fr;
    }

    .hud-hint {
        display: none;
    }

    #kao-corner-banner {
        width: min(280px, 70vw);
        right: 8px;
        bottom: 8px;
    }
}
