:root {
    --bg: #12161c;
    --panel: #1b2129;
    --panel-2: #232a34;
    --line: #2f3844;
    --text: #e5e9ef;
    --muted: #93a0b0;
    --accent: #f5b301;
    --danger: #e5484d;
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font: 14px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif;
    overflow: hidden;
    overscroll-behavior: none;
}

#app {
    display: grid;
    grid-template-columns: 260px 1fr auto;
    grid-template-rows: auto 1fr;
    height: 100%;
    height: 100dvh;
}

#topbar {
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: var(--panel);
    border-bottom: 1px solid var(--line);
    flex-wrap: wrap;
}

.brand {
    margin-right: 8px;
}

.spacer {
    flex: 1;
}

button {
    background: var(--panel-2);
    color: var(--text);
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 5px 10px;
    font: inherit;
    cursor: pointer;
    touch-action: manipulation;
}

button.primary {
    background: var(--accent);
    color: #1a1a1a;
    border-color: var(--accent);
}

#catalog-toggle {
    display: none;
}

.insp-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.insp-head h3 {
    margin: 4px 0;
}

.insp-head .close {
    padding: 2px 8px;
}

#joystick {
    position: absolute;
    left: calc(24px + env(safe-area-inset-left));
    bottom: calc(24px + env(safe-area-inset-bottom));
    width: 128px;
    height: 128px;
    border-radius: 50%;
    background: #ffffff1f;
    border: 2px solid #ffffff55;
    touch-action: none;
    z-index: 3;
}

#joystick .knob {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 56px;
    height: 56px;
    margin: -28px 0 0 -28px;
    border-radius: 50%;
    background: #ffffffaa;
    pointer-events: none;
}

#joystick[hidden],
#touch-actions[hidden] {
    display: none;
}

#touch-actions {
    position: absolute;
    right: calc(12px + env(safe-area-inset-right));
    bottom: calc(24px + env(safe-area-inset-bottom));
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 6px;
    z-index: 3;
}

#touch-actions button {
    min-width: 46px;
    height: 46px;
    font-size: 18px;
    background: #1b2129dd;
}

#touch-actions button.primary {
    font-size: 15px;
    background: var(--accent);
}

/* walking on a touch screen: hide the editor panel so it doesn't cover the view */
body.touch-walk #inspector {
    display: none;
}

body.touch-walk #hud {
    top: 10px;
    bottom: auto;
}

#viewport canvas {
    touch-action: none;
}

button:hover {
    border-color: #4a5668;
}

button.danger {
    color: #ffb4b6;
}

.seg {
    display: inline-flex;
}

.seg button {
    border-radius: 0;
}

.seg button:first-child {
    border-radius: 6px 0 0 6px;
}

.seg button:last-child {
    border-radius: 0 6px 6px 0;
}

.seg button.on {
    background: var(--accent);
    color: #1a1a1a;
    border-color: var(--accent);
}

.check {
    display: inline-flex;
    gap: 4px;
    align-items: center;
    color: var(--muted);
}

aside {
    background: var(--panel);
    overflow-y: auto;
    padding: 10px;
}

#catalog {
    border-right: 1px solid var(--line);
}

#inspector {
    width: 250px;
    border-left: 1px solid var(--line);
}

#inspector[hidden] {
    display: none;
}

input,
select {
    width: 100%;
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--line);
    border-radius: 5px;
    padding: 5px 6px;
    font: inherit;
}

input[type="color"] {
    padding: 0;
    height: 30px;
}

input[type="checkbox"] {
    width: auto;
}

label {
    display: block;
    color: var(--muted);
    font-size: 12px;
    margin: 6px 0;
}

.row3 {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 6px;
}

.btns {
    display: flex;
    gap: 6px;
    margin: 8px 0;
}

.btns button {
    flex: 1;
}

#insp-link {
    color: var(--accent);
    font-size: 13px;
}

.cat h4 {
    margin: 14px 0 4px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--muted);
}

.item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    text-align: left;
    margin: 2px 0;
    padding: 6px 8px;
    gap: 6px;
}

.item .dims {
    color: var(--muted);
    font-size: 11px;
    white-space: nowrap;
}

.swatch {
    width: 10px;
    height: 10px;
    border-radius: 2px;
    flex: none;
    border: 1px solid #0006;
}

.item .nm {
    flex: 1;
}

#custom {
    margin-top: 14px;
    border-top: 1px solid var(--line);
    padding-top: 10px;
}

#custom summary {
    cursor: pointer;
    color: var(--accent);
}

#custom button[type="submit"] {
    width: 100%;
    margin-top: 6px;
}

.muted {
    color: var(--muted);
    font-size: 12px;
}

#viewport {
    position: relative;
    overflow: hidden;
    min-width: 0;
}

#viewport canvas {
    display: block;
    outline: none;
}

#crosshair {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 14px;
    height: 14px;
    margin: -7px 0 0 -7px;
    pointer-events: none;
    background:
        linear-gradient(#fff, #fff) center/2px 14px no-repeat,
        linear-gradient(#fff, #fff) center/14px 2px no-repeat;
    mix-blend-mode: difference;
}

#hud {
    position: absolute;
    left: 12px;
    bottom: 12px;
    display: flex;
    gap: 12px;
    pointer-events: none;
    text-shadow: 0 1px 3px #000;
}

#hud-room {
    font-weight: 600;
}

#hud-hint {
    color: #d7dde6;
}

#walk-overlay {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    background: #0008;
    cursor: pointer;
}

#walk-overlay[hidden] {
    display: none;
}

#walk-overlay .card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 18px 24px;
    max-width: 420px;
}

#walk-overlay h2 {
    margin: 0 0 8px;
}

#walk-overlay p {
    margin: 4px 0;
    color: var(--muted);
}

#walk-overlay b {
    color: var(--text);
}

.room-label {
    color: #1d2530;
    background: #ffffffcc;
    padding: 1px 6px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 600;
    pointer-events: none;
    white-space: nowrap;
}

dialog {
    background: var(--panel);
    color: var(--text);
    border: 1px solid var(--line);
    border-radius: 10px;
    max-width: 480px;
}

dialog::backdrop {
    background: #0009;
}

dialog h3 {
    margin-bottom: 4px;
    color: var(--accent);
    font-size: 13px;
}

@media (max-width: 760px) {
    #app {
        grid-template-columns: 1fr;
        grid-template-rows: auto 1fr auto;
    }

    #topbar {
        flex-wrap: nowrap;
        overflow-x: auto;
        gap: 6px;
        padding: 6px 8px;
        padding-top: calc(6px + env(safe-area-inset-top));
        scrollbar-width: none;
    }

    #topbar>* {
        flex: none;
    }

    #topbar button {
        padding: 6px 9px;
    }

    .brand,
    .spacer {
        display: none;
    }

    #catalog-toggle {
        display: inline-block;
    }

    body.catalog-open #catalog-toggle {
        background: var(--accent);
        color: #1a1a1a;
    }

    #catalog {
        grid-row: 3;
        display: none;
        max-height: 42vh;
        border-right: 0;
        border-top: 1px solid var(--line);
        padding-bottom: calc(10px + env(safe-area-inset-bottom));
    }

    body.catalog-open #catalog {
        display: block;
    }

    #viewport {
        grid-row: 2;
    }

    #inspector {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        width: auto;
        max-height: 48vh;
        z-index: 10;
        border-left: 0;
        border-top: 1px solid var(--line);
        border-radius: 12px 12px 0 0;
        box-shadow: 0 -8px 24px #0008;
        padding-bottom: calc(10px + env(safe-area-inset-bottom));
    }

    input,
    select {
        font-size: 16px; /* stops iOS zooming into fields */
    }

    #hud-hint {
        display: none;
    }
}
