:root {
    color-scheme: dark;
    --bg: #0b1017;
    --panel: rgba(18, 26, 36, 0.86);
    --panel-2: #111923;
    --border: #2b394a;
    --text: #e8eef5;
    --muted: #91a1b4;
    --accent: #8db8e8;
    --accent-strong: #b8d7f8;
    --danger: #f3a6a6;
    --shadow: 0 20px 48px rgba(0, 0, 0, 0.28);
    --radius: 0.3rem;
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
    margin: 0;
    background:
        radial-gradient(circle at 12% 0%, rgba(106, 148, 190, 0.12), transparent 28rem),
        var(--bg);
    color: var(--text);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button, input { font: inherit; }
button { color: inherit; }

.app-shell {
    width: min(1180px, calc(100% - 32px));
    margin: 0 auto;
    padding: 28px 0 40px;
}

.topbar {
    display: flex;
    justify-content: space-between;
    gap: 24px;
    align-items: flex-start;
    margin-bottom: 18px;
}

.eyebrow {
    margin: 0 0 5px;
    color: var(--accent);
    font: 700 0.72rem/1.2 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    letter-spacing: 0.12em;
}

h1 { margin: 0; font-size: clamp(1.45rem, 3vw, 2rem); }
.subtitle { margin: 7px 0 0; color: var(--muted); max-width: 700px; line-height: 1.55; }

.privacy-badge {
    border: 1px solid var(--border);
    background: rgba(141, 184, 232, 0.08);
    color: var(--accent-strong);
    padding: 7px 10px;
    border-radius: var(--radius);
    white-space: nowrap;
    font-size: 0.82rem;
}

.workspace {
    display: grid;
    grid-template-columns: minmax(290px, 360px) minmax(0, 1fr);
    gap: 16px;
}

.panel {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--panel);
    box-shadow: var(--shadow);
    backdrop-filter: blur(14px);
}

.controls-panel { padding: 14px; }

.drop-zone {
    border: 1px dashed #52667d;
    border-radius: var(--radius);
    background: rgba(255, 255, 255, 0.018);
    padding: 24px 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 8px;
    transition: border-color .16s ease, background .16s ease;
    outline: none;
}

.drop-zone.dragover,
.drop-zone:focus-visible {
    border-color: var(--accent);
    background: rgba(141, 184, 232, 0.07);
}

.drop-zone svg,
.empty-state svg {
    width: 34px;
    height: 34px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.7;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.drop-zone svg { color: var(--accent); }
.drop-zone span { color: var(--muted); font-size: 0.82rem; }

.button {
    min-height: 36px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    padding: 7px 12px;
    cursor: pointer;
    transition: transform .08s ease, border-color .16s ease, background .16s ease;
}
.button:active:not(:disabled) { transform: translateY(1px); }
.button:disabled { opacity: .42; cursor: not-allowed; }
.button-primary { background: #d9e9fa; color: #0c1722; border-color: #d9e9fa; font-weight: 750; }
.button-secondary { background: #15202c; }
.button-secondary:hover:not(:disabled) { border-color: #52667d; }


.live-row {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 10px;
    margin-top: 14px;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--panel-2);
    cursor: pointer;
}
.live-row input { accent-color: #a7caef; }
.live-copy { display: grid; gap: 2px; min-width: 0; }
.live-copy strong { font-size: .84rem; }
.live-copy small { color: var(--muted); font-size: .72rem; line-height: 1.35; }
.live-pill {
    border: 1px solid #4d6c8c;
    border-radius: var(--radius);
    padding: 4px 6px;
    color: var(--accent-strong);
    font: 700 .65rem/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    letter-spacing: .08em;
}
.live-pill.paused { color: var(--muted); border-color: var(--border); }

.preview-title-row { display: flex; align-items: center; gap: 8px; }
.render-status {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 3px 6px;
    color: var(--muted);
    font: 650 .66rem/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.render-status.busy { color: var(--accent-strong); }
.render-status.ready { color: #b9dfc5; border-color: #385c46; }
.render-status.paused { color: #d4c5a0; border-color: #625637; }
.render-status.error { color: var(--danger); border-color: #6b3b3b; }

.control-group { margin-top: 18px; }
.control-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.control-head label { font-size: 0.88rem; font-weight: 680; }
.control-head output {
    font: 650 0.78rem/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    color: var(--accent-strong);
}
.control-group p { margin: 6px 0 0; color: var(--muted); font-size: 0.76rem; line-height: 1.45; }
input[type="range"] { width: 100%; margin: 9px 0 0; accent-color: #a7caef; }

.check-row {
    display: flex;
    gap: 9px;
    align-items: center;
    margin-top: 16px;
    color: #c8d3df;
    font-size: 0.84rem;
}
.check-row input { accent-color: #a7caef; }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 18px; }

.preview-panel { padding: 14px; min-width: 0; }
.preview-head,
.export-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}
.preview-head > div:first-child,
.export-row > div:first-child { display: grid; gap: 3px; }
.preview-head strong,
.export-row strong { font-size: .9rem; }
.preview-head span,
.export-row span { color: var(--muted); font-size: .77rem; }

.segmented {
    display: inline-flex;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}
.segmented button {
    background: #121b25;
    border: 0;
    border-right: 1px solid var(--border);
    padding: 6px 9px;
    font-size: .74rem;
    cursor: pointer;
}
.segmented button:last-child { border-right: 0; }
.segmented button.active { background: #26384b; color: #f4f8fc; }

.canvas-stage {
    width: 100%;
    aspect-ratio: 1;
    max-height: 660px;
    margin: 13px auto;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    display: grid;
    place-items: center;
    overflow: hidden;
    position: relative;
}
.canvas-stage.checker {
    background-color: #eef1f4;
    background-image:
        linear-gradient(45deg, #cdd3d9 25%, transparent 25%),
        linear-gradient(-45deg, #cdd3d9 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #cdd3d9 75%),
        linear-gradient(-45deg, transparent 75%, #cdd3d9 75%);
    background-size: 24px 24px;
    background-position: 0 0, 0 12px, 12px -12px, -12px 0;
}
.canvas-stage.dark { background: #101318; }
.canvas-stage.light { background: #fff; }
#previewCanvas { display: block; width: 100%; height: 100%; object-fit: contain; }
.empty-state {
    position: absolute;
    inset: 0;
    display: grid;
    place-content: center;
    justify-items: center;
    gap: 8px;
    color: #536172;
    text-align: center;
    padding: 20px;
    background: rgba(255,255,255,.4);
}
.empty-state.hidden { display: none; }

.export-row { margin-top: 8px; }
.export-actions { display: flex; gap: 8px; }

.status-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-top: 12px;
}
.status-grid > div {
    border: 1px solid var(--border);
    background: var(--panel-2);
    padding: 9px 10px;
    border-radius: var(--radius);
    display: grid;
    gap: 4px;
}
.status-grid span { color: var(--muted); font-size: .7rem; }
.status-grid strong { font: 650 .79rem/1.2 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

.toast {
    position: fixed;
    right: 18px;
    bottom: 18px;
    max-width: min(420px, calc(100vw - 36px));
    padding: 10px 12px;
    border-radius: var(--radius);
    background: #e7eff8;
    color: #101923;
    border: 1px solid #fff;
    box-shadow: 0 14px 36px rgba(0,0,0,.28);
    font-size: .84rem;
    opacity: 0;
    transform: translateY(8px);
    pointer-events: none;
    transition: opacity .18s ease, transform .18s ease;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { background: #ffe3e3; color: #3b1111; }

@media (max-width: 820px) {
    .app-shell { width: min(100% - 20px, 720px); padding-top: 16px; }
    .topbar { align-items: center; }
    .workspace { grid-template-columns: 1fr; }
    .controls-panel { order: 2; }
    .preview-panel { order: 1; }
    .canvas-stage { max-height: none; }
}

@media (max-width: 540px) {
    .topbar { align-items: flex-start; gap: 10px; }
    .privacy-badge { padding: 5px 7px; font-size: .72rem; }
    .preview-head { align-items: flex-start; flex-direction: column; }
    .segmented { width: 100%; }
    .segmented button { flex: 1; }
    .export-row { align-items: flex-start; flex-direction: column; }
    .export-actions { width: 100%; }
    .export-actions .button { flex: 1; }
    .status-grid { grid-template-columns: 1fr; }
}
