:root {
    color-scheme: light;
    font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 13px;
    color: #222735;
    background: #f6f7fa;

    --line: #e4e6ed;
    --muted: #7b8191;
    --accent: #6655df;
    --soft: #f0edff;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
}

button,
input,
select {
    font: inherit;
}

button,
a,
input,
select {
    -webkit-tap-highlight-color: transparent;
}

a {
    color: inherit;
    text-decoration: none;
}

a:hover {
    color: var(--accent);
}

button {
    cursor: pointer;
    border: 1px solid var(--line);
    border-radius: 7px;
    padding: 8px 11px;
    background: #fff;
    color: inherit;
    white-space: nowrap;
    transition: background .12s, border-color .12s;
}

button:hover {
    background: #f7f6ff;
    border-color: #c8c1f6;
}

button:disabled {
    opacity: .4;
    cursor: default;
}

button[aria-pressed="true"] {
    background: var(--soft);
    border-color: #c9c0fa;
    color: #5744cd;
}

input,
select {
    min-width: 0;
    border: 1px solid var(--line);
    border-radius: 7px;
    background: #fff;
    color: inherit;
    padding: 8px;
    width: 100%;
}

input[type="checkbox"] {
    width: 15px;
    height: 15px;
    accent-color: var(--accent);
    margin: 0;
}

input[type="color"] {
    height: 35px;
    padding: 4px;
    cursor: pointer;
}

input[type="range"] {
    padding: 0;
    border: 0;
    accent-color: var(--accent);
}

label {
    display: grid;
    gap: 6px;
    font-size: 12px;
    color: #646c7e;
}

h2 {
    font-size: 14px;
    margin: 0 0 12px;
}

h3 {
    font-size: 12px;
    margin: 23px 0 12px;
}

p {
    line-height: 1.5;
    margin: 0 0 14px;
}

.muted,
.hint {
    color: var(--muted);
    font-size: 12px;
}

.hint {
    font-size: 11px;
    margin-top: 10px;
}

.wide {
    width: 100%;
}

[hidden] {
    display: none !important;
}

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 3px;
}

.primary {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
    font-weight: 600;
}

.primary:hover {
    background: #5744cd;
    border-color: #5744cd;
}

.app {
    height: 100vh;
    height: 100dvh;
    display: grid;
    grid-template-rows: 60px 54px minmax(0, 1fr) 30px;
    overflow: hidden;
    min-width: 760px;
}

.topbar {
    display: flex;
    align-items: center;
    gap: 18px;
    padding: 0 20px;
    background: #fff;
    border-bottom: 1px solid var(--line);
}

.brand {
    display: flex;
    align-items: center;
    gap: 9px;
    font-size: 19px;
    letter-spacing: -.6px;
}

.brand span {
    font-size: 11px;
    font-weight: 500;
    letter-spacing: 0;
    color: var(--muted);
    border-left: 1px solid var(--line);
    margin-left: 8px;
    padding-left: 16px;
}

.history-actions {
    display: flex;
    gap: 6px;
    align-items: center;
}

.history-actions button {
    border-color: transparent;
}

.history-actions #undo,
.history-actions #redo {
    font-size: 21px;
    padding: 3px 9px;
}

.save-state {
    margin-right: auto;
    color: var(--muted);
    font-size: 11px;
}

.topbar > a:not(.brand) {
    font-size: 11px;
}

.export-controls {
    display: flex;
    align-items: center;
    gap: 8px;
}

.export-format-control {
    display: flex;
    align-items: center;
    gap: 7px;
    white-space: nowrap;
    color: var(--muted);
    font-size: 11px;
}

.export-format-control select {
    width: 88px;
    padding: 7px 26px 7px 8px;
    color: #303747;
    font-weight: 600;
}

.ribbon {
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 9px 16px;
    background: #fff;
    border-bottom: 1px solid var(--line);
    overflow-x: auto;
}

.ribbon button {
    padding: 6px 9px;
    font-size: 12px;
}

.ribbon select {
    width: 96px;
    padding: 6px;
}

.ribbon input[type="number"] {
    width: 62px;
    padding: 6px;
}

.ribbon input[type="color"] {
    width: 34px;
    height: 31px;
}

.ribbon-group {
    display: flex;
    gap: 6px;
    align-items: center;
}

.separator {
    width: 1px;
    height: 22px;
    background: var(--line);
    flex-shrink: 0;
    margin: 0 5px;
}

.selection-name {
    max-width: 130px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 12px;
    font-weight: 600;
}

.snap-toggle {
    display: flex;
    gap: 6px;
    align-items: center;
    margin-left: auto;
    white-space: nowrap;
}

.workspace {
    display: grid;
    grid-template-columns: 246px minmax(200px, 1fr) 278px;
    min-height: 0;
}

.library {
    background: #fff;
    border-right: 1px solid var(--line);
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.library-tabs {
    display: flex;
    gap: 2px;
    padding: 12px 9px;
    border-bottom: 1px solid var(--line);
}

.library-tabs button {
    flex: 1;
    padding: 8px 4px;
    font-size: 11px;
    border-color: transparent;
}

.library-content {
    padding: 21px 16px;
    overflow: auto;
    flex: 1;
    min-height: 0;
}

.element-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 9px;
}

.element-grid button {
    display: flex;
    flex-direction: column;
    gap: 10px;
    align-items: center;
    justify-content: center;
    height: 84px;
    background: #fafafe;
    border-color: #ececf3;
    font-size: 11px;
}

.element-grid button:hover {
    background: var(--soft);
}

.element-grid span {
    font-size: 25px;
    font-weight: 600;
    color: #7463d9;
    line-height: 1;
}

.library-footer {
    display: flex;
    gap: 18px;
    font-size: 11px;
    padding: 13px 16px;
    border-top: 1px solid var(--line);
    color: var(--muted);
}

.template-list {
    display: grid;
    gap: 8px;
}

.template-card {
    padding: 0;
    overflow: hidden;
    white-space: normal;
    text-align: left;
}

.template-thumb {
    height: 72px;
    background: #f0edff;
    display: grid;
    place-items: center;
    font-size: 24px;
    font-weight: 600;
    color: #715dd3;
}

.template-card:nth-child(3n + 2) .template-thumb {
    background: #192137;
    color: #c4b8ff;
}

.template-card:nth-child(3n) .template-thumb {
    background: #e5f4f2;
    color: #309784;
}

.template-card strong {
    display: block;
    padding: 11px;
    font-size: 12px;
}

.saved-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 30px;
    gap: 5px;
}

.saved-row button:first-child {
    overflow: hidden;
    text-overflow: ellipsis;
    text-align: left;
}

.saved-row button:last-child {
    padding: 5px;
}

.layer-list {
    display: grid;
    gap: 5px;
}

.layer-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 32px;
    gap: 4px;
}

.layer-row button:first-child {
    overflow: hidden;
    text-overflow: ellipsis;
    text-align: left;
    padding: 11px;
}

.layer-row button:last-child {
    padding: 4px;
}

.layer-row.active button:first-child {
    border-color: #b9aef0;
    background: var(--soft);
    color: #5744cd;
}

.stage-panel {
    min-height: 0;
    min-width: 0;
    display: flex;
    flex-direction: column;
    background: #eef0f5;
}

.stage-heading {
    height: 42px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 0 20px;
    font-size: 10px;
    color: var(--muted);
}

#font-status {
    max-width: 52%;
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
}

.viewport {
    flex: 1;
    min-height: 120px;
    overflow: auto;
    overscroll-behavior: contain;
}

.canvas-space {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 48px;
    min-width: 100%;
    min-height: 100%;
    width: max-content;
}

.artboard {
    position: relative;
    flex: none;
    width: 640px;
    height: 360px;
    background-color: #fff;
    background-image:
        linear-gradient(45deg, #e8e9ed 25%, transparent 25%),
        linear-gradient(-45deg, #e8e9ed 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #e8e9ed 75%),
        linear-gradient(-45deg, transparent 75%, #e8e9ed 75%);
    background-size: 16px 16px;
    background-position: 0 0, 0 8px, 8px -8px, -8px 0;
    box-shadow: 0 6px 35px #28345318;
    outline: 1px solid #dadde5;
}

.artboard canvas {
    display: block;
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}

#selection {
    touch-action: none;
    cursor: default;
}

.canvas-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 10px 20px;
    font-size: 10px;
    color: var(--muted);
}

.canvas-footer label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 11px;
}

.canvas-footer select {
    width: 74px;
    padding: 5px;
}

.transport {
    display: flex;
    gap: 14px;
    align-items: center;
    padding: 12px 20px;
    border-top: 1px solid #dfe3eb;
    background: #f8f9fc;
}

.transport button {
    min-width: 77px;
}

.transport input {
    flex: 1;
    min-width: 35px;
}

.transport output {
    font-size: 11px;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
    color: #697385;
}

.canvas-help {
    margin: 0;
    padding: 9px 12px;
    text-align: center;
    font-size: 10px;
    color: #838a9b;
    background: #f8f9fc;
}

.inspector {
    min-height: 0;
    display: flex;
    flex-direction: column;
    background: #fff;
    border-left: 1px solid var(--line);
}

.inspector-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 15px 17px;
    border-bottom: 1px solid var(--line);
}

.inspector-heading h2 {
    margin: 0;
}

.inspector-heading button {
    border: 0;
    font-size: 20px;
    padding: 0 5px;
    color: var(--muted);
}

#properties {
    overflow: auto;
    padding: 0 17px 20px;
    min-height: 0;
}

.property-section {
    padding: 18px 0;
    border-bottom: 1px solid var(--line);
}

.property-section:last-child {
    border: 0;
}

.property-section h3 {
    margin: 0 0 13px;
    font-size: 12px;
    color: #333b4d;
}

.property-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}

.property-grid .full {
    grid-column: 1 / -1;
}

.property-grid .check {
    display: flex;
    align-items: center;
    gap: 8px;
}

.property-grid input:invalid {
    border-color: #d3516a;
}

.property-section .hint {
    margin-bottom: 0;
}

.statusbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    border-top: 1px solid var(--line);
    padding: 0 16px;
    background: #fff;
    font-size: 10px;
    color: var(--muted);
}

.statusbar p {
    margin: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.statusbar > span {
    flex-shrink: 0;
}

.error {
    color: #b42335 !important;
}

.app.busy {
    cursor: progress;
}

.app.busy .workspace,
.app.busy .ribbon,
.app.busy .history-actions {
    pointer-events: none;
    opacity: .7;
}

.app.busy .export-controls {
    cursor: progress;
}

@media (min-width: 1600px) {
    .workspace {
        grid-template-columns: 270px minmax(200px, 1fr) 300px;
    }
}

@media (max-width: 1100px) {
    .workspace {
        grid-template-columns: 200px minmax(200px, 1fr) 240px;
    }

    .topbar {
        gap: 10px;
        padding: 0 12px;
    }

    .library-content {
        padding: 16px 12px;
    }

    .brand span {
        display: none;
    }

    .canvas-help {
        font-size: 9px;
    }

    .stage-heading {
        padding: 0 12px;
    }

    #font-status {
        display: none;
    }
}

@media (max-width: 800px) {
    .workspace {
        grid-template-columns: 160px minmax(200px, 1fr) 220px;
    }

    .app {
        min-width: 620px;
    }

    .topbar {
        gap: 6px;
    }

    .topbar .save-state {
        display: none;
    }

    .topbar .export-controls {
        margin-left: auto;
    }

    .export-format-control span {
        display: none;
    }

    .export-format-control select {
        width: 82px;
    }

    .topbar > a:not(.brand) {
        display: none;
    }

    .library-tabs {
        padding: 8px 3px;
    }

    .library-tabs button {
        font-size: 10px;
    }

    .library-content {
        padding: 14px 9px;
    }

    .element-grid {
        gap: 5px;
    }

    .element-grid button {
        font-size: 10px;
    }

    .ribbon {
        padding-left: 8px;
    }

    .statusbar > span {
        display: none;
    }

    .canvas-footer {
        padding: 8px;
    }

    .canvas-footer > span {
        display: none;
    }

    .transport {
        padding: 10px 8px;
        gap: 7px;
    }

    .transport output {
        font-size: 10px;
    }

    .transport button {
        min-width: 60px;
        padding: 7px;
    }

    .canvas-help {
        display: none;
    }
}

@media (prefers-reduced-motion: reduce) {
    * {
        transition: none !important;
    }
}