:root {
    color-scheme: dark;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: #0d1117;
    color: #f3f6fb;
}

* {
    box-sizing: border-box;
}

html,
body {
    width: 100%;
    height: 100%;
    margin: 0;
    overflow: hidden;
    background: #0d1117;
}

button,
select {
    width: 100%;
    min-height: 42px;
    border-radius: 8px;
    border: 1px solid #344054;
    background: #1a2230;
    color: #f3f6fb;
    padding: 9px 11px;
    font: inherit;
}

button {
    cursor: pointer;
    font-weight: 650;
}

button:hover:not(:disabled) {
    background: #253247;
}

button:disabled {
    cursor: not-allowed;
    opacity: 0.45;
}

button.primary {
    background: #315efb;
    border-color: #4770ff;
}

button.primary:hover:not(:disabled) {
    background: #416cff;
}

button.danger {
    color: #ffdad6;
    border-color: #743f42;
    background: #402426;
}

select {
    cursor: pointer;
}

.app-shell {
    display: grid;
    grid-template-columns: 310px minmax(0, 1fr);
    width: 100vw;
    height: 100vh;
}

.sidebar {
    z-index: 2;
    display: flex;
    flex-direction: column;
    gap: 16px;
    overflow-y: auto;
    padding: 20px;
    border-right: 1px solid #273244;
    background: #111823;
    box-shadow: 8px 0 30px rgba(0, 0, 0, 0.18);
}

.brand-row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
}

.brand {
    font-size: 1.5rem;
    font-weight: 800;
    letter-spacing: 0.08em;
}

.subtitle {
    margin-top: 2px;
    color: #98a7bd;
    font-size: 0.86rem;
}

.mode-badge {
    border-radius: 999px;
    padding: 5px 8px;
    background: #21355c;
    color: #bcd1ff;
    font-size: 0.67rem;
    font-weight: 800;
    letter-spacing: 0.06em;
}

.mode-badge.simulation {
    background: #513915;
    color: #ffd98a;
}

.panel-section {
    display: flex;
    flex-direction: column;
    gap: 9px;
}

.panel-section h2 {
    margin: 0 0 3px;
    font-size: 0.92rem;
    letter-spacing: 0.02em;
}

.panel-section label {
    margin-top: 3px;
    color: #aebbd0;
    font-size: 0.78rem;
    font-weight: 650;
}

.button-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.divider {
    width: 100%;
    height: 1px;
    margin: 5px 0;
    background: #273244;
}

.hint,
.controls-note {
    margin: 0;
    color: #8f9db2;
    font-size: 0.75rem;
    line-height: 1.45;
}

.status-card {
    padding: 12px;
    border: 1px solid #29364a;
    border-radius: 10px;
    background: #0d141f;
    color: #b7c4d7;
    font-size: 0.78rem;
    line-height: 1.45;
}

.status-title {
    margin-bottom: 4px;
    color: #f3f6fb;
    font-weight: 750;
}

.simulation-progress {
    margin-top: 6px;
    color: #88d8a5;
    white-space: pre-line; /* second line: grouping / path search figures */
}

.controls-note {
    margin-top: auto;
    padding-top: 10px;
    border-top: 1px solid #273244;
}

.viewport-host {
    position: relative;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
    background: #080b10;
}

#canvas {
    display: block;
    width: 100%;
    height: 100%;
    outline: none;
    background: #111;
    touch-action: none;
}

.canvas-label {
    position: absolute;
    top: 12px;
    right: 12px;
    pointer-events: none;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 999px;
    padding: 6px 9px;
    background: rgba(10, 15, 23, 0.78);
    color: #9bacbf;
    font-size: 0.7rem;
    backdrop-filter: blur(8px);
}

.hidden {
    display: none !important;
}

@media (max-width: 820px) {
    html,
    body {
        overflow-x: hidden;
        overflow-y: auto;
        overscroll-behavior-y: contain;
    }

    .app-shell {
        display: flex;
        flex-direction: column;
        width: 100%;
        height: auto;
        min-height: 100dvh;
    }

    /* Put the actual editor viewport first on phones. Users can interact with
       the scene immediately and scroll down to the detailed inspector. */
    .viewport-host {
        order: 1;
        width: 100%;
        height: 56dvh;
        min-height: 360px;
        max-height: 620px;
        flex: 0 0 auto;
        border-bottom: 1px solid #273244;
    }

    .sidebar {
        order: 2;
        width: 100%;
        max-height: none;
        gap: 13px;
        padding: 14px;
        border-right: 0;
        border-bottom: 0;
        box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.18);
    }

    button,
    select {
        min-height: 46px;
        font-size: 1rem;
    }

    /* 16px prevents iOS Safari from page-zooming when a numeric input is
       focused and gives the software keyboard a comfortable target. */
    .measurement-grid input[type="number"] {
        min-height: 46px;
        padding: 9px 10px;
        font-size: 16px;
    }

    .measurement-grid {
        gap: 10px;
    }

    .button-row {
        gap: 10px;
    }

    .controls-note {
        margin-top: 4px;
    }

    /* Runtime numbers are still available through the debug console, but the
       always-visible stats card consumes too much of a phone viewport. */
    .runtime-stats-panel {
        display: none;
    }

    .canvas-label {
        top: 8px;
        right: 8px;
    }

    .mobile-gesture-hint {
        position: absolute;
        left: 10px;
        right: 10px;
        bottom: 10px;
        z-index: 4;
        display: flex;
        flex-wrap: wrap;
        justify-content: center;
        gap: 5px 10px;
        pointer-events: none;
        border: 1px solid rgba(255, 255, 255, 0.11);
        border-radius: 10px;
        padding: 7px 9px;
        background: rgba(8, 13, 20, 0.76);
        color: #c9d5e6;
        font-size: 0.68rem;
        line-height: 1.25;
        text-align: center;
        backdrop-filter: blur(8px);
        transition: opacity 220ms ease;
    }

    .mobile-gesture-hint strong {
        color: #ffffff;
    }

    .viewport-host.mobile-gesture-used .mobile-gesture-hint {
        opacity: 0.50;
    }
}

/* ==========================================================================
   C++ / WebAssembly runtime debug UI
   ========================================================================== */

.runtime-stats-panel {
    position: absolute;
    top: 54px;
    left: 12px;
    z-index: 5;
    width: 238px;
    pointer-events: none;
    overflow: hidden;
    border: 1px solid rgba(126, 151, 186, 0.26);
    border-radius: 10px;
    background: rgba(8, 13, 20, 0.88);
    box-shadow: 0 14px 34px rgba(0, 0, 0, 0.28);
    backdrop-filter: blur(10px);
}

.runtime-stats-header {
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 9px 10px;
    border-bottom: 1px solid rgba(126, 151, 186, 0.18);
    color: #dce8f8;
    font-size: 0.72rem;
    font-weight: 800;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.runtime-status-dot,
.debug-console-dot {
    width: 8px;
    height: 8px;
    flex: 0 0 auto;
    border-radius: 50%;
    background: #67758a;
    box-shadow: 0 0 0 3px rgba(103, 117, 138, 0.12);
}

.runtime-status-dot.ready {
    background: #42d392;
    box-shadow: 0 0 0 3px rgba(66, 211, 146, 0.14);
}

.runtime-stats-grid {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 5px 12px;
    padding: 10px;
    font-family: "Cascadia Mono", "SFMono-Regular", Consolas, monospace;
    font-size: 0.69rem;
}

.runtime-stats-grid span {
    color: #8091aa;
}

.runtime-stats-grid strong {
    color: #d8e6f8;
    font-weight: 700;
    text-align: right;
}

.debug-console {
    position: absolute;
    left: 12px;
    bottom: 12px;
    z-index: 6;
    width: min(760px, calc(100% - 24px));
    max-height: 40vh;
    overflow: hidden;
    border: 1px solid rgba(126, 151, 186, 0.30);
    border-radius: 10px;
    background: rgba(5, 9, 14, 0.94);
    box-shadow: 0 18px 44px rgba(0, 0, 0, 0.34);
    backdrop-filter: blur(12px);
}

.debug-console.collapsed {
    width: min(320px, calc(100% - 24px));
}

.debug-console-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    min-height: 42px;
    padding: 7px 9px 7px 11px;
    border-bottom: 1px solid rgba(126, 151, 186, 0.18);
}

.debug-console.collapsed .debug-console-header {
    border-bottom: 0;
}

.debug-console-title {
    display: flex;
    align-items: center;
    min-width: 0;
    gap: 7px;
    color: #dce8f8;
    font-size: 0.72rem;
    font-weight: 800;
    letter-spacing: 0.03em;
    text-transform: uppercase;
}

.debug-console-dot {
    background: #42d392;
    box-shadow: 0 0 0 3px rgba(66, 211, 146, 0.13);
}

.debug-line-count {
    color: #718198;
    font-size: 0.62rem;
    font-weight: 650;
    letter-spacing: 0;
    text-transform: none;
}

.debug-console-actions {
    display: flex;
    gap: 6px;
}

.debug-mini-button {
    width: auto;
    min-height: 28px;
    padding: 4px 8px;
    border-radius: 6px;
    background: #151f2c;
    color: #b9c8db;
    font-size: 0.66rem;
    font-weight: 750;
}

.debug-console-body {
    display: flex;
    flex-direction: column;
    height: min(270px, 34vh);
}

.debug-console.collapsed .debug-console-body {
    display: none;
}

.debug-console-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 7px 10px;
    border-bottom: 1px solid rgba(126, 151, 186, 0.13);
    color: #74869e;
    font-size: 0.64rem;
}

.debug-autoscroll {
    display: flex;
    align-items: center;
    gap: 5px;
    margin: 0;
    white-space: nowrap;
    color: #8ea0b8 !important;
    font-size: 0.64rem !important;
    font-weight: 650 !important;
}

.debug-autoscroll input {
    margin: 0;
}

.debug-console-output {
    flex: 1;
    overflow: auto;
    padding: 8px 10px 12px;
    font-family: "Cascadia Mono", "SFMono-Regular", Consolas, "Liberation Mono", monospace;
    font-size: 0.68rem;
    line-height: 1.45;
    scrollbar-color: #33445c transparent;
}

.debug-line {
    padding: 1px 0;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    color: #aebcd0;
}

.debug-line.info {
    color: #a9c8ff;
}

.debug-line.debug {
    color: #aab5c5;
}

.debug-line.error {
    color: #ff8f87;
}

.debug-line.warning {
    color: #ffd47d;
}

.debug-line.web {
    color: #8ee0b0;
}

@media (max-width: 820px) {
    .runtime-stats-panel {
        top: 52px;
        left: 8px;
        width: 205px;
    }

    .runtime-stats-grid {
        font-size: 0.63rem;
    }

    .debug-console {
        left: 8px;
        right: 8px;
        bottom: 8px;
        width: auto;
        max-height: 46vh;
    }

    .debug-console.collapsed {
        width: 255px;
        right: auto;
    }

    .debug-console-body {
        height: min(245px, 40vh);
    }
}



/* ==========================================================================\n   Floor-plan editing / selected-object inspector\n   ========================================================================== */

.editor-subsection { display: flex; flex-direction: column; gap: 9px; }
.section-title-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.section-title-row h2 { margin: 0; }
.mini-badge { border: 1px solid #3a4b63; border-radius: 999px; padding: 3px 7px; background: #172233; color: #b9c9df; font-size: 0.66rem; font-weight: 800; }
.toggle-row { display: flex !important; align-items: center; gap: 8px; min-height: 34px; margin: 0 !important; color: #d8e1ee !important; }
.toggle-row input[type="checkbox"] { width: 16px; height: 16px; margin: 0; accent-color: #4770ff; }
.measurement-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.measurement-grid label { display: flex; flex-direction: column; gap: 4px; margin: 0 !important; }
.measurement-grid input[type="number"] { width: 100%; min-width: 0; min-height: 37px; border: 1px solid #344054; border-radius: 7px; background: #101823; color: #f3f6fb; padding: 7px 8px; font: inherit; font-size: 0.8rem; }
.measurement-grid input[type="number"]:focus { border-color: #597cff; outline: 2px solid rgba(71, 112, 255, 0.18); }
.measurement-grid input:disabled { opacity: 0.46; }
.inspector-disabled { opacity: 0.7; }
.subtle-danger { min-height: 36px; padding: 7px 10px; }

/* Native number spinners remain enabled for instant size feedback. */

.measurement-grid input.invalid-number {
    border-color: #ff7a72;
    outline: 2px solid rgba(255, 122, 114, 0.16);
}

.mobile-gesture-hint {
    display: none;
}


@media (max-width: 480px) {
    .viewport-host {
        height: 52dvh;
        min-height: 330px;
    }

    .sidebar {
        padding: 12px;
    }

    .measurement-grid {
        grid-template-columns: 1fr 1fr;
    }

    .brand {
        font-size: 1.3rem;
    }

    .hint,
    .controls-note {
        font-size: 0.78rem;
    }
}


/* ==========================================================================
   Audio developer panel
   ========================================================================== */

.audio-panel {
    gap: 10px;
}

.audio-panel-body {
    display: flex;
    flex-direction: column;
    gap: 9px;
}

.audio-panel.collapsed .audio-panel-body {
    display: none;
}

.audio-mini-button {
    width: auto;
    min-height: 30px;
    padding: 5px 9px;
    border-radius: 7px;
    font-size: 0.7rem;
}

.audio-meta-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    color: #aebdd1;
    font-size: 0.72rem;
}

.audio-subtle {
    color: #8394aa;
    font-size: 0.7rem;
}

.audio-bgm-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    border: 1px solid #2e3d52;
    border-radius: 8px;
    padding: 8px 9px;
    background: #111b28;
}

.audio-bgm-copy {
    display: flex;
    flex: 1;
    min-width: 0;
    flex-direction: column;
    gap: 2px;
    font-size: 0.73rem;
}

.audio-bgm-copy span {
    overflow: hidden;
    color: #8192a9;
    font-size: 0.65rem;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.audio-state-pill {
    flex: 0 0 auto;
    border: 1px solid #3d4c61;
    border-radius: 999px;
    padding: 3px 7px;
    color: #9baabd;
    font-size: 0.63rem;
    font-weight: 800;
    text-transform: uppercase;
}

.audio-state-pill.on {
    border-color: rgba(88, 208, 137, 0.45);
    background: rgba(88, 208, 137, 0.10);
    color: #8ee0b0;
}

.audio-sfx-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 7px;
}

.audio-sfx-button {
    position: relative;
    overflow: hidden;
    display: flex;
    min-height: 48px;
    flex-direction: column;
    align-items: flex-start;
    justify-content: center;
    gap: 2px;
    padding: 8px 10px;
    text-align: left;
}

.audio-sfx-name,
.audio-sfx-file {
    position: relative;
    z-index: 2;
}

.audio-sfx-name {
    color: #e5edf8;
    font-size: 0.76rem;
    font-weight: 750;
}

.audio-sfx-file {
    overflow: hidden;
    width: 100%;
    color: #7f91a9;
    font-size: 0.63rem;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.audio-sfx-bar {
    position: absolute;
    z-index: 1;
    left: 0;
    bottom: 0;
    width: 0;
    height: 3px;
    background: #597cff;
    transition: width 50ms linear;
}

.audio-sfx-button.playing {
    border-color: rgba(89, 124, 255, 0.65);
}

.audio-status {
    border-radius: 7px;
    padding: 7px 8px;
    background: rgba(255, 255, 255, 0.035);
    color: #91a2b8;
    font-size: 0.68rem;
    line-height: 1.35;
}

.audio-status.ok {
    background: rgba(88, 208, 137, 0.08);
    color: #8ee0b0;
}

.audio-status.error {
    background: rgba(255, 122, 114, 0.08);
    color: #ff8f87;
}

.audio-panel code {
    color: #adc4ff;
    font-family: "Cascadia Mono", "SFMono-Regular", Consolas, monospace;
    font-size: 0.92em;
}

@media (max-width: 820px) {
    .audio-panel .button-row {
        grid-template-columns: 1fr 1fr;
    }

    .audio-sfx-button {
        min-height: 52px;
    }
}
