/* base.css - reset, typography and the UI kit components built by js/ui.js:
   buttons, icon buttons, inputs, selects, number fields, segmented controls, switches,
   sliders, tabs, form rows, menus, popovers, modals, toasts, tooltips, colour swatches,
   the colour and font pickers and the busy overlay.
   Colours, fonts, radii and shadows come only from tokens.css. Safety orange here: primary
   buttons are solid --accent with --on-accent text; switches (on), slider fills, progress
   bars and the default toast edge use --accent-line; the highlighter swipe (--swipe) marks
   pressed buttons and selected tabs. Focus rings stay --ink. */

/* ------------------------------------------------------------------ reset */

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

html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    height: 100%;
}

body {
    margin: 0;
    min-height: 100%;
    font-family: var(--font-ui);
    font-size: 14px;
    line-height: 1.45;
    color: var(--text);
    background: var(--desk);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
    -webkit-tap-highlight-color: transparent;
}

h1, h2, h3, h4, h5, h6, p, figure, blockquote, dl, dd, ul, ol { margin: 0; }
h1, h2, h3, h4, h5, h6 { font-size: inherit; font-weight: 600; }
ul[role="list"], ol[role="list"] { list-style: none; padding: 0; }
img, picture, video, canvas, svg { display: block; }
table { border-collapse: collapse; }

input, button, textarea, select {
    font: inherit;
    color: inherit;
    letter-spacing: inherit;
}
button {
    margin: 0;
    padding: 0;
    border: 0;
    background: none;
    cursor: pointer;
    touch-action: manipulation;
}
button:disabled { cursor: default; }
a { color: var(--ink); text-underline-offset: 2px; }
a:hover { color: var(--ink-hover); text-decoration-color: var(--accent-line); }
kbd, code, pre, samp { font-family: var(--font-mono); }

[hidden] { display: none !important; }

:focus:not(:focus-visible) { outline: none; }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

::selection { background: var(--marker-soft); color: inherit; }

/* Thin, themed scrollbars. */
* { scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track, ::-webkit-scrollbar-corner { background: transparent; }
::-webkit-scrollbar-thumb {
    background-color: var(--line-strong);
    background-clip: padding-box;
    border: 3px solid transparent;
    border-radius: var(--pill);
}
::-webkit-scrollbar-thumb:hover { background-color: var(--text-3); }

/* Theme switches happen without every transition animating (ui.applyTheme). */
.ui-no-transitions *, .ui-no-transitions *::before, .ui-no-transitions *::after { transition: none !important; }

/* Screen-reader-only text. */
.sr-only {
    position: absolute !important;
    width: 1px; height: 1px;
    margin: -1px; padding: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
}

.icon { flex: none; }

/* ------------------------------------------------------------------ buttons */

.btn {
    --btn-h: 34px;
    position: relative;
    isolation: isolate;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    height: var(--btn-h);
    min-width: var(--btn-h);
    padding: 0 12px;
    border: 1px solid transparent;
    border-radius: var(--radius-s);
    background: transparent;
    color: var(--text);
    font-size: var(--fs-m);
    font-weight: 500;
    line-height: 1;
    white-space: nowrap;
    user-select: none;
    -webkit-user-select: none;
    transition: background-color var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease),
                color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
.btn.sm { --btn-h: 32px; padding: 0 10px; font-size: var(--fs-s); gap: 5px; }
.btn.icon-only { padding: 0; }
.btn-label { overflow: hidden; text-overflow: ellipsis; }
.btn-icon-end { opacity: 0.75; margin-left: -2px; }

/* ghost: text only (the default) */
.btn:not(.primary):not(.subtle):not(.outline):not(.danger):hover { background: var(--surface-3); }

/* subtle: filled inset */
.btn.subtle { background: var(--surface-2); border-color: var(--line); }
.btn.subtle:hover { background: var(--surface-3); }

/* outline */
.btn.outline { background: var(--surface); border-color: var(--line-strong); }
.btn.outline:hover { background: var(--surface-2); border-color: var(--text-3); }

/* primary: safety orange with near-black text (7:1), in both themes */
.btn.primary {
    background: var(--accent);
    color: var(--on-accent);
    font-weight: 600;
    box-shadow: var(--shadow-1), inset 0 -1px 0 rgba(0, 0, 0, 0.1);
}
.btn.primary:hover { background: var(--accent-hover); }
.btn.primary:active:not(:disabled) { background: var(--accent-press); }

/* danger: proof red, destructive actions only */
.btn.danger {
    background: var(--red);
    color: var(--text-on-ink);
    box-shadow: var(--shadow-1);
}
.btn.danger:hover { background: color-mix(in srgb, var(--red) 88%, var(--text)); }

.btn:active:not(:disabled) { transform: translateY(0.5px); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.45; pointer-events: none; box-shadow: none; }
/* a disabled primary turns neutral grey rather than a washed-out orange; it lights up when ready */
.btn.primary:disabled, .btn.primary[aria-disabled="true"] { opacity: 1; background: var(--surface-3); color: var(--text-3); }
.btn[aria-busy="true"] { cursor: progress; opacity: 0.75; }

/* Icon-only square button (toolbars, panels). */
.icon-btn {
    position: relative;
    isolation: isolate;
    display: inline-grid;
    place-items: center;
    flex: none;
    width: 34px;
    height: 34px;
    border-radius: var(--radius-s);
    color: var(--text-2);
    transition: background-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.icon-btn.sm { width: 32px; height: 32px; }
.icon-btn:hover { background: var(--surface-3); color: var(--text); }
.icon-btn:active:not(:disabled) .icon { transform: translateY(0.5px); }
.icon-btn:disabled, .icon-btn[aria-disabled="true"] { opacity: 0.4; pointer-events: none; }
.icon-btn.danger:hover { background: var(--red-soft); color: var(--red); }
.icon-btn.primary { background: var(--accent); color: var(--on-accent); }
.icon-btn.primary:hover { background: var(--accent-hover); color: var(--on-accent); }
.icon-btn.primary:active:not(:disabled) { background: var(--accent-press); }

/* Active / pressed state = the highlighter swipe: a marker stroke across the lower half,
   slightly skewed so it reads as drawn by hand. */
.btn[aria-pressed="true"], .btn.active,
.icon-btn[aria-pressed="true"], .icon-btn.active {
    color: var(--text);
    background: transparent;
}
.btn[aria-pressed="true"]::before, .btn.active::before,
.icon-btn[aria-pressed="true"]::before, .icon-btn.active::before {
    content: "";
    position: absolute;
    z-index: -1;
    inset: 4px 5px 3px;
    background: var(--swipe);
    border-radius: 3px 6px 2px 7px;
    transform: skewX(-14deg) rotate(-2deg);
    pointer-events: none;
}
.icon-btn[aria-pressed="true"]::before, .icon-btn.active::before { inset: 5px 6px 4px; }
.btn[aria-pressed="true"]:hover, .btn.active:hover,
.icon-btn[aria-pressed="true"]:hover, .icon-btn.active:hover { background: var(--surface-3); }

/* ------------------------------------------------------------------ inputs */

.input, select.select, .num, .font-picker {
    height: 34px;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-s);
    background: var(--surface-2);
    color: var(--text);
    font-size: var(--fs-m);
    transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease),
                background-color var(--dur-fast) var(--ease);
}
.input { width: 100%; min-width: 0; padding: 0 10px; }
textarea.input {
    height: auto;
    min-height: 76px;
    padding: 8px 10px;
    line-height: 1.45;
    resize: vertical;
}
.input::placeholder { color: var(--text-3); opacity: 1; }
.input:hover, select.select:hover, .num:hover, .font-picker:hover { border-color: var(--text-3); }
.input:focus, select.select:focus, .num:focus-within, .font-picker[aria-expanded="true"] {
    outline: none;
    border-color: var(--ink);
    box-shadow: 0 0 0 1px var(--ink);
    background: var(--surface);
}
.input:disabled, select.select:disabled { opacity: 0.5; cursor: not-allowed; }
.input[aria-invalid="true"] { border-color: var(--red); }
.input[aria-invalid="true"]:focus { box-shadow: 0 0 0 1px var(--red); }
input[type="search"].input::-webkit-search-decoration { -webkit-appearance: none; }

/* Input with a trailing icon button (password reveal). */
.input-group { position: relative; display: flex; width: 100%; min-width: 0; }
.input-group .input { padding-right: 40px; }
.input-group .input-reveal { position: absolute; top: 1px; right: 1px; height: 32px; width: 36px; }

/* Native select with a drawn caret. */
select.select {
    appearance: none;
    -webkit-appearance: none;
    min-width: 0;
    padding: 0 30px 0 10px;
    cursor: pointer;
    background-image:
        linear-gradient(45deg, transparent 50%, var(--text-2) 50%),
        linear-gradient(135deg, var(--text-2) 50%, transparent 50%);
    background-position: calc(100% - 15px) 52%, calc(100% - 10px) 52%;
    background-size: 5px 5px, 5px 5px;
    background-repeat: no-repeat;
    text-overflow: ellipsis;
}
select.select option, select.select optgroup { background: var(--surface); color: var(--text); }

/* Number field with unit suffix. */
.num {
    display: inline-flex;
    align-items: center;
    width: 96px;
    min-width: 0;
    padding: 0;
    cursor: text;
}
.num-input {
    flex: 1;
    width: 100%;
    min-width: 0;
    height: 100%;
    padding: 0 8px;
    border: 0;
    background: transparent;
    outline: none;
    font-family: var(--font-mono);
    font-size: 13px;
    font-variant-numeric: tabular-nums;
}
.num-input::placeholder { color: var(--text-3); }
.num-unit {
    flex: none;
    padding-right: 8px;
    color: var(--text-3);
    font-family: var(--font-mono);
    font-size: var(--fs-xs);
    user-select: none;
}
.num.is-disabled { opacity: 0.5; pointer-events: none; }

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

.seg {
    display: inline-flex;
    gap: 2px;
    padding: 2px;
    border: 1px solid var(--line);
    border-radius: calc(var(--radius-s) + 2px);
    background: var(--surface-2);
    max-width: 100%;
}
.seg-btn {
    flex: 1 1 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-width: 32px;
    height: 28px;
    padding: 0 10px;
    border-radius: var(--radius-s);
    color: var(--text-2);
    font-size: var(--fs-s);
    font-weight: 500;
    white-space: nowrap;
    transition: background-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease),
                box-shadow var(--dur-fast) var(--ease);
}
.seg-btn.icon-only { padding: 0 6px; }
.seg-btn:hover { color: var(--text); background: var(--surface-3); }
.seg-btn[aria-checked="true"] {
    background: var(--surface);
    color: var(--ink);
    box-shadow: var(--shadow-1), 0 0 0 1px var(--line);
}
:root[data-theme="dark"] .seg-btn[aria-checked="true"] { background: var(--surface-3); }
.seg-btn:disabled { opacity: 0.4; }
.seg.sm .seg-btn { height: 26px; padding: 0 8px; }
.seg-label { overflow: hidden; text-overflow: ellipsis; }

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

.switch {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 10px;
    min-height: 32px;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
}
.switch-input {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: 0;
    opacity: 0;
    pointer-events: none;
}
.switch-track {
    position: relative;
    flex: none;
    width: 34px;
    height: 20px;
    border-radius: var(--pill);
    background: var(--line-strong);
    transition: background-color var(--dur-fast) var(--ease);
}
.switch-thumb {
    position: absolute;
    top: 2px;
    left: 2px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--paper);
    box-shadow: var(--shadow-1);
    transition: transform var(--dur) var(--ease);
}
.switch:hover .switch-track { background: var(--text-3); }
.switch-input:checked + .switch-track { background: var(--accent-line); }
.switch-input:checked + .switch-track .switch-thumb { transform: translateX(14px); }
.switch-input:focus-visible + .switch-track { outline: 2px solid var(--ink); outline-offset: 2px; }
.switch-input:disabled + .switch-track { opacity: 0.45; }
.switch:has(.switch-input:disabled) { cursor: default; }
.switch-label { color: var(--text); font-size: var(--fs-m); }

/* ------------------------------------------------------------------ slider */

.slider {
    --fill: 50%;
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 32px;
    min-width: 0;
}
.slider-input {
    flex: 1;
    min-width: 60px;
    height: 22px;
    margin: 0;
    background: transparent;
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
}
.slider-input:focus-visible { outline: none; }
.slider-input:disabled { opacity: 0.45; cursor: default; }
.slider-input::-webkit-slider-runnable-track {
    height: 4px;
    border-radius: var(--pill);
    background: linear-gradient(to right, var(--accent-line) var(--fill), var(--line-strong) var(--fill));
}
.slider-input::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    margin-top: -6px;
    border: 2px solid var(--accent-line);
    border-radius: 50%;
    background: var(--paper);
    box-shadow: var(--shadow-1);
    transition: transform var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
.slider-input:active::-webkit-slider-thumb { transform: scale(1.12); }
.slider-input:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--ink); }
.slider-input::-moz-range-track { height: 4px; border-radius: var(--pill); background: var(--line-strong); }
.slider-input::-moz-range-progress { height: 4px; border-radius: var(--pill); background: var(--accent-line); }
.slider-input::-moz-range-thumb {
    width: 12px;
    height: 12px;
    border: 2px solid var(--accent-line);
    border-radius: 50%;
    background: var(--paper);
    box-shadow: var(--shadow-1);
}
.slider-input:focus-visible::-moz-range-thumb { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--ink); }
.slider-value {
    flex: none;
    min-width: 3.5em;
    text-align: right;
    color: var(--text-2);
    font-family: var(--font-mono);
    font-size: var(--fs-s);
    font-variant-numeric: tabular-nums;
}

/* ------------------------------------------------------------------ tabs */

.tabs {
    display: flex;
    gap: 2px;
    border-bottom: 1px solid var(--line);
    overflow-x: auto;
    scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
    position: relative;
    isolation: isolate;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    flex: none;
    height: 36px;
    padding: 0 10px;
    color: var(--text-2);
    font-size: var(--fs-s);
    font-weight: 500;
    white-space: nowrap;
    border-radius: var(--radius-s) var(--radius-s) 0 0;
    transition: color var(--dur-fast) var(--ease), background-color var(--dur-fast) var(--ease);
}
.tab.icon-only { padding: 0 9px; }
.tab:hover { color: var(--text); background: var(--surface-2); }
.tab[aria-selected="true"] { color: var(--text); }
.tab[aria-selected="true"]::before {
    content: "";
    position: absolute;
    z-index: -1;
    inset: 7px 5px 5px;
    background: var(--swipe);
    border-radius: 3px 6px 2px 7px;
    transform: skewX(-14deg) rotate(-2deg);
    pointer-events: none;
}
.tab:focus-visible { outline-offset: -2px; }

/* ------------------------------------------------------------------ form rows */

.field { display: grid; gap: 6px; min-width: 0; }
.field-label { color: var(--text-2); font-size: var(--fs-s); font-weight: 500; line-height: 1.3; }
.field-control { display: flex; align-items: center; gap: 8px; min-width: 0; }
.field-control > .input, .field-control > select.select,
.field-control > .font-picker, .field-control > .input-group, .field-control > .slider { flex: 1; min-width: 0; }
.field-hint { color: var(--text-3); font-size: var(--fs-xs); line-height: 1.4; }
.field-error { color: var(--red); font-size: var(--fs-s); line-height: 1.4; }
.field.inline {
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    column-gap: 12px;
}
.field.inline .field-hint, .field.inline .field-error { grid-column: 1 / -1; }

/* ------------------------------------------------------------------ overlay root */

/* A viewport-sized layer above the app; only its children take pointer events.
   Children stack in DOM order (newest on top); toasts and tooltips always sit above. */
#overlay-root {
    position: fixed;
    inset: 0;
    z-index: 1000;
    pointer-events: none;
}
#overlay-root > * { pointer-events: auto; }
.ui-floating { position: absolute; }

/* ------------------------------------------------------------------ menus & popovers */

.menu, .popover {
    max-width: calc(100vw - 16px);
    overflow: auto;
    overscroll-behavior: contain;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow-pop);
    animation: ui-pop var(--dur-fast) var(--ease);
}
.ui-floating[data-side="top"] { animation-name: ui-pop-up; }
.ui-floating[data-side="left"] { animation-name: ui-pop-left; }
.ui-floating[data-side="right"] { animation-name: ui-pop-right; }
.menu:focus, .popover:focus { outline: none; }

.menu {
    display: flex;
    flex-direction: column;
    min-width: 208px;
    padding: 4px;
}
.menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: none;
    width: 100%;
    min-height: 32px;
    padding: 6px 10px;
    border-radius: var(--radius-s);
    color: var(--text);
    font-size: var(--fs-m);
    line-height: 1.25;
    text-align: left;
}
.menu-item:hover, .menu-item:focus { outline: none; background: var(--surface-3); }
.menu-item:focus-visible { box-shadow: inset 0 0 0 1px var(--ink-line); }
.menu-item[aria-disabled="true"] { color: var(--text-3); cursor: default; background: none; box-shadow: none; }
.menu-item.danger { color: var(--red); }
.menu-item.danger:hover, .menu-item.danger:focus { background: var(--red-soft); }
.menu-check, .menu-icon {
    display: grid;
    place-items: center;
    flex: none;
    width: 16px;
    height: 16px;
    color: var(--text-2);
}
.menu-check { color: var(--ink); }
.menu-item.danger .menu-icon, .menu-item[aria-disabled="true"] .menu-icon { color: inherit; }
.menu-text { display: flex; flex-direction: column; gap: 1px; flex: 1; min-width: 0; }
.menu-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu-hint { color: var(--text-3); font-size: var(--fs-xs); line-height: 1.35; white-space: normal; }
.menu-key {
    flex: none;
    margin-left: 16px;
    color: var(--text-3);
    font-family: var(--font-mono);
    font-size: var(--fs-xs);
    letter-spacing: 0.02em;
}
.menu-sep { flex: none; height: 1px; margin: 4px 6px; background: var(--line); }
.menu-heading {
    flex: none;
    padding: 8px 10px 4px;
    color: var(--text-3);
    font-size: var(--fs-xs);
    font-weight: 600;
    letter-spacing: 0.02em;
}

.popover { min-width: 200px; padding: 12px; }
.popover-text { color: var(--text-2); }

/* ------------------------------------------------------------------ colour swatch & picker */

.swatch {
    display: inline-grid;
    place-items: center;
    flex: none;
    width: 34px;
    height: 34px;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-s);
    background: var(--surface-2);
    transition: border-color var(--dur-fast) var(--ease);
}
.swatch:hover { border-color: var(--text-3); }
.swatch[aria-expanded="true"] { border-color: var(--ink); box-shadow: 0 0 0 1px var(--ink); }
.swatch:disabled { opacity: 0.45; }
.swatch-chip {
    position: relative;
    display: block;
    width: 20px;
    height: 20px;
    overflow: hidden;
    border-radius: var(--radius-xs);
    background: var(--c, transparent);
    box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--text) 18%, transparent);
}
/* "No colour": checkerboard with a slash. */
.swatch-chip.is-none {
    background-color: var(--surface);
    background-image:
        linear-gradient(45deg, var(--line) 25%, transparent 25%, transparent 75%, var(--line) 75%),
        linear-gradient(45deg, var(--line) 25%, transparent 25%, transparent 75%, var(--line) 75%);
    background-size: 8px 8px;
    background-position: 0 0, 4px 4px;
}
.swatch-chip.is-none::after {
    content: "";
    position: absolute;
    left: calc(50% - 0.75px);
    top: -25%;
    width: 1.5px;
    height: 150%;
    background: var(--text-2);
    transform: rotate(45deg);
}

.cp { width: 240px; padding: 10px; display: grid; gap: 12px; }
.cp-section { display: grid; gap: 6px; }
.cp-label { color: var(--text-3); font-size: var(--fs-xs); font-weight: 600; }
.swatch-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
.swatch-cell {
    width: 100%;
    aspect-ratio: 1;
    border-radius: var(--radius-s);
    background: var(--c);
    box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--text) 10%, transparent);
    transition: transform var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
.swatch-cell.is-light { box-shadow: inset 0 0 0 1px var(--line-strong); }
.swatch-cell:hover { transform: scale(1.08); }
.swatch-cell[aria-pressed="true"] { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--ink); }
.cp-row { display: flex; align-items: center; gap: 4px; }
.cp-hex {
    display: flex;
    align-items: center;
    flex: 1;
    min-width: 0;
    height: 32px;
    padding: 0 8px;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-s);
    background: var(--surface-2);
    font-family: var(--font-mono);
    font-size: 13px;
    cursor: text;
}
.cp-hex:focus-within { border-color: var(--ink); box-shadow: 0 0 0 1px var(--ink); background: var(--surface); }
.cp-hex:has([aria-invalid="true"]) { border-color: var(--red); box-shadow: 0 0 0 1px var(--red); }
.cp-hash { color: var(--text-3); user-select: none; }
.cp-hex-input {
    flex: 1;
    width: 100%;
    min-width: 0;
    padding: 0 0 0 2px;
    border: 0;
    outline: none;
    background: transparent;
    text-transform: uppercase;
}
.cp-hex-input::placeholder { color: var(--text-3); text-transform: none; }
.cp-native { position: relative; display: inline-flex; }
.cp-native-input {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    padding: 0;
    border: 0;
    opacity: 0;
    pointer-events: none;
}
.cp-none {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    flex: none;
    height: 32px;
    padding: 0 8px;
    border-radius: var(--radius-s);
    color: var(--text-2);
    font-size: var(--fs-s);
}
.cp-none:hover { background: var(--surface-3); color: var(--text); }
.cp-none[aria-pressed="true"] { color: var(--text); box-shadow: inset 0 0 0 1px var(--ink); }
.cp-none .swatch-chip { width: 16px; height: 16px; }

/* ------------------------------------------------------------------ font picker */

.font-picker {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    max-width: 100%;
    padding: 0 8px 0 10px;
    text-align: left;
}
.font-picker:disabled { opacity: 0.5; }
.font-picker-name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 15px;
    line-height: 1.2;
}
.font-picker-caret { color: var(--text-3); }

.fp-popover {
    display: flex;
    flex-direction: column;
    width: 290px;
    max-height: min(440px, calc(100vh - 16px));
    padding: 0;
    overflow: hidden;
}
.fp { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.fp-search { flex: none; width: auto; margin: 8px; }
.fp-list {
    flex: 1;
    min-height: 0;
    padding-bottom: 6px;
    overflow-y: auto;
    overscroll-behavior: contain;
    border-top: 1px solid var(--line);
}
.fp-list:focus { outline: none; }
.fp-group-label {
    position: sticky;
    top: 0;
    z-index: 1;
    padding: 8px 12px 4px;
    background: var(--surface);
    color: var(--text-3);
    font-size: var(--fs-xs);
    font-weight: 600;
    letter-spacing: 0.02em;
}
.fp-option {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 36px;
    padding: 4px 12px;
    color: var(--text);
    cursor: pointer;
}
.fp-option.is-active { background: var(--surface-3); }
.fp-list:focus-visible .fp-option.is-active, .fp-search:focus-visible ~ .fp-list .fp-option.is-active {
    box-shadow: inset 2px 0 0 var(--ink);
}
.fp-option[aria-selected="true"] { color: var(--ink); }
.fp-name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 16px;
    line-height: 1.35;
}
.fp-check { color: var(--ink); }
.fp-empty { padding: 16px 12px; color: var(--text-3); font-size: var(--fs-s); }

/* ------------------------------------------------------------------ modals */

.modal-backdrop {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    padding: 16px;
    overflow-y: auto;
    background: color-mix(in srgb, var(--text) 35%, transparent);
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
    animation: ui-fade var(--dur) var(--ease);
}
/* In dark mode --text is light: dim with the desk colour instead. */
:root[data-theme="dark"] .modal-backdrop { background: color-mix(in srgb, var(--desk) 72%, transparent); }

.modal {
    display: flex;
    flex-direction: column;
    width: min(var(--modal-w, 440px), 100%);
    max-height: calc(100dvh - 32px);
    overflow: hidden;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-l);
    box-shadow: var(--shadow-pop);
    animation: ui-rise var(--dur) var(--ease);
}
.modal:focus { outline: none; }
.modal-head {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: none;
    padding: 18px 16px 4px 24px;
}
.modal-title {
    flex: 1;
    min-width: 0;
    color: var(--text);
    font-family: var(--font-display);
    font-size: var(--fs-xl);
    font-weight: 700;
    line-height: 1.2;
    letter-spacing: -0.01em;
}
.modal-title-spacer { flex: 1; }
.modal-close { color: var(--text-3); }
.modal-body {
    flex: 1 1 auto;
    min-height: 0;
    padding: 10px 24px 18px;
    overflow-y: auto;
    overscroll-behavior: contain;
}
.modal-text { color: var(--text-2); line-height: 1.5; }
.modal-text + .modal-text { margin-top: 8px; }
.modal-body > .field + .field { margin-top: 14px; }
.modal-foot {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 8px;
    flex: none;
    padding: 12px 24px 20px;
}
.modal.is-pending { cursor: progress; }
.modal.is-pending .modal-foot .btn { pointer-events: none; }

/* Phones: dialogs become full-screen sheets; short questions become bottom sheets. */
@media (max-width: 519.98px) {
    .modal-backdrop { padding: 0; place-items: stretch; }
    .modal {
        width: 100%;
        height: 100%;
        max-height: none;
        border: 0;
        border-radius: 0;
        animation-name: ui-sheet;
        padding-top: env(safe-area-inset-top, 0px);
        padding-bottom: env(safe-area-inset-bottom, 0px);
    }
    .modal-backdrop:has(> .modal-confirm), .modal-backdrop:has(> .modal-prompt) { place-items: end stretch; }
    .modal.modal-confirm, .modal.modal-prompt {
        height: auto;
        max-height: 100%;
        border-top: 1px solid var(--line);
        border-radius: var(--radius-l) var(--radius-l) 0 0;
    }
    .modal-head { padding: 16px 12px 4px 20px; }
    .modal-body { padding: 10px 20px 16px; }
    .modal-foot { padding: 12px 20px 16px; }
    .modal-foot .btn { flex: 1 1 0; }
}

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

.toast-stack {
    position: absolute;
    z-index: 20;
    left: 50%;
    bottom: calc(var(--status-h) + 12px + env(safe-area-inset-bottom, 0px));
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    width: max-content;
    max-width: calc(100vw - 24px);
    transform: translateX(-50%);
}
#overlay-root > .toast-stack { pointer-events: none; }
body[data-view="start"] .toast-stack { bottom: calc(20px + env(safe-area-inset-bottom, 0px)); }
.toast {
    --toast-accent: var(--accent-line);
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 44px;
    max-width: min(520px, calc(100vw - 24px));
    padding: 5px 5px 5px 12px;
    border: 1px solid var(--line);
    border-left: 3px solid var(--toast-accent);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    box-shadow: var(--shadow-pop);
    pointer-events: auto;
    animation: ui-toast-in var(--dur) var(--ease);
}
.toast-success { --toast-accent: var(--green); }
.toast-warn { --toast-accent: var(--amber); }
.toast-error { --toast-accent: var(--red); }
.toast-icon { display: grid; flex: none; color: var(--toast-accent); }
.toast-msg { flex: 1; min-width: 0; padding: 4px 0; font-size: var(--fs-m); line-height: 1.4; overflow-wrap: anywhere; }
.toast-action { flex: none; color: var(--ink); font-weight: 600; }
.toast-close { flex: none; color: var(--text-3); }
.toast.is-bump { animation: ui-bump 280ms var(--ease); }
.toast.is-leaving {
    opacity: 0;
    transform: translateY(6px);
    pointer-events: none;
    transition: opacity 160ms var(--ease), transform 160ms var(--ease);
}

/* ------------------------------------------------------------------ tooltips */

.tip {
    position: absolute;
    z-index: 30;
    display: flex;
    align-items: center;
    gap: 8px;
    max-width: min(280px, calc(100vw - 16px));
    padding: 5px 8px;
    border-radius: var(--radius-s);
    background: var(--text);
    color: var(--surface);
    box-shadow: var(--shadow-1);
    font-size: var(--fs-s);
    font-weight: 500;
    line-height: 1.3;
    animation: ui-fade var(--dur-fast) var(--ease);
}
#overlay-root > .tip { pointer-events: none; }
.tip-key {
    flex: none;
    padding: 1px 5px;
    border-radius: var(--radius-xs);
    background: color-mix(in srgb, var(--surface) 18%, transparent);
    font-family: var(--font-mono);
    font-size: var(--fs-xs);
    font-weight: 500;
    white-space: nowrap;
}

/* ------------------------------------------------------------------ busy overlay */

.busy {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    padding: 16px;
    background: color-mix(in srgb, var(--desk) 55%, transparent);
    -webkit-backdrop-filter: blur(1.5px);
    backdrop-filter: blur(1.5px);
    cursor: progress;
    /* Appear only if the job takes a moment, so quick ones do not flash. */
    animation: ui-fade var(--dur) var(--ease) 150ms both;
}
.busy-card {
    display: grid;
    gap: 12px;
    width: min(360px, 100%);
    padding: 18px 20px 20px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow-pop);
}
.busy-card:focus { outline: none; }
.busy-head { display: flex; align-items: baseline; gap: 12px; }
.busy-label { flex: 1; min-width: 0; color: var(--text); font-weight: 500; }
.busy-pct { flex: none; color: var(--text-2); font-family: var(--font-mono); font-size: var(--fs-s); font-variant-numeric: tabular-nums; }
.busy-bar {
    position: relative;
    height: 4px;
    overflow: hidden;
    border-radius: var(--pill);
    background: var(--accent-soft);
}
.busy-fill {
    width: 0;
    height: 100%;
    border-radius: inherit;
    background: var(--accent-line);
    transition: width var(--dur) var(--ease);
}
.busy-bar.is-indeterminate .busy-fill {
    position: absolute;
    top: 0;
    left: -36%;
    width: 36%;
    transition: none;
    animation: ui-indeterminate 1.1s ease-in-out infinite;
}

/* ------------------------------------------------------------------ touch */

@media (pointer: coarse) {
    .btn { --btn-h: 40px; }
    .btn.sm { --btn-h: 36px; }
    .icon-btn { width: 40px; height: 40px; }
    .icon-btn.sm { width: 36px; height: 36px; }
    .swatch { width: 40px; height: 40px; }
    .menu-item { min-height: 42px; }
    .input, select.select, .num, .font-picker { height: 40px; }
    /* 16px stops iOS zooming into focused fields. */
    .input, select.select, .num-input, .cp-hex { font-size: 16px; }
    .seg-btn { height: 34px; }
    .tab { height: 42px; }
    .fp-option { min-height: 44px; }
    .slider-input { height: 32px; }
    .slider-input::-webkit-slider-thumb { width: 22px; height: 22px; margin-top: -9px; }
    .slider-input::-moz-range-thumb { width: 18px; height: 18px; }
    .switch-track { width: 40px; height: 24px; }
    .switch-thumb { width: 20px; height: 20px; }
    .switch-input:checked + .switch-track .switch-thumb { transform: translateX(16px); }
}

/* ------------------------------------------------------------------ motion */

@keyframes ui-fade { from { opacity: 0; } }
@keyframes ui-pop { from { opacity: 0; transform: translateY(-4px) scale(0.98); } }
@keyframes ui-pop-up { from { opacity: 0; transform: translateY(4px) scale(0.98); } }
@keyframes ui-pop-left { from { opacity: 0; transform: translateX(4px) scale(0.98); } }
@keyframes ui-pop-right { from { opacity: 0; transform: translateX(-4px) scale(0.98); } }
@keyframes ui-rise { from { opacity: 0; transform: translateY(8px) scale(0.985); } }
@keyframes ui-sheet { from { opacity: 0; transform: translateY(24px); } }
@keyframes ui-toast-in { from { opacity: 0; transform: translateY(8px); } }
@keyframes ui-bump { 40% { transform: translateY(-3px); } }
@keyframes ui-indeterminate { from { left: -36%; } to { left: 100%; } }

@media (prefers-reduced-motion: reduce) {
    .busy-bar.is-indeterminate .busy-fill { animation-duration: 2.4s; }
    .toast.is-bump { animation: none; }
    .swatch-cell:hover { transform: none; }
}
