:root {
    --bg: #f5f7f7;
    --panel: rgba(255, 255, 255, 0.88);
    --ink: #263031;
    --muted: #667071;
    --line: rgba(103, 113, 114, 0.18);
    --primary: #3f6f87;
    --primary-ink: #f8fbfc;
    --shadow: 0 22px 54px -28px rgba(30, 42, 44, 0.35);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    font-family: "Manrope", sans-serif;
    background: linear-gradient(135deg, #fbfbfa 0%, var(--bg) 48%, #e7ecec 100%);
    color: var(--ink);
}

.material-symbols-outlined {
    font-family: "Material Symbols Outlined";
    font-weight: normal;
    font-style: normal;
    font-size: 22px;
    line-height: 1;
    letter-spacing: normal;
    text-transform: none;
    white-space: nowrap;
    direction: ltr;
    font-variation-settings: "FILL" 0, "wght" 300, "GRAD" 0, "opsz" 24;
}

.sky-tool {
    min-height: 100vh;
    display: grid;
    grid-template-rows: auto 1fr;
    gap: 18px;
    padding: 22px;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    padding: 18px 20px;
    background: var(--panel);
    border: 1px solid var(--line);
    box-shadow: var(--shadow);
}

.eyebrow {
    margin: 0 0 6px;
    color: #7a694c;
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0.24em;
    text-transform: uppercase;
}

h1 {
    margin: 0;
    font-size: clamp(1.5rem, 3vw, 2.35rem);
    letter-spacing: -0.03em;
}

.layout {
    display: grid;
    grid-template-columns: 320px minmax(0, 1fr);
    gap: 18px;
    min-height: 0;
}

.panel,
.canvas-shell,
.result-shell {
    background: var(--panel);
    border: 1px solid var(--line);
    box-shadow: var(--shadow);
}

.panel {
    align-self: start;
    display: grid;
    gap: 16px;
    padding: 16px;
}

.upload {
    min-height: 170px;
    display: grid;
    place-items: center;
    gap: 8px;
    padding: 18px;
    border: 1px dashed rgba(63, 111, 135, 0.45);
    background: rgba(255, 255, 255, 0.62);
    cursor: pointer;
    text-align: center;
}

.upload .material-symbols-outlined {
    font-size: 42px;
    color: var(--primary);
}

.upload small,
.hint {
    color: var(--muted);
    line-height: 1.6;
}

.control {
    display: grid;
    gap: 8px;
}

.control label {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    font-size: 12px;
    font-weight: 800;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

select,
input[type="range"] {
    width: 100%;
}

select {
    min-height: 44px;
    padding: 0 12px;
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.84);
    color: var(--ink);
    font: inherit;
}

input[type="range"] {
    appearance: none;
    height: 2px;
    background: rgba(103, 113, 114, 0.36);
}

input[type="range"]::-webkit-slider-thumb {
    appearance: none;
    width: 16px;
    height: 16px;
    background: var(--primary);
}

.actions {
    display: grid;
    gap: 10px;
}

.tool-tabs {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
}

.tool-tab {
    min-height: 48px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 0 8px;
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.86);
    color: var(--ink);
    cursor: pointer;
    font: inherit;
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.tool-tab.active {
    background: var(--primary);
    color: var(--primary-ink);
    border-color: transparent;
}

.tool-tab .material-symbols-outlined {
    font-size: 20px;
}

.btn,
.link-btn,
.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.86);
    color: var(--ink);
    cursor: pointer;
    font: inherit;
    font-size: 12px;
    font-weight: 800;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    text-decoration: none;
}

.btn,
.link-btn {
    min-height: 46px;
    padding: 0 14px;
}

.icon-btn {
    width: 42px;
    height: 42px;
}

.btn.primary {
    background: var(--primary);
    color: var(--primary-ink);
    border-color: transparent;
}

.btn:disabled,
.icon-btn:disabled {
    opacity: 0.42;
    cursor: not-allowed;
}

.hint {
    margin: 0;
    font-size: 13px;
}

.workbench {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(360px, 0.9fr);
    align-items: stretch;
    gap: 18px;
    min-width: 0;
}

.canvas-shell {
    position: relative;
    min-height: 68vh;
    display: grid;
    place-items: center;
    padding: 16px;
    overflow: hidden;
}

#skyCanvas {
    display: block;
    max-width: 100%;
    max-height: calc(100vh - 180px);
    touch-action: none;
    cursor: crosshair;
    background: rgba(255, 255, 255, 0.76);
}

.empty-state {
    position: absolute;
    inset: 0;
    display: grid;
    place-content: center;
    justify-items: center;
    gap: 10px;
    color: var(--muted);
    pointer-events: none;
}

.empty-state .material-symbols-outlined {
    font-size: 54px;
    color: var(--primary);
}

.result-shell {
    min-height: 68vh;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    overflow: hidden;
}

.result-header {
    min-height: 54px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 8px 12px 8px 16px;
    border-bottom: 1px solid var(--line);
}

.result-stage {
    position: relative;
    min-height: 0;
    display: grid;
    place-items: center;
    overflow: hidden;
    background: rgba(255, 255, 255, 0.7);
}

.result-stage::after {
    content: attr(data-preview-state);
    position: absolute;
    left: 14px;
    bottom: 14px;
    z-index: 3;
    max-width: calc(100% - 28px);
    padding: 8px 10px;
    background: rgba(38, 48, 49, 0.78);
    color: #fff;
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    opacity: 0;
    transform: translateY(4px);
    transition: opacity 0.16s ease, transform 0.16s ease;
    pointer-events: none;
}

.result-stage.is-preview-busy::after {
    opacity: 1;
    transform: translateY(0);
}

.result-stage.is-preview-busy #skyResult {
    opacity: 0.72;
}

#skyResult {
    display: block;
    width: 100%;
    height: 100%;
    max-height: calc(100vh - 180px);
    object-fit: contain;
}

#maskEditCanvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    touch-action: none;
    pointer-events: none;
}

#maskEditCanvas.is-brush {
    cursor: cell;
    pointer-events: auto;
}

@media (max-width: 1180px) {
    .workbench {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 900px) {
    .layout {
        grid-template-columns: 1fr;
    }

    .canvas-shell,
    .result-shell {
        min-height: 52vh;
    }
}
