:root {
    --bg: #0b0f14;
    --panel: #111821;
    --panel-2: #16202b;
    --line: #253241;
    --text: #edf3fb;
    --muted: #9aa9ba;
    --accent: #6ee7b7;
    --accent-2: #38bdf8;
    --danger: #fb7185;
    --shadow: 0 24px 80px rgba(0, 0, 0, .42);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    color: var(--text);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    letter-spacing: 0;
}

a {
    color: inherit;
    text-decoration: none;
}

button,
input {
    font: inherit;
}

.app-shell {
    display: grid;
    grid-template-columns: 280px 1fr;
    min-height: 100vh;
}

.sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    border-right: 1px solid var(--line);
    background: #0d131a;
    padding: 24px;
    display: flex;
    flex-direction: column;
}

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

.brand-mark {
    width: 44px;
    height: 44px;
    display: grid;
    place-items: center;
    border: 1px solid rgba(110, 231, 183, .35);
    background: #102019;
    color: var(--accent);
    font-weight: 800;
    border-radius: 8px;
}

.brand strong,
.brand span {
    display: block;
}

.brand span,
.eyebrow,
.metric span,
.cape-meta span,
.detail-stats span,
.form-note {
    color: var(--muted);
}

.side-nav {
    display: grid;
    gap: 8px;
    margin-top: 36px;
}

.side-nav a,
.side-footer button,
.ghost-button,
.primary-button,
.danger-button,
.card-actions a,
.card-actions button {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    color: var(--text);
    min-height: 40px;
    padding: 10px 14px;
    cursor: pointer;
}

.side-nav a.active,
.primary-button,
.primary-action {
    border-color: rgba(110, 231, 183, .45);
    background: var(--accent);
    color: #05110d;
    font-weight: 700;
}

.side-footer {
    margin-top: auto;
    display: grid;
    gap: 12px;
    color: var(--muted);
}

.side-footer form,
.side-footer button {
    width: 100%;
}

.content {
    padding: 30px;
}

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 20px;
}

.topbar h1,
.modal h2,
.login-panel h1,
.empty-state h2 {
    margin: 0;
}

.eyebrow {
    margin: 0 0 6px;
    text-transform: uppercase;
    font-size: 12px;
    font-weight: 700;
}

.top-actions,
.modal-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.status-row {
    display: grid;
    grid-template-columns: 160px minmax(220px, 1fr) 160px;
    gap: 12px;
    margin: 28px 0;
}

.metric,
.cape-card,
.empty-state {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
}

.metric {
    padding: 16px;
    min-width: 0;
}

.metric strong {
    display: block;
    margin-top: 8px;
    font-size: 22px;
}

.clip {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.flash {
    padding: 14px 16px;
    border-radius: 8px;
    margin-bottom: 18px;
}

.flash.success,
.login-alert.success {
    background: rgba(34, 197, 94, .13);
    border: 1px solid rgba(34, 197, 94, .35);
}

.flash.error,
.login-alert.error {
    background: rgba(251, 113, 133, .13);
    border: 1px solid rgba(251, 113, 133, .35);
}

.cape-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
    gap: 16px;
}

.cape-card {
    overflow: hidden;
}

.cape-open {
    width: 100%;
    border: 0;
    padding: 0;
    background: transparent;
    color: inherit;
    text-align: left;
    cursor: pointer;
}

.cape-preview,
.detail-preview {
    background:
            linear-gradient(45deg, #101820 25%, transparent 25%),
            linear-gradient(-45deg, #101820 25%, transparent 25%),
            linear-gradient(45deg, transparent 75%, #101820 75%),
            linear-gradient(-45deg, transparent 75%, #101820 75%),
            #0a0f15;
    background-size: 22px 22px;
    background-position: 0 0, 0 11px, 11px -11px, -11px 0;
}

.cape-preview {
    aspect-ratio: 16 / 10;
    display: grid;
    place-items: center;
    border-bottom: 1px solid var(--line);
}

.cape-preview img,
.detail-preview img {
    image-rendering: pixelated;
    max-width: 80%;
    max-height: 80%;
}

.cape-meta {
    padding: 14px;
}

.cape-meta strong {
    display: block;
    margin-bottom: 5px;
}

.dot {
    display: inline-block;
    width: 4px;
    height: 4px;
    margin: 0 8px 2px;
    border-radius: 50%;
    background: var(--muted);
}

.card-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    padding: 0 14px 14px;
}

.card-actions a,
.card-actions button {
    text-align: center;
    min-height: 36px;
    padding: 8px 10px;
}

.empty-state {
    padding: 48px;
    text-align: center;
}

.empty-state p {
    color: var(--muted);
}

.modal-backdrop {
    position: fixed;
    inset: 0;
    display: none;
    place-items: center;
    padding: 24px;
    background: rgba(0, 0, 0, .66);
    z-index: 10;
}

.modal-backdrop.is-open {
    display: grid;
}

.modal {
    width: min(560px, 100%);
    max-height: calc(100vh - 48px);
    overflow: auto;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.modal.wide {
    width: min(860px, 100%);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 20px;
    border-bottom: 1px solid var(--line);
}

.icon-button {
    width: 40px;
    height: 40px;
    border: 1px solid var(--line);
    background: var(--panel-2);
    color: var(--text);
    border-radius: 8px;
    cursor: pointer;
    font-size: 24px;
    line-height: 1;
}

.form-grid {
    display: grid;
    gap: 18px;
    padding: 20px;
}

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

.form-grid label span {
    color: var(--muted);
    font-size: 14px;
}

.form-grid input {
    min-height: 46px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #0b1118;
    color: var(--text);
    padding: 10px 12px;
}

.modal-actions {
    justify-content: flex-end;
    padding-top: 4px;
}

.modal-actions.left {
    justify-content: flex-start;
}

.danger-button {
    border-color: rgba(251, 113, 133, .45);
    background: rgba(251, 113, 133, .14);
    color: #fecdd3;
}

.detail-layout {
    display: grid;
    grid-template-columns: 300px 1fr;
    gap: 20px;
    padding: 20px;
}

.detail-preview {
    min-height: 330px;
    display: grid;
    place-items: center;
    border: 1px solid var(--line);
    border-radius: 8px;
}

.detail-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}

.detail-stats div {
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel-2);
}

.detail-stats strong {
    display: block;
    margin-top: 6px;
    font-size: 18px;
}

.frame-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 18px 0;
}

.frame-list a {
    min-width: 44px;
    padding: 8px 10px;
    text-align: center;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel-2);
    color: var(--text);
}

.login-page {
    display: grid;
    place-items: center;
}

.login-shell {
    width: min(460px, calc(100% - 32px));
}

.login-panel {
    padding: 34px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    box-shadow: var(--shadow);
}

.login-panel .brand-mark {
    margin-bottom: 18px;
}

.login-panel p {
    color: var(--muted);
}

.primary-action {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-height: 46px;
    margin-top: 18px;
    border-radius: 8px;
}

.login-alert {
    padding: 12px;
    border-radius: 8px;
    margin: 16px 0 0;
}

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

    .sidebar {
        position: relative;
        height: auto;
    }

    .status-row,
    .detail-layout {
        grid-template-columns: 1fr;
    }

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