/* ==========================================================================
   Agent Silicon Valley — 3D Living City HUD & Stylesheet
   ========================================================================== */

:root {
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --glass-bg: rgba(15, 23, 42, 0.78);
    --glass-bg-strong: rgba(15, 23, 42, 0.90);
    --glass-border: rgba(255, 255, 255, 0.14);
    --text-primary: #f8fafc;
    --text-secondary: #cbd5e1;
    --text-muted: #94a3b8;
    --accent: #ef4444;
    --accent-blue: #38bdf8;
    --shadow-lg: 0 20px 50px rgba(2, 6, 23, 0.45);
    --radius-lg: 18px;
    --radius-md: 12px;
    --radius-pill: 999px;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: var(--font-sans);
    background: #8ec5e8;
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
    user-select: none;
}

/* 3D Viewport */
.city-viewport {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100dvh;
    overflow: hidden;
}

#city-canvas {
    display: block;
    width: 100%;
    height: 100%;
    cursor: grab;
    touch-action: none;
}

#city-canvas:active {
    cursor: grabbing;
}

#city-canvas.is-hovering {
    cursor: pointer;
}

/* Floating 3D Plaza Labels */
.plaza-labels-layer {
    position: fixed;
    inset: 0;
    pointer-events: none;
    overflow: hidden;
    z-index: 5;
    transition: opacity 0.25s ease;
}

.plaza-labels-layer.is-hidden {
    opacity: 0;
}

.plaza-pin {
    position: absolute;
    left: 0;
    top: 0;
    transform: translate(-50%, -100%);
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 2px 8px 2px 5px;
    border-radius: 999px;
    background: rgba(15, 23, 42, 0.82);
    border: 1.5px solid var(--pin-color, #38bdf8);
    color: #fff;
    font-size: 10.5px;
    font-weight: 700;
    letter-spacing: 0.01em;
    white-space: nowrap;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.32);
    backdrop-filter: blur(6px);
    will-change: transform, opacity;
    transition: opacity 0.18s ease, border-color 0.2s ease, background 0.2s ease;
}

.plaza-pin::after {
    content: '';
    position: absolute;
    left: 50%;
    bottom: -5px;
    transform: translateX(-50%);
    width: 0;
    height: 0;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-top: 5px solid var(--pin-color, #38bdf8);
}

.plaza-pin.is-hovered {
    background: var(--pin-color, #2563eb);
    border-color: #ffffff;
    z-index: 12;
}

.plaza-pin-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--pin-color, #38bdf8);
    flex-shrink: 0;
    box-shadow: 0 0 8px var(--pin-color, #38bdf8);
}

.plaza-pin.is-hovered .plaza-pin-dot {
    background: #ffffff;
}

/* Loader */
.city-loader {
    position: fixed;
    inset: 0;
    z-index: 60;
    display: grid;
    place-items: center;
    background: radial-gradient(circle at 30% 20%, #1e3a5f, #0b1220 75%);
    transition: opacity 0.5s ease, visibility 0.5s ease;
}

.city-loader.is-done {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.loader-card {
    width: min(440px, 90vw);
    padding: 32px 28px;
    border-radius: 22px;
    background: rgba(15, 23, 42, 0.85);
    border: 1px solid rgba(255, 255, 255, 0.14);
    box-shadow: var(--shadow-lg);
    text-align: center;
}

.loader-badge {
    display: inline-block;
    padding: 5px 12px;
    border-radius: var(--radius-pill);
    background: rgba(239, 68, 68, 0.18);
    border: 1px solid rgba(239, 68, 68, 0.45);
    color: #fca5a5;
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0.12em;
    margin-bottom: 14px;
}

.loader-title {
    font-size: 26px;
    font-weight: 900;
    letter-spacing: 0.04em;
    color: #ffffff;
    margin-bottom: 8px;
}

.loader-sub {
    margin: 0 0 22px;
    font-size: 13.5px;
    color: var(--text-secondary);
    line-height: 1.5;
}

.loader-bar {
    height: 6px;
    border-radius: 99px;
    background: rgba(255, 255, 255, 0.1);
    overflow: hidden;
}

.loader-bar span {
    display: block;
    height: 100%;
    width: 20%;
    border-radius: 99px;
    background: linear-gradient(90deg, #ef4444, #f59e0b, #38bdf8);
    transition: width 0.35s ease;
}

.webgl-fallback {
    position: fixed;
    inset: 0;
    z-index: 40;
    display: grid;
    place-items: center;
    background: #0f172a;
    padding: 24px;
}

.webgl-fallback[hidden] {
    display: none;
}

.fallback-card {
    max-width: 460px;
    padding: 28px;
    border-radius: var(--radius-lg);
    background: rgba(30, 41, 59, 0.9);
    border: 1px solid var(--glass-border);
    text-align: center;
}

/* Top-Left Brand HUD */
.hud-brand {
    position: fixed;
    top: 16px;
    left: 16px;
    z-index: 20;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: auto;
}

.brand-logo {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 9px 15px 9px 10px;
    border-radius: 16px;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    backdrop-filter: blur(14px);
    box-shadow: 0 10px 30px rgba(2, 6, 23, 0.28);
}

.brand-cube {
    width: 38px;
    height: 38px;
    border-radius: 11px;
    display: grid;
    place-items: center;
    font-weight: 900;
    font-size: 15px;
    letter-spacing: 0.04em;
    color: #fff;
    background: linear-gradient(135deg, #ef4444 0%, #f97316 100%);
    box-shadow: 0 6px 16px rgba(239, 68, 68, 0.42);
    flex-shrink: 0;
}

.brand-text h1 {
    margin: 0;
    font-size: 15px;
    font-weight: 800;
    letter-spacing: 0.02em;
    line-height: 1.15;
    color: #ffffff;
}

.brand-text p {
    margin: 2px 0 0;
    font-size: 11.5px;
    color: var(--text-secondary);
}

.hud-live-stats {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.live-pill,
.stat-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 10px;
    border-radius: var(--radius-pill);
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    backdrop-filter: blur(10px);
    font-size: 11.5px;
    color: var(--text-secondary);
}

.live-pill {
    color: #86efac;
    font-weight: 700;
    letter-spacing: 0.05em;
}

.live-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #22c55e;
    box-shadow: 0 0 8px #22c55e;
}

@media (prefers-reduced-motion: no-preference) {
    .live-dot {
        animation: livePulse 2s ease-in-out infinite;
    }
}

@keyframes livePulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.45; transform: scale(0.82); }
}

.stat-pill strong {
    color: #ffffff;
    font-weight: 700;
}

/* Top-Right Controls HUD */
.hud-controls {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 20;
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 8px;
    max-width: calc(100vw - 380px);
}

.control-group {
    display: inline-flex;
    align-items: center;
    padding: 4px;
    gap: 3px;
    border-radius: 13px;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    backdrop-filter: blur(14px);
    box-shadow: 0 8px 24px rgba(2, 6, 23, 0.25);
}

.hud-btn {
    appearance: none;
    border: 0;
    background: transparent;
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 12px;
    font-weight: 600;
    padding: 7px 11px;
    border-radius: 9px;
    cursor: pointer;
    white-space: nowrap;
    transition: background-color 0.16s ease, color 0.16s ease;
}

.hud-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #ffffff;
}

.hud-btn:focus-visible,
.directory-toggle:focus-visible,
.plaza-list-btn:focus-visible,
.chip:focus-visible,
.icon-close-btn:focus-visible,
.dialog-close:focus-visible,
.btn-primary:focus-visible,
.btn-secondary:focus-visible {
    outline: 2px solid #38bdf8;
    outline-offset: 2px;
}

.hud-btn.is-active {
    background: rgba(255, 255, 255, 0.18);
    color: #ffffff;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.16);
}

/* Bottom-Left Plaza Directory */
.hud-directory-wrap {
    position: fixed;
    left: 16px;
    bottom: 16px;
    z-index: 25;
}

.directory-toggle {
    display: inline-flex;
    align-items: center;
    gap: 9px;
    padding: 11px 16px;
    border-radius: 14px;
    background: var(--glass-bg-strong);
    border: 1px solid rgba(255, 255, 255, 0.18);
    color: #ffffff;
    font-family: inherit;
    font-size: 13.5px;
    font-weight: 700;
    cursor: pointer;
    backdrop-filter: blur(14px);
    box-shadow: 0 12px 30px rgba(2, 6, 23, 0.38);
    transition: transform 0.16s ease, background-color 0.16s ease;
}

.directory-toggle:hover {
    background: rgba(30, 41, 59, 0.95);
    transform: translateY(-1px);
}

.dir-count {
    padding: 2px 8px;
    border-radius: var(--radius-pill);
    background: rgba(239, 68, 68, 0.9);
    color: #ffffff;
    font-size: 11.5px;
    font-weight: 800;
}

.directory-panel {
    position: absolute;
    left: 0;
    bottom: 56px;
    width: min(370px, calc(100vw - 32px));
    max-height: min(68dvh, 560px);
    display: flex;
    flex-direction: column;
    border-radius: var(--radius-lg);
    background: var(--glass-bg-strong);
    border: 1px solid rgba(255, 255, 255, 0.16);
    backdrop-filter: blur(18px);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}

.directory-panel[hidden] {
    display: none;
}

.directory-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
    padding: 16px 16px 10px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.directory-header h2 {
    margin: 0;
    font-size: 15px;
    font-weight: 800;
}

.directory-header p {
    margin: 3px 0 0;
    font-size: 11.5px;
    color: var(--text-muted);
}

.icon-close-btn {
    border: 0;
    width: 30px;
    height: 30px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 14px;
    flex-shrink: 0;
}

.icon-close-btn:hover {
    background: rgba(255, 255, 255, 0.16);
    color: #fff;
}

.directory-search {
    padding: 10px 14px 6px;
}

.directory-search input {
    width: 100%;
    padding: 9px 12px;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.14);
    background: rgba(2, 6, 23, 0.55);
    color: #fff;
    font-family: inherit;
    font-size: 13px;
}

.directory-search input::placeholder {
    color: var(--text-muted);
}

.district-chips {
    display: flex;
    gap: 5px;
    padding: 6px 14px 10px;
    overflow-x: auto;
    scrollbar-width: none;
}

.district-chips::-webkit-scrollbar {
    display: none;
}

.chip {
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-secondary);
    padding: 5px 10px;
    border-radius: var(--radius-pill);
    font-family: inherit;
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
    cursor: pointer;
    transition: background-color 0.15s ease, color 0.15s ease;
}

.chip.is-active {
    background: var(--chip-accent, #ef4444);
    border-color: transparent;
    color: #ffffff;
}

.plaza-list {
    list-style: none;
    margin: 0;
    padding: 4px 10px 12px;
    overflow-y: auto;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.plaza-list-item[hidden] {
    display: none;
}

.plaza-list-btn {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border: 1px solid transparent;
    border-radius: 11px;
    background: rgba(255, 255, 255, 0.03);
    color: var(--text-primary);
    font-family: inherit;
    text-align: left;
    cursor: pointer;
    transition: background-color 0.15s ease, border-color 0.15s ease;
}

.plaza-list-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.12);
}

.plaza-list-icon {
    width: 34px;
    height: 34px;
    border-radius: 10px;
    border: 1px solid transparent;
    display: grid;
    place-items: center;
    font-size: 16px;
    flex-shrink: 0;
}

.plaza-list-info {
    display: flex;
    flex-direction: column;
    min-width: 0;
    flex: 1;
}

.plaza-list-info strong {
    font-size: 13px;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.plaza-list-info small {
    font-size: 11px;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.plaza-list-arrow {
    color: var(--text-muted);
    font-size: 14px;
}

/* Bottom-Center Hint */
.hud-hint {
    position: fixed;
    left: 50%;
    bottom: 16px;
    transform: translateX(-50%);
    z-index: 15;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    border-radius: var(--radius-pill);
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    backdrop-filter: blur(12px);
    font-size: 12px;
    color: var(--text-secondary);
    pointer-events: none;
    white-space: nowrap;
}

.hud-hint strong {
    color: #ffffff;
    font-weight: 700;
}

.hud-hint .sep {
    opacity: 0.4;
}

/* Hover Tooltip */
.hover-tooltip {
    position: fixed;
    left: 0;
    top: 0;
    z-index: 30;
    pointer-events: none;
    min-width: 210px;
    max-width: 280px;
    padding: 10px 13px;
    border-radius: 13px;
    background: var(--glass-bg-strong);
    border: 1px solid rgba(255, 255, 255, 0.2);
    backdrop-filter: blur(12px);
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.4);
}

.hover-tooltip[hidden] {
    display: none;
}

.tooltip-top {
    display: flex;
    align-items: center;
    gap: 10px;
}

.tooltip-icon {
    width: 34px;
    height: 34px;
    border-radius: 9px;
    background: rgba(255, 255, 255, 0.1);
    display: grid;
    place-items: center;
    font-size: 17px;
    flex-shrink: 0;
}

.tooltip-name {
    font-size: 13.5px;
    font-weight: 800;
    color: #fff;
    line-height: 1.2;
}

.tooltip-cat {
    font-size: 11px;
    color: var(--text-secondary);
    margin-top: 2px;
}

.tooltip-foot {
    margin-top: 8px;
    padding-top: 6px;
    border-top: 1px solid rgba(255, 255, 255, 0.09);
    font-size: 11px;
    color: #7dd3fc;
    font-weight: 600;
}

/* Native Modal <dialog> (Modern Web Guidance compliant) */
dialog.plaza-dialog {
    padding: 0;
    border: 0;
    background: transparent;
    color: var(--text-primary);
    width: min(500px, calc(100vw - 28px));
    max-height: calc(100dvh - 36px);
    border-radius: 22px;
    box-shadow: var(--shadow-lg);
    overflow: visible;
}

dialog.plaza-dialog:modal {
    overscroll-behavior: contain;
}

dialog.plaza-dialog::backdrop {
    background: rgba(2, 6, 23, 0.58);
    backdrop-filter: blur(5px);
    overflow: hidden;
    overscroll-behavior: contain;
}

.dialog-shell {
    position: relative;
    border-radius: 22px;
    background: rgba(15, 23, 42, 0.96);
    border: 1px solid rgba(255, 255, 255, 0.16);
    overflow: hidden;
    user-select: text;
}

.dialog-accent-bar {
    height: 6px;
    width: 100%;
    background: linear-gradient(90deg, #ef4444, #f59e0b);
}

.dialog-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 14px;
    padding: 20px 22px 14px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.dialog-identity {
    display: flex;
    align-items: center;
    gap: 13px;
}

.dialog-icon {
    width: 50px;
    height: 50px;
    border-radius: 14px;
    display: grid;
    place-items: center;
    font-size: 24px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.14);
    flex-shrink: 0;
}

.dialog-district {
    display: inline-block;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: #93c5fd;
    margin-bottom: 3px;
}

.dialog-head h1 {
    margin: 0;
    font-size: 20px;
    font-weight: 800;
    line-height: 1.2;
}

.dialog-close {
    width: 34px;
    height: 34px;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 15px;
}

.dialog-close:hover {
    background: rgba(255, 255, 255, 0.15);
    color: #ffffff;
}

.dialog-body {
    padding: 16px 22px 18px;
}

.dialog-category-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 12px;
}

.dialog-category {
    font-size: 12px;
    font-weight: 700;
    padding: 4px 10px;
    border-radius: var(--radius-pill);
    background: rgba(255, 255, 255, 0.09);
    color: #e2e8f0;
}

.dialog-status-badge {
    font-size: 11.5px;
    font-weight: 700;
    padding: 4px 10px;
    border-radius: var(--radius-pill);
    background: rgba(245, 158, 11, 0.18);
    border: 1px solid rgba(245, 158, 11, 0.45);
    color: #fcd34d;
}

.dialog-tagline {
    margin: 0 0 8px;
    font-size: 14.5px;
    font-weight: 600;
    color: #f8fafc;
    line-height: 1.45;
}

.dialog-description {
    margin: 0 0 14px;
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.6;
}

.dialog-features {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 16px;
}

.feature-tag {
    font-size: 11.5px;
    font-weight: 600;
    padding: 4px 9px;
    border-radius: 8px;
    background: rgba(56, 189, 248, 0.12);
    border: 1px solid rgba(56, 189, 248, 0.25);
    color: #bae6fd;
}

.dialog-future-box {
    display: flex;
    gap: 12px;
    padding: 13px 14px;
    border-radius: 14px;
    background: rgba(30, 41, 59, 0.78);
    border: 1px dashed rgba(148, 163, 184, 0.35);
}

.future-icon {
    font-size: 20px;
    line-height: 1;
    margin-top: 2px;
}

.dialog-future-box strong {
    display: block;
    font-size: 13px;
    color: #f8fafc;
    margin-bottom: 4px;
}

.dialog-future-box p {
    margin: 0;
    font-size: 12px;
    color: var(--text-muted);
    line-height: 1.5;
}

.dialog-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    padding: 14px 22px 18px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(2, 6, 23, 0.3);
}

.btn-primary,
.btn-secondary {
    font-family: inherit;
    font-size: 13px;
    font-weight: 700;
    padding: 10px 16px;
    border-radius: 11px;
    cursor: pointer;
    border: 0;
    transition: background-color 0.15s ease, transform 0.12s ease;
}

.btn-primary {
    background: linear-gradient(135deg, #ef4444, #f97316);
    color: #ffffff;
}

.btn-primary:hover {
    filter: brightness(1.08);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.1);
    color: #e2e8f0;
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.18);
}

/* Responsive adjustments */
@media (max-width: 960px) {
    .hud-controls {
        max-width: calc(100vw - 32px);
        top: auto;
        bottom: 70px;
        right: 16px;
    }

    .hud-hint {
        display: none;
    }
}

@media (max-width: 600px) {
    .brand-text p {
        display: none;
    }

    .hud-live-stats {
        display: none;
    }

    .hud-controls {
        bottom: 66px;
        gap: 5px;
    }

    .hud-btn {
        padding: 6px 8px;
        font-size: 11px;
    }
}
