:root {
    --prime-blue: #0578FF;
    --bg: #0a0c0e;
    --bg-panel: #111417;
    --bg-card: #16191c;
    --bg-input: #1d2125;
    --border: rgba(255, 255, 255, 0.08);
    --border-strong: rgba(255, 255, 255, 0.16);
    --text: #f0f2f5;
    --text-dim: #8a8f98;
    --warn: #ffb648;
    --radius: 12px;
    --panel-width: 340px;
}

* {
    box-sizing: border-box;
}

html {
    color-scheme: dark;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
    -webkit-font-smoothing: antialiased;
}

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

.app {
    display: grid;
    grid-template-columns: var(--panel-width) minmax(0, 1fr);
    min-height: 100vh;
}

/* ---------- Settings panel ---------- */

.panel {
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    padding: 24px 20px 32px;
    background: var(--bg-panel);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.brand h1 {
    margin: 0 0 4px;
    font-size: 20px;
    letter-spacing: -0.01em;
}

.brand p {
    margin: 0;
    color: var(--text-dim);
    font-size: 13px;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 7px;
    min-width: 0;
}

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

.field-label {
    display: flex;
    justify-content: space-between;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-dim);
}

.field-label output {
    color: var(--text);
    font-variant-numeric: tabular-nums;
    letter-spacing: 0;
}

textarea {
    width: 100%;
    resize: vertical;
    min-height: 96px;
    padding: 12px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 10px;
    font-size: 15px;
    line-height: 1.4;
}

textarea:focus,
select:focus-visible,
button:focus-visible,
input:focus-visible {
    outline: 2px solid var(--prime-blue);
    outline-offset: 1px;
}

input[type="range"] {
    width: 100%;
    margin: 0;
    accent-color: var(--prime-blue);
}

.seg {
    display: flex;
    padding: 3px;
    gap: 3px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 10px;
}

.seg button {
    flex: 1;
    padding: 7px 6px;
    background: none;
    border: 0;
    border-radius: 7px;
    color: var(--text-dim);
    cursor: pointer;
    white-space: nowrap;
}

.seg button small {
    display: block;
    font-size: 10.5px;
    opacity: 0.75;
}

.seg button:hover {
    color: var(--text);
}

.seg button[aria-pressed="true"] {
    background: var(--prime-blue);
    color: #fff;
}

.swatches {
    display: flex;
    align-items: center;
    gap: 8px;
}

.swatches button {
    width: 30px;
    height: 30px;
    padding: 0;
    border-radius: 50%;
    border: 1px solid var(--border-strong);
    background: var(--c);
    cursor: pointer;
}

.swatches button[aria-pressed="true"] {
    box-shadow: 0 0 0 2px var(--bg-panel), 0 0 0 4px var(--prime-blue);
}

.swatch-custom {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
    padding: 4px 10px 4px 4px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 999px;
    cursor: pointer;
    font-size: 12px;
    font-variant-numeric: tabular-nums;
}

.swatch-custom input {
    width: 24px;
    height: 24px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: none;
    cursor: pointer;
}

.swatch-custom input::-webkit-color-swatch-wrapper {
    padding: 0;
}

.swatch-custom input::-webkit-color-swatch {
    border: 1px solid var(--border-strong);
    border-radius: 50%;
}

.help {
    margin-top: auto;
    padding-top: 14px;
    border-top: 1px solid var(--border);
    color: var(--text-dim);
    font-size: 12.5px;
}

.help summary {
    cursor: pointer;
    color: var(--text);
}

.help p {
    margin: 8px 0 0;
}

/* ---------- Font grid ---------- */

.main {
    padding: 20px 28px 60px;
    min-width: 0;
}

.chips {
    position: sticky;
    top: 0;
    z-index: 5;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 6px 0 12px;
    background: linear-gradient(var(--bg) 82%, transparent);
}

.chips button {
    padding: 7px 14px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 999px;
    color: var(--text-dim);
    cursor: pointer;
}

.chips button:hover {
    color: var(--text);
    border-color: var(--border-strong);
}

.chips button[aria-pressed="true"] {
    background: var(--text);
    border-color: var(--text);
    color: #000;
    font-weight: 600;
}

.view-note {
    margin: 2px 0 18px;
    color: var(--text-dim);
    font-size: 13px;
}

.view-note strong {
    color: var(--text);
}

.group-title {
    margin: 26px 0 12px;
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--text-dim);
}

.group-title:first-child {
    margin-top: 0;
}

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 18px;
}

.card {
    display: flex;
    flex-direction: column;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.stage {
    --check-a: #1f2327;
    --check-b: #2a2f34;
    background-color: var(--check-a);
    background-image:
        linear-gradient(45deg, var(--check-b) 25%, transparent 25%, transparent 75%, var(--check-b) 75%),
        linear-gradient(45deg, var(--check-b) 25%, transparent 25%, transparent 75%, var(--check-b) 75%);
    background-size: 20px 20px;
    background-position: 0 0, 10px 10px;
}

#sections.light .stage {
    --check-a: #e9ecef;
    --check-b: #cfd4d9;
}

.stage canvas {
    display: block;
    width: 100%;
    aspect-ratio: var(--ratio, 4 / 5);
}

.meta {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 12px 14px 14px;
    flex: 1;
}

.title-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 4px 8px;
}

.name {
    font-size: 15px;
}

.tag {
    flex: none;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 10.5px;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-dim);
}

.tag[data-tag="Primary"] {
    background: rgba(5, 120, 255, 0.18);
    color: #6db1ff;
}

.style-select {
    width: 100%;
    padding: 7px 8px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 8px;
}

.style-name {
    margin: 0;
    color: var(--text-dim);
    font-size: 13px;
}

.warn {
    margin: 0;
    color: var(--warn);
    font-size: 12px;
}

.actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: auto;
    padding-top: 4px;
}

.btn {
    padding: 7px 14px;
    background: var(--prime-blue);
    border: 1px solid transparent;
    border-radius: 8px;
    color: #fff;
    font-weight: 600;
    white-space: nowrap;
    cursor: pointer;
}

.btn:hover {
    filter: brightness(1.12);
}

.btn:disabled {
    opacity: 0.45;
    cursor: default;
    filter: none;
}

.btn-ghost {
    margin-left: auto;
    background: none;
    border-color: var(--border-strong);
    color: var(--text-dim);
    font-weight: 500;
}

.btn-ghost:hover {
    color: var(--text);
    filter: none;
}

.load-error {
    padding: 40px 0;
    color: var(--warn);
}

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

    .panel {
        position: static;
        height: auto;
        border-right: 0;
        border-bottom: 1px solid var(--border);
    }

    .main {
        padding: 14px 16px 48px;
    }

    .grid {
        grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
        gap: 12px;
    }

    .chips {
        flex-wrap: nowrap;
        overflow-x: auto;
        margin: 0 -16px;
        padding: 6px 16px 12px;
        scrollbar-width: none;
    }

    .chips button {
        flex: none;
    }

    .btn-ghost {
        flex-basis: 100%;
        margin-left: 0;
    }
}
