:root {
    --ink: #2b2733;
    --muted: #6b6475;
    --line: #e4e0ea;
    --panel: #fbfaf8;
    --page: #f1eee9;
    --accent: #6a5acd;
    --accent-soft: #eeebfb;
    --gold: #e9a23b;
    font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
    color: var(--ink);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--page); }

button {
    font: inherit;
    font-size: 0.9rem;
    padding: 0.4rem 0.75rem;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: white;
    color: var(--ink);
    cursor: pointer;
}
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: 0.45; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: white; font-weight: 600; }
button.accent { background: var(--accent-soft); border-color: var(--accent); }

input, select { font: inherit; font-size: 0.9rem; }
select, input:not([type=checkbox]):not([type=range]):not([type=color]) {
    width: 100%; padding: 0.3rem 0.4rem; border: 1px solid var(--line); border-radius: 5px; background: white;
}

/* ---------- Layout ---------- */
.toolbar {
    display: flex; flex-wrap: wrap; align-items: center; gap: 0.75rem 1.25rem;
    padding: 0.6rem 1rem; background: white; border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; font-size: 1.15rem; color: var(--accent); margin-right: 0.5rem; }
.group { display: flex; gap: 0.35rem; flex-wrap: wrap; }
.toggle { display: flex; align-items: center; gap: 0.35rem; font-size: 0.9rem; color: var(--muted); }

.workspace {
    display: grid;
    grid-template-columns: 250px minmax(0, 1fr) 300px;
    height: calc(100vh - 56px);
}

.panel { background: var(--panel); overflow-y: auto; padding: 0.75rem 1rem 2rem; }
.panel.layers { border-right: 1px solid var(--line); }
.panel.props { border-left: 1px solid var(--line); }
.panel h3 { font-size: 0.8rem; letter-spacing: 0.06em; text-transform: uppercase; color: var(--accent); margin: 1rem 0 0.5rem; }
.panel h3 small { text-transform: none; letter-spacing: 0; color: var(--muted); font-weight: 400; }
.panel h4 { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); margin: 1rem 0 0.3rem; }
.panel label { display: block; font-size: 0.85rem; margin: 0.35rem 0; }
.panel label.check { display: flex; align-items: center; gap: 0.4rem; }
.help { font-size: 0.8rem; color: var(--muted); margin: 0.3rem 0 0.6rem; }
.row { display: flex; gap: 0.35rem; margin-bottom: 0.4rem; flex-wrap: wrap; }
.row.end { justify-content: flex-end; margin-top: 1rem; }

.layer-list { list-style: none; margin: 0.5rem 0 0; padding: 0; }
.layer-list li {
    display: flex; align-items: center; gap: 0.5rem; padding: 0.4rem; border-radius: 6px; cursor: pointer;
}
.layer-list li:hover { background: #f1eff6; }
.layer-list li.selected { background: var(--accent-soft); }
.layer-list .swatch { width: 16px; height: 16px; border-radius: 50%; border: 2px solid; flex: none; }
.layer-list .name { display: flex; flex-direction: column; font-size: 0.85rem; min-width: 0; }
.layer-list .name small { color: var(--muted); font-size: 0.72rem; }

.preview { display: flex; flex-direction: column; background: #2b2b33; min-height: 0; }
.canvas { flex: 1; display: flex; align-items: center; justify-content: center; padding: 1rem; min-height: 0; }
.canvas svg { width: auto; height: auto; max-width: 100%; max-height: 100%; aspect-ratio: 1 / 1; background: white; border-radius: 4px; box-shadow: 0 4px 24px rgba(0,0,0,0.35); }
.status { color: #d9d6e2; font-size: 0.82rem; padding: 0.45rem 1rem; background: #23232a; }

.num { display: grid; grid-template-columns: 92px 1fr 62px; align-items: center; gap: 0.4rem; margin: 0.3rem 0; font-size: 0.85rem; }
.num input[type=range] { width: 100%; accent-color: var(--accent); }

/* ---------- Shape preferences ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(20, 18, 28, 0.45); display: flex; align-items: center; justify-content: center; z-index: 50; }
.modal { background: white; border-radius: 10px; padding: 1.25rem 1.5rem; width: min(900px, 94vw); max-height: 88vh; overflow-y: auto; }
.modal h3 { margin-top: 0; color: var(--accent); }
.pref-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 0.4rem; }
.pref { display: flex; justify-content: space-between; align-items: center; border: 1px solid var(--line); border-radius: 6px; padding: 0.3rem 0.5rem; font-size: 0.85rem; }
.pref.never { opacity: 0.55; background: #f5f5f5; }
.pref.favorite { border-color: var(--gold); background: #fff8e8; }
.seg { display: flex; gap: 2px; }
.seg button { padding: 0.1rem 0.4rem; font-size: 0.8rem; }
.seg button.on { background: var(--accent-soft); border-color: var(--accent); }

@media (max-width: 1000px) {
    .workspace { grid-template-columns: 1fr; height: auto; }
    .preview { height: 70vh; }
}

/* ---------- Blazor loading and errors ---------- */
#blazor-error-ui { background: lightyellow; bottom: 0; box-shadow: 0 -1px 2px rgba(0,0,0,0.2); display: none; left: 0; padding: 0.6rem 1.25rem; position: fixed; width: 100%; z-index: 1000; }
#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: 0.75rem; top: 0.5rem; }
.loading-progress { position: relative; display: block; width: 8rem; height: 8rem; margin: 20vh auto 1rem auto; }
.loading-progress circle { fill: none; stroke: #e0e0e0; stroke-width: 0.6rem; transform-origin: 50% 50%; transform: rotate(-90deg); }
.loading-progress circle:last-child { stroke: var(--accent); stroke-dasharray: calc(3.141 * var(--blazor-load-percentage, 0%) * 0.8), 500%; transition: stroke-dasharray 0.05s ease-in-out; }
.loading-progress-text { position: absolute; text-align: center; font-weight: bold; inset: calc(20vh + 3.25rem) 0 auto 0.2rem; }
.loading-progress-text:after { content: var(--blazor-load-percentage-text, "Loading"); }

/* ---------- Saving ---------- */
a.button { display: inline-block; text-decoration: none; font-size: 0.9rem; padding: 0.4rem 0.75rem; border: 1px solid var(--line); border-radius: 6px; background: white; color: var(--ink); }
a.button.primary { background: var(--accent); border-color: var(--accent); color: white; font-weight: 600; }
button.save.unsaved { border-color: var(--gold); background: #fff8e8; }
.count { color: var(--muted); font-size: 0.9rem; }

/* ---------- Gallery ---------- */
.gallery-page { padding: 1rem 1.25rem 3rem; }
.export-bar { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 0.75rem 1.25rem; background: white; border: 1px solid var(--line); border-radius: 10px; padding: 0.8rem 1rem; }
.export-bar label { display: flex; flex-direction: column; font-size: 0.82rem; color: var(--muted); gap: 0.2rem; }
.export-bar label.radio { flex-direction: row; align-items: center; gap: 0.35rem; color: var(--ink); }
.export-bar input:not([type=radio]):not([type=checkbox]), .export-bar select { min-width: 160px; }
.message { margin: 0.8rem 0; color: var(--muted); }
.empty { text-align: center; padding: 4rem 1rem; color: var(--muted); }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 1rem; margin-top: 1rem; }
.card { background: white; border: 2px solid var(--line); border-radius: 10px; padding: 0.6rem; display: flex; flex-direction: column; gap: 0.3rem; }
.card.chosen { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.thumb { position: relative; aspect-ratio: 1 / 1; cursor: pointer; background: white; border-radius: 6px; overflow: hidden; }
.thumb img { width: 100%; height: 100%; object-fit: contain; }
.thumb input { position: absolute; top: 6px; left: 6px; width: 20px; height: 20px; accent-color: var(--accent); }
.card .title { font-weight: 600; font-size: 0.92rem; cursor: text; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card .meta { font-size: 0.75rem; color: var(--muted); }
.card .actions { display: flex; gap: 0.35rem; }
.card .actions button { flex: 1; padding: 0.3rem; }
.rename { display: flex; gap: 0.3rem; }

/* ---------- KDP export and page order ---------- */
.kdp { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr); gap: 1rem; margin-top: 0.75rem; background: white; border: 1px solid var(--line); border-radius: 10px; padding: 0.8rem 1rem; }
.kdp-fields { display: flex; flex-direction: column; gap: 0.4rem; }
.kdp-fields label { display: flex; flex-direction: column; font-size: 0.82rem; color: var(--muted); gap: 0.2rem; }
.kdp-fields label.radio { flex-direction: row; align-items: center; gap: 0.35rem; color: var(--ink); }
.preflight { list-style: none; margin: 0; padding: 0; font-size: 0.85rem; }
.preflight li { padding: 0.25rem 0; }
.preflight li.ok { color: #2e7d4f; }
.preflight li.warn { color: #a56a00; }
.book-order { margin-top: 0.75rem; background: white; border: 1px solid var(--line); border-radius: 10px; padding: 0.6rem 1rem; }
.book-order h3 { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--accent); margin: 0.2rem 0 0.5rem; }
.book-order h3 small { text-transform: none; letter-spacing: 0; color: var(--muted); font-weight: 400; }
.book-order ol { list-style: none; display: flex; gap: 0.6rem; overflow-x: auto; margin: 0; padding: 0 0 0.4rem; }
.book-order li { flex: none; width: 110px; display: flex; flex-direction: column; align-items: center; gap: 0.2rem; font-size: 0.75rem; }
.book-order li img { width: 90px; height: 90px; object-fit: contain; border: 1px solid var(--line); border-radius: 4px; }
.book-order li span { max-width: 110px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.book-order li button { padding: 0.1rem 0.5rem; font-size: 0.75rem; }
.book-order li { flex-wrap: wrap; flex-direction: row; justify-content: center; }
.badge { position: absolute; top: 6px; left: 6px; min-width: 24px; height: 24px; border-radius: 12px; background: var(--accent); color: white; font-size: 0.8rem; font-weight: 700; display: flex; align-items: center; justify-content: center; padding: 0 6px; }
.badge.empty { background: white; border: 2px solid var(--line); }
@media (max-width: 900px) { .kdp { grid-template-columns: 1fr; } }

/* ---------- Cover ---------- */
.cover { margin-top: 0.75rem; background: white; border: 1px solid var(--line); border-radius: 10px; padding: 0.6rem 1rem 0.9rem; }
.cover-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; }
.cover h3 { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--accent); margin: 0.2rem 0; }
.cover h3 small { text-transform: none; letter-spacing: 0; color: var(--muted); font-weight: 400; }
.cover-grid { display: grid; grid-template-columns: 280px minmax(0, 1fr); gap: 1rem; margin-top: 0.5rem; }
.cover-fields { display: flex; flex-direction: column; gap: 0.45rem; }
.cover-fields label { display: flex; flex-direction: column; font-size: 0.82rem; color: var(--muted); gap: 0.2rem; }
.cover-fields label.radio { flex-direction: row; align-items: center; gap: 0.35rem; color: var(--ink); }
.cover-fields textarea { font: inherit; font-size: 0.85rem; padding: 0.35rem; border: 1px solid var(--line); border-radius: 5px; resize: vertical; }
.color-row { display: flex; gap: 1rem; }
.color-row label { flex-direction: row; align-items: center; gap: 0.4rem; color: var(--ink); }
.swatches { display: flex; flex-wrap: wrap; gap: 0.3rem; }
.swatch-btn { width: 34px; height: 28px; padding: 0; font-family: Georgia, serif; font-weight: 700; border: 1px solid var(--line); }
.cover-preview { min-width: 0; }
.cover-preview canvas { width: 100%; height: auto; display: block; border-radius: 4px; box-shadow: 0 2px 12px rgba(0,0,0,0.18); }
.legend { font-size: 0.75rem; color: var(--muted); margin: 0.4rem 0 0; }
.legend .trim { color: #d32f2f; } .legend .spine { color: #1565c0; } .legend .safe { color: #2e7d32; } .legend .bar { color: #6a1b9a; }
@media (max-width: 900px) { .cover-grid { grid-template-columns: 1fr; } }
