/* =========================================================================
   STL Sign Studio — visual system
   A precision-tool aesthetic: hairline rules, micro labels, one accent.
   Tokens are defined for the dark theme on :root and overridden for light
   on [data-theme="light"]; nothing outside this block hardcodes a colour.
   ========================================================================= */

:root {
    color-scheme: dark;

    --bg:        #0f1113;
    --bg-panel:  #15171a;
    --bg-sunken: #101214;
    --bg-field:  #1b1e22;
    --bg-hover:  #22262b;
    --bg-active: #2b3037;

    --line:      #26292e;
    --line-soft: #1e2126;
    --line-hard: #363b42;

    --fg:        #e7eaee;
    --fg-2:      #9aa2ac;
    --fg-3:      #6b737d;

    --accent:      #ff8a3d;
    --accent-soft: #ffb083;
    --accent-wash: rgba(255, 138, 61, 0.13);
    --accent-ink:  #171008;

    --ok:   #4ec9a0;
    --warn: #e5b23c;
    --err:  #ef6a5a;

    --viewport: #16181b;
    --viewport-2: #0d0f11;

    --font-ui: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --font-mono: ui-monospace, "SFMono-Regular", "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;

    --r-sm: 3px;
    --r:    5px;
    --r-lg: 8px;

    --topbar-h: 50px;
    --status-h: 30px;
    --rail-w: 356px;

    --shadow-pop: 0 12px 34px rgba(0, 0, 0, 0.55), 0 2px 6px rgba(0, 0, 0, 0.4);
}

[data-theme="light"] {
    color-scheme: light;

    --bg:        #eceef1;
    --bg-panel:  #ffffff;
    --bg-sunken: #f4f5f7;
    --bg-field:  #ffffff;
    --bg-hover:  #f0f1f4;
    --bg-active: #e4e7ec;

    --line:      #dcdfe4;
    --line-soft: #e7e9ed;
    --line-hard: #c3c8d0;

    --fg:        #1b1e23;
    --fg-2:      #5c646f;
    --fg-3:      #868e99;

    --accent:      #d2621b;
    --accent-soft: #b8551620;
    --accent-wash: rgba(210, 98, 27, 0.10);
    --accent-ink:  #ffffff;

    --ok:   #1f9d74;
    --warn: #b3822a;
    --err:  #cf4436;

    --viewport: #e6e8ec;
    --viewport-2: #d3d7dd;

    --shadow-pop: 0 12px 30px rgba(20, 26, 36, 0.16), 0 2px 6px rgba(20, 26, 36, 0.1);
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
    height: 100%;
    margin: 0;
}

body {
    background: var(--bg);
    color: var(--fg);
    font-family: var(--font-ui);
    font-size: 13px;
    line-height: 1.45;
    -webkit-font-smoothing: antialiased;
    overflow: hidden;
}

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

::selection { background: var(--accent-wash); }

/* Scrollbars kept thin so the rail reads as one surface, not a scrolling box. */
.scroll { scrollbar-width: thin; scrollbar-color: var(--line-hard) transparent; }
.scroll::-webkit-scrollbar { width: 10px; height: 10px; }
.scroll::-webkit-scrollbar-thumb {
    background: var(--line-hard);
    border: 3px solid transparent;
    background-clip: content-box;
    border-radius: 6px;
}
.scroll::-webkit-scrollbar-thumb:hover { background-clip: content-box; background-color: var(--fg-3); }
.scroll::-webkit-scrollbar-track { background: transparent; }

/* =========================================================================
   App frame
   ========================================================================= */

.app {
    max-width: 100vw;
    overflow: hidden;
    display: grid;
    grid-template-rows: var(--topbar-h) 1fr var(--status-h);
    grid-template-columns: var(--rail-w) 1fr;
    grid-template-areas:
        "topbar topbar"
        "rail   stage"
        "status status";
    height: 100vh;
    height: 100dvh;
}

/* ------------------------------ topbar ---------------------------------- */

.topbar {
    grid-area: topbar;
    /* The topbar sits in a `1fr` grid column, so its min-content width would
       otherwise set the floor for the whole app and push the page sideways. */
    min-width: 0;
    overflow: hidden;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 12px 0 14px;
    background: var(--bg-panel);
    border-bottom: 1px solid var(--line);
}

.brand {
    min-width: 0;
    flex: 0 1 auto;
    display: flex;
    align-items: center;
    gap: 9px;
    padding-right: 12px;
    margin-right: 2px;
    border-right: 1px solid var(--line);
    height: 100%;
}

.brand-mark {
    width: 24px;
    height: 24px;
    border-radius: var(--r-sm);
    background: var(--accent);
    color: var(--accent-ink);
    display: grid;
    place-items: center;
    flex: 0 0 auto;
}
.brand-mark svg { width: 15px; height: 15px; display: block; }

.brand-name {
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 13px;
    font-weight: 600;
    letter-spacing: -0.01em;
    white-space: nowrap;
}
.brand-name b { font-weight: 600; }
.brand-name span { color: var(--fg-3); font-weight: 500; }

.topbar-spacer { flex: 1 1 auto; }

.topbar-group {
    display: flex;
    align-items: center;
    gap: 6px;
}

.topbar-sep {
    width: 1px;
    height: 22px;
    background: var(--line);
    margin: 0 4px;
}

/* ------------------------------ rail ------------------------------------ */

.rail {
    grid-area: rail;
    background: var(--bg-panel);
    border-right: 1px solid var(--line);
    overflow-y: auto;
    overflow-x: hidden;
}

.rail-inner { padding: 0 0 40px; }

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

.stage {
    grid-area: stage;
    min-width: 0;
    position: relative;
    background: var(--viewport);
    overflow: hidden;
}

#viewport {
    position: absolute;
    inset: 0;
}
#viewport canvas { display: block; }

/* ------------------------------ status bar ------------------------------ */

.statusbar {
    grid-area: status;
    min-width: 0;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
    display: flex;
    align-items: center;
    gap: 0;
    padding: 0 12px;
    background: var(--bg-panel);
    border-top: 1px solid var(--line);
    font-size: 11px;
    color: var(--fg-2);
}
.statusbar::-webkit-scrollbar { height: 0; }

.stat {
    display: flex;
    align-items: baseline;
    gap: 6px;
    padding: 0 12px;
    border-right: 1px solid var(--line-soft);
    white-space: nowrap;
}
.stat:first-child { padding-left: 0; }

.stat-k {
    font-size: 10px;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--fg-3);
}
.stat-v {
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--fg);
    font-variant-numeric: tabular-nums;
}

.status-flags {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 6px;
    padding-left: 12px;
}

.flag {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    height: 19px;
    padding: 0 8px;
    border-radius: 10px;
    font-size: 10.5px;
    font-weight: 500;
    letter-spacing: 0.02em;
    white-space: nowrap;
}
.flag::before {
    content: "";
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: currentColor;
}
.flag.is-ok   { color: var(--ok);   background: color-mix(in srgb, var(--ok) 13%, transparent); }
.flag.is-warn { color: var(--warn); background: color-mix(in srgb, var(--warn) 15%, transparent); }
.flag.is-err  { color: var(--err);  background: color-mix(in srgb, var(--err) 15%, transparent); }

/* =========================================================================
   Controls
   ========================================================================= */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    height: 30px;
    padding: 0 11px;
    background: var(--bg-field);
    border: 1px solid var(--line-hard);
    border-radius: var(--r);
    color: var(--fg);
    font-size: 12.5px;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.12s, border-color 0.12s, color 0.12s;
}
.btn:hover { background: var(--bg-hover); }
.btn:active { background: var(--bg-active); }
.btn:disabled { opacity: 0.4; cursor: default; pointer-events: none; }
.btn svg { width: 14px; height: 14px; flex: 0 0 auto; }

.btn.is-primary {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--accent-ink);
    font-weight: 600;
}
.btn.is-primary:hover { background: var(--accent-soft); border-color: var(--accent-soft); }

.btn.is-quiet {
    background: transparent;
    border-color: transparent;
    color: var(--fg-2);
}
.btn.is-quiet:hover { background: var(--bg-hover); color: var(--fg); }

.btn.is-icon {
    width: 30px;
    padding: 0;
}

.btn.is-danger:hover { color: var(--err); border-color: color-mix(in srgb, var(--err) 45%, transparent); }

.btn.is-block { width: 100%; }

:where(button, input, select, a, [tabindex]):focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}

/* --- segmented control --- */

.seg {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: 1fr;
    background: var(--bg-sunken);
    border: 1px solid var(--line);
    border-radius: var(--r);
    padding: 2px;
    gap: 2px;
}
.seg button {
    height: 24px;
    padding: 0 6px;
    background: transparent;
    border: 0;
    border-radius: 3px;
    color: var(--fg-2);
    font-size: 11.5px;
    font-weight: 500;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    white-space: nowrap;
    overflow: hidden;
    transition: background 0.1s, color 0.1s;
}
.seg button svg { width: 13px; height: 13px; }
.seg button:hover { color: var(--fg); background: var(--bg-hover); }
.seg button[aria-pressed="true"] {
    background: var(--bg-active);
    color: var(--fg);
    box-shadow: inset 0 0 0 1px var(--line-hard);
}
.seg.is-accent button[aria-pressed="true"] {
    background: var(--accent-wash);
    color: var(--accent);
    box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 40%, transparent);
}

/* --- fields --- */

.field-label {
    display: block;
    font-size: 10.5px;
    font-weight: 600;
    letter-spacing: 0.07em;
    text-transform: uppercase;
    color: var(--fg-3);
}

.field-row {
    display: grid;
    grid-template-columns: 1fr;
    align-content: start;
    gap: 6px;
    margin-bottom: 13px;
}
.field-row:last-child { margin-bottom: 0; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 13px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; margin-bottom: 13px; }
.grid-2:last-child, .grid-3:last-child { margin-bottom: 0; }

/* Columns are stretched to equal height, so a per-row margin here would show up
   as a vertical offset between the two columns rather than as spacing. */
.grid-2 > .field-row,
.grid-3 > .field-row { margin-bottom: 0; }

.num {
    position: relative;
    display: flex;
    align-items: center;
    background: var(--bg-field);
    border: 1px solid var(--line-hard);
    border-radius: var(--r);
    height: 30px;
    overflow: hidden;
    transition: border-color 0.12s;
}
.num:focus-within { border-color: var(--accent); }
.num input {
    flex: 1 1 auto;
    min-width: 0;
    height: 100%;
    padding: 0 4px 0 9px;
    background: none;
    border: 0;
    outline: none;
    font-family: var(--font-mono);
    font-size: 12.5px;
    font-variant-numeric: tabular-nums;
}
.num input::-webkit-outer-spin-button,
.num input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.num input[type="number"] { -moz-appearance: textfield; }
.num .unit {
    padding-right: 9px;
    font-size: 10.5px;
    color: var(--fg-3);
    font-family: var(--font-mono);
    pointer-events: none;
    user-select: none;
}

.text-input {
    width: 100%;
    height: 30px;
    padding: 0 9px;
    background: var(--bg-field);
    border: 1px solid var(--line-hard);
    border-radius: var(--r);
    outline: none;
    font-size: 13px;
    transition: border-color 0.12s;
}
.text-input:focus { border-color: var(--accent); }
.text-input::placeholder { color: var(--fg-3); }

select.select {
    width: 100%;
    height: 30px;
    padding: 0 26px 0 9px;
    background: var(--bg-field);
    border: 1px solid var(--line-hard);
    border-radius: var(--r);
    outline: none;
    font-size: 12.5px;
    cursor: pointer;
    appearance: none;
    background-image: linear-gradient(45deg, transparent 50%, currentColor 50%),
                      linear-gradient(135deg, currentColor 50%, transparent 50%);
    background-position: calc(100% - 14px) 13px, calc(100% - 10px) 13px;
    background-size: 4px 4px, 4px 4px;
    background-repeat: no-repeat;
    transition: border-color 0.12s;
}
select.select:focus { border-color: var(--accent); }
select.select option { background: var(--bg-panel); color: var(--fg); }

/* --- slider + number pair --- */

.slider {
    display: grid;
    grid-template-columns: 1fr 76px;
    align-items: center;
    gap: 10px;
}
input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 18px;
    background: none;
    outline: none;
    cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track {
    height: 3px;
    border-radius: 2px;
    background: var(--line-hard);
}
input[type="range"]::-moz-range-track {
    height: 3px;
    border-radius: 2px;
    background: var(--line-hard);
}
input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 13px;
    height: 13px;
    margin-top: -5px;
    border-radius: 50%;
    background: var(--fg);
    border: 0;
    box-shadow: 0 0 0 1px var(--bg-panel);
    transition: background 0.12s;
}
input[type="range"]::-moz-range-thumb {
    width: 13px;
    height: 13px;
    border-radius: 50%;
    background: var(--fg);
    border: 0;
}
input[type="range"]:hover::-webkit-slider-thumb { background: var(--accent); }
input[type="range"]:hover::-moz-range-thumb { background: var(--accent); }

/* --- switch --- */

.switch {
    display: flex;
    align-items: center;
    gap: 9px;
    cursor: pointer;
    user-select: none;
    font-size: 12.5px;
}
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch .track {
    position: relative;
    width: 30px;
    height: 17px;
    flex: 0 0 auto;
    border-radius: 9px;
    background: var(--bg-sunken);
    box-shadow: inset 0 0 0 1px var(--line-hard);
    transition: background 0.15s, box-shadow 0.15s;
}
.switch .track::after {
    content: "";
    position: absolute;
    top: 3px;
    left: 3px;
    width: 11px;
    height: 11px;
    border-radius: 50%;
    background: var(--fg-3);
    transition: transform 0.15s, background 0.15s;
}
.switch input:checked + .track {
    background: var(--accent-wash);
    box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 55%, transparent);
}
.switch input:checked + .track::after {
    transform: translateX(13px);
    background: var(--accent);
}
.switch input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }

/* --- colour picker --- */

.color {
    display: flex;
    align-items: center;
    gap: 8px;
    height: 30px;
    padding: 0 8px 0 4px;
    background: var(--bg-field);
    border: 1px solid var(--line-hard);
    border-radius: var(--r);
    cursor: pointer;
    transition: border-color 0.12s;
}
.color:hover { border-color: var(--fg-3); }
.color input[type="color"] {
    width: 22px;
    height: 22px;
    flex: 0 0 auto;
    padding: 0;
    border: 0;
    border-radius: var(--r-sm);
    background: none;
    cursor: pointer;
    overflow: hidden;
}
.color input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
.color input[type="color"]::-webkit-color-swatch {
    border: 1px solid rgba(128, 128, 128, 0.45);
    border-radius: var(--r-sm);
}
.color input[type="color"]::-moz-color-swatch {
    border: 1px solid rgba(128, 128, 128, 0.45);
    border-radius: var(--r-sm);
}
.color .hex {
    font-family: var(--font-mono);
    font-size: 11.5px;
    color: var(--fg-2);
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

.swatches {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    margin-top: 8px;
}
.swatches button {
    width: 19px;
    height: 19px;
    padding: 0;
    border-radius: var(--r-sm);
    border: 1px solid rgba(128, 128, 128, 0.35);
    cursor: pointer;
    transition: transform 0.1s;
}
.swatches button:hover { transform: scale(1.15); }

.hint {
    font-size: 11px;
    line-height: 1.5;
    color: var(--fg-3);
}

/* =========================================================================
   Rail sections
   ========================================================================= */

.section { border-bottom: 1px solid var(--line); }

.section-head {
    display: flex;
    align-items: center;
    gap: 9px;
    width: 100%;
    height: 40px;
    padding: 0 14px;
    background: none;
    border: 0;
    cursor: pointer;
    text-align: left;
    color: var(--fg);
}
.section-head:hover { background: var(--bg-hover); }
.section-head .chev {
    width: 11px;
    height: 11px;
    flex: 0 0 auto;
    color: var(--fg-3);
    transition: transform 0.16s ease;
}
.section[data-open="true"] .section-head .chev { transform: rotate(90deg); }
.section-head .title {
    font-size: 11.5px;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    flex: 1 1 auto;
}
.section-head .badge {
    font-family: var(--font-mono);
    font-size: 10px;
    color: var(--fg-3);
    background: var(--bg-sunken);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 1px 6px;
}

.section-body { padding: 2px 14px 16px; }
.section[data-open="false"] .section-body { display: none; }

.subhead {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 16px 0 10px;
    font-size: 10.5px;
    font-weight: 600;
    letter-spacing: 0.07em;
    text-transform: uppercase;
    color: var(--fg-3);
}
.subhead::after {
    content: "";
    flex: 1 1 auto;
    height: 1px;
    background: var(--line);
}

/* =========================================================================
   Element list (text lines + symbols)
   ========================================================================= */

.elements { display: flex; flex-direction: column; gap: 7px; }

.el {
    background: var(--bg-sunken);
    border: 1px solid var(--line);
    border-radius: var(--r);
    transition: border-color 0.12s, opacity 0.12s;
}
.el:focus-within { border-color: var(--line-hard); }
.el.is-dragging { opacity: 0.4; }
.el.is-drop-target { border-color: var(--accent); }
.el.is-muted .el-head .el-text { opacity: 0.45; text-decoration: line-through; }

.el-head {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 5px 5px 5px 3px;
}

.el-grip {
    width: 16px;
    height: 26px;
    flex: 0 0 auto;
    display: grid;
    place-items: center;
    color: var(--fg-3);
    cursor: grab;
}
.el-grip:active { cursor: grabbing; }
.el-grip svg { width: 11px; height: 11px; }

.el-kind {
    width: 22px;
    height: 22px;
    flex: 0 0 auto;
    display: grid;
    place-items: center;
    border-radius: var(--r-sm);
    background: var(--bg-active);
    color: var(--fg-2);
    font-size: 10px;
    font-weight: 700;
}
.el-kind svg { width: 13px; height: 13px; }

.el-text {
    flex: 1 1 auto;
    min-width: 0;
    height: 26px;
    padding: 0 7px;
    background: var(--bg-field);
    border: 1px solid transparent;
    border-radius: var(--r-sm);
    outline: none;
    font-size: 12.5px;
    transition: border-color 0.12s;
}
.el-text:focus { border-color: var(--accent); }
.el-text::placeholder { color: var(--fg-3); }

.el-label {
    flex: 1 1 auto;
    min-width: 0;
    font-size: 12.5px;
    color: var(--fg-2);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding-left: 3px;
}

.el-btn {
    width: 24px;
    height: 24px;
    flex: 0 0 auto;
    display: grid;
    place-items: center;
    background: none;
    border: 0;
    border-radius: var(--r-sm);
    color: var(--fg-3);
    cursor: pointer;
    transition: background 0.1s, color 0.1s, transform 0.16s;
}
.el-btn:hover { background: var(--bg-hover); color: var(--fg); }
.el-btn.is-remove:hover { color: var(--err); }
.el-btn svg { width: 13px; height: 13px; }
.el[data-open="true"] .el-btn.is-expand { transform: rotate(180deg); }

.el-body {
    padding: 4px 10px 12px 24px;
    border-top: 1px solid var(--line-soft);
    margin-top: 1px;
}
.el[data-open="false"] .el-body { display: none; }

.el-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 9px 10px;
    margin-top: 10px;
}
.el-grid .span-2 { grid-column: span 2; }

/* --- font select rendered in its own face --- */

select.font-select { font-size: 13px; }
select.font-select option { font-size: 14px; }

.font-preview {
    height: 46px;
    margin-top: 7px;
    border: 1px solid var(--line);
    border-radius: var(--r);
    background: var(--bg-field);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    padding: 0 10px;
    color: var(--fg);
    font-size: 22px;
    line-height: 1;
    white-space: nowrap;
}

/* =========================================================================
   Symbol picker
   ========================================================================= */

.symbol-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 5px;
    max-height: 172px;
    overflow-y: auto;
    padding: 3px;
    background: var(--bg-field);
    border: 1px solid var(--line);
    border-radius: var(--r);
}
.symbol-grid button {
    aspect-ratio: 1;
    display: grid;
    place-items: center;
    background: none;
    border: 1px solid transparent;
    border-radius: var(--r-sm);
    color: var(--fg-2);
    cursor: pointer;
    transition: background 0.1s, color 0.1s, border-color 0.1s;
}
.symbol-grid button:hover { background: var(--bg-hover); color: var(--fg); }
.symbol-grid button[aria-pressed="true"] {
    background: var(--accent-wash);
    border-color: color-mix(in srgb, var(--accent) 45%, transparent);
    color: var(--accent);
}
.symbol-grid svg { width: 19px; height: 19px; }

/* =========================================================================
   Viewport overlays
   ========================================================================= */

.vp-overlay {
    position: absolute;
    z-index: 3;
    display: flex;
    gap: 5px;
    pointer-events: none;
}
.vp-overlay > * { pointer-events: auto; }

.vp-tl { top: 12px; left: 12px; }
.vp-tr { top: 12px; right: 12px; }
.vp-bl { bottom: 12px; left: 12px; flex-direction: column; align-items: flex-start; }
.vp-br { bottom: 12px; right: 12px; flex-direction: column; }

.vp-cluster {
    display: flex;
    gap: 1px;
    background: color-mix(in srgb, var(--bg-panel) 88%, transparent);
    backdrop-filter: blur(8px);
    border: 1px solid var(--line);
    border-radius: var(--r);
    padding: 3px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.22);
}
.vp-cluster.is-col { flex-direction: column; }

.vp-btn {
    height: 26px;
    min-width: 26px;
    padding: 0 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    background: none;
    border: 0;
    border-radius: 3px;
    color: var(--fg-2);
    font-size: 11.5px;
    font-weight: 500;
    letter-spacing: 0.02em;
    cursor: pointer;
    transition: background 0.1s, color 0.1s;
}
.vp-btn:hover { background: var(--bg-hover); color: var(--fg); }
.vp-btn[aria-pressed="true"] { background: var(--accent-wash); color: var(--accent); }
.vp-btn svg { width: 14px; height: 14px; }

.vp-readout {
    font-family: var(--font-mono);
    font-size: 10.5px;
    color: var(--fg-3);
    background: color-mix(in srgb, var(--bg-panel) 80%, transparent);
    backdrop-filter: blur(8px);
    border: 1px solid var(--line);
    border-radius: var(--r);
    padding: 4px 8px;
    letter-spacing: 0.02em;
}

.vp-empty {
    position: absolute;
    inset: 0;
    display: grid;
    place-content: center;
    justify-items: center;
    gap: 8px;
    text-align: center;
    color: var(--fg-3);
    pointer-events: none;
    z-index: 2;
}
.vp-empty svg { width: 34px; height: 34px; opacity: 0.5; }
.vp-empty p { margin: 0; font-size: 12.5px; }
.vp-empty small { font-size: 11px; opacity: 0.75; }
.vp-empty.is-hidden { display: none; }

.vp-busy {
    position: absolute;
    top: 12px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 4;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 5px 11px;
    font-size: 11.5px;
    color: var(--fg-2);
    background: color-mix(in srgb, var(--bg-panel) 92%, transparent);
    border: 1px solid var(--line);
    border-radius: 20px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.25);
    opacity: 0;
    transition: opacity 0.18s;
    pointer-events: none;
}
.vp-busy.is-on { opacity: 1; }
.vp-busy::before {
    content: "";
    width: 11px;
    height: 11px;
    border-radius: 50%;
    border: 2px solid var(--line-hard);
    border-top-color: var(--accent);
    animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* =========================================================================
   Popovers / dialogs
   ========================================================================= */

.pop {
    position: fixed;
    z-index: 60;
    width: 290px;
    padding: 14px;
    background: var(--bg-panel);
    border: 1px solid var(--line-hard);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-pop);
}
.pop[hidden] { display: none; }
.pop-title {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.07em;
    text-transform: uppercase;
    color: var(--fg-3);
    margin: 0 0 12px;
}
.pop-actions {
    display: flex;
    gap: 7px;
    margin-top: 15px;
}
.pop-actions .btn { flex: 1 1 auto; }

/* The vectorizer takes up three quarters of the window.
 *
 * The preview is the point of the tool, and at a stage height of 260 px there
 * is nothing to see on a 1024 px mark. That this costs nothing is measured and
 * not assumed: drawing the same geometry over 5.8 times the area goes from 1.1
 * to 1.9 ms (`node $SP/browser/paint-cost.mjs`, stage 490x260 against
 * 1060x700), against a mean of 103.6 ms for the recompute behind it (`node
 * $SP/browser/panel-class-cost.mjs`).
 *
 * Centred rather than hung off an anchor: for a panel this size there is no
 * sense in hanging under the card head. That also retires `keepInWindow` -- a
 * fixed height in vh cannot grow out of the bottom of the window, and that is
 * exactly what the function was there for.
 *
 * A fixed height rather than a `max-height`: a panel whose stage breathes with
 * the length of the hint texts jumps to a different size on every language
 * switch.
 *
 * 84vh against 78vw, and the asymmetry is measured rather than tidy. The
 * pictures this panel shows are square-ish -- mark3tone.png is 1024x1024 -- and
 * `object-fit: contain` in a landscape stage is height-bound, so every pixel of
 * extra width is letterbox and only height enlarges the preview. At 1500x980,
 * 78vh left the stage at 804x624 = 502018 px2 and 82vh put it at 804x664;
 * widening to 82vw instead would have bought 864x624 and moved the picture's
 * scale by exactly nothing -- 0.607 either way, because 622/1024 is the smaller
 * ratio in both (`node $SP/browser/zz-panel-metrics.mjs`).
 *
 * The last two points of height are the slider column's doing. Widening that
 * column to 360 px is free for the preview and not free for the stage *box*:
 * the width it takes was letterbox, but the box is what 'the panel takes up
 * most of the screen' measures, and at 82vh a 360 px column left the stage at
 * 764x664 = 507296 px2, just under that assertion's 509600. Rather than move
 * the assertion to fit the change, the height paid for it -- in the one
 * dimension the preview actually uses. */
.pop.is-wide {
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    width: min(1180px, 78vw);
    height: 84vh;
    max-height: calc(100vh - 24px);
    min-width: 520px;
    display: flex;
    flex-direction: column;
}
/* Required by the rule above, and introduced with it.
 *
 * `.pop[hidden] { display: none }` and `.pop.is-wide` tie on specificity — two
 * classes or attributes each — and `.pop.is-wide` comes later, so the moment it
 * gained a `display` of its own it started winning that tie. A hidden trace
 * panel then computes `display: flex` and sits, fully laid out and interactive,
 * at whatever position it was last opened at, silently swallowing clicks meant
 * for whatever is underneath. Measured on the real stylesheet, no interaction,
 * panel hidden: only `width` -> `none`; plus `display: flex` -> `flex`; plus
 * this line -> `none`.
 *
 * Worth knowing how it was found: the panel's own suite stayed green, because
 * nothing there clicks through a closed panel. It surfaced one task later, when
 * importing artwork began opening and closing the panel routinely and a click
 * on "Add graphic" in a different suite landed on the invisible panel instead. */
.pop.is-wide[hidden] { display: none; }
.pop.is-wide > * { flex: 0 0 auto; }
.pop.is-wide > .trace-body { flex: 1 1 auto; min-height: 0; }

/* Stage on the left, sliders on the right.
 *
 * 360 px, and the number is measured rather than drawn. The picture is square
 * and the stage is landscape, so part of the stage width is letterbox that the
 * preview never uses: at a 320 px column that slack is 116 px at 1280x800,
 * 140 px at 1500x980 and 68 px at 1920x1080. 360 px is the widest column that
 * spends only slack at all three -- the picture measures 514 / 662 / 744 px
 * either way -- and it is exactly the width at which the rows stop overflowing
 * at 1920x1080 (776 px of rows in a 746 px column at 320, 727 in 746 at 360).
 * 400 px would start eating the picture at 1920x1080, 744 -> 732. Swept with
 * `node $SP/browser/zz-column-sweep.mjs`, both languages.
 *
 * `minmax(0, 1fr)` and not `1fr`, because a grid item otherwise refuses to
 * shrink below its content width and the stage would push the column open. */
.trace-body {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 360px;
    gap: 16px;
    min-height: 0;
}
@media (max-width: 900px) {
    .trace-body { grid-template-columns: minmax(0, 1fr); grid-template-rows: 1fr auto; }
}

/* The picture and the paths are two layers of one box, so a path sits on the
   pixels it came from rather than merely near them — the same arrangement the
   step editor uses for its histogram and stop track. */
.trace-stage {
    position: relative;
    min-height: 0;
    border: 1px solid var(--line);
    border-radius: var(--r-sm);
    background: var(--bg-sunken);
    overflow: hidden;
}
.trace-image,
.trace-paths {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}
/* `contain`, not the default stretch: the overlay letterboxes the picture into
   the stage with a min() fit, and a stretched picture underneath would put
   every path beside the pixels it was traced from. Pixelated for the same
   reason `.img-preview` is — smoothing hides the speckle the culls exist for. */
.trace-image {
    object-fit: contain;
    image-rendering: pixelated;
}

.trace-controls {
    display: flex;
    flex-direction: column;
    gap: 13px;
    min-height: 0;
    overflow-y: auto;
    padding-right: 4px;
}
.trace-controls .field-row { margin-bottom: 0; }

/* Fade the edge the column continues past, and only that edge.
 *
 * The column scrolls at every window size below 1920x1080, and the way it ended
 * was the problem rather than the scrolling: at 1280x800 in German it stops
 * after a whole hint paragraph, flush above the readout's rule, with nothing in
 * its shape to suggest a fifth and sixth row exist. A reader concludes the tool
 * has four settings, and one of the two it hides is the fit tolerance -- the
 * widest-acting slider of the six. At 1500x980 it happened to break mid-row
 * instead, and that ragged edge was the only hint that scrolling was possible;
 * leaving that to chance is not a design.
 *
 * `overflow-y: scroll` was the cheaper answer and is the wrong one twice over.
 * A gutter that is always there says the same thing whether or not anything is
 * hidden, and at 1920x1080 nothing is; and there is no gutter to see anyway --
 * measured, `offsetWidth - clientWidth` is 0 px on this column at all three
 * window sizes (`node $SP/browser/zz-panel-metrics.mjs`), because the scrollbar
 * is an overlay one that paints nothing until it is used. This says only what
 * is true, which is why the witness can assert both directions.
 *
 * A mask and not a painted gradient: the fade has to work over `--bg-panel` in
 * both themes, and a gradient to a fixed colour would need a value per theme
 * and would be wrong the moment either changes. A mask fades to whatever is
 * behind, which is checked on the light shot as well as the dark one.
 *
 * Both edges, because the defect is symmetric: scrolled to the bottom, the
 * column would hide the material switch and the threshold just as quietly.
 * `mask-origin` defaults to the border box, which does not scroll, so the fade
 * stays pinned to the edge instead of travelling with the rows.
 *
 * Two stops at the same position when a side is off, so one rule covers all
 * three states and neither side fades unless `markScrollEdges` says so. */
.trace-controls {
    --fade-above: 0px;
    --fade-below: 0px;
}
.trace-controls[data-more="above"],
.trace-controls[data-more="both"] { --fade-above: 34px; }
.trace-controls[data-more="below"],
.trace-controls[data-more="both"] { --fade-below: 34px; }
.trace-controls[data-more] {
    -webkit-mask-image: linear-gradient(to bottom,
        transparent 0, #000 var(--fade-above),
        #000 calc(100% - var(--fade-below)), transparent 100%);
    mask-image: linear-gradient(to bottom,
        transparent 0, #000 var(--fade-above),
        #000 calc(100% - var(--fade-below)), transparent 100%);
}

.trace-readout {
    margin: 10px 0 0;
    padding-top: 9px;
    border-top: 1px solid var(--line-soft);
    font-size: 11px;
    line-height: 1.55;
    color: var(--fg-2);
    letter-spacing: 0.02em;
}
/* The class lands on the readout itself, not on a child. */
.trace-readout.is-over { color: var(--warn); }
/* Drei Ausgänge statt zwei: der Import fragt Kurven oder Pixel, das
   Nachjustieren nur Übernehmen oder Abbrechen. `.pop-actions .btn` verteilt
   sie gleichmäßig, aber der primäre Ausgang darf nicht der schmalste sein. */
.pop-actions #btnTraceApply { flex: 1.4 1 auto; }
/* `.btn` ist `display: inline-flex`, was das `hidden`-Attribut überschreibt;
   ohne diese Zeile blitzt der Pixel-Ausgang im Nachjustier-Modus auf. */
.pop-actions .btn[hidden] { display: none; }

.scrim {
    position: fixed;
    inset: 0;
    z-index: 50;
    background: rgba(0, 0, 0, 0.4);
}
.scrim[hidden] { display: none; }

.menu {
    position: fixed;
    z-index: 60;
    min-width: 200px;
    padding: 5px;
    background: var(--bg-panel);
    border: 1px solid var(--line-hard);
    border-radius: var(--r);
    box-shadow: var(--shadow-pop);
}
.menu[hidden] { display: none; }
.menu button {
    display: flex;
    align-items: center;
    gap: 9px;
    width: 100%;
    height: 28px;
    padding: 0 9px;
    background: none;
    border: 0;
    border-radius: var(--r-sm);
    color: var(--fg);
    font-size: 12.5px;
    text-align: left;
    cursor: pointer;
}
.menu button:hover { background: var(--bg-hover); }
.menu button svg { width: 14px; height: 14px; color: var(--fg-3); flex: 0 0 auto; }
.menu button .sub { margin-left: auto; font-size: 10.5px; color: var(--fg-3); font-family: var(--font-mono); }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 5px 2px; }

/* --- toast --- */

.toasts {
    position: fixed;
    bottom: calc(var(--status-h) + 14px);
    left: 50%;
    transform: translateX(-50%);
    z-index: 70;
    display: flex;
    flex-direction: column;
    gap: 7px;
    align-items: center;
    pointer-events: none;
}
.toast {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 8px 14px;
    background: var(--bg-panel);
    border: 1px solid var(--line-hard);
    border-radius: 20px;
    box-shadow: var(--shadow-pop);
    font-size: 12.5px;
    animation: toast-in 0.2s ease;
}
.toast.is-err { border-color: color-mix(in srgb, var(--err) 55%, transparent); color: var(--err); }
.toast.is-ok::before {
    content: "";
    width: 6px; height: 6px; border-radius: 50%; background: var(--ok);
}
@keyframes toast-in {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: none; }
}

/* --- language switch --- */

.lang {
    display: flex;
    gap: 1px;
    background: var(--bg-sunken);
    border: 1px solid var(--line);
    border-radius: var(--r);
    padding: 2px;
}
.lang button {
    height: 22px;
    padding: 0 8px;
    background: none;
    border: 0;
    border-radius: 3px;
    color: var(--fg-3);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.04em;
    cursor: pointer;
}
.lang button:hover { color: var(--fg); }
.lang button[aria-pressed="true"] { background: var(--bg-active); color: var(--fg); }

/* =========================================================================
   Warnings list
   ========================================================================= */

.warnings { display: flex; flex-direction: column; gap: 7px; }
.warn-item {
    display: flex;
    gap: 8px;
    padding: 8px 10px;
    border-radius: var(--r);
    font-size: 11.5px;
    line-height: 1.45;
    background: var(--bg-sunken);
    border: 1px solid var(--line);
}
.warn-item svg { width: 14px; height: 14px; flex: 0 0 auto; margin-top: 1px; }
.warn-item.is-warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 30%, transparent); }
.warn-item.is-err  { color: var(--err);  border-color: color-mix(in srgb, var(--err) 32%, transparent); }
.warn-item.is-ok   { color: var(--fg-2); }

/* =========================================================================
   Responsive
   ========================================================================= */

.mobile-tabs { display: none; }

@media (max-width: 900px) {
    .app {
        grid-template-columns: 1fr;
        grid-template-areas:
            "topbar"
            "stage"
            "status";
    }
    .rail {
        position: fixed;
        inset: var(--topbar-h) 0 var(--status-h) 0;
        z-index: 40;
        border-right: 0;
        border-top: 1px solid var(--line);
    }
    body[data-panel="view"] .rail { display: none; }
    .mobile-tabs { display: flex; }
    .brand-name span { display: none; }
    .topbar { gap: 6px; padding: 0 8px; }
}

@media (max-width: 620px) {
    .brand { padding-right: 8px; }
    .brand-name b { display: none; }
    .hide-sm { display: none !important; }
}

@media (max-width: 560px) {
    #btnExport span { display: none; }
    #btnExport { width: 32px; padding: 0; }
    .stat { padding: 0 9px; }
    .vp-overlay { gap: 4px; }
}

.is-hidden { display: none !important; }
.sr-only {
    position: absolute;
    width: 1px; height: 1px;
    padding: 0; margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

/* =========================================================================
   Bundled typefaces
   One @font-face per bundled TTF, each under its own family name so there is
   no weight/style matching to get wrong. `font-display: swap` keeps the rail
   readable while a face downloads; the faces are only referenced by the font
   <select> and its preview strip, so nothing else blocks on them.
   Family names mirror the keys in js/fonts.js — verify.py checks the parity.
   ========================================================================= */

@font-face { font-family: 'sf-roboto_bold';      src: url('../fonts/Roboto-Bold.ttf') format('truetype'); font-display: swap; }
@font-face { font-family: 'sf-roboto';           src: url('../fonts/Roboto-Regular.ttf') format('truetype'); font-display: swap; }
@font-face { font-family: 'sf-open_sans_bold';   src: url('../fonts/OpenSans-Bold.ttf') format('truetype'); font-display: swap; }
@font-face { font-family: 'sf-open_sans';        src: url('../fonts/OpenSans-Regular.ttf') format('truetype'); font-display: swap; }
@font-face { font-family: 'sf-oswald_bold';      src: url('../fonts/Oswald-Bold.ttf') format('truetype'); font-display: swap; }
@font-face { font-family: 'sf-oswald';           src: url('../fonts/Oswald-Regular.ttf') format('truetype'); font-display: swap; }
@font-face { font-family: 'sf-roboto_mono';      src: url('../fonts/RobotoMono-Bold.ttf') format('truetype'); font-display: swap; }
@font-face { font-family: 'sf-montserrat_bold';  src: url('../fonts/Montserrat-Bold.ttf') format('truetype'); font-display: swap; }
@font-face { font-family: 'sf-bangers';          src: url('../fonts/Bangers-Regular.ttf') format('truetype'); font-display: swap; }
@font-face { font-family: 'sf-caveat_bold';      src: url('../fonts/Caveat-Bold.ttf') format('truetype'); font-display: swap; }
@font-face { font-family: 'sf-caveat';           src: url('../fonts/Caveat-Regular.ttf') format('truetype'); font-display: swap; }
@font-face { font-family: 'sf-pacifico';         src: url('../fonts/Pacifico-Regular.ttf') format('truetype'); font-display: swap; }
@font-face { font-family: 'sf-permanent_marker'; src: url('../fonts/PermanentMarker-Regular.ttf') format('truetype'); font-display: swap; }

/* =========================================================================
   Element card fields sit inside a two-column grid, so they carry no
   bottom margin of their own.
   ========================================================================= */

.el-grid .field-row { margin-bottom: 0; }
.el-grid .field-row .hint { margin-top: 6px; }

/* --- floating dimension tags over the viewport --- */

.dim-label {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 2;
    padding: 2px 6px;
    border-radius: 3px;
    background: color-mix(in srgb, var(--bg-panel) 85%, transparent);
    border: 1px solid var(--line);
    color: var(--fg-2);
    font-family: var(--font-mono);
    font-size: 10px;
    line-height: 1.35;
    letter-spacing: 0.02em;
    white-space: nowrap;
    pointer-events: none;
    transition: opacity 0.15s;
}

/* ============================ graphic import ============================== */
/* The step editor is where an imported picture is actually authored, so it gets
   the room and the contrast: a preview, the tone distribution it is cutting,
   and the stops sitting on that distribution rather than beside it. */

.grid-3 {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
}

.add-row {
    margin-top: 9px;
}

.img-source {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 9px;
    border: 1px dashed var(--line);
    border-radius: var(--r-sm);
    background: var(--bg-2);
    transition: border-color .12s ease, background .12s ease;
}

.img-source.is-over {
    border-color: var(--accent);
    background: var(--accent-wash);
}

.img-editor {
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 100%;
}

.img-preview {
    width: 100%;
    height: 132px;
    object-fit: contain;
    border: 1px solid var(--line);
    border-radius: var(--r-sm);
    background: var(--bg-2);
    /* Artwork is authored at pixel scale; smoothing it here would hide exactly
       the speckle the cull and the blur exist to remove. */
    image-rendering: pixelated;
}

.img-preview.is-empty {
    opacity: .35;
}

/* The histogram and the stop track share one box so a handle sits on the tone
   it selects, not merely near it. */
.img-levels {
    position: relative;
    height: 52px;
    border: 1px solid var(--line);
    border-radius: var(--r-sm);
    background: var(--bg-2);
    overflow: hidden;
}

.img-hist {
    position: absolute;
    inset: 0 0 8px 0;
    width: 100%;
    height: calc(100% - 8px);
    opacity: .55;
}

.img-track {
    position: absolute;
    inset: 0;
    touch-action: none;
}

.img-stop {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 3px;
    margin-left: -1.5px;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: var(--stop-color, var(--accent));
    cursor: ew-resize;
}

.img-stop::after {
    content: "";
    position: absolute;
    left: 50%;
    bottom: 0;
    width: 9px;
    height: 9px;
    margin-left: -4.5px;
    border: 1px solid var(--bg-1);
    border-radius: 2px;
    background: inherit;
}

.img-stop[aria-pressed="true"] {
    box-shadow: 0 0 0 1px var(--bg-1), 0 0 0 2px var(--accent);
}

.img-stops {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.img-stop-row {
    display: grid;
    grid-template-columns: 10px 1fr 1fr 28px 24px;
    gap: 5px;
    align-items: center;
}

.img-stop-row.is-selected .img-stop-chip {
    box-shadow: 0 0 0 2px var(--accent);
}

.img-stop-chip {
    width: 10px;
    height: 10px;
    border-radius: 2px;
    border: 1px solid var(--line);
}

.img-stop-row input[type="number"] {
    width: 100%;
    min-width: 0;
    padding: 3px 5px;
    border: 1px solid var(--line);
    border-radius: var(--r-sm);
    background: var(--bg-1);
    color: var(--ink-1);
    font: inherit;
    font-family: var(--mono);
    font-size: 11px;
}

.img-stop-color {
    width: 28px;
    height: 22px;
    padding: 0;
    border: 1px solid var(--line);
    border-radius: var(--r-sm);
    background: none;
    cursor: pointer;
}

.img-stop-drop {
    display: grid;
    place-items: center;
    width: 22px;
    height: 22px;
    padding: 0;
    border: 1px solid transparent;
    border-radius: var(--r-sm);
    background: none;
    color: var(--ink-3);
    cursor: pointer;
}

.img-stop-drop:hover:not(:disabled) {
    border-color: var(--line);
    color: var(--ink-1);
}

.img-stop-drop:disabled {
    opacity: .3;
    cursor: default;
}

.img-stop-drop svg {
    width: 12px;
    height: 12px;
}

.btn.is-quiet {
    padding: 3px 8px;
    font-size: 11px;
}

.img-count {
    display: flex;
    gap: 6px;
    align-items: center;
}

.img-count .num {
    flex: 1 1 auto;
    min-width: 0;
}

.img-count .btn.is-quiet {
    flex: 0 0 auto;
}

/* ------------------------------ qr element ------------------------------ */

/* The per-type fields nest inside the card's own two-column grid. */
.el-grid .qr-fields {
    grid-column: span 2;
    padding: 9px;
    border: 1px solid var(--line);
    border-radius: var(--r-sm);
    background: var(--bg-2);
}

.text-input.is-area {
    height: auto;
    min-height: 58px;
    padding: 6px 9px;
    line-height: 1.4;
    resize: vertical;
    font-family: inherit;
}

/* Always black on white whatever the theme: the preview is there to be
   scanned, and a scanner wants the textbook symbol. */
.qr-preview {
    display: block;
    width: 168px;
    max-width: 100%;
    aspect-ratio: 1;
    margin: 2px auto 6px;
    border-radius: var(--r-sm);
    background: #ffffff;
    image-rendering: pixelated;
}

.qr-preview.is-empty {
    opacity: .25;
}

.ht-preview {
    height: auto;
    max-height: 200px;
    background: #ffffff;
    image-rendering: auto;
}
