*, *::before, *::after {
    box-sizing: border-box;
}

:root {
    --bg: #07080a;
    --surface: #0d0f12;
    --surface2: #0a0c0e;
    --border: #1a1f26;
    --border2: #2d3748;
    --accent: #2563eb;
    --accent2: #60a5fa;
    --text: #f0f2f4;
    --muted: #6b7280;
    --muted2: #9ca3af;
    --danger: #f87171;
}

html,
body {
    width: 100%;
    height: 100%;
    margin: 0;
    overflow: hidden;
    background: var(--bg);
    color: var(--text);
    font-family: "Segoe UI", system-ui, sans-serif;
    font-size: 13px;
}

.app {
    width: 100%;
    height: 100%;
    min-width: 0;
}

.viewer-app {
    display: flex;
    flex-direction: column;
}

.game-app {
    display: block;
    background: black;
}

.game-app .viewport {
    width: 100%;
    height: 100%;
}

.editor-app {
    display: grid;
    grid-template-rows: 36px 32px 1fr;
}

.toolbar {
    height: 36px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 0 10px 0 12px;
    background: var(--surface);
    border-bottom: 0.5px solid var(--border);
}

.tool-strip {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 0 10px 0 12px;
    background: var(--surface);
    border-bottom: 0.5px solid var(--border);
}

.toolbar-left,
.toolbar-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
}

.toolbar-title {
    font-size: 12px;
    font-weight: 600;
    color: var(--text);
    letter-spacing: 0.04em;
    white-space: nowrap;
}

.toolbar-scene,
#status {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--muted2);
    font: 11.5px "Cascadia Code", "Consolas", monospace;
}

#status.error {
    color: var(--danger);
}

.menu {
    position: relative;
}

.menu-button,
.icon-btn,
.tool-btn {
    height: 28px;
    border: none;
    background: transparent;
    color: var(--muted2);
    font: inherit;
    font-size: 12px;
    cursor: pointer;
}

.menu-button {
    padding: 0 10px;
}

.editor-app .menu-button {
    height: 36px;
    border-radius: 0;
}

.viewer-app .menu-button {
    border-radius: 4px;
}

.menu-button:hover,
.menu.open .menu-button,
.tool-btn:hover,
.tool-btn.active,
.icon-btn:hover {
    color: var(--text);
    background: rgba(255, 255, 255, 0.07);
}

.menu-panel {
    position: absolute;
    top: 32px;
    left: 0;
    min-width: 190px;
    padding: 4px;
    border: 0.5px solid var(--border2);
    border-radius: 6px;
    background: var(--surface);
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.45);
    opacity: 0;
    transform: translateY(-4px);
    pointer-events: none;
    transition: opacity 0.12s, transform 0.12s;
    z-index: 30;
}

.menu.open .menu-panel {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

.menu-item {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 7px 9px;
    border: none;
    background: transparent;
    color: var(--muted2);
    font: inherit;
    font-size: 12px;
    text-align: left;
    cursor: pointer;
}

.viewer-app .menu-item {
    border-radius: 4px;
}

.editor-app .menu-item {
    border-radius: 0;
}

.menu-item:hover {
    color: var(--text);
    background: rgba(255, 255, 255, 0.06);
}

.menu-item kbd {
    color: var(--muted);
    font: 10px "Cascadia Code", "Consolas", monospace;
}

.menu-label {
    padding: 7px 9px 4px;
    color: var(--muted);
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.icon-btn {
    width: 28px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border-radius: 4px;
    color: var(--muted);
    line-height: 0;
    transition: color 0.15s, background 0.15s;
}

.icon-btn svg {
    display: block;
    width: 16px;
    height: 16px;
    fill: currentColor;
}

.tool-btn {
    width: 30px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border-radius: 0;
}

.tool-btn img {
    width: 16px;
    height: 16px;
    display: block;
    object-fit: contain;
}

.tool-btn svg {
    width: 16px;
    height: 16px;
    display: block;
    fill: currentColor;
}

.viewport {
    position: relative;
    flex: 1;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
    background: var(--bg);
}

canvas {
    display: block;
    width: 100%;
    height: 100%;
}

.workspace {
    display: grid;
    grid-template-columns: 260px 1fr 280px;
    min-height: 0;
}

.sidebar,
.inspector {
    min-width: 0;
    background: var(--surface);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.sidebar {
    border-right: 0.5px solid var(--border);
}

.inspector {
    border-left: 0.5px solid var(--border);
}

.panel-head {
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 12px;
    border-bottom: 0.5px solid var(--border);
    flex-shrink: 0;
}

.panel-title {
    color: var(--muted);
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.head-actions {
    display: flex;
    align-items: center;
    gap: 2px;
}

.tree,
.inspector-body {
    flex: 1;
    min-height: 0;
    overflow: auto;
    padding: 6px;
}

.tree-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 8px;
    border-radius: 5px;
    color: var(--muted2);
    cursor: pointer;
    font: 12px "Cascadia Code", "Consolas", monospace;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tree-icon {
    width: 14px;
    color: var(--muted);
    flex-shrink: 0;
}

.tree-icon img,
.picker-icon img {
    width: 16px;
    height: 16px;
    display: block;
    object-fit: contain;
}

.tree-label {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tree-folder {
    color: var(--text);
    font-weight: 500;
}

.tree-item:hover {
    background: rgba(255, 255, 255, 0.04);
    color: var(--text);
}

.tree-item.active {
    background: rgba(37, 99, 235, 0.16);
    color: var(--accent2);
}

.selection-box {
    position: absolute;
    border: 1px solid var(--accent2);
    background: rgba(96, 165, 250, 0.12);
    pointer-events: none;
    display: none;
    z-index: 10;
}

.field {
    display: grid;
    gap: 5px;
    margin-bottom: 10px;
}

.field label,
.field > span {
    color: var(--muted);
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.field input {
    width: 100%;
    border: 0.5px solid var(--border2);
    border-radius: 5px;
    background: var(--surface2);
    color: var(--text);
    padding: 7px 8px;
    font: 12px "Cascadia Code", "Consolas", monospace;
    outline: none;
}

.field select {
    width: 100%;
    border: 0.5px solid var(--border2);
    border-radius: 5px;
    background: var(--surface2);
    color: var(--text);
    padding: 7px 8px;
    font: 12px "Cascadia Code", "Consolas", monospace;
    outline: none;
}

.field-row {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 6px;
}

.small-btn {
    border: 0.5px solid var(--border2);
    border-radius: 4px;
    background: transparent;
    color: var(--muted2);
    padding: 0 10px;
    font: inherit;
    font-size: 12px;
    cursor: pointer;
}

.small-btn:hover {
    color: var(--text);
    border-color: var(--accent2);
}

.checkbox-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
    color: var(--muted2);
    font-size: 12px;
}

.checkbox-row input {
    accent-color: var(--accent);
}

.modal-overlay {
    position: fixed;
    inset: 0;
    display: none;
    align-items: flex-start;
    justify-content: center;
    padding-top: 84px;
    background: rgba(0, 0, 0, 0.42);
    z-index: 100;
}

.modal-overlay.open {
    display: flex;
}

.picker-modal {
    width: min(420px, calc(100vw - 32px));
    max-height: min(520px, calc(100vh - 120px));
    display: grid;
    grid-template-rows: auto 1fr;
    gap: 6px;
    padding: 8px;
    border: 0.5px solid var(--border2);
    border-radius: 6px;
    background: var(--surface);
    box-shadow: 0 18px 40px rgba(0, 0, 0, 0.5);
}

.settings-modal {
    width: min(420px, calc(100vw - 32px));
    border: 0.5px solid var(--border2);
    border-radius: 6px;
    background: var(--surface);
    box-shadow: 0 18px 40px rgba(0, 0, 0, 0.5);
}

.modal-head {
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 8px 0 12px;
    border-bottom: 0.5px solid var(--border);
}

.settings-body {
    padding: 10px;
}

.picker-search {
    width: 100%;
    border: 0.5px solid var(--border2);
    border-radius: 4px;
    background: var(--surface2);
    color: var(--text);
    padding: 8px 10px;
    font: 12px "Cascadia Code", "Consolas", monospace;
    outline: none;
}

.picker-list {
    min-height: 0;
    overflow: auto;
}

.picker-item {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 8px 9px;
    border: none;
    border-radius: 0;
    background: transparent;
    color: var(--muted2);
    font: inherit;
    text-align: left;
    cursor: pointer;
}

.picker-item:hover {
    color: var(--text);
    background: rgba(255, 255, 255, 0.06);
}

.picker-icon {
    width: 18px;
    color: var(--muted);
    text-align: center;
    flex-shrink: 0;
}

.context-menu {
    position: fixed;
    min-width: 190px;
    display: none;
    padding: 4px;
    border: 0.5px solid var(--border2);
    border-radius: 4px;
    background: var(--surface);
    box-shadow: 0 14px 32px rgba(0, 0, 0, 0.48);
    z-index: 150;
}

.context-menu.open {
    display: block;
}

.context-menu button {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 7px 9px;
    border: none;
    border-radius: 0;
    background: transparent;
    color: var(--muted2);
    font: inherit;
    font-size: 12px;
    text-align: left;
    cursor: pointer;
}

.context-menu button:hover {
    color: var(--text);
    background: rgba(255, 255, 255, 0.06);
}

.context-menu button:disabled {
    color: var(--muted);
    cursor: default;
    opacity: 0.48;
}

.context-menu button:disabled:hover {
    background: transparent;
}

.context-menu .separator {
    height: 1px;
    margin: 4px;
    background: var(--border);
}

.vector {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
}

.empty {
    color: var(--muted);
    padding: 10px 8px;
    font-size: 12px;
}

.hidden {
    display: none;
}

.playtest-status {
    position: fixed;
    left: 12px;
    bottom: 10px;
    z-index: 20;
    color: var(--muted2);
    font: 11.5px "Cascadia Code", "Consolas", monospace;
    pointer-events: none;
}

.playtest-status.error {
    color: var(--danger);
}
