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

:root {
    --primary: #111111;
    --primary-dark: #000000;
    --bg: #fafafa;
    --bg-light: #ffffff;
    --surface: #eaeaea;
    --surface-strong: #d6d6d6;
    --surface-soft: #f5f5f5;
    --text: #111111;
    --text-dim: #666666;
    --accent: #d93025;
    --radius: 12px;
    --radius-lg: 20px;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-md: 0 10px 30px rgba(0, 0, 0, 0.06);
    --sidebar-width: 280px;
}

body {
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--text);
    height: 100vh;
    overflow: hidden;
}

.hidden {
    display: none !important;
}

/* ===== Setup Panel ===== */
#setup-panel {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background:
        radial-gradient(circle at top, rgba(0, 0, 0, 0.035), transparent 35%),
        linear-gradient(180deg, #ffffff 0%, #f7f7f7 100%);
    z-index: 1000;
}

.setup-card {
    background: var(--bg-light);
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: 24px;
    box-shadow: var(--shadow-md);
    padding: 40px;
    max-width: 520px;
    width: 90%;
    text-align: center;
}

.brand-mark {
    width: 14px;
    height: 14px;
    margin: 0 auto 18px;
    background: #111111;
    clip-path: polygon(50% 0, 0 100%, 100% 100%);
}

.setup-card h1 {
    font-size: 30px;
    line-height: 1.05;
    letter-spacing: -0.04em;
    margin-bottom: 10px;
}

.setup-card > p {
    color: var(--text-dim);
    margin-bottom: 24px;
    font-size: 14px;
}

#existing-users h3 {
    font-size: 14px;
    color: var(--text-dim);
    margin-bottom: 8px;
}

#user-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 12px;
}

.user-list-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 14px;
    background: var(--bg-light);
    border: 1px solid var(--surface);
    border-radius: var(--radius);
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s, transform 0.2s;
}

.user-list-item:hover {
    border-color: var(--surface-strong);
    background: var(--surface-soft);
    transform: translateY(-1px);
}

.user-list-item .user-name {
    font-weight: 600;
    font-size: 14px;
}

.user-list-item .user-meta {
    font-size: 12px;
    color: var(--text-dim);
}

.divider {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 16px 0;
    color: var(--text-dim);
    font-size: 13px;
}

.divider::before,
.divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--surface);
}

.input-group {
    text-align: left;
    margin-bottom: 20px;
}

.input-group.compact {
    margin-bottom: 12px;
}

.input-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 6px;
    color: var(--text);
}

.input-group input {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--surface);
    border-radius: var(--radius);
    background: #ffffff;
    color: var(--text);
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
}

.input-group input:focus {
    border-color: #bdbdbd;
    box-shadow: 0 0 0 4px rgba(0, 0, 0, 0.04);
}

.input-group a {
    display: inline-block;
    margin-top: 4px;
    font-size: 12px;
    color: var(--primary);
    text-decoration: none;
}

.input-group a:hover {
    text-decoration: underline;
}

#start-btn {
    width: 100%;
    padding: 14px;
    margin-top: 12px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 999px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s, transform 0.2s, box-shadow 0.2s;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.14);
}

#start-btn:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
}

/* ===== App Layout ===== */
#app {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

/* Header */
#header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 18px;
    background: rgba(255, 255, 255, 0.92);
    border-bottom: 1px solid var(--surface);
    flex-shrink: 0;
    backdrop-filter: blur(12px);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 8px;
}

.header-label {
    font-size: 14px;
    font-weight: 600;
}

.car-label {
    display: flex;
    align-items: center;
    gap: 6px;
}

.car-label .car-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
}

.header-sep {
    color: var(--text-dim);
    font-size: 14px;
}

.header-info {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 13px;
    color: var(--text-dim);
    font-family: 'SF Mono', 'Fira Code', monospace;
}

.icon-btn {
    background: #ffffff;
    border: 1px solid var(--surface);
    border-radius: var(--radius);
    color: var(--text);
    padding: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
}

.icon-btn:hover {
    background: var(--surface-soft);
    border-color: var(--surface-strong);
}

.icon-btn.small {
    padding: 4px 8px;
    font-size: 18px;
    line-height: 1;
}

/* ===== Car Panel (Sidebar) ===== */
#car-panel {
    width: var(--sidebar-width);
    background: rgba(255, 255, 255, 0.96);
    border-right: 1px solid var(--surface);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    overflow-y: auto;
    backdrop-filter: blur(10px);
}

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

.panel-header h3 {
    font-size: 14px;
    font-weight: 600;
}

#car-list {
    flex: 1;
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.car-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius);
    cursor: pointer;
    transition: background 0.15s;
    position: relative;
}

.car-item:hover {
    background: var(--surface-soft);
}

.car-item.active {
    background: #ffffff;
    border: 1px solid var(--surface-strong);
    box-shadow: var(--shadow-sm);
}

.car-item .car-color-dot {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    flex-shrink: 0;
}

.car-item .car-info {
    flex: 1;
    min-width: 0;
}

.car-item .car-item-name {
    font-size: 14px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.car-item .car-item-pos {
    font-size: 11px;
    color: var(--text-dim);
    font-family: 'SF Mono', 'Fira Code', monospace;
}

.car-item .car-actions {
    display: flex;
    gap: 2px;
    opacity: 0;
    transition: opacity 0.15s;
}

.car-item:hover .car-actions {
    opacity: 1;
}

.car-action-btn {
    background: none;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    padding: 4px;
    font-size: 14px;
    border-radius: 4px;
    transition: all 0.15s;
}

.car-action-btn:hover {
    color: var(--text);
    background: var(--surface-soft);
}

.car-action-btn.delete:hover {
    color: var(--accent);
}

.panel-action-btn {
    margin: 8px;
    padding: 10px;
    background: #ffffff;
    border: 1px dashed var(--surface);
    border-radius: var(--radius);
    color: var(--text-dim);
    font-size: 13px;
    cursor: pointer;
    transition: all 0.15s;
}

.panel-action-btn:hover {
    border-color: var(--surface-strong);
    color: var(--text);
    background: var(--surface-soft);
}

/* Add car form */
#add-car-form {
    padding: 12px;
    border-top: 1px solid var(--surface);
}

.color-picker {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.color-opt {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 2px solid transparent;
    cursor: pointer;
    transition: all 0.15s;
}

.color-opt:hover {
    transform: scale(1.15);
}

.color-opt.selected {
    border-color: #ffffff;
    box-shadow: 0 0 0 2px #111111;
}

.form-actions {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}

.btn-primary {
    padding: 8px 16px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, transform 0.15s;
}

.btn-primary:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
}

.btn-ghost {
    padding: 8px 16px;
    background: #ffffff;
    color: var(--text-dim);
    border: 1px solid var(--surface);
    border-radius: 999px;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.15s;
}

.btn-ghost:hover {
    color: var(--text);
    border-color: var(--surface-strong);
    background: var(--surface-soft);
}

/* ===== Main Content ===== */
#main-content {
    display: flex;
    flex: 1;
    min-height: 0;
}

#map-container {
    flex: 1;
    position: relative;
    background: #f3f3f3;
}

#map {
    width: 100%;
    height: 100%;
}

#streetview-container {
    flex: 1;
    position: relative;
    background: #0c0c0c;
    display: flex;
    align-items: center;
    justify-content: center;
    border-left: 1px solid var(--surface);
}

#streetview {
    width: 100%;
    height: 100%;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

#streetview-placeholder {
    text-align: center;
    color: var(--text-dim);
}

#streetview-placeholder p {
    margin: 4px 0;
}

#streetview-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

#streetview-viewer {
    width: 100%;
    height: 100%;
}

#streetview-info {
    position: absolute;
    bottom: 12px;
    left: 12px;
    background: rgba(255, 255, 255, 0.92);
    border: 1px solid rgba(255, 255, 255, 0.5);
    padding: 6px 10px;
    border-radius: 999px;
    font-size: 12px;
    color: #111111;
}

#streetview-loading,
#streetview-error {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.8);
    color: #d0d0d0;
    font-size: 14px;
}

#streetview-debug {
    position: absolute;
    top: 12px;
    right: 12px;
    z-index: 5;
    min-width: 170px;
    background: rgba(15, 23, 42, 0.82);
    color: #e2e8f0;
    border: 1px solid rgba(148, 163, 184, 0.35);
    border-radius: 10px;
    padding: 8px 10px;
    font-size: 12px;
    line-height: 1.45;
    backdrop-filter: blur(8px);
}

.spinner {
    width: 36px;
    height: 36px;
    border: 3px solid rgba(255, 255, 255, 0.16);
    border-top-color: #ffffff;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-bottom: 12px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Controls */
#controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 32px;
    padding: 14px 24px;
    background: rgba(255, 255, 255, 0.95);
    border-top: 1px solid var(--surface);
    flex-shrink: 0;
    backdrop-filter: blur(12px);
}

.speed-control {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
}

.speed-control label {
    color: var(--text-dim);
    font-weight: 600;
}

#speed-slider {
    width: 80px;
    accent-color: var(--primary);
}

#speed-value {
    color: var(--text);
    font-weight: 600;
    min-width: 32px;
}

.direction-pad {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

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

.dpad-btn {
    width: 48px;
    height: 48px;
    border: 1px solid var(--surface);
    border-radius: 14px;
    background: #ffffff;
    color: var(--text);
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.1s;
    user-select: none;
    -webkit-user-select: none;
}

.dpad-btn:hover {
    background: var(--surface-soft);
}

.dpad-btn:active,
.dpad-btn.active {
    background: var(--primary);
    border-color: var(--primary);
    transform: scale(0.95);
    color: #ffffff;
}

.control-hints {
    display: flex;
    flex-direction: column;
    gap: 2px;
    font-size: 12px;
    color: var(--text-dim);
}

/* Car Marker */
.car-marker {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.15s ease;
}

.car-marker svg {
    width: 36px;
    height: 36px;
    filter: drop-shadow(0 6px 16px rgba(0, 0, 0, 0.18));
}

/* ===== Modal ===== */
.modal {
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.32);
    backdrop-filter: blur(8px);
}

.modal-content {
    position: relative;
    background: var(--bg-light);
    border: 1px solid var(--surface);
    border-radius: 20px;
    box-shadow: var(--shadow-md);
    padding: 24px;
    width: 90%;
    max-width: 400px;
    max-height: 80vh;
    overflow-y: auto;
}

.modal-content.small {
    max-width: 320px;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.modal-header h3 {
    font-size: 16px;
}

#modal-user-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 16px;
}

.modal-user-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    background: #ffffff;
    border: 1px solid var(--surface);
    border-radius: var(--radius);
    transition: border-color 0.2s;
}

.modal-user-item.active {
    border-color: var(--surface-strong);
    box-shadow: var(--shadow-sm);
}

.modal-user-item .user-info {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    flex: 1;
}

.modal-user-item .user-info .user-name {
    font-weight: 600;
    font-size: 14px;
}

.modal-user-item .user-info .user-car-count {
    font-size: 12px;
    color: var(--text-dim);
}

.modal-user-item .user-delete-btn {
    background: none;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    padding: 4px 8px;
    font-size: 13px;
    border-radius: 4px;
    transition: all 0.15s;
}

.modal-user-item .user-delete-btn:hover {
    color: var(--accent);
    background: rgba(217, 48, 37, 0.08);
}

.modal-footer {
    padding-top: 8px;
}

/* MapLibre overrides */
.maplibregl-ctrl-bottom-left,
.maplibregl-ctrl-bottom-right {
    display: none !important;
}

.maplibregl-ctrl-group {
    border: 1px solid var(--surface) !important;
    border-radius: 14px !important;
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

.maplibregl-ctrl-group button {
    background: #ffffff !important;
}

/* Responsive */
@media (max-width: 768px) {
    #main-content {
        flex-direction: column;
    }

    #car-panel {
        width: 100%;
        max-height: 40vh;
        border-right: none;
        border-bottom: 1px solid var(--surface);
    }

    #map-container,
    #streetview-container {
        flex: 1;
        min-height: 0;
    }

    #controls {
        gap: 16px;
        padding: 8px 16px;
    }

    .control-hints {
        display: none;
    }

    .dpad-btn {
        width: 42px;
        height: 42px;
    }
}
