:root {
    color-scheme: light;
    --bg: #f5f5f7;
    --surface: #ffffff;
    --surface-soft: #fbfbfd;
    --surface-muted: #ececf1;
    --surface-translucent: rgba(255, 255, 255, 0.76);
    --card-bg: rgba(255, 255, 255, 0.88);
    --panel-bg: rgba(255, 255, 255, 0.9);
    --placeholder-bg: linear-gradient(135deg, #f7f7f9, #ececf1);
    --placeholder-tile: #ffffff;
    --text: #1d1d1f;
    --muted: #6e6e73;
    --line: #e5e5ea;
    --line-strong: #c7c7cc;
    --shadow: 0 18px 50px rgba(0, 0, 0, 0.08);
    --shadow-soft: 0 8px 28px rgba(0, 0, 0, 0.06);
    --blue: #0071e3;
    --blue-dark: #005bb5;
    --button-text: #ffffff;
    --pill-active-bg: #1d1d1f;
    --pill-active-text: #ffffff;
    --red: #d92d20;
    --danger-bg: #fff1f0;
    --success-bg: #ecfdf3;
    --success-text: #067647;
    --focus-ring: rgba(0, 113, 227, 0.12);
    --primary-shadow: rgba(0, 113, 227, 0.24);
    --handle-line: #a1a1a6;
    --radius: 18px;
}

[data-theme="dark"] {
    color-scheme: dark;
    --bg: #161719;
    --surface: #222326;
    --surface-soft: #2a2b2f;
    --surface-muted: #303136;
    --surface-translucent: rgba(34, 35, 38, 0.78);
    --card-bg: rgba(35, 36, 40, 0.88);
    --panel-bg: rgba(35, 36, 40, 0.92);
    --placeholder-bg: linear-gradient(135deg, #2a2b2f, #202124);
    --placeholder-tile: #303136;
    --text: #f5f5f7;
    --muted: #b2b2b8;
    --line: #3a3b40;
    --line-strong: #52535a;
    --shadow: 0 20px 58px rgba(0, 0, 0, 0.34);
    --shadow-soft: 0 10px 32px rgba(0, 0, 0, 0.24);
    --blue: #6aa9ff;
    --blue-dark: #4d94ee;
    --button-text: #101114;
    --pill-active-bg: #f5f5f7;
    --pill-active-text: #17181b;
    --red: #ff8a80;
    --danger-bg: rgba(255, 138, 128, 0.14);
    --success-bg: rgba(87, 171, 116, 0.16);
    --success-text: #8fd7a8;
    --focus-ring: rgba(106, 169, 255, 0.22);
    --primary-shadow: rgba(106, 169, 255, 0.2);
    --handle-line: #878891;
}

* {
    box-sizing: border-box;
}

html {
    min-height: 100%;
}

body {
    min-height: 100%;
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    line-height: 1.5;
    transition: background-color 180ms ease, color 180ms ease;
}

a {
    color: inherit;
}

button,
input,
textarea {
    font: inherit;
}

.shell {
    width: min(1120px, calc(100% - 32px));
    margin: 0 auto;
}

.site-header {
    padding: 44px 0 24px;
}

.site-header.compact {
    padding-bottom: 8px;
}

.header-inner {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 24px;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.eyebrow {
    margin: 0 0 8px;
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0;
    text-transform: uppercase;
}

h1,
h2,
h3,
p {
    margin-top: 0;
}

h1 {
    margin-bottom: 10px;
    font-size: clamp(2.2rem, 6vw, 4.5rem);
    line-height: 1.02;
    letter-spacing: 0;
}

h2 {
    margin-bottom: 16px;
    font-size: 1.45rem;
    line-height: 1.2;
}

h3 {
    margin-bottom: 6px;
    font-size: 1.05rem;
}

.lead {
    max-width: 620px;
    margin-bottom: 0;
    color: var(--muted);
    font-size: 1.08rem;
}

.ghost-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 40px;
    padding: 9px 14px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--surface-translucent);
    color: var(--text);
    font-size: 0.92rem;
    font-weight: 650;
    text-decoration: none;
    transition: border-color 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}

.ghost-link:hover {
    border-color: var(--line-strong);
    box-shadow: var(--shadow-soft);
    transform: translateY(-1px);
}

.theme-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 40px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--surface-translucent);
    color: var(--text);
    cursor: pointer;
    padding: 9px 14px;
    font-size: 0.92rem;
    font-weight: 650;
    transition: background 160ms ease, border-color 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}

.theme-toggle:hover {
    border-color: var(--line-strong);
    box-shadow: var(--shadow-soft);
    transform: translateY(-1px);
}

.theme-toggle-icon {
    position: relative;
    display: inline-block;
    width: 16px;
    height: 16px;
    border-radius: 999px;
    background: var(--text);
    box-shadow: inset -5px -4px 0 var(--surface-translucent);
}

[data-theme="dark"] .theme-toggle-icon {
    box-shadow: 0 0 0 4px rgba(245, 245, 247, 0.08);
}

.toolbar {
    display: grid;
    gap: 12px;
    margin: 22px 0 28px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--panel-bg);
    box-shadow: var(--shadow-soft);
    padding: 12px;
    transition: background-color 180ms ease, border-color 180ms ease, box-shadow 180ms ease;
}

.toolbar-row,
.filter-panel {
    display: grid;
    gap: 10px;
}

.toolbar-row-primary {
    grid-template-columns: 1fr;
}

.search-field,
.filter-field {
    display: grid;
    gap: 8px;
}

.search-field span,
.filter-field span,
.filter-heading span,
.form label span {
    color: var(--muted);
    font-size: 0.86rem;
    font-weight: 650;
}

input[type="search"],
input[type="text"],
input[type="password"],
input[type="file"],
select,
textarea {
    width: 100%;
    min-height: 48px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: var(--surface);
    color: var(--text);
    padding: 12px 14px;
    outline: none;
    transition: border-color 160ms ease, box-shadow 160ms ease;
}

select {
    appearance: none;
    background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
    background-position: calc(100% - 18px) 21px, calc(100% - 13px) 21px;
    background-repeat: no-repeat;
    background-size: 5px 5px, 5px 5px;
    cursor: pointer;
    padding-right: 38px;
}

textarea {
    min-height: 120px;
    resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--blue);
    box-shadow: 0 0 0 4px var(--focus-ring);
}

.filter-panel {
    padding-top: 2px;
}

.filter-group {
    display: grid;
    gap: 9px;
}

.filter-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.filter-field.has-value select,
.filter-field.has-value input {
    border-color: var(--blue);
    box-shadow: 0 0 0 3px var(--focus-ring);
}

.tag-filters,
.tags {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.tag-filter,
.tags span {
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--surface);
    color: var(--muted);
    padding: 7px 11px;
    font-size: 0.84rem;
    font-weight: 650;
}

.tag-filter {
    cursor: pointer;
    transition: background 160ms ease, border-color 160ms ease, color 160ms ease;
}

.tag-filter.is-active,
.tag-filter:hover {
    border-color: var(--pill-active-bg);
    background: var(--pill-active-bg);
    color: var(--pill-active-text);
}

.cards-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 18px;
    padding-bottom: 48px;
}

.script-card {
    display: flex;
    min-height: 100%;
    overflow: hidden;
    flex-direction: column;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--card-bg);
    box-shadow: var(--shadow-soft);
    transition: background-color 180ms ease, border-color 180ms ease, box-shadow 180ms ease, opacity 160ms ease, transform 160ms ease;
}

.card-image,
.card-placeholder {
    width: 100%;
    aspect-ratio: 16 / 9;
}

.card-image {
    display: block;
    object-fit: cover;
    background: var(--surface-soft);
}

.card-placeholder {
    display: grid;
    place-items: center;
    background: var(--placeholder-bg);
}

.card-placeholder span {
    display: grid;
    width: 64px;
    height: 64px;
    place-items: center;
    border-radius: 18px;
    background: var(--placeholder-tile);
    color: var(--muted);
    font-size: 2rem;
    font-weight: 800;
    box-shadow: var(--shadow-soft);
}

.card-body {
    flex: 1;
    padding: 20px 20px 12px;
}

.card-meta {
    margin-bottom: 8px;
    color: var(--muted);
    font-size: 0.82rem;
    font-weight: 650;
}

.card-body h2 {
    margin-bottom: 8px;
}

.card-body p {
    color: var(--muted);
}

.card-actions {
    padding: 0 20px 20px;
}

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 42px;
    border: 0;
    border-radius: 999px;
    padding: 10px 16px;
    cursor: pointer;
    font-weight: 700;
    text-decoration: none;
    transition: background 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}

.button:hover {
    transform: translateY(-1px);
}

.button-primary {
    background: var(--blue);
    color: var(--button-text);
}

.button-primary:hover {
    background: var(--blue-dark);
    box-shadow: 0 10px 26px var(--primary-shadow);
}

.button-secondary {
    background: var(--surface-muted);
    color: var(--text);
}

.button-danger {
    background: var(--danger-bg);
    color: var(--red);
}

.button:disabled {
    cursor: progress;
    opacity: 0.68;
    transform: none;
}

.link-button {
    width: fit-content;
    border: 0;
    background: transparent;
    color: var(--blue);
    cursor: pointer;
    padding: 0;
    font-weight: 700;
    text-align: left;
}

.link-button:hover {
    color: var(--blue-dark);
}

[hidden] {
    display: none !important;
}

.empty-state {
    display: none;
    margin-bottom: 48px;
    padding: 28px;
    border: 1px dashed var(--line-strong);
    border-radius: var(--radius);
    color: var(--muted);
    text-align: center;
}

.empty-state.is-visible {
    display: grid;
    justify-items: center;
    gap: 14px;
}

.empty-state p {
    margin: 0;
}

.admin-shell {
    display: grid;
    gap: 22px;
    padding: 22px 0 56px;
}

.panel {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--panel-bg);
    box-shadow: var(--shadow-soft);
    padding: 22px;
    transition: background-color 180ms ease, border-color 180ms ease, box-shadow 180ms ease;
}

.panel.narrow {
    max-width: 440px;
}

.password-panel {
    max-width: 820px;
}

.passkey-login-panel {
    display: grid;
    gap: 16px;
}

.password-fallback {
    border-top: 1px solid var(--line);
    margin-top: 2px;
    padding-top: 16px;
}

.section-heading {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 18px;
}

.section-heading h2 {
    margin-bottom: 0;
}

.form {
    display: grid;
    gap: 16px;
}

.form label {
    display: grid;
    gap: 8px;
}

.form-grid {
    display: grid;
    gap: 16px;
}

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

.form-actions {
    display: flex;
    justify-content: flex-start;
}

.help-text,
.save-status {
    margin: 0;
    color: var(--muted);
    font-size: 0.9rem;
}

.message {
    margin: 0;
    border-radius: 14px;
    padding: 12px 14px;
    font-weight: 650;
}

.message.success {
    background: var(--success-bg);
    color: var(--success-text);
}

.message.error {
    background: var(--danger-bg);
    color: var(--red);
}

.admin-list {
    display: grid;
    gap: 12px;
}

.admin-list.is-sorting {
    user-select: none;
}

.admin-item {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 14px;
    align-items: center;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: var(--surface);
    padding: 14px;
    touch-action: pan-y;
    transition: border-color 160ms ease, box-shadow 160ms ease, opacity 160ms ease, transform 160ms ease;
}

.admin-item.is-dragging {
    z-index: 20;
    opacity: 0.72;
    pointer-events: none;
    box-shadow: var(--shadow);
    transform: scale(1.01);
}

.admin-item.is-drop-target {
    border-color: var(--blue);
}

.drag-placeholder {
    min-height: 76px;
    border: 1px dashed var(--blue);
    border-radius: 16px;
    background: var(--surface-soft);
    box-shadow: inset 0 0 0 1px var(--focus-ring);
}

body.is-sorting {
    cursor: grabbing;
    user-select: none;
}

.drag-handle {
    display: grid;
    width: 38px;
    height: 46px;
    place-items: center;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--surface-soft);
    cursor: grab;
    touch-action: none;
}

.drag-handle span {
    display: block;
    width: 16px;
    height: 2px;
    border-radius: 99px;
    background: var(--handle-line);
}

.drag-handle:active {
    cursor: grabbing;
}

.admin-item-main {
    min-width: 0;
}

.admin-item-main p {
    overflow-wrap: anywhere;
    margin-bottom: 10px;
    color: var(--muted);
    font-size: 0.92rem;
}

.compact-tags {
    gap: 6px;
}

.compact-tags span {
    padding: 5px 9px;
    font-size: 0.78rem;
}

.admin-actions {
    display: flex;
    grid-column: 1 / -1;
    flex-wrap: wrap;
    gap: 8px;
}

.delete-form {
    margin: 0;
}

.passkeys-panel {
    display: grid;
    gap: 18px;
}

.passkey-add-form {
    border-bottom: 1px solid var(--line);
    padding-bottom: 18px;
}

.passkeys-list {
    display: grid;
    gap: 12px;
}

.passkey-item {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
    align-items: center;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: var(--surface);
    padding: 14px;
}

.passkey-item-main {
    min-width: 0;
}

.passkey-item-main h3 {
    margin-bottom: 4px;
}

.passkey-item-main p {
    margin: 0;
    color: var(--muted);
    font-size: 0.9rem;
}

.passkeys-empty {
    margin-bottom: 0;
}

.is-hidden {
    display: none;
}

@media (min-width: 720px) {
    .toolbar {
        padding: 14px;
    }

    .toolbar-row-primary {
        grid-template-columns: minmax(260px, 1fr) minmax(190px, 240px);
        align-items: end;
    }

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

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

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

    .admin-item {
        grid-template-columns: auto 1fr auto;
    }

    .admin-actions {
        grid-column: auto;
        justify-content: flex-end;
    }

    .passkey-item {
        grid-template-columns: 1fr auto;
    }
}

@media (min-width: 1040px) {
    .cards-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

@media (max-width: 640px) {
    .shell {
        width: min(100% - 24px, 1120px);
    }

    .site-header {
        padding-top: 28px;
    }

    .header-inner,
    .section-heading {
        flex-direction: column;
    }

    .header-actions {
        width: 100%;
        justify-content: space-between;
    }

    .ghost-link,
    .theme-toggle,
    .button {
        min-height: 44px;
    }

    .panel {
        padding: 18px;
    }

    .toolbar {
        padding: 12px;
    }
}
