:root {
    --bg: #f1eadb;
    --panel: #fbf8f2;
    --panel-strong: #fffdf8;
    --line: #c9bda8;
    --line-strong: #927f62;
    --text: #1e1a14;
    --muted: #6d6254;
    --accent: #006e52;
    --accent-soft: #d7f0e7;
    --danger: #a33a22;
    --danger-soft: #fbe1da;
    --warning: #8b5600;
    --warning-soft: #fdecc9;
    --shadow: 0 16px 36px rgba(41, 31, 17, 0.14);
    --font-ui: "Segoe UI", "Helvetica Neue", Helvetica, Arial, sans-serif;
    --font-mono: "Cascadia Code", Consolas, "Liberation Mono", monospace;
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    height: 100%;
    overflow: hidden;
    color: var(--text);
    background:
        radial-gradient(circle at top left, rgba(255, 255, 255, 0.8), transparent 28%),
        linear-gradient(180deg, #f8f3e8 0%, var(--bg) 100%);
    font-family: var(--font-ui);
}

button,
input,
label,
summary {
    font: inherit;
}

button,
input[type="color"] {
    border-radius: 10px;
}

button {
    border: 1px solid var(--line-strong);
    background: var(--panel-strong);
    color: var(--text);
    cursor: pointer;
    padding: 0.48rem 0.72rem;
    transition: transform 120ms ease, background-color 120ms ease, border-color 120ms ease;
}

button:hover:enabled {
    transform: translateY(-1px);
    border-color: var(--accent);
}

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

.danger-button {
    background: var(--danger);
    border-color: var(--danger);
    color: #fff;
}

.app-shell {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    height: 100dvh;
    overflow: hidden;
}

.top-toolbar {
    display: flex;
    gap: 0.55rem 0.7rem;
    align-items: center;
    justify-content: flex-start;
    flex-wrap: nowrap;
    padding: 0.65rem 0.85rem;
    border-bottom: 1px solid rgba(146, 127, 98, 0.35);
    background: rgba(251, 248, 242, 0.88);
    backdrop-filter: blur(16px);
    box-shadow: 0 6px 18px rgba(61, 47, 24, 0.08);
    overflow-x: auto;
}

.toolbar-group {
    display: flex;
    gap: 0.4rem;
    align-items: center;
    flex-wrap: nowrap;
    flex: 0 0 auto;
}

.toolbar-zoom {
    margin-left: auto;
}

.status-chip {
    display: inline-flex;
    align-items: center;
    padding: 0.34rem 0.58rem;
    border: 1px solid var(--line);
    background: var(--panel);
    border-radius: 999px;
    white-space: nowrap;
    font-size: 0.88rem;
}

.status-chip.status-ok {
    background: var(--panel);
}

.status-chip.status-warning {
    background: var(--warning-soft);
    border-color: #ddb769;
    color: #5f3f07;
}

.status-chip.status-error {
    background: var(--danger-soft);
    border-color: #d89081;
    color: #772515;
}

.editor-layout {
    display: grid;
    grid-template-columns: 84px minmax(0, 1fr) 330px;
    min-height: 0;
    overflow: hidden;
}

.tool-rail,
.inspector {
    padding: 0.8rem;
    background: rgba(251, 248, 242, 0.72);
}

.tool-rail {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    border-right: 1px solid rgba(146, 127, 98, 0.32);
}

.tool-button {
    width: 100%;
    min-height: 50px;
    padding: 0.65rem 0.55rem;
    font-size: 0.94rem;
}

.tool-button.is-active {
    border-color: var(--accent);
    background: var(--accent-soft);
    color: #063b2e;
}

.workspace {
    position: relative;
    min-width: 0;
    display: grid;
    grid-template-rows: minmax(0, 1fr);
    padding: 0.8rem;
    overflow: hidden;
}

.viewport {
    position: relative;
    min-height: 0;
    overflow: hidden;
    border: 1px solid rgba(146, 127, 98, 0.42);
    border-radius: 18px;
    background:
        linear-gradient(45deg, rgba(201, 189, 168, 0.18) 25%, transparent 25%, transparent 75%, rgba(201, 189, 168, 0.18) 75%),
        linear-gradient(45deg, rgba(201, 189, 168, 0.18) 25%, transparent 25%, transparent 75%, rgba(201, 189, 168, 0.18) 75%);
    background-size: 28px 28px;
    background-position: 0 0, 14px 14px;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.55), var(--shadow);
    user-select: none;
}

.scene-svg,
.overlay-svg {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.text-edit-overlay {
    position: absolute;
    min-width: 24px;
    padding: 0.12rem 0.3rem;
    border: 2px solid #1a73e8;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.97);
    box-shadow: 0 14px 32px rgba(26, 115, 232, 0.18);
    outline: 3px solid rgba(26, 115, 232, 0.16);
    outline-offset: 0;
    z-index: 5;
}

.empty-state {
    position: absolute;
    top: 1rem;
    left: 1rem;
    max-width: 320px;
    padding: 0.85rem 1rem;
    border-radius: 14px;
    border: 1px solid rgba(146, 127, 98, 0.38);
    background: rgba(255, 253, 248, 0.9);
    color: var(--muted);
    z-index: 2;
}

.empty-state p {
    margin: 0;
}

.empty-state p + p {
    margin-top: 0.45rem;
}

.notice-region {
    position: absolute;
    right: 1.35rem;
    top: 1rem;
    display: grid;
    gap: 0.55rem;
    max-width: min(460px, calc(100% - 2.7rem));
    z-index: 8;
}

.notice {
    border-radius: 14px;
    border: 1px solid var(--line);
    background: rgba(255, 253, 248, 0.96);
    box-shadow: var(--shadow);
    padding: 0.8rem 0.9rem;
}

.notice .notice-header button {
    padding: 0.35rem 0.55rem;
}

.notice.notice-warning {
    border-color: #ddb769;
    background: rgba(253, 236, 201, 0.96);
}

.notice.notice-error {
    border-color: #d89081;
    background: rgba(251, 225, 218, 0.98);
}

.notice-header {
    display: flex;
    gap: 1rem;
    justify-content: space-between;
    align-items: flex-start;
}

.notice-title {
    font-weight: 700;
}

.notice-body {
    color: var(--muted);
    margin-top: 0.35rem;
    white-space: pre-wrap;
}

.inspector {
    display: flex;
    flex-direction: column;
    gap: 0.7rem;
    border-left: 1px solid rgba(146, 127, 98, 0.32);
    overflow: auto;
    min-height: 0;
}

.inspector-section {
    border: 1px solid rgba(146, 127, 98, 0.32);
    border-radius: 16px;
    background: rgba(255, 253, 248, 0.86);
    padding: 0.8rem;
}

.inspector-section h2,
.inspector-group h3 {
    margin: 0 0 0.55rem;
    font-size: 0.95rem;
}

.inspector-group + .inspector-group {
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid rgba(146, 127, 98, 0.24);
}

.inspector-group.inspector-details {
    margin-top: 0.8rem;
    padding-top: 0;
    border-top: 0;
}

.inspector-details summary {
    cursor: pointer;
    color: var(--muted);
    font-size: 0.9rem;
    font-weight: 600;
}

.field-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.6rem;
}

.field-grid.field-grid-single {
    grid-template-columns: 1fr;
}

.field {
    display: grid;
    gap: 0.22rem;
}

.field label,
.inline-toggle {
    font-size: 0.86rem;
    color: var(--muted);
}

.field input[type="number"],
.field input[type="text"] {
    width: 100%;
    border: 1px solid var(--line);
    background: #fff;
    color: var(--text);
    padding: 0.4rem 0.5rem;
    border-radius: 10px;
}

.field textarea {
    width: 100%;
    min-height: 110px;
    border: 1px solid var(--line);
    background: #fff;
    border-radius: 10px;
    font-family: var(--font-mono);
    padding: 0.55rem;
    resize: vertical;
}

.action-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.42rem;
}

.help-text,
.meta-list {
    color: var(--muted);
    font-size: 0.86rem;
}

.meta-list {
    display: grid;
    gap: 0.32rem;
}

.log-section summary {
    cursor: pointer;
    font-weight: 700;
    font-size: 0.92rem;
}

.log-controls {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.7rem;
    margin-bottom: 0.55rem;
}

.log-output {
    max-height: 260px;
    overflow: auto;
    margin: 0;
    padding: 0.7rem;
    border-radius: 12px;
    background: #1c1a16;
    color: #f5f1e7;
    font-size: 0.8rem;
    font-family: var(--font-mono);
    white-space: pre-wrap;
    word-break: break-word;
}

.confirm-dialog {
    border: 1px solid rgba(146, 127, 98, 0.4);
    border-radius: 18px;
    box-shadow: var(--shadow);
    padding: 0;
    width: min(520px, calc(100vw - 2rem));
}

.confirm-dialog form {
    padding: 1.2rem 1.2rem 1rem;
}

.confirm-dialog::backdrop {
    background: rgba(23, 19, 13, 0.36);
}

.confirm-dialog h2,
.confirm-dialog p {
    margin: 0;
}

.confirm-details {
    color: var(--muted);
    margin-top: 0.8rem;
    white-space: pre-wrap;
}

.confirm-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.6rem;
    padding: 0;
    margin: 1rem 0 0;
}

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

.button-priority-primary:hover:enabled {
    border-color: #0a8f6c;
    background: #0a8f6c;
}

.button-priority-secondary {
    border-color: var(--line-strong);
    background: rgba(255, 255, 255, 0.72);
}

.button-priority-tertiary {
    border-color: rgba(146, 127, 98, 0.55);
    background: rgba(255, 253, 248, 0.55);
    padding-inline: 0.65rem;
}

.bottom-statusbar {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.5rem 0.8rem;
    border-top: 1px solid rgba(146, 127, 98, 0.32);
    background: rgba(251, 248, 242, 0.88);
    min-height: 44px;
}

.status-hint {
    min-width: 0;
    margin-left: auto;
    color: var(--muted);
    font-size: 0.88rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

@media (max-width: 1200px) {
    .editor-layout {
        grid-template-columns: 78px minmax(0, 1fr) 290px;
    }
}

@media (max-width: 980px) {
    .editor-layout {
        grid-template-columns: 78px minmax(0, 1fr);
        grid-template-rows: 1fr auto;
    }

    .inspector {
        grid-column: 1 / -1;
        border-left: 0;
        border-top: 1px solid rgba(146, 127, 98, 0.32);
    }

    .bottom-statusbar {
        flex-wrap: wrap;
    }

    .status-hint {
        width: 100%;
        margin-left: 0;
    }
}
