:root {
    --paper: #f5f5f5;
    --panel: #fff;
    --ink: #222;
    --muted: #606060;
    --line: #ccc;
    --accent: #0067c0;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    height: 100%;
}

body {
    min-width: 320px;
    height: 100%;
    overflow: hidden;
    color: var(--ink);
    background-color: var(--paper);
    font: 14px/1.4 Aptos, "Segoe UI", sans-serif;
}

#render-canvas {
    position: fixed;
    inset: 0;
    z-index: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.app-shell {
    position: relative;
    z-index: 1;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    height: 100dvh;
}

.toolbar {
    z-index: 2;
    border-bottom: 1px solid var(--line);
    background: var(--paper);
}

.toolbar-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px 20px;
    width: 100%;
    min-height: 52px;
    padding: 10px 16px;
}

h1 {
    font-size: 1rem;
    font-weight: 600;
    line-height: 1.4;
}

.controls {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    flex-wrap: wrap;
    min-width: 0;
    gap: 8px 16px;
}

.grid-controls {
    display: flex;
    align-items: center;
    gap: 10px;
}

.grid-control {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--ink);
    font-size: 0.8rem;
    white-space: nowrap;
}

.composite-control {
    display: flex;
    align-items: center;
    gap: 7px;
    color: var(--ink);
    font-size: 0.8rem;
    white-space: nowrap;
    cursor: pointer;
}

.composite-control input {
    width: 16px;
    height: 16px;
    accent-color: var(--accent);
    cursor: pointer;
}

select {
    width: 56px;
    min-height: 32px;
    padding: 4px 6px;
    border: 1px solid #aaa;
    border-radius: 2px;
    color: var(--ink);
    background: var(--panel);
    font: inherit;
    cursor: pointer;
}

select:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

#status {
    color: var(--muted);
    font-size: 0.875rem;
    font-variant-numeric: tabular-nums;
    overflow-wrap: anywhere;
}

button {
    min-height: 32px;
    padding: 5px 12px;
    border: 1px solid #aaa;
    border-radius: 2px;
    color: var(--ink);
    background: #eee;
    font: inherit;
    white-space: nowrap;
    cursor: pointer;
}

button:hover {
    border-color: #888;
    background: #e4e4e4;
}

button:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

button:active {
    background: #d8d8d8;
}

main {
    display: grid;
    grid-template-columns: repeat(var(--view-columns, 2), minmax(0, 1fr));
    grid-template-rows: repeat(var(--view-rows, 2), minmax(0, 1fr));
    width: 100%;
    min-height: 0;
    overflow: hidden;
    background: transparent;
}

.empty-state {
    display: grid;
    grid-column: 1 / -1;
    grid-row: 1 / -1;
    min-height: 100%;
    padding: 40px 24px;
    place-items: center;
    color: var(--muted);
    background: var(--panel);
    text-align: center;
}

.model-row {
    display: flex;
    flex-direction: column;
    width: 100%;
    min-width: 0;
    min-height: 0;
    background: var(--panel);
    border-right: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
    overflow: hidden;
}

.model-row.is-ready {
    background: transparent;
}

.model-header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 8px;
    min-height: 30px;
    padding: 5px 8px;
    border-bottom: 1px solid var(--line);
    background: var(--paper);
}

.model-title {
    min-width: 0;
    overflow: hidden;
    font-size: 0.8rem;
    font-weight: 400;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.model-state {
    flex: 0 0 auto;
    color: var(--muted);
    font-size: 0.75rem;
}

.model-viewport {
    position: relative;
    flex: 1 1 auto;
    width: 100%;
    min-height: 0;
    background: var(--panel);
    cursor: grab;
    overflow: hidden;
    touch-action: none;
    user-select: none;
}

.model-row.is-ready .model-viewport {
    background: transparent;
}

.model-viewport.is-interacting {
    cursor: grabbing;
}

.model-viewport:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: -2px;
}

.model-row.is-error .model-header {
    border-bottom: 0;
}

.model-row.is-error .model-state {
    color: #9b2f1b;
}

.model-error {
    padding: 12px;
    border-top: 1px solid var(--line);
    color: #8b2424;
    background: #fff0f0;
    font: 0.8rem/1.45 Consolas, monospace;
    overflow-wrap: anywhere;
}

@media (max-width: 720px) {
    .toolbar-content {
        align-items: stretch;
        flex-direction: column;
        gap: 8px;
        padding: 10px 12px;
    }

    .controls {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        justify-content: stretch;
        gap: 10px;
    }

    #status {
        grid-column: 1 / -1;
    }

    .grid-controls {
        grid-column: 1 / -1;
    }

    main {
        width: 100%;
    }
}