/* ─── Reset & Base ──────────────────────────────────────────── */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

:root {
    --panel-bg: rgba(255, 255, 255, 0.95);
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    --accent-light: #6b7a99;
    --accent-dark: #3a4a6b;
    --text-primary: #1a1a1a;
    --text-secondary: #777;
    --border: #ddd;

    /* spacing scale */
    --sp-xs: 8px;
    --sp-sm: 12px;
    --sp-md: 16px;
    --sp-lg: 24px;
    --sp-xl: 32px;

    /* safe area insets (notch/home bar) */
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left: env(safe-area-inset-left, 0px);
    --safe-right: env(safe-area-inset-right, 0px);
}

html,
body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    touch-action: none;
    /* let JS handle all touch */
}

body {
    font-family: 'Lato', sans-serif;
    background: #000;
    color: #e8e8e8;
    font-size: 16px;
    /* base for rem */
}

/* ─── Canvas ─────────────────────────────────────────────────── */
#canvas-container {
    position: fixed;
    inset: 0;
    z-index: 1;
}

/* ─── SEO hidden content ─────────────────────────────────────── */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(1px, 1px, 1px, 1px);
    white-space: nowrap;
}

/* ─── Info Panel — mobile: collapsed chip + expand drawer ───── */
.info-panel {
    position: fixed;
    bottom: calc(var(--safe-bottom) + 88px);
    left: var(--sp-md);
    right: var(--sp-md);
    z-index: 100;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.35s ease;
}

.info-panel.visible {
    opacity: 1;
    pointer-events: auto;
}

/* Collapsed chip — always visible when panel is visible */
.info-chip {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: rgba(10, 10, 10, 0.72);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 40px;
    padding: 10px 16px 10px 18px;
    cursor: pointer;
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
    gap: 10px;
}

.chip-text {
    display: flex;
    flex-direction: column;
    gap: 1px;
    min-width: 0;
}

.chip-category {
    font-size: 0.62rem;
    text-transform: uppercase;
    letter-spacing: 0.14em;
    color: rgba(255, 255, 255, 0.45);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chip-name {
    font-family: 'Crimson Pro', serif;
    font-size: 1.05rem;
    font-weight: 600;
    color: #fff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chip-toggle {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.12);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s ease, transform 0.3s ease;
    font-size: 0.7rem;
    color: rgba(255, 255, 255, 0.7);
}

.info-chip:active .chip-toggle {
    background: rgba(255, 255, 255, 0.22);
}

/* Expanded drawer — slides up from below the chip */
.info-drawer {
    background: var(--panel-bg);
    border-radius: 4px;
    box-shadow: var(--shadow);
    overflow: hidden;
    max-height: 0;
    transition: max-height 0.38s cubic-bezier(0.4, 0, 0.2, 1),
        margin-top 0.38s ease,
        opacity 0.25s ease;
    margin-top: 0;
    opacity: 0;
}

.info-panel.expanded .info-drawer {
    max-height: 55vh;
    margin-top: 8px;
    opacity: 1;
}

.info-panel.expanded .chip-toggle {
    transform: rotate(180deg);
    background: rgba(255, 255, 255, 0.2);
}

.info-drawer-inner {
    padding: var(--sp-md) var(--sp-lg) var(--sp-lg);
    overflow-y: auto;
    max-height: 55vh;
    -webkit-overflow-scrolling: touch;
}

/* drag handle */
.drawer-handle {
    width: 36px;
    height: 4px;
    background: #ddd;
    border-radius: 2px;
    margin: 12px auto 10px;
}

.object-label {
    font-family: 'Crimson Pro', serif;
    font-size: clamp(1.3rem, 5vw, 2.2rem);
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
    letter-spacing: -0.02em;
    line-height: 1.2;
}

.object-category {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.15em;
    color: var(--text-secondary);
    margin-bottom: var(--sp-md);
    font-weight: 400;
}

.object-description {
    font-size: 0.92rem;
    line-height: 1.65;
    color: #2a2a2a;
    margin-bottom: var(--sp-sm);
}

.object-stats {
    border-top: 1px solid var(--border);
    padding-top: var(--sp-md);
    margin-top: var(--sp-md);
}

.stat-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: var(--sp-xs);
    font-size: 0.88rem;
}

.stat-label {
    color: var(--text-secondary);
    font-weight: 300;
}

.stat-value {
    color: var(--text-primary);
    font-weight: 400;
    font-family: 'Crimson Pro', serif;
}

/* ─── Scale Indicator ────────────────────────────────────────── */
.scale-indicator {
    position: fixed;
    bottom: calc(var(--safe-bottom) + var(--sp-md));
    right: calc(var(--safe-right) + var(--sp-md));
    background: var(--panel-bg);
    padding: var(--sp-sm) var(--sp-md);
    box-shadow: var(--shadow);
    border-radius: 4px;
    z-index: 100;
    pointer-events: none;
    min-width: 90px;
    opacity: 0.8;
}

.scale-title {
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.scale-value {
    font-family: 'Crimson Pro', serif;
    font-size: clamp(1.5rem, 5vw, 2.4rem);
    font-weight: 600;
    color: var(--text-primary);
    line-height: 1;
}

/* ─── Velocity Meter ─────────────────────────────────────────── */
.velocity-meter {
    position: fixed;
    top: calc(var(--safe-top) + var(--sp-md));
    right: calc(var(--safe-right) + var(--sp-md));
    background: var(--panel-bg);
    padding: var(--sp-sm) var(--sp-md);
    box-shadow: var(--shadow);
    border-radius: 4px;
    z-index: 100;
    pointer-events: none;
    min-width: 140px;
}

.velocity-label {
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.velocity-value {
    font-family: 'Crimson Pro', serif;
    font-size: clamp(1.2rem, 4vw, 1.8rem);
    font-weight: 600;
    color: var(--text-primary);
    line-height: 1;
}

.velocity-bar {
    width: 100%;
    height: 3px;
    background: #e0e0e0;
    margin-top: 8px;
    border-radius: 2px;
    overflow: hidden;
}

.velocity-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent-light), var(--accent-dark));
    width: 0%;
    transition: width 0.2s ease;
    border-radius: 2px;
}

/* ─── Progress Indicator ─────────────────────────────────────── */
.progress-indicator {
    position: fixed;
    top: calc(var(--safe-top) + var(--sp-md));
    left: calc(var(--safe-left) + var(--sp-md));
    width: min(200px, 45vw);
    background: var(--panel-bg);
    padding: var(--sp-sm) var(--sp-md);
    box-shadow: var(--shadow);
    border-radius: 4px;
    z-index: 100;
    pointer-events: none;
}

.progress-label {
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.progress-track {
    width: 100%;
    height: 5px;
    background: #e0e0e0;
    border-radius: 3px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent-light), var(--accent-dark));
    width: 0%;
    transition: width 0.3s ease;
    border-radius: 3px;
}

/* ─── Controls ───────────────────────────────────────────────── */
.controls {
    position: fixed;
    bottom: calc(var(--safe-bottom) + var(--sp-md));
    left: calc(var(--safe-left) + var(--sp-md));
    z-index: 100;
    display: flex;
    gap: var(--sp-xs);
}

.control-hint {
    background: var(--panel-bg);
    padding: var(--sp-xs) var(--sp-sm);
    font-size: 0.78rem;
    color: #444;
    box-shadow: var(--shadow);
    border-radius: 4px;
    display: flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}

.key {
    background: #2a2a2a;
    color: #fff;
    padding: 3px 8px;
    border-radius: 3px;
    font-family: 'Courier New', monospace;
    font-size: 0.72rem;
    min-width: 26px;
    text-align: center;
}

/* ─── Touch navigation buttons (mobile-only) ─────────────────── */
.touch-nav {
    display: none;
    /* shown on touch via media query */
    position: fixed;
    bottom: calc(var(--safe-bottom) + var(--sp-md));
    left: 50%;
    transform: translateX(-50%);
    z-index: 200;
    gap: var(--sp-sm);
}

.touch-btn {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: none;
    background: var(--panel-bg);
    box-shadow: var(--shadow);
    font-size: 1.4rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-primary);
    /* prevent text selection on long press */
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
    transition: transform 0.1s ease, background 0.15s ease;
}

.touch-btn:active {
    transform: scale(0.92);
    background: #ebebeb;
}

/* ─── Start Screen ───────────────────────────────────────────── */
.start-screen {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.95);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--sp-xl) var(--sp-lg);
    text-align: center;
    opacity: 1;
    transition: opacity 0.5s ease;
}

.start-screen.hidden {
    opacity: 0;
    pointer-events: none;
}

.start-title {
    font-family: 'Crimson Pro', serif;
    font-size: clamp(2rem, 9vw, 3.5rem);
    font-weight: 600;
    color: #fff;
    margin-bottom: var(--sp-md);
    letter-spacing: -0.02em;
    line-height: 1.1;
}

.start-subtitle {
    font-size: clamp(0.88rem, 3.5vw, 1.1rem);
    color: #aaa;
    margin-bottom: var(--sp-xl);
    max-width: 560px;
    line-height: 1.7;
}

.start-btn {
    background: #fff;
    color: #000;
    border: none;
    padding: 16px 40px;
    font-family: 'Lato', sans-serif;
    font-size: clamp(0.85rem, 3vw, 1rem);
    font-weight: 400;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    cursor: pointer;
    border-radius: 2px;
    transition: transform 0.25s ease, box-shadow 0.25s ease;
    box-shadow: 0 8px 30px rgba(255, 255, 255, 0.15);
    /* min touch target 44px */
    min-height: 52px;
    touch-action: manipulation;
}

.start-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 40px rgba(255, 255, 255, 0.25);
}

.start-btn:active {
    transform: translateY(0);
}

/* ─── Tablet (≥ 600px) ───────────────────────────────────────── */
@media (min-width: 600px) {

    /* Revert to classic side panel — hide chip/drawer pattern */
    .info-panel {
        bottom: auto;
        top: 50%;
        left: var(--sp-xl);
        right: auto;
        width: 340px;
        transform: translateY(-50%);
        background: var(--panel-bg);
        border-radius: 2px;
        box-shadow: var(--shadow);
        padding: var(--sp-lg) var(--sp-xl);
        opacity: 0;
        transition: opacity 0.4s ease;
    }

    .info-panel.visible {
        opacity: 1;
    }

    /* Hide the chip; show drawer content directly in panel */
    .info-chip {
    }

    .chip-toggle {
        display: none;
    }

    .info-drawer {
        max-height: none !important;
        margin-top: 0 !important;
        opacity: 1 !important;
        overflow: visible;
        background: transparent;
        box-shadow: none;
        border-radius: 0;
    }

    .info-drawer-inner {
        padding: 0;
        max-height: none;
        overflow: visible;
    }

    .drawer-handle {
        display: none;
    }

    .scale-indicator {
        right: calc(var(--safe-right) + 32px);
        bottom: calc(var(--safe-bottom) + 36px);
        padding: var(--sp-md) var(--sp-lg);
        min-width: 120px;
        opacity: 1;
    }

    .velocity-meter {
        top: calc(var(--safe-top) + 36px);
        right: calc(var(--safe-right) + 32px);
        padding: var(--sp-md) var(--sp-lg);
        min-width: 180px;
    }

    .progress-indicator {
        top: calc(var(--safe-top) + 36px);
        left: calc(var(--safe-left) + var(--sp-xl));
        width: 220px;
        padding: var(--sp-md) var(--sp-lg);
    }

    .controls {
        bottom: calc(var(--safe-bottom) + 36px);
        left: calc(var(--safe-left) + var(--sp-xl));
        flex-direction: row;
        gap: var(--sp-sm);
    }

    .control-hint {
        padding: 10px var(--sp-md);
        font-size: 0.82rem;
    }
}

/* ─── Desktop (≥ 1024px) ─────────────────────────────────────── */
@media (min-width: 1024px) {
    .info-panel {
        left: 60px;
        max-width: 420px;
        padding: 35px 40px;
    }

    .scale-indicator {
        right: 50px;
        bottom: 40px;
        padding: 25px 30px;
        opacity: 1;
    }

    .velocity-meter {
        top: 40px;
        right: 50px;
        padding: 20px 25px;
    }

    .progress-indicator {
        top: 40px;
        left: 60px;
        width: 250px;
        padding: 20px 25px;
    }

    .controls {
        bottom: 40px;
        left: 60px;
    }

    .touch-nav {
        display: none !important;
        /* never show on desktop */
    }
}

/* ─── Pointer: coarse = touchscreen → show touch controls ───── */
@media (pointer: coarse) {
    .touch-nav {
        display: flex;
    }

    /* Hide keyboard hints on touch devices */
    .controls .control-hint:first-child,
    .controls .control-hint:nth-child(2) {
        display: none;
    }

    /* Ensure scale + velocity don't overlap touch buttons */
    .scale-indicator {
        bottom: calc(var(--safe-bottom) + 84px);
    }
}

/* ─── Landscape phone fix ────────────────────────────────────── */
@media (max-height: 500px) and (orientation: landscape) {
    .info-panel {
        bottom: auto;
        top: var(--sp-sm);
        left: var(--sp-md);
        right: auto;
        max-width: 280px;
        max-height: 80vh;
        transform: none;
        font-size: 0.85em;
    }

    .start-screen {
        flex-direction: row;
        gap: var(--sp-xl);
        text-align: left;
        align-items: center;
        justify-content: center;
    }

    .start-title {
        font-size: 2rem;
    }

    .start-subtitle {
        font-size: 0.82rem;
        margin-bottom: var(--sp-md);
    }

    .velocity-meter,
    .progress-indicator {
        top: var(--sp-sm);
        padding: var(--sp-xs) var(--sp-sm);
    }

    .progress-indicator {
        width: 140px;
    }

    .touch-btn {
        width: 50px;
        height: 50px;
        font-size: 1.1rem;
    }
}