/* --- Canvas and container management --- */
canvas {
    display: block;
    width: 100%;
    height: 100%;
    max-width: 100%;
    touch-action: none;
}

canvas.full-canvas {
    position: absolute;
    inset: 0;
}

.full-canvas {
    cursor: crosshair;
}

.toy-container {
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100dvh;
    min-height: 0;
    overflow: hidden;
    padding: var(--control-clearance) max(12px, env(safe-area-inset-right, 0px))
        calc(var(--nav-pad) + 12px) max(12px, env(safe-area-inset-left, 0px));
}

#ui-layer {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: var(--control-clearance) max(16px, env(safe-area-inset-right, 0px))
        var(--nav-pad) max(16px, env(safe-area-inset-left, 0px));
    pointer-events: none;
    transition: opacity 1s ease-in-out;
    z-index: 100;
}

.fade-out {
    opacity: 0;
    pointer-events: none;
}

.glass-panel {
    display: inline-block;
    margin: 0;
    padding: clamp(1.25rem, 4vw, 2rem) clamp(1.5rem, 6vw, 3rem);
    max-width: 100%;
    border: 1px solid var(--glass-border);
    border-radius: 20px;
    appearance: none;
    -webkit-appearance: none;
    background: var(--glass-bg);
    color: var(--text-primary);
    font: inherit;
    line-height: 1.4;
    text-align: center;
    backdrop-filter: blur(10px);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    cursor: pointer;
    pointer-events: auto;
    transition: transform 0.3s ease, background 0.3s ease;
}

.start-title {
    display: block;
    margin-bottom: 0.5rem;
    color: #ffffff;
    font-size: clamp(1.875rem, 6vw, 3rem);
    font-weight: 500;
    line-height: 1.2;
    letter-spacing: 0.1em;
}

.start-copy {
    display: block;
    color: #cbd5e1;
    font-size: 0.875rem;
    font-weight: 300;
    line-height: 1.5;
    letter-spacing: 0.12em;
}

@media (hover: hover) {
    .glass-panel:hover {
        transform: scale(1.02);
        background: rgba(255, 255, 255, 0.08);
    }
}

/* --- Navigation --- */
#nav-bar {
    position: fixed;
    bottom: max(12px, env(safe-area-inset-bottom, 0px));
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-content: center;
    gap: 6px;
    width: max-content;
    max-width: min(
        720px,
        calc(
            100vw - env(safe-area-inset-left, 0px) -
                env(safe-area-inset-right, 0px) - 1rem
        )
    );
    max-height: min(40dvh, 200px);
    overflow-y: auto;
    padding: 8px 10px;
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 16px;
    background: rgba(15, 23, 42, 0.85);
    backdrop-filter: blur(10px);
    overscroll-behavior: contain;
    scrollbar-width: thin;
    touch-action: manipulation;
    -webkit-overflow-scrolling: touch;
    transition: opacity 0.5s ease;
    z-index: 200;
}

.nav-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    padding: 10px 12px;
    border: none;
    border-radius: 12px;
    background: none;
    color: var(--text-secondary);
    font-family: "Avenir Next", "Segoe UI", system-ui, sans-serif;
    font-size: clamp(11px, 2.8vw, 13px);
    font-weight: 500;
    line-height: 1.2;
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
    touch-action: manipulation;
    transition: color 0.2s ease, background 0.2s ease;
}

@media (hover: hover) {
    .nav-btn:hover {
        color: #f8fafc;
        background: rgba(255, 255, 255, 0.1);
        box-shadow: 0 0 10px rgba(255, 255, 255, 0.05);
    }
}

.nav-btn.active,
.nav-btn[aria-current="page"] {
    color: #f8fafc;
    background: rgba(255, 255, 255, 0.15);
    box-shadow: 0 0 15px rgba(255, 255, 255, 0.1);
}

#hint {
    position: absolute;
    right: 0;
    bottom: var(--nav-pad) !important;
    left: 0;
    padding: 0 max(1rem, env(safe-area-inset-left, 0px))
        max(1rem, env(safe-area-inset-right, 0px));
    max-width: 100%;
    color: var(--text-secondary);
    font-size: clamp(0.75rem, 2.5vw, 0.875rem);
    font-weight: 300;
    line-height: 1.5;
    letter-spacing: 0.16em;
    text-align: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 1s ease-in-out;
}

/* --- Top canvas instructions --- */
.match-ui {
    position: absolute;
    top: calc(var(--control-clearance) + 4px);
    left: 0;
    width: 100%;
    padding: 0 max(16px, env(safe-area-inset-right, 0px))
        max(16px, env(safe-area-inset-left, 0px));
    text-align: center;
    pointer-events: none;
    z-index: 10;
}

.toy-instruction {
    margin: 0;
    color: var(--text-secondary);
    font-size: clamp(0.75rem, 2.5vw, 0.875rem);
    font-weight: 500;
    line-height: 1.4;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.scene-hint {
    position: absolute;
    bottom: calc(var(--nav-pad) + 26px);
    left: 50%;
    z-index: 12;
    width: max-content;
    max-width: calc(100% - 2rem);
    margin: 0;
    padding: 8px 14px;
    border: 1px solid rgba(148, 163, 184, 0.12);
    border-radius: 999px;
    background: rgba(8, 20, 29, 0.38);
    color: rgba(226, 232, 240, 0.66);
    font-size: clamp(0.65rem, 2.2vw, 0.75rem);
    font-weight: 500;
    line-height: 1.3;
    letter-spacing: 0.16em;
    text-align: center;
    text-transform: uppercase;
    backdrop-filter: blur(8px);
    transform: translateX(-50%);
    transition: opacity 0.8s ease, transform 0.8s ease;
    pointer-events: none;
}

.scene-hint.dismissed {
    opacity: 0;
    transform: translate(-50%, 5px);
}
