:root {
    --app: #17131a;
    --panel: #201b23;
    --panel-2: #251f29;
    --input: #2a242e;
    --border: #3b3340;
    --border-strong: #554a5b;
    --text: #efe9f1;
    --muted: #b3a8b8;
    --faint: #8a7f8e;
    --accent: #c9a3c9;
    --accent-soft: #dcbfdc;
    --accent-ink: #17131a;
    --selected: #3a2f3d;
    --gold: #e8c468;
    --gold-bg: #3a3320;
    --danger: #f0a8a0;
    --danger-bg: #3d2226;
    --ok: #7fd1a0;
    --ok-bg: #1f3428;
    --warn-bg: #3a3320;
    --control: 38px;
    --radius: 10px;
    --font: Inter, 'Segoe UI Variable Text', 'Segoe UI', system-ui, sans-serif;
    --heading: 'Space Grotesk', Montserrat, 'Segoe UI', system-ui, sans-serif;
    --mono: ui-monospace, Consolas, 'Cascadia Mono', monospace;
    color-scheme: dark;
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    min-height: 100%;
    background: var(--app);
    color: var(--text);
    font: 14px/1.45 var(--font);
}

h1,
h2,
h3 {
    font-family: var(--heading);
    font-weight: 600;
    margin: 0;
}

a {
    color: var(--accent-soft);
}

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

:focus-visible {
    outline: 2px solid var(--gold);
    outline-offset: 2px;
}

[hidden] {
    display: none !important;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 20px;
    padding: 10px 24px;
    background: var(--panel);
    border-bottom: 1px solid var(--border);
}

.brand {
    font-size: 18px;
    white-space: nowrap;
}

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

.tab {
    display: inline-flex;
    align-items: center;
    height: var(--control);
    padding: 0 14px;
    border-radius: 8px;
    color: var(--muted);
    text-decoration: none;
    font-weight: 500;
}

.tab:hover {
    background: #2c2530;
    color: var(--text);
}

.tab[aria-current="page"] {
    background: var(--selected);
    color: var(--text);
    box-shadow: inset 0 -2px 0 var(--accent);
}

.topbar .links {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    margin-left: auto;
}

.btn {
    height: var(--control);
    min-width: var(--control);
    padding: 0 14px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-weight: 500;
    white-space: nowrap;
    text-decoration: none;
    cursor: pointer;
}

.btn:hover:not(:disabled) {
    background: #2c2530;
    border-color: var(--border-strong);
}

.btn:disabled {
    color: var(--faint);
    cursor: default;
}

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

.btn.primary:hover:not(:disabled) {
    background: var(--accent-soft);
    border-color: var(--accent-soft);
}

.btn.danger {
    color: var(--danger);
}

.btn.danger:hover:not(:disabled) {
    background: var(--danger-bg);
    border-color: #6b3a40;
}

.btn.small {
    height: 30px;
    min-width: 30px;
    padding: 0 10px;
    font-size: 13px;
}

.btn.ghost {
    border-color: transparent;
}

.pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 24px;
    padding: 0 10px;
    border-radius: 999px;
    background: var(--input);
    color: var(--muted);
    font-size: 12px;
    font-weight: 500;
    white-space: nowrap;
}

.pill::before {
    content: '';
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: currentColor;
}

.pill.good {
    background: var(--ok-bg);
    color: var(--ok);
}

.pill.warn {
    background: var(--warn-bg);
    color: var(--gold);
}

.pill.bad {
    background: var(--danger-bg);
    color: var(--danger);
}

.page {
    max-width: 1320px;
    margin: 0 auto;
    padding: 24px;
}

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(380px, 1fr));
    gap: 16px;
    align-items: start;
}

.card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px 20px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    min-width: 0;
}

.grid.pair {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

@media (max-width: 900px) {
    .grid.pair {
        grid-template-columns: minmax(0, 1fr);
    }
}

.card.wide {
    grid-column: 1 / -1;
}

.card-head {
    display: flex;
    align-items: center;
    gap: 10px;
}

.card-head h2 {
    font-size: 15px;
}

.card-head .end {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 8px;
}

.big {
    display: flex;
    align-items: baseline;
    gap: 8px;
    font-family: var(--heading);
}

.big .value {
    font-size: 34px;
    font-weight: 600;
    line-height: 1;
}

.big .of {
    color: var(--muted);
    font-size: 18px;
}

.meter {
    height: 8px;
    border-radius: 999px;
    background: var(--input);
    overflow: hidden;
}

.meter > span {
    display: block;
    height: 100%;
    width: 0;
    background: linear-gradient(90deg, #b293b2, var(--accent-soft));
    border-radius: inherit;
    transition: width 0.4s ease;
}

.meter.done > span {
    background: linear-gradient(90deg, var(--gold), #f3dc9c);
}

.sub {
    color: var(--muted);
    font-size: 13px;
}

.row {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 10px;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 5px;
    min-width: 0;
}

.field.grow {
    flex: 1 1 200px;
}

.field-label {
    font-size: 12px;
    color: var(--muted);
}

.input,
.select,
.textarea {
    height: var(--control);
    min-width: 0;
    padding: 0 12px;
    background: var(--input);
    border: 1px solid var(--border);
    border-radius: 8px;
}

.textarea {
    height: auto;
    min-height: 76px;
    padding: 10px 12px;
    resize: vertical;
    line-height: 1.45;
}

.input:hover,
.select:hover,
.textarea:hover {
    border-color: var(--border-strong);
}

.input.num {
    width: 110px;
}

.input.mono,
.textarea.mono {
    font-family: var(--mono);
    font-size: 13px;
}

.check {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: var(--control);
    cursor: pointer;
}

.check input {
    width: 17px;
    height: 17px;
    accent-color: var(--accent);
}

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

.hint {
    margin: 0;
    font-size: 12.5px;
    color: var(--muted);
}

.notice {
    margin: 0;
    padding: 10px 12px;
    border-radius: 8px;
    background: var(--warn-bg);
    border: 1px solid #5a4d2c;
    color: #f3e2b0;
    font-size: 13px;
}

.status-list {
    display: grid;
    grid-template-columns: max-content 1fr;
    align-items: center;
    gap: 10px 14px;
    margin: 0;
}

.status-list dt {
    color: var(--muted);
    font-size: 13px;
}

.status-list dd {
    margin: 0;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px 10px;
    min-width: 0;
}

.auth-box {
    border: 1px dashed var(--accent);
    border-radius: 8px;
    padding: 12px 14px;
    background: var(--selected);
}

.auth-box p {
    margin: 4px 0;
}

.auth-code {
    font: 600 30px/1.2 var(--mono);
    letter-spacing: 4px;
    color: var(--gold);
}

.button-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.divider {
    height: 1px;
    background: var(--border);
    margin: 2px 0;
}

.log {
    margin: 0;
    padding: 0;
    list-style: none;
    max-height: 280px;
    overflow-y: auto;
    font: 12.5px/1.6 var(--mono);
    color: var(--muted);
}

.log li {
    padding: 3px 0;
    border-bottom: 1px solid #2a242e;
    overflow-wrap: anywhere;
}

.log .err {
    color: var(--danger);
}

.log .ok {
    color: var(--text);
}

.obs {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: var(--control);
    padding: 0 6px 0 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--input);
}

.obs code {
    font: 12.5px var(--mono);
    color: var(--muted);
    user-select: all;
}

.toasts {
    position: fixed;
    right: 24px;
    bottom: 24px;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 8px;
    z-index: 50;
    pointer-events: none;
}

.toast {
    padding: 10px 16px;
    border-radius: 8px;
    background: var(--selected);
    border: 1px solid var(--border-strong);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

.toast.err {
    border-color: #6b3a40;
    color: var(--danger);
}

@media (max-width: 720px) {
    .page {
        padding: 14px;
    }

    .grid {
        grid-template-columns: 1fr;
    }
}

.cmd-layout {
    display: grid;
    grid-template-columns: 280px minmax(0, 1fr);
    gap: 16px;
    align-items: start;
}

.cmd-list {
    position: sticky;
    top: 76px;
    padding: 14px;
    gap: 10px;
}

.cmd-items {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin: 0;
    padding: 0;
    list-style: none;
    max-height: calc(100vh - 300px);
    overflow-y: auto;
}

.cmd-item {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
    padding: 9px 12px;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 8px;
    text-align: left;
    cursor: pointer;
}

.cmd-item:hover {
    background: #2c2530;
}

.cmd-item[aria-current="true"] {
    background: var(--selected);
    border-color: var(--accent);
}

.cmd-item .name {
    font-family: var(--mono);
    font-weight: 600;
}

.cmd-item .what {
    font-size: 12px;
    color: var(--muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
}

.cmd-item.off .name {
    color: var(--faint);
    text-decoration: line-through;
}

.builtin {
    border-top: 1px solid var(--border);
    padding-top: 10px;
    font-size: 12.5px;
    color: var(--muted);
}

.builtin code {
    color: var(--text);
}

.name-input {
    display: flex;
    align-items: center;
    height: 46px;
    padding-left: 12px;
    background: var(--input);
    border: 1px solid var(--border);
    border-radius: 8px;
    font: 600 20px var(--mono);
    flex: 1 1 260px;
}

.name-input span {
    color: var(--gold);
}

.name-input input {
    flex: 1;
    min-width: 0;
    height: 100%;
    padding: 0 12px 0 2px;
    background: transparent;
    border: 0;
    font: inherit;
}

.name-input input:focus-visible {
    outline: none;
}

.name-input:focus-within {
    outline: 2px solid var(--gold);
    outline-offset: 2px;
}

.actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.action {
    border: 1px solid var(--border);
    border-left: 3px solid var(--accent);
    border-radius: 8px;
    background: var(--panel-2);
    padding: 12px 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.action[data-type="overlay"] {
    border-left-color: #8fb7e8;
}

.action[data-type="value"] {
    border-left-color: var(--gold);
}

.action[data-type="script"] {
    border-left-color: var(--ok);
}

.action-head {
    display: flex;
    align-items: center;
    gap: 6px;
}

.action-head .title {
    font-weight: 600;
    margin-right: auto;
}

.action-head .num {
    color: var(--faint);
    font-family: var(--mono);
    font-size: 12px;
    margin-right: 4px;
}

.script-box {
    height: 260px;
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
}

.script-box textarea {
    width: 100%;
    height: 100%;
    border: 0;
    border-radius: 0;
    resize: none;
}

.chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.chip {
    height: 28px;
    padding: 0 10px;
    background: var(--gold-bg);
    border: 1px solid #5a4d2c;
    border-radius: 6px;
    color: var(--gold);
    font: 12.5px var(--mono);
    cursor: pointer;
}

.chip:hover {
    border-color: var(--gold);
}

.run {
    border-bottom: 1px solid #2a242e;
    padding: 8px 0;
    font-size: 13px;
}

.run:last-child {
    border-bottom: 0;
}

.run-head {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 10px;
    align-items: center;
}

.run-head code {
    font-weight: 600;
}

.run-steps {
    margin: 4px 0 0;
    padding-left: 18px;
    color: var(--muted);
    font: 12.5px/1.6 var(--mono);
    overflow-wrap: anywhere;
}

.run-steps .err {
    color: var(--danger);
}

.runs {
    max-height: 360px;
    overflow-y: auto;
}

.var-intro {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px 24px;
    margin-bottom: 16px;
}

.var-intro .hint {
    margin: 0;
    max-width: 760px;
}

.var-intro .input {
    width: 280px;
}

.var-list {
    display: flex;
    flex-direction: column;
}

.var-row {
    display: grid;
    grid-template-columns: minmax(180px, 1fr) minmax(200px, 1.1fr) auto;
    align-items: center;
    gap: 8px 16px;
    padding: 10px 0;
    border-bottom: 1px solid #2a242e;
}

.var-row:last-child {
    border-bottom: 0;
}

.var-row.dirty .var-value .input {
    border-color: var(--gold);
}

.var-name {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px 10px;
    min-width: 0;
}

.var-label {
    font-weight: 600;
}

.var-label.mono {
    font-family: var(--mono);
}

.var-note {
    flex-basis: 100%;
    font-size: 12.5px;
    color: var(--muted);
}

.var-name .chip {
    height: 24px;
    font-size: 12px;
}

.var-value {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
}

.var-value .input {
    flex: 1;
    min-width: 0;
}

.var-row.counter .var-value .input {
    flex: 0 1 140px;
}

.var-readonly {
    font: 600 16px var(--heading);
    overflow-wrap: anywhere;
}

.var-readonly.muted {
    font: 400 14px var(--font);
    font-style: italic;
}

.var-meanwhile {
    font-size: 12px;
    color: var(--gold);
    white-space: nowrap;
}

.var-actions {
    display: flex;
    justify-content: flex-end;
    gap: 6px;
}

.var-actions:empty {
    display: none;
}

.var-row:has(.var-actions:empty) {
    grid-template-columns: minmax(180px, 1fr) minmax(200px, 1.1fr);
}

.var-rename {
    display: flex;
    gap: 6px;
    width: 100%;
}

.var-rename .input {
    flex: 1;
    min-width: 0;
}

.var-empty {
    padding: 18px 0;
    color: var(--muted);
}

.var-add {
    margin-top: 6px;
    padding-top: 14px;
    border-top: 1px solid var(--border);
}

@media (max-width: 900px) {
    .var-row {
        grid-template-columns: 1fr;
    }

    .var-actions {
        justify-content: flex-start;
        min-width: 0;
    }
}

.empty {
    padding: 30px 10px;
    text-align: center;
    color: var(--muted);
}

.dirty-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--gold);
}

@media (max-width: 900px) {
    .cmd-layout {
        grid-template-columns: 1fr;
    }

    .cmd-list {
        position: static;
    }
}

.login-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
}

.login-card {
    width: min(400px, 100%);
}

.user-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.user-list li {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: var(--control);
    padding: 0 4px 0 12px;
    background: var(--panel-2);
    border: 1px solid var(--border);
    border-radius: 8px;
}

.user-list .who {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
}
