/* SVGeometric. Dark theme with an older desktop app look: beveled gradient
   buttons, gradient section bars and inset fields. */

:root {
    --bg: #0f1113;
    --stage: #16191c;
    --panel: #1a1d21;
    --panel-2: #20242a;
    --panel-3: #272c32;
    --line: #262b31;
    --line-2: #323941;
    --dark-line: #08090b;
    --text: #e8eaed;
    --text-2: #b9c0c8;
    --muted: #7f8893;
    --faint: #59616b;
    --accent: #ff6b3d;
    --accent-2: #ff8a63;
    --accent-ink: #1a0d08;
    --focus: #5aa2ff;
    --focus-glow: 0 0 0 1px #5aa2ff, 0 0 6px rgba(90, 162, 255, 0.55);
    --ok: #4cc38a;
    --danger: #ff5d5d;
    --emboss: 0 -1px 0 rgba(0, 0, 0, 0.6);

    /* Ordinary buttons */
    --btn-1: #3d444c;
    --btn-2: #2b3036;
    --btn-border: #0e1012;
    --btn-border-bottom: #050607;
    --btn-hover-1: #474f58;
    --btn-hover-2: #32383f;
    --btn-pressed: #1b1e22;
    --btn-highlight: inset 0 1px 0 rgba(255, 255, 255, 0.09);
    --pressed-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.5);

    /* Export button and other orange fills. Dark text, white on this orange is too faint */
    --go-1: #ff8a5c;
    --go-2: #ec5a2a;
    --go-border: #8f3312;
    --go-hover-1: #ff9b72;
    --go-hover-2: #f4683a;

    /* Buy me a coffee button */
    --coffee-1: #ffe066;
    --coffee-2: #f0bf1a;
    --coffee-border: #7a5c00;
    --coffee-hover-1: #ffe985;
    --coffee-hover-2: #f6ca33;
    --coffee-ink: #2b2100;

    /* Section bars and dialog headers */
    --bar-1: #2a2f35;
    --bar-2: #212529;
    --bar-border: #0c0e10;
    --bar-highlight: rgba(255, 255, 255, 0.06);

    --header-1: #2d3339;
    --header-2: #16191c;

    --input-bg: #111316;
    --input-border: #07080a;
    --input-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.55);

    /* Silver knobs on sliders and switches */
    --knob: linear-gradient(#f6f7f8, #c3c8ce);
    --knob-hover: linear-gradient(#ffffff, #d3d7dc);
    --knob-shadow: inset 0 1px 0 #fff, 0 1px 2px rgba(0, 0, 0, 0.6);

    --select-arrow: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='8' height='10' viewBox='0 0 8 10'%3E%3Cpath d='M4 0 8 4H0zM4 10 0 6h8z' fill='%23b9c0c8'/%3E%3C/svg%3E");

    --radius: 3px;
    --radius-lg: 5px;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-float: 0 1px 4px rgba(0, 0, 0, 0.6);
    --shadow-pop: 0 5px 14px rgba(0, 0, 0, 0.55);
    --topbar-h: 48px;
    --left-w: 310px;
    --right-w: 300px;
    --font: "Helvetica Neue", Helvetica, Arial, sans-serif;
    --mono: Menlo, Consolas, "Courier New", monospace;
    color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
    margin: 0;
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font: 13px/1.4 var(--font);
    overflow: hidden;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
::selection { background: #b3d4fc; color: #000; }
kbd {
    display: inline-block;
    min-width: 20px;
    font: bold 11px/16px var(--font);
    text-align: center;
    padding: 0 5px;
    border: 1px solid var(--btn-border);
    border-bottom-color: var(--btn-border-bottom);
    border-radius: var(--radius);
    background: linear-gradient(var(--btn-1), var(--btn-2));
    box-shadow: var(--btn-highlight), 0 1px 0 rgba(0, 0, 0, 0.5);
    color: var(--text);
    text-shadow: var(--emboss);
}

.ic { width: 18px; height: 18px; flex: none; fill: currentColor; }
/* Read by screen readers, not shown */
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* ------------------------------------------------------------------ top bar */

.topbar {
    height: var(--topbar-h);
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 12px;
    background: linear-gradient(var(--header-1), var(--header-2));
    border-bottom: 1px solid #000;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08), 0 1px 3px rgba(0, 0, 0, 0.4);
    position: relative;
    z-index: 5;
}

.brand {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: bold;
    letter-spacing: -0.01em;
    font-size: 16px;
    margin: 0 6px 0 0;
    white-space: nowrap;
    color: #fff;
    text-shadow: 0 -1px 0 #000;
}
.brand .logo { width: 28px; height: 28px; color: var(--accent); filter: drop-shadow(0 -1px 0 rgba(0, 0, 0, 0.7)); }
.brand-light { font-weight: normal; color: var(--text-2); }

.spacer { flex: 1; }

.btn, .icon-btn, .design-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 30px;
    border-radius: var(--radius);
    border: 1px solid var(--btn-border);
    border-bottom-color: var(--btn-border-bottom);
    background: linear-gradient(var(--btn-1), var(--btn-2));
    box-shadow: var(--btn-highlight), var(--shadow-sm);
    color: var(--text);
    padding: 0 12px;
    font-size: 12px;
    font-weight: bold;
    text-shadow: var(--emboss);
    white-space: nowrap;
}
.btn .ic, .icon-btn .ic, .design-btn .ic { filter: drop-shadow(0 -1px 0 rgba(0, 0, 0, 0.6)); }
.btn:hover, .icon-btn:hover, .design-btn:hover { background: linear-gradient(var(--btn-hover-1), var(--btn-hover-2)); color: #fff; }
.btn:active, .icon-btn:active, .design-btn:active { background: var(--btn-pressed); box-shadow: var(--pressed-shadow); }
.icon-btn { width: 30px; padding: 0; justify-content: center; color: var(--text-2); }
#resetParams span { display: none; }
.icon-btn:disabled { opacity: 0.35; box-shadow: none; pointer-events: none; }
.icon-btn.coffee {
    border-color: var(--coffee-border);
    background: linear-gradient(var(--coffee-1), var(--coffee-2));
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.4), var(--shadow-sm);
    color: var(--coffee-ink);
}
.icon-btn.coffee .ic { filter: none; }
.icon-btn.coffee:hover { background: linear-gradient(var(--coffee-hover-1), var(--coffee-hover-2)); color: var(--coffee-ink); }
.icon-btn.coffee:active { background: var(--coffee-2); box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.3); }
.btn.accent {
    border-color: var(--go-border);
    background: linear-gradient(var(--go-1), var(--go-2));
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35), var(--shadow-sm);
    color: var(--accent-ink);
    text-shadow: 0 1px 0 rgba(255, 255, 255, 0.25);
}
.btn.accent .ic { filter: none; }
.btn.accent:hover { background: linear-gradient(var(--go-hover-1), var(--go-hover-2)); color: var(--accent-ink); }
.btn.accent:active { background: var(--go-2); box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.3); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }

.design-btn { min-width: 210px; padding: 0 10px; height: 36px; font-weight: normal; }
.design-btn .ic { color: var(--muted); }
.design-btn .chev { margin-left: auto; }
.design-btn-text { display: flex; flex-direction: column; align-items: flex-start; line-height: 1.15; }
.design-cat { font-size: 9.5px; font-weight: bold; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.design-name { font-weight: bold; font-size: 13px; }

/* Field with the label in a box on the left and the button joined on the right */
.seed-box {
    display: flex;
    align-items: stretch;
    height: 30px;
    border: 1px solid var(--input-border);
    border-radius: var(--radius);
    background: var(--input-bg);
    box-shadow: var(--input-shadow), 0 1px 0 rgba(255, 255, 255, 0.06);
    overflow: hidden;
}
.seed-box label {
    display: flex;
    align-items: center;
    padding: 0 8px 0 9px;
    border-right: 1px solid var(--input-border);
    background: linear-gradient(var(--bar-1), var(--bar-2));
    box-shadow: var(--btn-highlight);
    color: var(--text-2);
    font-size: 12px;
    font-weight: bold;
    text-shadow: var(--emboss);
}
.seed-box input {
    width: 92px;
    height: 100%;
    padding: 0 0 0 8px;
    border: 0;
    background: transparent;
    font-size: 12.5px;
    font-variant-numeric: tabular-nums;
    -moz-appearance: textfield;
}
.seed-box input::-webkit-outer-spin-button, .seed-box input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.seed-box input:focus { outline: none; }
.seed-box:focus-within { border-color: var(--focus); box-shadow: var(--input-shadow), var(--focus-glow); }
.seed-box .icon-btn { border: 0; border-left: 1px solid var(--input-border); border-radius: 0; height: 100%; box-shadow: var(--btn-highlight); }

.export, .reset { position: relative; display: flex; }
.reset #resetParams { border-radius: var(--radius) 0 0 var(--radius); }
.reset .caret { width: 22px; border-radius: 0 var(--radius) var(--radius) 0; border-left: 0; }
.reset .caret .ic { width: 14px; height: 14px; }
.reset .menu { left: 0; right: auto; }
.export .btn.accent:first-child { border-radius: var(--radius) 0 0 var(--radius); }
.export .caret { border-radius: 0 var(--radius) var(--radius) 0; padding: 0 7px; border-left: 0; }

.menu {
    position: absolute;
    top: calc(100% + 4px);
    right: 0;
    min-width: 260px;
    background: var(--panel-2);
    background-clip: padding-box;
    border: 1px solid rgba(0, 0, 0, 0.7);
    border-radius: var(--radius-lg);
    padding: 4px 0;
    box-shadow: var(--shadow-pop);
    z-index: 20;
}
.menu button {
    display: block;
    width: 100%;
    text-align: left;
    border: 0;
    background: transparent;
    padding: 5px 14px;
    border-radius: 0;
    color: var(--text);
}
.menu button:hover, .menu button:focus-visible {
    outline: none;
    background: linear-gradient(var(--go-1), var(--go-2));
    color: var(--accent-ink);
}
.menu button small { display: block; color: var(--muted); font-size: 11px; }
.menu button:hover small, .menu button:focus-visible small { color: rgba(26, 13, 8, 0.75); }
.menu hr { border: 0; border-top: 1px solid var(--bar-border); border-bottom: 1px solid var(--bar-highlight); margin: 4px 0; }
#exportMenu { max-height: calc(100dvh - 76px); overflow-y: auto; }

/* ------------------------------------------------------------------ layout */

.tabs { display: none; }

.layout {
    display: grid;
    grid-template-columns: var(--left-w) minmax(0, 1fr) var(--right-w);
    height: calc(100vh - var(--topbar-h));
    height: calc(100dvh - var(--topbar-h));
}

.panel {
    background: var(--panel);
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: thin;
    scrollbar-color: #3a414a transparent;
}
.panel.left { border-right: 1px solid var(--dark-line); }
.panel.right { border-left: 1px solid var(--dark-line); }

.design-info { padding: 12px 12px 10px; }
.design-info h2 { margin: 0 0 3px; font-size: 17px; font-weight: bold; letter-spacing: -0.01em; text-shadow: var(--emboss); }
.design-info p { margin: 0; color: var(--muted); font-size: 12px; }
.phone-tools { display: none; }
/* Wraps rather than running past the panel on a narrow phone or with a wider font. */
.panel-foot { display: flex; flex-wrap: wrap; gap: 4px 14px; padding: 12px 12px 16px; font-size: 11.5px; }
.panel-foot a { color: var(--muted); text-decoration: none; }
.panel-foot a:hover { color: var(--text); text-decoration: underline; }

/* ------------------------------------------------------------------ controls */

.controls { padding: 12px 12px 6px; }

.section-label {
    margin: 14px 0 8px;
    font-size: 11px;
    font-weight: bold;
    color: var(--muted);
    text-shadow: var(--emboss);
    display: flex;
    align-items: center;
    gap: 8px;
}
.section-label::after { content: ""; flex: 1; height: 1px; background: var(--bar-border); box-shadow: 0 1px 0 var(--bar-highlight); }

.ctl { margin: 0 0 10px; }
.ctl[hidden] { display: none; }
.ctl-head {
    display: flex;
    align-items: center;
    gap: 5px;
    margin-bottom: 4px;
    min-height: 18px;
}
.ctl-head label {
    color: var(--text);
    font-size: 12px;
    user-select: none;
    cursor: default;
}
.ctl-head .hint {
    flex: none;
    width: 14px; height: 14px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: var(--faint);
    color: var(--panel);
    font-size: 10px;
    font-weight: bold;
    line-height: 1;
    display: inline-grid;
    place-items: center;
    cursor: help;
}
.ctl-head .hint:hover, .ctl-head .hint[aria-expanded="true"] { background: var(--focus); }
.ctl-hint { margin: 5px 0 0; color: var(--muted); font-size: 11px; line-height: 1.45; }
.lock-btn {
    margin-left: auto;
    width: 20px; height: 20px;
    border: 0;
    background: transparent;
    color: var(--muted);
    display: grid;
    place-items: center;
    border-radius: var(--radius);
    opacity: 0;
    transition: opacity 0.12s;
    padding: 0;
}
.lock-btn .ic { width: 13px; height: 13px; }
.ctl:hover .lock-btn, .lock-btn.locked, .lock-btn:focus-visible { opacity: 1; }
.lock-btn:hover { color: var(--text); }
.lock-btn.locked { color: var(--accent); }

.ctl-row { display: flex; align-items: center; gap: 10px; }

input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    flex: 1;
    min-width: 0;
    height: 20px;
    background: transparent;
    margin: 0;
    cursor: pointer;
    --from: 0%;
    --to: 50%;
    --track: linear-gradient(to right, var(--input-bg) var(--from), var(--accent) var(--from), var(--accent) var(--to), var(--input-bg) var(--to));
}
input[type="range"]::-webkit-slider-runnable-track {
    box-sizing: border-box;
    height: 6px;
    border: 1px solid var(--input-border);
    border-radius: 3px;
    background: var(--track);
    box-shadow: var(--input-shadow), 0 1px 0 rgba(255, 255, 255, 0.06);
}
input[type="range"]::-moz-range-track {
    height: 6px;
    box-sizing: border-box;
    border: 1px solid var(--input-border);
    border-radius: 3px;
    background: var(--track);
    box-shadow: var(--input-shadow), 0 1px 0 rgba(255, 255, 255, 0.06);
}
input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    box-sizing: border-box;
    width: 14px; height: 14px;
    margin-top: -5px;
    border-radius: 50%;
    border: 1px solid var(--dark-line);
    background: var(--knob);
    box-shadow: var(--knob-shadow);
}
input[type="range"]:hover::-webkit-slider-thumb { background: var(--knob-hover); }
input[type="range"]::-moz-range-thumb {
    box-sizing: border-box;
    width: 14px; height: 14px;
    border-radius: 50%;
    border: 1px solid var(--dark-line);
    background: var(--knob);
    box-shadow: var(--knob-shadow);
}
input[type="range"]:hover::-moz-range-thumb { background: var(--knob-hover); }
input[type="range"]:focus-visible { outline: none; }
input[type="range"]:focus-visible::-webkit-slider-thumb { box-shadow: var(--knob-shadow), var(--focus-glow); }
input[type="range"]:focus-visible::-moz-range-thumb { box-shadow: var(--knob-shadow), var(--focus-glow); }

.num {
    width: 66px;
    height: 26px;
    padding: 0 6px;
    border-radius: var(--radius);
    border: 1px solid var(--input-border);
    background: var(--input-bg);
    box-shadow: var(--input-shadow), 0 1px 0 rgba(255, 255, 255, 0.06);
    font-size: 12px;
    font-variant-numeric: tabular-nums;
    text-align: right;
    -moz-appearance: textfield;
}
.num::-webkit-outer-spin-button, .num::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

select {
    width: 100%;
    height: 28px;
    padding: 0 24px 0 8px;
    border-radius: var(--radius);
    border: 1px solid var(--btn-border);
    border-bottom-color: var(--btn-border-bottom);
    appearance: none;
    -webkit-appearance: none;
    background: var(--select-arrow) no-repeat right 8px center, linear-gradient(var(--btn-1), var(--btn-2));
    box-shadow: var(--btn-highlight), var(--shadow-sm);
    font-size: 12px;
    text-shadow: var(--emboss);
    text-overflow: ellipsis;
    cursor: pointer;
}
select:hover { background: var(--select-arrow) no-repeat right 8px center, linear-gradient(var(--btn-hover-1), var(--btn-hover-2)); }
select option { background: var(--panel-2); text-shadow: none; }
.text-input, textarea {
    width: 100%;
    height: 28px;
    padding: 0 8px;
    border-radius: var(--radius);
    border: 1px solid var(--input-border);
    background: var(--input-bg);
    box-shadow: var(--input-shadow), 0 1px 0 rgba(255, 255, 255, 0.06);
}
textarea { height: auto; min-height: 60px; padding: 6px 8px; resize: vertical; font-family: var(--mono); font-size: 11.5px; }
.text-input { font-family: var(--mono); font-size: 12px; }
select:focus-visible { outline: none; border-color: var(--focus); box-shadow: var(--btn-highlight), var(--focus-glow); }
.text-input:focus, textarea:focus, .num:focus { outline: none; border-color: var(--focus); box-shadow: var(--input-shadow), var(--focus-glow); }

/* toggle switch: recessed track, silver knob */
.ctl-check .ctl-row { justify-content: space-between; }
.switch { position: relative; width: 34px; height: 18px; flex: none; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; z-index: 1; }
.switch span {
    position: absolute; inset: 0;
    border-radius: 9px;
    border: 1px solid var(--input-border);
    background: var(--input-bg);
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.6), 0 1px 0 rgba(255, 255, 255, 0.06);
    transition: background 0.15s;
}
.switch span::after {
    content: "";
    position: absolute;
    top: 0; left: 0;
    width: 16px; height: 16px;
    border-radius: 50%;
    background: var(--knob);
    box-shadow: var(--knob-shadow);
    transition: transform 0.15s;
}
.switch input:checked + span { background: linear-gradient(var(--go-2), var(--go-1)); border-color: var(--go-border); }
.switch input:checked + span::after { transform: translateX(16px); }
.switch input:focus-visible + span { outline: none; box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.6), var(--focus-glow); }

.color-input {
    width: 34px; height: 26px;
    padding: 0;
    border: 1px solid var(--btn-border);
    border-bottom-color: var(--btn-border-bottom);
    border-radius: var(--radius);
    background: linear-gradient(var(--btn-1), var(--btn-2));
    box-shadow: var(--btn-highlight), var(--shadow-sm);
    cursor: pointer;
}
.color-input:hover { background: linear-gradient(var(--btn-hover-1), var(--btn-hover-2)); }
.color-input::-webkit-color-swatch-wrapper { padding: 4px; }
.color-input::-webkit-color-swatch { border: 1px solid rgba(0, 0, 0, 0.6); border-radius: 2px; }
.color-input::-moz-color-swatch { border: 1px solid rgba(0, 0, 0, 0.6); border-radius: 2px; }

.image-ctl .ctl-row { gap: 6px; }
.image-ctl .file-name { flex: 1; min-width: 0; color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.image-ctl .btn { height: 26px; padding: 0 10px; font-size: 12px; }
.image-ctl .icon-btn { width: 26px; height: 26px; }

/* collapsible sections: gradient bar with a triangle that turns down when open */
.out-section > summary {
    list-style: none;
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 32px;
    padding: 6px 12px 6px 11px;
    border-top: 1px solid var(--bar-highlight);
    border-bottom: 1px solid var(--bar-border);
    background: linear-gradient(var(--bar-1), var(--bar-2));
    font-weight: bold;
    font-size: 13px;
    text-shadow: var(--emboss);
    cursor: pointer;
    user-select: none;
}
.out-section > summary::-webkit-details-marker { display: none; }
.out-section > summary::before {
    content: "";
    flex: none;
    width: 0;
    height: 0;
    border-style: solid;
    border-width: 4px 0 4px 6px;
    border-color: transparent transparent transparent var(--muted);
    transition: transform 0.12s ease-out;
}
.out-section[open] > summary::before { transform: rotate(90deg); }
.out-section > summary:hover { background: linear-gradient(var(--bar-2), var(--bar-2)); }
.out-section > summary:focus-visible { outline: none; box-shadow: inset 0 0 0 2px var(--focus); }
.out-section > summary > span:first-child { flex: none; }
.out-section > summary > .ic { display: none; }
.out-section > summary .badge {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    color: var(--muted);
    font-weight: normal;
    font-size: 11px;
    text-align: right;
    white-space: nowrap;
    text-overflow: ellipsis;
}
.out-section .controls { border-bottom: 1px solid var(--bar-border); }
.out-note { color: var(--muted); font-size: 11px; line-height: 1.45; margin: 2px 0 10px; }
.out-note code { font-family: var(--mono); color: var(--text-2); }

.seg { display: flex; border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.seg button {
    flex: 1;
    height: 26px;
    border: 1px solid var(--btn-border);
    border-bottom-color: var(--btn-border-bottom);
    background: linear-gradient(var(--btn-1), var(--btn-2));
    box-shadow: var(--btn-highlight);
    color: var(--text-2);
    font-size: 12px;
    text-shadow: var(--emboss);
}
.seg button + button { margin-left: -1px; }
.seg button:first-child { border-radius: var(--radius) 0 0 var(--radius); }
.seg button:last-child { border-radius: 0 var(--radius) var(--radius) 0; }
.seg button:hover:not(.on) { background: linear-gradient(var(--btn-hover-1), var(--btn-hover-2)); color: var(--text); }
.seg button.on { background: var(--btn-pressed); box-shadow: var(--pressed-shadow); color: var(--text); font-weight: bold; }

/* pens */
.pen-row {
    display: grid;
    grid-template-columns: 22px 34px 1fr 60px;
    align-items: center;
    gap: 8px;
    padding: 5px 0;
}
/* an idle pen is dimmed, but not the parts listed under it, those are still controls */
.pen-row.unused > :not(.pen-meta), .pen-row.unused .pen-count { opacity: 0.45; }
.pen-row .eye { width: 22px; height: 22px; border: 0; background: none; color: var(--text-2); padding: 0; display: grid; place-items: center; }
.pen-row .eye:hover { color: var(--text); }
.pen-row .eye.off { color: var(--muted); }
.pen-row .eye .ic { width: 16px; height: 16px; }
.pen-row .pen-name {
    min-width: 0;
    height: 26px;
    border: 1px solid transparent;
    background: transparent;
    border-radius: var(--radius);
    padding: 0 6px;
    font-size: 12px;
}
.pen-row .pen-name:hover { border-color: var(--input-border); background: var(--input-bg); box-shadow: var(--input-shadow); }
.pen-row .pen-name:focus { outline: none; border-color: var(--focus); background: var(--input-bg); box-shadow: var(--input-shadow), var(--focus-glow); }
.pen-row .pen-meta {
    grid-column: 3 / 5;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px;
    min-width: 0;
    margin-top: -4px;
    padding-left: 7px;
    color: var(--muted);
    font-size: 11px;
    font-variant-numeric: tabular-nums;
}
.pen-parts { display: contents; }
.pen-count:empty { display: none; }
/* A part of a scene, under the pen that draws it. The select lies over it, see renderParts in app.js */
.part {
    position: relative;
    display: inline-flex;
    align-items: center;
    min-width: 0;
    max-width: 100%;
    height: 20px;
    padding: 0 18px 0 6px;
    border: 1px solid var(--btn-border);
    border-bottom-color: var(--btn-border-bottom);
    border-radius: var(--radius);
    background: var(--select-arrow) no-repeat right 5px center, linear-gradient(var(--btn-1), var(--btn-2));
    box-shadow: var(--btn-highlight), var(--shadow-sm);
    color: var(--text);
    text-shadow: var(--emboss);
}
.part > span { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.part select { position: absolute; inset: 0; width: 100%; height: 100%; padding: 0; border: 0; opacity: 0; }
.part:hover { background-image: var(--select-arrow), linear-gradient(var(--btn-hover-1), var(--btn-hover-2)); }
.part:focus-within { border-color: var(--focus); box-shadow: var(--btn-highlight), var(--focus-glow); }
/* moved by hand */
.part.moved > span::before {
    content: "";
    display: inline-block;
    width: 5px; height: 5px;
    margin: 0 5px 1px 0;
    border-radius: 50%;
    background: var(--accent);
    vertical-align: middle;
}
.parts-moved { display: flex; align-items: center; gap: 10px; padding: 4px 0 8px; }
.parts-moved .out-note { flex: 1; margin: 0; }
.parts-moved .btn { height: 26px; padding: 0 10px; }
.pen-row .num { width: 60px; }
.pen-all { border-top: 1px solid var(--bar-border); margin-top: 2px; }
.pen-all-label { padding-left: 7px; font-size: 12px; color: var(--text-2); }
.pen-width-wrap { position: relative; }
.pen-width-wrap::after { content: "mm"; position: absolute; right: 22px; top: 6px; font-size: 10px; color: var(--muted); pointer-events: none; display: none; }

/* snapshots */
.snaps { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.snap { position: relative; }
.snap-restore {
    display: block;
    width: 100%;
    aspect-ratio: 1;
    border-radius: var(--radius);
    overflow: hidden;
    border: 1px solid var(--btn-border);
    background: var(--input-bg);
    box-shadow: var(--shadow-sm);
    padding: 0;
}
.snap-restore img { width: 100%; height: 100%; object-fit: contain; display: block; }
.snap .del {
    position: absolute; top: 3px; right: 3px;
    width: 20px; height: 20px;
    border-radius: 50%;
    border: 1px solid rgba(0, 0, 0, 0.6);
    background: rgba(20, 22, 25, 0.85);
    padding: 0;
    /* Faded out rather than display: none, so screen readers still find it */
    display: grid;
    opacity: 0;
    place-items: center;
    color: #fff;
}
.snap:hover .del, .snap:focus-within .del { opacity: 1; }
.snap .del .ic { width: 12px; height: 12px; }
.snap-restore:hover { border-color: var(--accent); box-shadow: 0 0 6px rgba(255, 107, 61, 0.4); }
.snaps-empty { color: var(--muted); font-size: 11.5px; }

/* ------------------------------------------------------------------ stage */

.stage {
    position: relative;
    overflow: hidden;
    background-color: var(--stage);
    background-image: radial-gradient(rgba(255, 255, 255, 0.04) 1px, transparent 1px), linear-gradient(#1c2024, #111315);
    background-size: 18px 18px, 100% 100%;
    touch-action: none;
}
.stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#view { cursor: grab; }
/* The WebGL line layer sits over the paper, pointer events go through to #view */
#lines { pointer-events: none; }
#view.panning { cursor: grabbing; }

/* one joined row of buttons */
.stage-tools {
    position: absolute;
    top: 10px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    border-radius: var(--radius);
    border: 1px solid var(--btn-border);
    border-bottom-color: var(--btn-border-bottom);
    background: linear-gradient(var(--btn-1), var(--btn-2));
    box-shadow: var(--btn-highlight), var(--shadow-float);
    z-index: 2;
}
.tool {
    width: 32px; height: 28px;
    border: 0;
    border-radius: 0;
    background: transparent;
    color: var(--text-2);
    display: grid;
    place-items: center;
}
.tool:first-child { border-radius: 2px 0 0 2px; }
.tool:last-child { border-radius: 0 2px 2px 0; }
.tool + .tool { border-left: 1px solid var(--btn-border); }
.tool:hover { background: linear-gradient(var(--btn-hover-1), var(--btn-hover-2)); color: var(--text); }
.tool.on { background: var(--btn-pressed); box-shadow: var(--pressed-shadow); color: var(--accent); }
.tool .ic { width: 17px; height: 17px; filter: drop-shadow(0 -1px 0 rgba(0, 0, 0, 0.6)); }
.stage-tools .sep { align-self: stretch; width: 1px; background: var(--btn-border); }
.stage-tools select { width: auto; height: 28px; border: 0; border-radius: 0; box-shadow: none; background-color: transparent; padding: 0 22px 0 8px; }
.zoom-label { font-size: 11.5px; font-variant-numeric: tabular-nums; color: var(--text-2); text-shadow: var(--emboss); min-width: 46px; text-align: center; }

.stage-msg {
    position: absolute;
    top: 50px;
    left: 50%;
    transform: translateX(-50%);
    padding: 6px 12px;
    border-radius: 4px;
    background: rgba(24, 27, 31, 0.92);
    border: 1px solid rgba(0, 0, 0, 0.7);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
    color: #fff;
    font-size: 12px;
    text-shadow: 0 -1px 0 #000;
    z-index: 2;
    pointer-events: none;
}
.stage-msg.error { color: #ffb3b3; border-color: #5b2a2a; background: rgba(50, 20, 20, 0.92); max-width: 70%; pointer-events: auto; }
/* Fast designs finish within a frame or two, so only show the busy message when it takes a moment. Otherwise it flickers while dragging a slider. */
#busy { animation: busy-delay 0s 0.2s backwards; }
@keyframes busy-delay { from { opacity: 0; } }
.drop-hint {
    position: absolute;
    inset: 16px;
    border: 2px dashed var(--accent);
    border-radius: 6px;
    background: rgba(255, 107, 61, 0.08);
    display: grid;
    place-items: center;
    color: var(--text);
    font-size: 15px;
    font-weight: bold;
    text-shadow: var(--emboss);
    z-index: 3;
    pointer-events: none;
}
.drop-hint[hidden] { display: none; }

.statusbar {
    position: absolute;
    left: 12px;
    right: 12px;
    bottom: 12px;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 6px;
    pointer-events: none;
    z-index: 2;
}
.stat {
    display: inline-flex;
    align-items: baseline;
    gap: 5px;
    padding: 4px 9px;
    border-radius: var(--radius);
    background: rgba(26, 29, 33, 0.95);
    background-clip: padding-box;
    border: 1px solid rgba(0, 0, 0, 0.6);
    box-shadow: var(--shadow-float);
    font-size: 11.5px;
    color: var(--text-2);
    white-space: nowrap;
}
.stat b { font-weight: bold; color: var(--text); font-variant-numeric: tabular-nums; }
.stat.dim { color: var(--muted); }

/* ------------------------------------------------------------------ gallery */

.gallery {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 30;
    display: grid;
    place-items: center;
    padding: 24px;
}
.gallery[hidden] { display: none; }
.gallery:focus-visible { outline: none; }
.gallery-inner, .keys-inner {
    width: min(1180px, 100%);
    height: min(860px, 100%);
    background: var(--panel);
    background-clip: padding-box;
    border: 1px solid rgba(0, 0, 0, 0.7);
    border-radius: 6px;
    box-shadow: 0 3px 12px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
/* The list scrolls when the window is shorter than it */
.keys-inner { width: min(560px, 100%); height: auto; max-height: 100%; }
.gallery-head {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px 8px 16px;
    border-bottom: 1px solid var(--bar-border);
    background: linear-gradient(var(--bar-1), var(--bar-2));
    box-shadow: inset 0 1px 0 var(--bar-highlight);
}
.gallery-head h2 { margin: 0 8px 0 0; font-size: 15px; font-weight: bold; text-shadow: var(--emboss); }
.gallery-head input[type="search"] {
    flex: 1;
    max-width: 340px;
    height: 28px;
    padding: 0 12px 0 27px;
    border-radius: 14px;
    border: 1px solid var(--input-border);
    background: var(--input-bg) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24'%3E%3Ccircle cx='10.5' cy='10.5' r='6.5' fill='none' stroke='%237f8893' stroke-width='2.4'/%3E%3Cpath d='m15.5 15.5 5 5' stroke='%237f8893' stroke-width='2.4' stroke-linecap='round'/%3E%3C/svg%3E") no-repeat 9px center;
    box-shadow: var(--input-shadow), 0 1px 0 rgba(255, 255, 255, 0.06);
    font-size: 12px;
}
.gallery-head input[type="search"]::placeholder { color: var(--faint); }
.gallery-head input[type="search"]:focus { outline: none; border-color: var(--focus); box-shadow: var(--input-shadow), var(--focus-glow); }
.gallery-head .icon-btn:last-child { margin-left: auto; }
.gallery-empty { margin: 0; padding: 28px 18px; color: var(--muted); text-align: center; }
.gallery-body { overflow-y: auto; padding: 4px 18px 24px; scrollbar-width: thin; scrollbar-color: #3a414a transparent; }
.gallery-cat {
    margin: 18px 2px 12px;
    padding-bottom: 4px;
    border-bottom: 1px solid var(--bar-border);
    box-shadow: 0 1px 0 var(--bar-highlight);
    font-size: 13px;
    font-weight: bold;
    color: var(--text);
    text-shadow: var(--emboss);
}
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(168px, 1fr)); gap: 14px; }
.card {
    display: flex;
    flex-direction: column;
    text-align: left;
    padding: 0;
    border-radius: 4px;
    border: 1px solid var(--btn-border);
    background: linear-gradient(var(--panel-3), var(--panel-2));
    box-shadow: var(--btn-highlight), 0 1px 3px rgba(0, 0, 0, 0.45);
    overflow: hidden;
    transition: border-color 0.12s, box-shadow 0.12s;
}
@media (hover: hover) {
    .card:hover { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent), 0 0 10px rgba(255, 107, 61, 0.35); }
}
.card.current { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent), 0 1px 3px rgba(0, 0, 0, 0.45); }
.card .thumb { aspect-ratio: 1; width: 100%; display: block; background: #fbfaf6; border-bottom: 1px solid var(--btn-border); }
a.card { color: inherit; text-decoration: none; }
a.card .thumb { object-fit: cover; }
.card .card-name .ic { width: 11px; height: 11px; vertical-align: -1px; color: var(--muted); }
.card .card-text { padding: 7px 10px 10px; }
.card .card-name { font-weight: bold; font-size: 12.5px; text-shadow: var(--emboss); }
.card .card-desc { color: var(--muted); font-size: 11px; margin-top: 2px; line-height: 1.4; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

.keys { display: grid; grid-template-columns: max-content 1fr; gap: 10px 18px; padding: 16px 20px 22px; margin: 0; min-height: 0; overflow-y: auto; }
.keys dt { text-align: right; color: var(--text-2); }
.keys dd { margin: 0; color: var(--text-2); }

/* ------------------------------------------------------------------ toasts */

.toasts { position: fixed; bottom: 18px; right: 18px; display: flex; flex-direction: column; gap: 6px; z-index: 40; }
.toast {
    padding: 7px 12px;
    border-radius: 4px;
    background: rgba(24, 27, 31, 0.94);
    border: 1px solid rgba(0, 0, 0, 0.7);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
    color: #fff;
    font-size: 12px;
    text-shadow: 0 -1px 0 #000;
    animation: toast-in 0.15s ease-out;
}
.toast.error { border-color: #5b2a2a; color: #ffb3b3; background: rgba(50, 20, 20, 0.94); }
.toast.install { display: flex; align-items: center; gap: 12px; padding: 10px; max-width: min(400px, calc(100vw - 36px)); }
.install-icon {
    width: 38px; height: 38px;
    flex: none;
    display: grid;
    place-items: center;
    border-radius: 8px;
    background: linear-gradient(var(--header-1), var(--header-2));
    border: 1px solid #000;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.12);
}
.install-logo { width: 26px; height: 26px; color: var(--accent); }
.install-text { display: flex; flex-direction: column; gap: 1px; min-width: 0; flex: 1; }
.install-text b { font-size: 13px; font-weight: bold; color: var(--text); }
.install-text span { font-size: 12px; color: var(--muted); text-shadow: none; }
.toast.install .btn { height: 28px; padding: 0 12px; }
.toast.install .icon-btn { width: 28px; height: 28px; border-color: transparent; background: transparent; box-shadow: none; color: var(--muted); }
.toast.install .icon-btn:hover { background: var(--panel-2); color: var(--text); }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } }

/* ------------------------------------------------------------------ responsive */

@media (max-width: 1280px) {
    .brand span { display: none; }
}

@media (max-width: 1100px) {
    :root { --left-w: 320px; }
    /* Design / Paper & Output switch, as a segmented control in a bar */
    .tabs {
        display: flex;
        align-items: center;
        position: absolute;
        top: var(--topbar-h);
        left: 0;
        width: var(--left-w);
        height: 38px;
        padding: 0 12px;
        background: linear-gradient(var(--bar-1), var(--bar-2));
        border-right: 1px solid var(--dark-line);
        border-bottom: 1px solid var(--bar-border);
        box-shadow: inset 0 1px 0 var(--bar-highlight);
        z-index: 3;
    }
    .tabs button {
        flex: 1;
        height: 26px;
        border: 1px solid var(--btn-border);
        border-bottom-color: var(--btn-border-bottom);
        background: linear-gradient(var(--btn-1), var(--btn-2));
        box-shadow: var(--btn-highlight);
        color: var(--text-2);
        font-size: 12px;
        font-weight: bold;
        text-shadow: var(--emboss);
    }
    .tabs button + button { margin-left: -1px; }
    .tabs button[data-tab="design"] { border-radius: var(--radius) 0 0 var(--radius); }
    .tabs button[data-tab="output"] { border-radius: 0 var(--radius) var(--radius) 0; }
    .tabs button:hover:not(.active) { background: linear-gradient(var(--btn-hover-1), var(--btn-hover-2)); color: var(--text); }
    .tabs button.active { background: var(--btn-pressed); box-shadow: var(--pressed-shadow); color: var(--text); }
    .tabs button[data-tab="preview"] { display: none; }
    .layout { grid-template-columns: var(--left-w) minmax(0, 1fr); }
    .panel { margin-top: 38px; }
    .panel.left, .panel.right { grid-column: 1; grid-row: 1; border-left: 0; border-right: 1px solid var(--dark-line); }
    .stage { grid-column: 2; grid-row: 1; }
    .layout[data-tab="design"] .panel.right,
    .layout[data-tab="preview"] .panel.right { display: none; }
    .layout[data-tab="output"] .panel.left { display: none; }
    .seed-box label, .hide-sm { display: none; }
    .seed-box input { padding-left: 10px; }
    .btn.primary span { display: none; }
    .btn.primary { width: 30px; padding: 0; justify-content: center; }
}


/* narrow tablets: keep the whole top bar on screen */
@media (max-width: 860px) {
    .export .btn.accent span { display: none; }
    .design-btn { min-width: 170px; }
}

/* phones: fixed app shell — top bar, drawing, the active panel, and a bottom tab bar */
@media (max-width: 720px) {
    :root { --topbar-h: 52px; --tabs-h: 50px; }
    body { display: flex; flex-direction: column; height: 100dvh; }
    .topbar { flex: none; gap: 6px; padding: 0 8px; }
    .spacer, #snapshotBtn { display: none; }
    .brand { margin: 0; }
    .design-btn { min-width: 0; flex: 1 1 auto; padding: 0 8px 0 12px; }
    .design-btn > .ic:first-child, .design-cat { display: none; }
    .design-btn-text { min-width: 0; }
    .design-name { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .export { margin-left: 2px; }

    .tabs {
        order: 3;
        flex: none;
        position: static;
        width: auto;
        height: calc(var(--tabs-h) + env(safe-area-inset-bottom));
        padding: 0 12px env(safe-area-inset-bottom);
        border: 0;
        border-top: 1px solid #000;
        background: linear-gradient(var(--header-1), var(--header-2));
        box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
    }
    .tabs button { height: 34px; font-size: 13px; }
    .tabs button[data-tab="output"] { border-radius: 0; }
    .tabs button[data-tab="preview"] { display: block; border-radius: 0 var(--radius) var(--radius) 0; }

    .layout { display: flex; flex-direction: column; flex: 1; min-height: 0; height: auto; }
    .stage { order: -1; flex: 0 0 40%; border-bottom: 1px solid var(--dark-line); }
    .layout[data-tab="preview"] .stage { flex: 1; border-bottom: 0; }
    .panel { flex: 1; min-height: 0; margin-top: 0; border: 0 !important; }
    .layout[data-tab="preview"] .panel { display: none; }
    /* the compact preview above a panel is just the drawing; the Preview tab has the tools */
    .layout:not([data-tab="preview"]) .stage-tools,
    .layout:not([data-tab="preview"]) .statusbar { display: none; }

    .phone-tools { display: flex; gap: 8px; padding: 0 12px 10px; }
    .phone-tools .seed-box { flex: 1; min-width: 0; }
    .phone-tools .seed-box label { display: flex; }
    .phone-tools .seed-box input { flex: 1; min-width: 0; width: auto; }
    .phone-tools #resetParams { width: auto; padding: 0 12px; }
    .phone-tools .reset .menu { left: auto; right: 0; }
    .phone-tools #resetParams span { display: inline; }

    .stage-tools { top: 8px; max-width: calc(100% - 16px); }
    .statusbar { bottom: 8px; left: 8px; right: 8px; }
    .stage-msg { top: 12px; }
    .layout[data-tab="preview"] .stage-msg { top: 60px; }
    .stage-msg.error { max-width: calc(100% - 24px); }

    .gallery { padding: 0; }
    .gallery-inner { height: 100%; border-radius: 0; border: 0; }
    .gallery-head { flex-wrap: wrap; gap: 8px; padding: 8px 10px 10px 12px; }
    .gallery-head h2 { margin-right: auto; }
    .gallery-head input[type="search"] { order: 5; flex: 1 0 100%; max-width: none; height: 32px; border-radius: 16px; }
    .gallery-head .icon-btn:last-child { margin-left: 0; }
    .gallery-body { padding: 0 12px 20px; }
    .cards { grid-template-columns: repeat(2, 1fr); gap: 10px; }
    .card .card-text { padding: 7px 9px 9px; }
    .keys { grid-template-columns: 1fr; gap: 2px; padding: 14px 18px 20px; }
    .keys dt { text-align: left; margin-top: 10px; }

    .toasts { left: 12px; right: 12px; bottom: calc(var(--tabs-h) + 12px + env(safe-area-inset-bottom)); align-items: center; }
}

/* short landscape screens (phones on their side): give the drawing the height */
@media (max-height: 520px) and (min-width: 721px) {
    :root { --topbar-h: 44px; }
    .design-btn { height: 32px; }
    .statusbar { display: none; }
    .design-info { padding-top: 10px; }
}

/* touch: no hover to reveal controls, and fingers need bigger targets */
@media (hover: none) {
    .lock-btn { opacity: 0.55; }
    .lock-btn.locked { opacity: 1; }
    .snap .del { opacity: 1; }
    /* touch keeps :hover after a tap, which would leave buttons looking lit */
    .btn:hover:not(:active), .icon-btn:hover:not(:active), .design-btn:hover:not(:active) { background: linear-gradient(var(--btn-1), var(--btn-2)); }
    .btn.accent:hover:not(:active) { background: linear-gradient(var(--go-1), var(--go-2)); }
    .icon-btn.coffee:hover:not(:active) { background: linear-gradient(var(--coffee-1), var(--coffee-2)); }
    .seed-box .icon-btn:hover:not(:active) { background: linear-gradient(var(--btn-1), var(--btn-2)); }
}
@media (pointer: coarse) {
    .lock-btn { width: 30px; height: 30px; margin: -6px -6px -6px auto; }
    .lock-btn .ic { width: 15px; height: 15px; }
    .ctl-head .hint { width: 20px; height: 20px; font-size: 12px; }
    input[type="range"] { height: 32px; }
    input[type="range"]::-webkit-slider-thumb { width: 22px; height: 22px; margin-top: -9px; }
    input[type="range"]::-moz-range-thumb { width: 22px; height: 22px; }
    .num { height: 32px; }
    select, .text-input { height: 36px; }
    .switch { width: 42px; height: 24px; }
    .switch span { border-radius: 12px; }
    .switch span::after { width: 22px; height: 22px; }
    .switch input:checked + span::after { transform: translateX(18px); }
    .color-input { width: 40px; height: 32px; }
    .seg button { height: 34px; }
    .tool { width: 40px; height: 36px; }
    .menu button { padding: 10px 14px; }
    .pen-row { grid-template-columns: 28px 40px 1fr 66px; }
    .pen-row .eye { width: 28px; height: 28px; }
    .pen-row .num { width: 66px; }
    .pen-row .pen-meta { gap: 6px; margin-top: 0; }
    .part { height: 30px; padding: 0 22px 0 9px; font-size: 13px; background-position: right 8px center, 0 0; }
    .parts-moved .btn { height: 34px; }
    .image-ctl .btn { height: 34px; }
    .image-ctl .icon-btn { width: 34px; height: 34px; }
    .snap .del { width: 26px; height: 26px; }
}
/* iOS zooms the page into any focused field under 16px */
@supports (-webkit-touch-callout: none) {
    @media (pointer: coarse) {
        input, select, textarea, .num { font-size: 16px; }
        .num, .pen-row .num { width: 76px; }
        .pen-row { grid-template-columns: 28px 40px 1fr 76px; }
    }
}
