:root {
    --bg: #101317;
    --panel: rgba(20, 24, 29, 0.92);
    --panel-solid: #181d23;
    --line: rgba(255, 255, 255, 0.12);
    --text: #eef2f4;
    --muted: #9ca7ad;
    --accent: #f0b24f;
    --accent-2: #4cc9a4;
    --danger: #e96d5f;
    --vacuum: #76a7ff;
    --target: #f25f5c;
    font-family: Inter, "Segoe UI", Arial, sans-serif;
}

* {
    box-sizing: border-box;
}

html,
body {
    width: 100%;
    height: 100%;
    margin: 0;
    overflow: hidden;
    background: var(--bg);
    color: var(--text);
}

button,
input,
select {
    font: inherit;
}

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

.viewport-panel {
    position: relative;
    min-width: 0;
    min-height: 0;
    background: #11161b;
}

#sceneCanvas {
    display: block;
    width: 100%;
    height: 100%;
}

.topbar {
    position: absolute;
    top: 18px;
    left: 20px;
    right: 20px;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    pointer-events: none;
}

.topbar h1 {
    margin: 0;
    font-size: 26px;
    line-height: 1;
    letter-spacing: 0;
}

.topbar p {
    margin: 7px 0 0;
    color: var(--muted);
    font-size: 14px;
}

.status-pill {
    min-width: 92px;
    padding: 8px 12px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: rgba(10, 12, 15, 0.65);
    color: var(--accent-2);
    text-align: center;
    font-size: 13px;
}

.top-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.top-link {
    padding: 8px 12px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: rgba(10, 12, 15, 0.65);
    color: var(--text);
    text-decoration: none;
    font-size: 13px;
    pointer-events: auto;
}

.hud {
    position: absolute;
    left: 20px;
    bottom: 20px;
    width: min(620px, calc(100% - 40px));
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(12, 15, 18, 0.7);
    backdrop-filter: blur(10px);
}

.hud-grid,
.metric-strip {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 10px;
}

.hud-grid span,
.metric-strip span,
label {
    display: block;
    color: var(--muted);
    font-size: 12px;
    line-height: 1.2;
}

.hud-grid strong,
.metric-strip strong {
    display: block;
    margin-top: 4px;
    font-size: 16px;
    font-weight: 700;
    color: var(--text);
    white-space: nowrap;
}

.legend {
    position: absolute;
    right: 20px;
    bottom: 20px;
    display: flex;
    gap: 14px;
    padding: 9px 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(12, 15, 18, 0.7);
    color: var(--muted);
    font-size: 13px;
}

.legend span {
    display: inline-flex;
    align-items: center;
    gap: 7px;
}

.legend-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--accent);
}

.legend-dot.vacuum {
    background: var(--vacuum);
}

.legend-dot.target {
    background: var(--target);
}

.control-panel {
    grid-column: 2;
    grid-row: 1 / 3;
    overflow: auto;
    border-left: 1px solid var(--line);
    background: var(--panel-solid);
}

.panel-section {
    padding: 18px;
    border-bottom: 1px solid var(--line);
}

.section-title {
    display: flex;
    gap: 10px;
    align-items: center;
    justify-content: space-between;
}

h2 {
    margin: 0 0 14px;
    font-size: 15px;
    line-height: 1.2;
    font-weight: 700;
}

.section-title h2 {
    margin-bottom: 0;
}

.control-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
    margin-top: 14px;
}

input,
select {
    width: 100%;
    min-height: 36px;
    margin-top: 6px;
    padding: 7px 9px;
    border: 1px solid #323a43;
    border-radius: 6px;
    background: #101419;
    color: var(--text);
    outline: none;
}

select {
    min-width: 150px;
    margin-top: 0;
}

input:focus,
select:focus {
    border-color: var(--accent);
}

.button-row,
.segmented {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
    margin-top: 14px;
}

button {
    min-height: 38px;
    border: 1px solid #38424c;
    border-radius: 6px;
    background: #202832;
    color: var(--text);
    cursor: pointer;
}

button:hover {
    border-color: var(--accent);
}

button.primary {
    border-color: #c7842d;
    background: #bd7623;
    color: #14100a;
    font-weight: 700;
}

.segmented button.active,
.tabs button.active {
    border-color: var(--accent-2);
    background: rgba(76, 201, 164, 0.16);
    color: #c8fff0;
}

.bottom-panel {
    grid-column: 1;
    grid-row: 2;
    min-width: 0;
    overflow: hidden;
    border-top: 1px solid var(--line);
    background: var(--panel);
}

.tabs {
    display: flex;
    gap: 8px;
    padding: 12px 16px 0;
}

.tabs button {
    min-width: 128px;
}

.tab-panel {
    display: none;
    padding: 14px 16px 16px;
}

.tab-panel.active {
    display: block;
}

.designer-layout {
    margin-bottom: 12px;
}

.constructor-controls {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(138px, 158px));
    gap: 10px;
    align-items: start;
    justify-content: start;
}

.mini-control {
    min-width: 0;
    padding: 9px 10px;
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.025);
}

.mini-control input {
    min-height: 34px;
    margin-top: 7px;
    padding: 6px 8px;
}

.metric-strip {
    grid-template-columns: repeat(5, minmax(0, 1fr));
}

.curve-row {
    margin-top: 14px;
    padding-top: 12px;
    border-top: 1px solid var(--line);
}

.curve-readout {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    color: var(--muted);
    font-size: 12px;
}

.curve-readout span {
    padding: 5px 8px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.04);
}

.note {
    margin: 14px 0 0;
    color: var(--muted);
    font-size: 13px;
}

@media (max-width: 1080px) {
    .app-shell {
        grid-template-columns: 1fr;
        grid-template-rows: minmax(420px, 1fr) auto auto;
        overflow: auto;
        height: auto;
        min-height: 100vh;
    }

    body {
        overflow: auto;
    }

    .control-panel {
        grid-column: 1;
        grid-row: 2;
        border-left: 0;
        border-top: 1px solid var(--line);
    }

    .bottom-panel {
        grid-row: 3;
    }

    .hud-grid,
    .constructor-controls,
    .metric-strip {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

@media (max-width: 640px) {
    .control-grid,
    .button-row,
    .segmented,
    .hud-grid,
    .constructor-controls,
    .metric-strip {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .topbar,
    .legend {
        display: none;
    }

    .hud {
        left: 10px;
        bottom: 10px;
        width: calc(100% - 20px);
    }
}
