:root {
    color-scheme: dark;
    --bg: #07111f;
    --bg-2: #0b1729;
    --panel: rgba(10, 18, 34, 0.78);
    --panel-strong: rgba(11, 20, 38, 0.94);
    --panel-border: rgba(173, 194, 224, 0.14);
    --text: #edf4ff;
    --muted: #9cadc8;
    --muted-strong: #c8d4e6;
    --accent: #57d8c6;
    --accent-strong: #2db3a2;
    --accent-soft: rgba(87, 216, 198, 0.16);
    --gold: #f7b84b;
    --gold-soft: rgba(247, 184, 75, 0.16);
    --danger: #ff6d6d;
    --danger-soft: rgba(255, 109, 109, 0.18);
    --success: #64e48d;
    --success-soft: rgba(100, 228, 141, 0.16);
    --shadow: 0 28px 80px rgba(0, 0, 0, 0.42);
    --shadow-soft: 0 18px 40px rgba(0, 0, 0, 0.18);
    --radius-xl: 28px;
    --radius-lg: 22px;
    --radius-md: 16px;
    --radius-sm: 12px;
    --line: 1px solid rgba(173, 194, 224, 0.1);
    --mono: "Cascadia Mono", "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
    --sans: "Aptos", "Segoe UI", "Helvetica Neue", Arial, sans-serif;
}

* {
    box-sizing: border-box;
}

html {
    min-height: 100%;
}

body.app-body {
    margin: 0;
    min-height: 100vh;
    font-family: var(--sans);
    color: var(--text);
    background:
        radial-gradient(circle at top left, rgba(87, 216, 198, 0.18), transparent 30%),
        radial-gradient(circle at top right, rgba(247, 184, 75, 0.14), transparent 34%),
        linear-gradient(180deg, #08101d 0%, #091120 40%, #050b14 100%);
    overflow-x: hidden;
}

body.app-body::before {
    content: "";
    position: fixed;
    inset: 0;
    background-image: linear-gradient(rgba(255, 255, 255, 0.015) 1px, transparent 1px), linear-gradient(90deg, rgba(255, 255, 255, 0.015) 1px, transparent 1px);
    background-size: 56px 56px;
    mask-image: linear-gradient(180deg, rgba(0, 0, 0, 0.45), transparent 90%);
    pointer-events: none;
    z-index: 0;
}

.app-backdrop {
    position: fixed;
    inset: auto;
    width: 36rem;
    height: 36rem;
    filter: blur(90px);
    opacity: 0.58;
    pointer-events: none;
    z-index: 0;
}

.app-backdrop-a {
    top: -8rem;
    left: -10rem;
    background: rgba(87, 216, 198, 0.18);
}

.app-backdrop-b {
    right: -12rem;
    bottom: -14rem;
    background: rgba(247, 184, 75, 0.14);
}

.topbar,
.app-shell {
    position: relative;
    z-index: 1;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 1.2rem 1.4rem;
    margin: 0 auto;
    max-width: 1440px;
}

.brand-block {
    display: flex;
    align-items: center;
    gap: 1rem;
    min-width: 0;
}

.brand-mark {
    width: 3rem;
    height: 3rem;
    border-radius: 18px;
    display: grid;
    place-items: center;
    text-decoration: none;
    color: #04131c;
    font-weight: 800;
    letter-spacing: 0.08em;
    background: linear-gradient(135deg, var(--accent), #e2fff8 55%, var(--gold));
    box-shadow: 0 18px 30px rgba(14, 69, 64, 0.35);
}

.brand-title {
    font-size: 1rem;
    font-weight: 700;
    letter-spacing: 0.01em;
}

.brand-subtitle {
    font-size: 0.85rem;
    color: var(--muted);
    margin-top: 0.1rem;
}

.topnav,
.topbar-meta {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.nav-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 2.6rem;
    padding: 0.55rem 1rem;
    border-radius: 999px;
    color: var(--muted-strong);
    text-decoration: none;
    border: 1px solid transparent;
    transition: transform 120ms ease, border-color 120ms ease, background-color 120ms ease, color 120ms ease;
}

.nav-link:hover,
.nav-link:focus-visible {
    transform: translateY(-1px);
    border-color: rgba(173, 194, 224, 0.16);
    background: rgba(255, 255, 255, 0.03);
    color: var(--text);
    outline: none;
}

.nav-link.is-active {
    background: rgba(87, 216, 198, 0.14);
    border-color: rgba(87, 216, 198, 0.28);
    color: #dcfffa;
}

.app-shell {
    width: min(1440px, calc(100% - 2.8rem));
    margin: 0 auto;
    padding: 0 0 2.5rem;
}

.flash {
    margin-bottom: 1rem;
    padding: 1rem 1.1rem;
    border-radius: var(--radius-lg);
    border: var(--line);
    box-shadow: var(--shadow-soft);
    backdrop-filter: blur(18px);
}

.flash-success {
    background: linear-gradient(180deg, rgba(100, 228, 141, 0.18), rgba(100, 228, 141, 0.08));
    border-color: rgba(100, 228, 141, 0.24);
}

.flash-error {
    background: linear-gradient(180deg, rgba(255, 109, 109, 0.2), rgba(255, 109, 109, 0.08));
    border-color: rgba(255, 109, 109, 0.28);
}

.flash-info {
    background: linear-gradient(180deg, rgba(87, 216, 198, 0.18), rgba(87, 216, 198, 0.08));
    border-color: rgba(87, 216, 198, 0.22);
}

.card {
    border: var(--line);
    background: var(--panel);
    backdrop-filter: blur(20px);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow);
}

.hero-block {
    display: grid;
    grid-template-columns: minmax(0, 1.4fr) minmax(280px, 0.8fr);
    gap: 1rem;
    padding: 1.5rem;
    margin-bottom: 1rem;
}

.hero-block.compact-hero {
    grid-template-columns: 1.4fr 0.8fr;
}

.hero-copy h1,
.hero-card h1 {
    margin: 0.2rem 0 0.8rem;
    font-size: clamp(2rem, 4vw, 3.8rem);
    line-height: 0.97;
    letter-spacing: -0.04em;
}

.hero-copy p,
.hero-card p,
.muted,
.status-line,
.slot-row .muted,
.form-footnote,
.small {
    color: var(--muted);
}

.eyebrow {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.16em;
    color: var(--gold);
    margin-bottom: 0.75rem;
}

.hero-actions,
.hero-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem;
    margin-top: 1rem;
}

.hero-note {
    margin-top: 1rem;
    padding: 0.9rem 1rem;
    border-radius: var(--radius-md);
    background: rgba(255, 255, 255, 0.04);
    color: var(--muted-strong);
    border: 1px solid rgba(173, 194, 224, 0.08);
}

.hero-status {
    display: grid;
    gap: 0.75rem;
}

.status-card {
    padding: 1rem 1rem 1.1rem;
    border-radius: var(--radius-lg);
    background: var(--panel-strong);
    border: 1px solid rgba(173, 194, 224, 0.1);
    box-shadow: var(--shadow-soft);
}

.status-label,
.output-label,
.toolbar-chip,
.script-card-slot,
.stat-label,
.metric-label {
    display: block;
    color: var(--muted);
    font-size: 0.82rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

.status-card strong {
    display: block;
    margin-top: 0.35rem;
    font-size: 1.12rem;
}

.stat-grid,
.metric-grid,
.profile-grid,
.admin-grid,
.dashboard-grid,
.workspace-grid {
    display: grid;
    gap: 1rem;
}

.stat-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    margin-bottom: 1rem;
}

.stat-card {
    padding: 1.15rem;
}

.stat-value {
    font-size: clamp(1.5rem, 2.7vw, 2.3rem);
    font-weight: 800;
    letter-spacing: -0.04em;
}

.metric-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    margin-bottom: 1rem;
}

.metric-card {
    padding: 1rem 1rem 1.05rem;
    border: 1px solid rgba(173, 194, 224, 0.11);
}

.metric-value {
    font-size: clamp(1.6rem, 3vw, 2.8rem);
    font-weight: 800;
    letter-spacing: -0.05em;
}

.metric-value span {
    font-size: 0.95rem;
    color: var(--muted);
    font-weight: 600;
}

.metric-label {
    margin-top: 0.4rem;
    color: var(--muted-strong);
}

.metric-detail {
    margin-top: 0.55rem;
    color: var(--muted);
    line-height: 1.45;
}

.metric-card.is-ok {
    box-shadow: inset 0 0 0 1px rgba(100, 228, 141, 0.08);
}

.metric-card.is-warning {
    box-shadow: inset 0 0 0 1px rgba(247, 184, 75, 0.08);
}

.metric-card.is-error {
    box-shadow: inset 0 0 0 1px rgba(255, 109, 109, 0.1);
}

.dashboard-grid {
    grid-template-columns: 1.2fr 0.8fr;
    margin-bottom: 1rem;
}

.panel-card,
.auth-layout .form-card,
.auth-layout .hero-card,
.sidebar-card,
.editor-card {
    padding: 1.35rem;
}

.card-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 0.95rem;
}

.card-head h2,
.card-head h3 {
    margin: 0;
    letter-spacing: -0.03em;
}

.card-head p {
    margin: 0.2rem 0 0;
    max-width: 58ch;
}

.table-wrap,
.reading-table-wrap {
    overflow: auto;
    border-radius: var(--radius-lg);
    border: 1px solid rgba(173, 194, 224, 0.08);
}

.table {
    width: 100%;
    border-collapse: collapse;
    min-width: 780px;
    background: rgba(255, 255, 255, 0.02);
}

.table th,
.table td {
    padding: 0.85rem 0.9rem;
    border-bottom: 1px solid rgba(173, 194, 224, 0.08);
    text-align: left;
    vertical-align: top;
}

.table thead th {
    position: sticky;
    top: 0;
    z-index: 1;
    background: rgba(7, 17, 31, 0.96);
    color: var(--muted-strong);
    font-size: 0.79rem;
    text-transform: uppercase;
    letter-spacing: 0.12em;
}

.table tbody tr:hover {
    background: rgba(255, 255, 255, 0.03);
}

.button {
    appearance: none;
    border: 1px solid transparent;
    border-radius: 999px;
    padding: 0.72rem 1.1rem;
    font: inherit;
    color: var(--text);
    text-decoration: none;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    transition: transform 120ms ease, background-color 120ms ease, border-color 120ms ease, box-shadow 120ms ease;
}

.button:hover,
.button:focus-visible {
    transform: translateY(-1px);
    outline: none;
}

.button-primary {
    background: linear-gradient(135deg, var(--accent), #9af3e7);
    color: #06201b;
    box-shadow: 0 16px 30px rgba(31, 124, 112, 0.25);
    border-color: rgba(255, 255, 255, 0.1);
}

.button-secondary {
    background: linear-gradient(135deg, #24364f, #1a2940);
    border-color: rgba(173, 194, 224, 0.16);
}

.button-ghost {
    background: rgba(255, 255, 255, 0.03);
    border-color: rgba(173, 194, 224, 0.12);
}

.button-danger {
    background: linear-gradient(135deg, #c14141, #ff7070);
    color: #170505;
    border-color: rgba(255, 255, 255, 0.08);
}

.button-block {
    width: 100%;
}

.chip {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.45rem 0.75rem;
    border-radius: 999px;
    border: 1px solid rgba(173, 194, 224, 0.12);
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--muted-strong);
    background: rgba(255, 255, 255, 0.03);
}

.chip-soft {
    background: rgba(255, 255, 255, 0.04);
}

.chip-accent {
    background: var(--accent-soft);
    border-color: rgba(87, 216, 198, 0.22);
    color: #d9fff8;
}

.chip-warning {
    background: var(--gold-soft);
    border-color: rgba(247, 184, 75, 0.22);
    color: #ffefc6;
}

.metric-card .chip,
.user-card .chip,
.script-card .chip {
    margin-left: auto;
}

.auth-layout {
    display: grid;
    grid-template-columns: minmax(0, 1.05fr) minmax(340px, 0.95fr);
    gap: 1rem;
    align-items: stretch;
}

.auth-layout.account-layout {
    grid-template-columns: 1fr 1fr;
}

.form-card,
.hero-card {
    padding: 1.4rem;
}

.stack-form {
    display: grid;
    gap: 0.95rem;
}

.field {
    display: grid;
    gap: 0.35rem;
}

.field span {
    font-size: 0.85rem;
    color: var(--muted-strong);
}

input,
select,
textarea {
    width: 100%;
    border-radius: 16px;
    border: 1px solid rgba(173, 194, 224, 0.14);
    background: rgba(5, 10, 18, 0.72);
    color: var(--text);
    padding: 0.82rem 0.95rem;
    font: inherit;
    outline: none;
    transition: border-color 120ms ease, box-shadow 120ms ease, background-color 120ms ease;
}

input:focus,
select:focus,
textarea:focus {
    border-color: rgba(87, 216, 198, 0.34);
    box-shadow: 0 0 0 4px rgba(87, 216, 198, 0.1);
    background: rgba(8, 15, 26, 0.92);
}

textarea,
.textarea {
    min-height: 220px;
    resize: vertical;
    line-height: 1.55;
}

.form-footnote {
    margin-top: 1rem;
    font-size: 0.92rem;
}

.form-footnote a,
.muted a {
    color: #d9fff8;
    text-decoration: none;
}

.form-footnote a:hover,
.muted a:hover {
    text-decoration: underline;
}

.hero-card {
    display: grid;
    align-content: center;
}

.hero-card p {
    line-height: 1.65;
    max-width: 60ch;
}

.hero-pills .chip,
.hero-actions .button {
    white-space: nowrap;
}

.workspace-grid {
    grid-template-columns: 360px minmax(0, 1fr);
    align-items: start;
    margin-bottom: 1rem;
}

.sidebar-card {
    display: grid;
    gap: 1rem;
}

.script-list {
    display: grid;
    gap: 0.75rem;
}

.script-card {
    width: 100%;
    text-align: left;
    padding: 0.95rem 1rem;
    border-radius: 20px;
    border: 1px solid rgba(173, 194, 224, 0.1);
    background: rgba(255, 255, 255, 0.03);
    color: var(--text);
    cursor: pointer;
    display: grid;
    gap: 0.35rem;
    transition: transform 120ms ease, border-color 120ms ease, background-color 120ms ease, box-shadow 120ms ease;
}

.script-card:hover,
.script-card:focus-visible,
.script-card.is-selected {
    transform: translateY(-1px);
    border-color: rgba(87, 216, 198, 0.28);
    background: rgba(87, 216, 198, 0.08);
    outline: none;
    box-shadow: 0 14px 26px rgba(0, 0, 0, 0.16);
}

.script-card-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.8rem;
}

.script-card-slot,
.script-card-detail {
    font-size: 0.85rem;
    color: var(--muted);
}

.script-card-value {
    font-weight: 700;
}

.editor-card {
    display: grid;
    gap: 1rem;
}

.editor-head {
    margin-bottom: 0;
}

.editor-meta {
    display: flex;
    gap: 0.45rem;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.editor-form {
    display: grid;
    gap: 1rem;
}

.hidden-label {
    display: none;
}

.editor-toolbar {
    display: flex;
    gap: 0.8rem;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
}

.editor-toolbar-left,
.editor-toolbar-right {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    align-items: center;
}

.toolbar-chip {
    display: inline-flex;
    align-items: center;
    min-height: 2.3rem;
    padding: 0 0.8rem;
    border-radius: 999px;
    border: 1px solid rgba(173, 194, 224, 0.12);
    background: rgba(255, 255, 255, 0.03);
    color: var(--muted-strong);
}

.toolbar-chip-soft {
    background: rgba(87, 216, 198, 0.08);
    border-color: rgba(87, 216, 198, 0.16);
    color: #dbfff8;
}

.toolbar-chip-warning {
    background: rgba(247, 184, 75, 0.12);
    border-color: rgba(247, 184, 75, 0.22);
    color: #ffe7b2;
}

.toolbar-chip-error {
    background: rgba(255, 109, 109, 0.12);
    border-color: rgba(255, 109, 109, 0.22);
    color: #ffd1d1;
}

.code-editor {
    display: grid;
    grid-template-columns: 4.5rem minmax(0, 1fr);
    min-height: 540px;
    border-radius: 22px;
    overflow: hidden;
    border: 1px solid rgba(173, 194, 224, 0.12);
    background: rgba(3, 8, 15, 0.78);
}

.editor-lines {
    margin: 0;
    padding: 1rem 0.7rem 1rem 0.9rem;
    background: rgba(255, 255, 255, 0.02);
    color: rgba(173, 194, 224, 0.6);
    font-family: var(--mono);
    font-size: 0.9rem;
    line-height: 1.56;
    overflow: hidden;
    user-select: none;
    white-space: pre;
}

#script-editor {
    border: none;
    border-left: 1px solid rgba(173, 194, 224, 0.08);
    border-radius: 0;
    background: transparent;
    font-family: var(--mono);
    font-size: 0.95rem;
    line-height: 1.56;
    padding: 1rem 1rem 1rem 0.95rem;
    min-height: 540px;
    resize: none;
    tab-size: 4;
}

.output-panel,
.revision-panel {
    padding-top: 0.2rem;
}

.output-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.75rem;
}

.output-box {
    padding: 0.95rem 1rem;
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(173, 194, 224, 0.08);
}

.output-box strong {
    display: block;
    margin-top: 0.4rem;
    font-size: 1.08rem;
}

.output-box.wide {
    grid-column: 1 / -1;
}

.revision-list {
    display: grid;
    gap: 0.75rem;
}

.revision-item {
    padding: 1rem;
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(173, 194, 224, 0.08);
}

.revision-meta {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    color: var(--muted-strong);
    margin-bottom: 0.4rem;
}

.revision-summary {
    color: var(--muted);
    margin-bottom: 0.75rem;
}

.revision-item pre {
    margin: 0;
    padding: 0.85rem;
    border-radius: 14px;
    background: rgba(4, 9, 16, 0.85);
    color: #d9e7ff;
    font-family: var(--mono);
    font-size: 0.85rem;
    line-height: 1.45;
    overflow: auto;
    max-height: 22rem;
}

.profile-strip,
.slot-list,
.user-grid {
    display: grid;
    gap: 0.8rem;
}

.profile-strip {
    margin-top: 1rem;
}

.profile-card {
    display: grid;
    gap: 0.25rem;
    padding: 0.9rem 1rem;
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(173, 194, 224, 0.08);
}

.profile-card strong {
    margin-bottom: 0.25rem;
}

.profile-values {
    display: flex;
    gap: 0.8rem;
    flex-wrap: wrap;
    color: var(--muted);
    font-size: 0.92rem;
}

.slot-row {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    align-items: flex-start;
    padding: 0.9rem 1rem;
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(173, 194, 224, 0.08);
}

.slot-meta {
    color: var(--muted-strong);
    text-align: right;
    max-width: 18rem;
}

.sandbox-note {
    padding: 0.95rem 1rem;
    border-radius: 18px;
    background: rgba(247, 184, 75, 0.08);
    border: 1px solid rgba(247, 184, 75, 0.18);
    color: #ffeac1;
    line-height: 1.5;
}

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

.user-card {
    padding: 1rem;
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(173, 194, 224, 0.09);
}

.user-card-head {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    align-items: flex-start;
    margin-bottom: 0.5rem;
}

.user-card-badges {
    display: flex;
    gap: 0.45rem;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.user-card-meta {
    color: var(--muted);
    font-size: 0.92rem;
    margin-top: 0.3rem;
}

.user-card-form {
    display: grid;
    gap: 0.7rem;
    margin-top: 0.9rem;
}

.admin-reset-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1rem;
}

.inline-form {
    display: inline-flex;
}

.small {
    font-size: 0.9rem;
}

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

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

.no-wrap {
    white-space: nowrap;
}

@media (max-width: 1180px) {
    .hero-block,
    .dashboard-grid,
    .workspace-grid,
    .auth-layout,
    .admin-grid {
        grid-template-columns: 1fr;
    }

    .stat-grid,
    .metric-grid,
    .user-grid,
    .admin-reset-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .topbar {
        align-items: flex-start;
        flex-direction: column;
    }

    .topbar-meta,
    .topnav {
        justify-content: flex-start;
    }
}

@media (max-width: 780px) {
    .app-shell {
        width: min(100% - 1rem, 1440px);
    }

    .topbar {
        padding: 1rem 0.2rem 0.75rem;
    }

    .hero-block,
    .panel-card,
    .auth-layout .form-card,
    .auth-layout .hero-card,
    .sidebar-card,
    .editor-card {
        padding: 1rem;
    }

    .stat-grid,
    .metric-grid,
    .user-grid,
    .admin-reset-grid,
    .output-grid {
        grid-template-columns: 1fr;
    }

    .code-editor {
        grid-template-columns: 3.4rem minmax(0, 1fr);
    }

    #script-editor,
    .editor-lines {
        min-height: 440px;
    }

    .table {
        min-width: 700px;
    }

    .slot-row,
    .revision-meta,
    .hero-status,
    .user-card-head {
        flex-direction: column;
    }

    .editor-toolbar,
    .editor-toolbar-right,
    .editor-toolbar-left {
        width: 100%;
        justify-content: flex-start;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        animation: none !important;
        transition: none !important;
    }
}
