*,
*::before,
*::after
{
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    border: 0;
    border-radius: 0;
}

:root
{
    --bg: #ffffff;
    --fg: #000000;
    --panel: #f3f3f3;
    --band: #e4e4e4;
    --field: #ececec;
    --field-hover: #dedede;
    --field-focus: #ffffff;
    --muted: #5a5a5a;
    --faint: #a3a3a3;
    --primary-hover: #2e2e2e;
    --chrome: #000000;
    --chrome-fg: #ffffff;
    --chrome-muted: #a6a6a6;
    --chrome-hover: #262626;
    --chrome-field: #1c1c1c;
    --chrome-line: #3a3a3a;
    --chrome-primary-hover: #d9d9d9;
    --stage: #e6e6e6;
    --cv-bed: #d4d4d4;
    --cv-grid-minor: #c7c7c7;
    --cv-grid-major: #adadad;
    --cv-label: #6f6f6f;
    --cv-paper: #ffffff;
    --cv-margin: #bdbdbd;
    --cv-ink: #000000;
    --cv-ghost: #b3b3b3;
    --cv-travel: #8c8c8c;
    --cv-select: #000000;
    --cv-handle: #ffffff;
    --cv-warn: #000000;
    --font-ui: 'IBM Plex Mono', ui-monospace, Consolas, 'SFMono-Regular', Menlo, monospace;
    --font-mono: 'IBM Plex Mono', ui-monospace, Consolas, 'SFMono-Regular', Menlo, monospace;
    color-scheme: light;
}

@media (prefers-color-scheme: dark)
{
    :root:not([data-theme="light"])
    {
        --bg: #0a0a0a;
        --fg: #f5f5f5;
        --panel: #161616;
        --band: #262626;
        --field: #1f1f1f;
        --field-hover: #2b2b2b;
        --field-focus: #000000;
        --muted: #a3a3a3;
        --faint: #5c5c5c;
        --primary-hover: #d4d4d4;
        --chrome: #f2f2f2;
        --chrome-fg: #000000;
        --chrome-muted: #5c5c5c;
        --chrome-hover: #d9d9d9;
        --chrome-field: #e3e3e3;
        --chrome-line: #bdbdbd;
        --chrome-primary-hover: #2a2a2a;
        --stage: #050505;
        --cv-bed: #1f1f1f;
        --cv-grid-minor: #292929;
        --cv-grid-major: #3a3a3a;
        --cv-label: #858585;
        --cv-paper: #303030;
        --cv-margin: #4a4a4a;
        --cv-ink: #ffffff;
        --cv-ghost: #4d4d4d;
        --cv-travel: #7a7a7a;
        --cv-select: #ffffff;
        --cv-handle: #000000;
        --cv-warn: #ffffff;
        color-scheme: dark;
    }
}

:root[data-theme="dark"]
{
    --bg: #0a0a0a;
    --fg: #f5f5f5;
    --panel: #161616;
    --band: #262626;
    --field: #1f1f1f;
    --field-hover: #2b2b2b;
    --field-focus: #000000;
    --muted: #a3a3a3;
    --faint: #5c5c5c;
    --primary-hover: #d4d4d4;
    --chrome: #f2f2f2;
    --chrome-fg: #000000;
    --chrome-muted: #5c5c5c;
    --chrome-hover: #d9d9d9;
    --chrome-field: #e3e3e3;
    --chrome-line: #bdbdbd;
    --chrome-primary-hover: #2a2a2a;
    --stage: #050505;
    --cv-bed: #1f1f1f;
    --cv-grid-minor: #292929;
    --cv-grid-major: #3a3a3a;
    --cv-label: #858585;
    --cv-paper: #303030;
    --cv-margin: #4a4a4a;
    --cv-ink: #ffffff;
    --cv-ghost: #4d4d4d;
    --cv-travel: #7a7a7a;
    --cv-select: #ffffff;
    --cv-handle: #000000;
    --cv-warn: #ffffff;
    color-scheme: dark;
}

:focus,
:focus-visible
{
    outline: 0;
}

[hidden]
{
    display: none !important;
}

html,
body
{
    height: 100%;
}

body
{
    background: var(--bg);
    color: var(--fg);
    font-family: var(--font-ui);
    font-size: 12.5px;
    line-height: 1.45;
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
}

h1,
h2,
h3,
h4
{
    font-weight: 600;
    font-size: inherit;
}

button,
input,
select,
textarea
{
    font: inherit;
    color: inherit;
    background: none;
    outline: 0;
}

button
{
    cursor: pointer;
}

button:disabled
{
    cursor: not-allowed;
    opacity: 0.35;
}

.icon
{
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    flex: none;
    user-select: none;
    pointer-events: none;
}

.icon svg
{
    display: block;
    width: 100%;
    height: 100%;
    fill: currentColor;
}

#icon-sprite
{
    position: absolute;
    width: 0;
    height: 0;
    overflow: hidden;
}

.btn
{
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    height: 32px;
    padding: 0 12px;
    background: var(--field);
    color: var(--fg);
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
    user-select: none;
}

.btn .icon
{
    width: 20px;
    height: 20px;
    margin-left: -2px;
}

.btn:hover:not(:disabled)
{
    background: var(--field-hover);
}

.btn.primary
{
    background: var(--fg);
    color: var(--bg);
}

.btn.primary:hover:not(:disabled)
{
    background: var(--primary-hover);
}

.btn.ghost
{
    background: transparent;
}

.btn.ghost:hover:not(:disabled)
{
    background: var(--field);
}

.btn.block
{
    display: flex;
    width: 100%;
}

.btn.small
{
    height: 26px;
    padding: 0 8px;
    font-size: 12px;
}

.btn.active
{
    background: var(--fg);
    color: var(--bg);
}

.icon-btn
{
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    flex: none;
    background: transparent;
    color: inherit;
}

.icon-btn:hover:not(:disabled)
{
    background: var(--field);
}

.icon-btn.small
{
    width: 26px;
    height: 26px;
}

.icon-btn.small .icon
{
    width: 20px;
    height: 20px;
}

.icon-btn.active
{
    background: var(--fg);
    color: var(--bg);
}

.btn:focus-visible,
.icon-btn:focus-visible,
.chip:focus-visible,
.tab:focus-visible,
.seg button:focus-visible
{
    background: var(--fg);
    color: var(--bg);
}

input[type="text"],
input[type="number"],
input[type="search"],
select,
textarea
{
    display: block;
    width: 100%;
    height: 30px;
    padding: 0 8px;
    background-color: var(--field);
    color: var(--fg);
    font-size: 13px;
}

textarea
{
    height: auto;
    padding: 8px;
    resize: vertical;
    line-height: 1.45;
}

input[type="text"]:hover,
input[type="number"]:hover,
input[type="search"]:hover,
select:hover,
textarea:hover
{
    background-color: var(--field-hover);
}

input[type="text"]:focus,
input[type="number"]:focus,
input[type="search"]:focus,
select:focus,
textarea:focus
{
    background-color: var(--field-focus);
}

input::placeholder,
textarea::placeholder
{
    color: var(--faint);
}

input[type="number"]
{
    appearance: textfield;
    -moz-appearance: textfield;
    font-variant-numeric: tabular-nums;
}

input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button
{
    -webkit-appearance: none;
    margin: 0;
}

input[type="search"]::-webkit-search-cancel-button
{
    -webkit-appearance: none;
}

select
{
    appearance: none;
    -webkit-appearance: none;
    padding-right: 26px;
    cursor: pointer;
    text-overflow: ellipsis;
    background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%);
    background-position: calc(100% - 14px) 52%, calc(100% - 9px) 52%;
    background-size: 5px 5px, 5px 5px;
    background-repeat: no-repeat;
}

select option,
select optgroup
{
    background: var(--bg);
    color: var(--fg);
}

input[type="range"]
{
    -webkit-appearance: none;
    appearance: none;
    display: block;
    width: 100%;
    height: 20px;
    background: transparent;
    cursor: pointer;
}

input[type="range"]::-webkit-slider-runnable-track
{
    height: 2px;
    background: var(--faint);
    border: 0;
    border-radius: 0;
}

input[type="range"]::-webkit-slider-thumb
{
    -webkit-appearance: none;
    width: 12px;
    height: 12px;
    margin-top: -5px;
    background: var(--fg);
    border: 0;
    border-radius: 0;
}

input[type="range"]::-moz-range-track
{
    height: 2px;
    background: var(--faint);
    border: 0;
    border-radius: 0;
}

input[type="range"]::-moz-range-progress
{
    height: 2px;
    background: var(--fg);
    border: 0;
    border-radius: 0;
}

input[type="range"]::-moz-range-thumb
{
    width: 12px;
    height: 12px;
    background: var(--fg);
    border: 0;
    border-radius: 0;
}

input[type="range"]:focus-visible::-webkit-slider-thumb
{
    width: 16px;
    height: 16px;
    margin-top: -7px;
}

input[type="range"]:focus-visible::-moz-range-thumb
{
    width: 16px;
    height: 16px;
}

input[type="checkbox"]
{
    -webkit-appearance: none;
    appearance: none;
    flex: none;
    width: 30px;
    height: 16px;
    cursor: pointer;
    background: linear-gradient(var(--muted), var(--muted)) no-repeat 3px 50% / 10px 10px, var(--field-hover);
    transition: background-position 0.12s;
}

input[type="checkbox"]:checked
{
    background: linear-gradient(var(--bg), var(--bg)) no-repeat calc(100% - 3px) 50% / 10px 10px, var(--fg);
}

input[type="checkbox"]:focus-visible
{
    background: linear-gradient(var(--bg), var(--bg)) no-repeat 3px 50% / 10px 10px, var(--muted);
}

input[type="checkbox"]:checked:focus-visible
{
    background: linear-gradient(var(--bg), var(--bg)) no-repeat calc(100% - 3px) 50% / 10px 10px, var(--primary-hover);
}

input:disabled,
select:disabled,
textarea:disabled
{
    opacity: 0.4;
    cursor: not-allowed;
}

*
{
    scrollbar-width: thin;
    scrollbar-color: var(--faint) transparent;
}

::-webkit-scrollbar
{
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track
{
    background: transparent;
}

::-webkit-scrollbar-thumb
{
    background: var(--faint);
    border: 0;
    border-radius: 0;
}

::selection
{
    background: var(--fg);
    color: var(--bg);
}

.muted
{
    color: var(--muted);
}

.mono
{
    font-family: var(--font-mono);
    font-size: 12px;
}

.spacer
{
    flex: 1;
}

.chip
{
    height: 26px;
    padding: 0 10px;
    background: var(--field);
    font-size: 12px;
    white-space: nowrap;
}

.chip:hover
{
    background: var(--field-hover);
}

.chip.active
{
    background: var(--fg);
    color: var(--bg);
}

.tabs
{
    display: flex;
    gap: 2px;
}

.tab
{
    flex: 1;
    height: 40px;
    font-size: 12.5px;
    font-weight: 600;
    color: var(--chrome-muted);
    background: var(--chrome);
}

.tab:hover
{
    color: var(--chrome-fg);
}

.tab.active
{
    background: var(--bg);
    color: var(--fg);
}

.tab:focus-visible
{
    background: var(--chrome-fg);
    color: var(--chrome);
}

.seg
{
    display: flex;
    gap: 2px;
}

.seg button
{
    flex: 1;
    height: 30px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    background: var(--field);
    font-size: 12px;
}

.seg button:hover
{
    background: var(--field-hover);
}

.seg button.active
{
    background: var(--fg);
    color: var(--bg);
}

.seg button .icon
{
    width: 20px;
    height: 20px;
}

.field
{
    display: grid;
    grid-template-columns: 108px minmax(0, 1fr);
    align-items: center;
    gap: 10px;
    min-height: 32px;
}

.field + .field,
.check + .field,
.field + .check
{
    margin-top: 8px;
}

.field > label,
.field > .label
{
    color: var(--muted);
    font-size: 12px;
    line-height: 1.25;
}

.group-title
{
    margin: 18px 0 8px;
    padding-top: 12px;
    background: linear-gradient(var(--band), var(--band)) no-repeat top / 100% 1px;
    font-size: 10.5px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--muted);
}

.section-head + .group-title
{
    margin-top: 0;
    padding-top: 0;
    background: none;
}

.field.stack
{
    grid-template-columns: minmax(0, 1fr);
    gap: 4px;
}

.control
{
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.control input[type="number"]
{
    width: 64px;
    flex: none;
    text-align: right;
}

.control input[type="number"].fill
{
    width: auto;
    flex: 1;
    min-width: 0;
    text-align: left;
}

.control .unit
{
    width: 24px;
    flex: none;
    color: var(--muted);
    font-size: 11px;
}

.pair
{
    display: grid;
    grid-template-columns: 12px minmax(0, 1fr) 12px minmax(0, 1fr) 26px;
    align-items: center;
    gap: 6px;
}

.pair input
{
    padding: 0 6px;
}

.pair > span
{
    color: var(--muted);
    font-size: 11px;
}

.check
{
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 30px;
    cursor: pointer;
    user-select: none;
}

.check span
{
    flex: 1;
}

.hint
{
    color: var(--muted);
    font-size: 11.5px;
    line-height: 1.45;
}

.hint.lead
{
    margin-bottom: 12px;
}

.field + .hint,
.check + .hint,
.more + .hint
{
    margin-top: 8px;
}

.hint + .field,
.hint + .check,
.warning + .more,
.hint + .more
{
    margin-top: 10px;
}

.warning
{
    background: var(--fg);
    color: var(--bg);
    padding: 6px 10px;
    font-size: 12px;
    line-height: 1.4;
}

.progress
{
    height: 6px;
    background: var(--band);
    overflow: hidden;
}

.progress > span
{
    display: block;
    height: 100%;
    width: 0;
    background: var(--fg);
    transition: width 0.2s;
}

#toasts
{
    position: fixed;
    left: 50%;
    bottom: 92px;
    transform: translateX(-50%);
    z-index: 200;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    pointer-events: none;
}

.toast
{
    max-width: min(520px, calc(100vw - 32px));
    padding: 10px 14px;
    background: var(--fg);
    color: var(--bg);
    font-size: 13px;
    pointer-events: auto;
    animation: toast-in 0.18s ease-out;
}

.toast.error::before
{
    content: 'Error · ';
    font-weight: 700;
}

@keyframes toast-in
{
    from
    {
        opacity: 0;
        transform: translateY(6px);
    }
    to
    {
        opacity: 1;
        transform: translateY(0);
    }
}

#modal
{
    position: fixed;
    inset: 0;
    z-index: 150;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    background: rgba(0, 0, 0, 0.55);
}

#modal-box
{
    width: min(460px, 100%);
    max-height: calc(100vh - 32px);
    overflow: auto;
    background: var(--bg);
    color: var(--fg);
    padding: 22px;
}

#modal-box.wide
{
    width: min(760px, 100%);
}

#modal-title
{
    font-size: 17px;
    margin-bottom: 10px;
}

#modal-body
{
    color: var(--fg);
    line-height: 1.55;
}

#modal-body p + p
{
    margin-top: 8px;
}

#modal-body input
{
    margin-top: 12px;
}

#modal-body h4
{
    margin: 16px 0 6px;
    font-size: 12px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--muted);
}

#modal-body ul
{
    padding-left: 18px;
}

#modal-body li + li
{
    margin-top: 4px;
}

#modal-body a
{
    color: var(--fg);
    text-decoration: underline;
    text-underline-offset: 2px;
}

#modal-body kbd
{
    font-family: var(--font-mono);
    font-size: 11px;
    background: var(--field);
    padding: 1px 5px;
}

#modal-body pre
{
    font-family: var(--font-mono);
    font-size: 11.5px;
    background: var(--panel);
    padding: 10px;
    max-height: 60vh;
    overflow: auto;
    white-space: pre;
}

#modal-actions
{
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 20px;
}
