:root {
    --bg: #07111f;
    --bg-soft: #0c1829;
    --panel: rgba(18, 31, 51, .82);
    --panel-solid: #121f33;
    --text: #f6f8ff;
    --muted: #9aabc4;
    --line: rgba(176, 196, 226, .14);
    --primary: #7969ff;
    --primary-light: #9d92ff;
    --accent: #4de1c1;
    --danger: #ff6f91;
    --warning: #ffc66d;
    --radius: 20px;
    --shadow: 0 22px 55px rgba(0, 0, 0, .25);
}

* { box-sizing: border-box; }
html { color-scheme: dark; }
body {
    margin: 0;
    min-height: 100vh;
    color: var(--text);
    background:
        radial-gradient(circle at 15% -5%, rgba(121, 105, 255, .22), transparent 34rem),
        radial-gradient(circle at 100% 15%, rgba(77, 225, 193, .1), transparent 28rem),
        var(--bg);
    font: 15px/1.55 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

a { color: inherit; text-decoration: none; }
button, input, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }

.topbar {
    position: sticky;
    z-index: 10;
    top: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 72px;
    padding: 0 max(24px, calc((100vw - 1240px) / 2));
    border-bottom: 1px solid var(--line);
    background: rgba(7, 17, 31, .82);
    backdrop-filter: blur(18px);
}

.brand { display: flex; align-items: center; gap: 11px; font-size: 18px; font-weight: 750; letter-spacing: -.02em; }
.brand-mark {
    display: grid;
    width: 34px;
    height: 34px;
    place-items: center;
    border-radius: 11px;
    color: #fff;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    box-shadow: 0 8px 24px rgba(121, 105, 255, .36);
}

.nav-links { display: flex; align-items: center; gap: 24px; color: var(--muted); }
.nav-links a:hover, .link-button:hover { color: var(--text); }
.inline-form { display: inline; margin: 0; }
.link-button { padding: 0; color: var(--muted); border: 0; background: none; cursor: pointer; }

.page-shell { width: min(1240px, calc(100% - 48px)); margin: 0 auto; padding: 54px 0 80px; }
.page-heading, .detail-title-row {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 24px;
}
.page-heading { margin-bottom: 34px; }
.page-heading.compact { margin-bottom: 24px; }
.page-heading h1, .detail-heading h1 { margin: 7px 0 8px; font-size: clamp(32px, 5vw, 52px); line-height: 1.05; letter-spacing: -.045em; }
.page-heading p, .detail-copy p { max-width: 690px; margin: 0; color: var(--muted); }
.eyebrow { color: var(--accent); font-size: 12px; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }
.heading-actions { display: flex; align-items: center; gap: 12px; }

.panel {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--panel);
    box-shadow: var(--shadow);
    backdrop-filter: blur(12px);
}

.button {
    display: inline-flex;
    min-height: 44px;
    align-items: center;
    justify-content: center;
    padding: 10px 18px;
    border: 1px solid transparent;
    border-radius: 12px;
    font-weight: 750;
    cursor: pointer;
    transition: transform .18s ease, border-color .18s ease, background .18s ease, opacity .18s ease;
}
.button:hover { transform: translateY(-1px); }
.button:disabled { cursor: not-allowed; opacity: .55; transform: none; }
.button.primary { color: #fff; background: linear-gradient(135deg, var(--primary), #6553ee); box-shadow: 0 10px 28px rgba(121, 105, 255, .28); }
.button.secondary { color: var(--text); border-color: var(--line); background: rgba(255, 255, 255, .04); }
.button.danger { color: #ffdce5; border-color: rgba(255, 111, 145, .25); background: rgba(255, 111, 145, .08); }
.button.wide { width: 100%; }

.status-pill {
    display: inline-flex;
    flex: 0 0 auto;
    align-items: center;
    gap: 7px;
    padding: 5px 10px;
    border: 1px solid var(--line);
    border-radius: 999px;
    color: var(--muted);
    background: rgba(255, 255, 255, .04);
    font-size: 12px;
    font-weight: 800;
    letter-spacing: .02em;
}
.status-pill::before { width: 7px; height: 7px; border-radius: 50%; background: currentColor; content: ""; }
.status-pill.ready { color: var(--accent); background: rgba(77, 225, 193, .08); }
.status-pill.queued, .status-pill.processing { color: var(--warning); background: rgba(255, 198, 109, .08); }
.status-pill.failed { color: var(--danger); background: rgba(255, 111, 145, .08); }

.video-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 22px; }
.video-card { overflow: hidden; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); box-shadow: 0 16px 42px rgba(0,0,0,.16); }
.poster { position: relative; display: block; overflow: hidden; aspect-ratio: 16 / 9; background: #0c1627; }
.poster img { width: 100%; height: 100%; object-fit: cover; transition: transform .35s ease; }
.video-card:hover .poster img { transform: scale(1.025); }
.poster::after { position: absolute; inset: 0; background: linear-gradient(180deg, transparent 50%, rgba(2, 8, 15, .68)); content: ""; }
.poster-placeholder { display: grid; width: 100%; height: 100%; place-items: center; background: linear-gradient(135deg, rgba(121,105,255,.45), rgba(77,225,193,.15)); }
.poster-placeholder span { color: rgba(255,255,255,.75); font-size: 72px; font-weight: 850; }
.play-chip { position: absolute; z-index: 1; bottom: 14px; left: 14px; display: grid; width: 40px; height: 40px; place-items: center; border: 1px solid rgba(255,255,255,.22); border-radius: 50%; background: rgba(4,11,20,.68); backdrop-filter: blur(8px); }
.video-card-body { padding: 20px; }
.card-title-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.video-card h2 { margin: 0; font-size: 19px; line-height: 1.25; letter-spacing: -.02em; }
.video-card p { min-height: 46px; margin: 10px 0 18px; color: var(--muted); font-size: 14px; }
.metadata { display: flex; flex-wrap: wrap; gap: 8px 14px; color: #7386a2; font-size: 12px; }
.metadata.large { margin-top: 24px; font-size: 13px; }
.offline-state.saved { color: var(--accent); }

.empty-state { padding: 72px 28px; text-align: center; }
.empty-state .empty-icon { display: grid; width: 58px; height: 58px; margin: 0 auto 18px; place-items: center; border-radius: 18px; color: var(--accent); background: rgba(77,225,193,.1); font-size: 25px; }
.empty-state h2 { margin: 0 0 8px; }
.empty-state p { margin: 0 auto 24px; color: var(--muted); }

.auth-layout { display: grid; min-height: calc(100vh - 206px); align-items: center; grid-template-columns: 1.25fr .75fr; gap: clamp(36px, 8vw, 110px); }
.auth-copy h1 { max-width: 770px; margin: 14px 0 18px; font-size: clamp(42px, 6vw, 72px); line-height: 1; letter-spacing: -.055em; }
.auth-copy > p { max-width: 680px; color: var(--muted); font-size: 18px; }
.feature-row { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 28px; }
.feature-row span { padding: 8px 12px; border: 1px solid var(--line); border-radius: 999px; color: #bfd0e8; background: rgba(255,255,255,.03); font-size: 13px; }
.auth-card { display: grid; gap: 18px; padding: 30px; }
.auth-card h2 { margin: 4px 0 0; font-size: 28px; }
label { display: grid; gap: 7px; color: #c6d1e2; font-size: 13px; font-weight: 700; }
input, textarea {
    width: 100%;
    padding: 12px 14px;
    color: var(--text);
    border: 1px solid var(--line);
    border-radius: 12px;
    outline: none;
    background: rgba(4, 12, 22, .62);
    transition: border-color .18s ease, box-shadow .18s ease;
}
input:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(121,105,255,.14); }
.form-error { padding: 11px 13px; border: 1px solid rgba(255,111,145,.25); border-radius: 10px; color: #ffd6df; background: rgba(255,111,145,.08); }

.upload-panel { padding: 30px; }
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 18px; }
.form-grid .full { grid-column: 1 / -1; }
.drop-zone { min-height: 220px; margin-top: 24px; place-items: center; align-content: center; border: 1px dashed rgba(157,146,255,.46); border-radius: 18px; background: rgba(121,105,255,.055); cursor: pointer; text-align: center; transition: border-color .18s, background .18s; }
.drop-zone:hover, .drop-zone.dragging { border-color: var(--accent); background: rgba(77,225,193,.06); }
.drop-zone input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.drop-zone strong { font-size: 18px; }
.drop-zone > span:last-child { color: var(--muted); font-weight: 500; }
.drop-icon { display: grid; width: 52px; height: 52px; margin-bottom: 12px; place-items: center; border-radius: 16px; color: var(--primary-light); background: rgba(121,105,255,.14); font-size: 26px; }
.form-actions { display: flex; justify-content: flex-end; gap: 12px; margin-top: 24px; }
.progress-wrap { margin-top: 24px; }
.progress-wrap.small { margin: 16px 0; }
.progress-copy { display: flex; justify-content: space-between; gap: 20px; margin-bottom: 9px; }
.progress-track { overflow: hidden; height: 9px; border-radius: 99px; background: rgba(255,255,255,.07); }
.progress-bar { width: 0; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--primary), var(--accent)); transition: width .25s ease; }
.muted { color: var(--muted); }
.notice-card { margin-top: 18px; padding: 16px 18px; border: 1px solid var(--line); border-radius: 14px; color: #c4d0e2; background: rgba(255,255,255,.025); }
.notice-card p { margin: 4px 0 0; color: var(--muted); }
code { padding: 2px 6px; border-radius: 5px; color: #dcd7ff; background: rgba(121,105,255,.12); }

.back-link { display: inline-block; margin-bottom: 23px; color: var(--muted); }
.detail-heading { margin-bottom: 28px; }
.detail-title-row { align-items: center; }
.player-shell { position: relative; overflow: hidden; border: 1px solid var(--line); border-radius: var(--radius); background: #02060c; box-shadow: var(--shadow); }
.player-shell video { display: block; width: 100%; max-height: min(72vh, 760px); aspect-ratio: 16/9; background: #000; }
.player-message { position: absolute; inset: 0; display: grid; place-items: center; padding: 20px; color: #cbd7e8; background: rgba(2,6,12,.72); text-align: center; pointer-events: none; }
.player-message:empty { display: none; }
.detail-grid { display: grid; grid-template-columns: 1fr 360px; gap: 22px; margin-top: 22px; }
.detail-copy, .offline-card { padding: 26px; }
.detail-copy h2, .offline-card h2 { margin: 0 0 10px; }
.offline-card h2 { margin-top: 7px; }
.offline-card p { color: var(--muted); }
.offline-card .button + .button { margin-top: 10px; }
.processing-card { display: flex; gap: 18px; align-items: flex-start; padding: 30px; }
.processing-card h2 { margin: 0 0 5px; }
.processing-card p { margin: 0; color: var(--muted); }
.spinner { width: 28px; height: 28px; flex: 0 0 auto; border: 3px solid rgba(255,255,255,.1); border-top-color: var(--primary-light); border-radius: 50%; animation: spin .85s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.error-log { overflow: auto; max-height: 280px; padding: 14px; border-radius: 10px; color: #ffbacb; background: rgba(0,0,0,.24); white-space: pre-wrap; }

.offline-list { display: grid; gap: 14px; }
.offline-item { display: grid; align-items: center; grid-template-columns: minmax(0, 1fr) auto; gap: 24px; padding: 20px 22px; border: 1px solid var(--line); border-radius: 16px; background: var(--panel); }
.offline-item h2 { margin: 0 0 5px; font-size: 19px; }
.offline-item p { margin: 0; color: var(--muted); font-size: 13px; }
.offline-actions { display: flex; gap: 10px; }
.offline-item.expired { opacity: .62; }
.offline-now-playing { margin-top: 40px; }
.offline-now-playing > .detail-title-row { margin-bottom: 14px; }
.offline-now-playing h2 { margin: 4px 0 0; }

.toast { position: fixed; z-index: 50; right: 22px; bottom: 22px; max-width: min(390px, calc(100vw - 44px)); padding: 13px 16px; border: 1px solid var(--line); border-radius: 12px; color: var(--text); background: #17263b; box-shadow: var(--shadow); opacity: 0; pointer-events: none; transform: translateY(12px); transition: opacity .2s, transform .2s; }
.toast.visible { opacity: 1; transform: none; }
.toast.error { border-color: rgba(255,111,145,.34); color: #ffdce4; }

@media (max-width: 900px) {
    .video-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .auth-layout { grid-template-columns: 1fr; padding-top: 30px; }
    .auth-copy { text-align: center; }
    .auth-copy > p { margin-left: auto; margin-right: auto; }
    .feature-row { justify-content: center; }
    .auth-card { width: min(480px, 100%); margin: 0 auto; }
    .detail-grid { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
    .topbar { min-height: 64px; padding: 0 16px; }
    .brand > span:last-child { display: none; }
    .nav-links { gap: 13px; font-size: 13px; }
    .nav-links a[href*="admin"] { display: none; }
    .page-shell { width: min(100% - 28px, 1240px); padding: 34px 0 60px; }
    .page-heading, .detail-title-row { align-items: flex-start; flex-direction: column; }
    .heading-actions { width: 100%; justify-content: space-between; }
    .video-grid { grid-template-columns: 1fr; }
    .form-grid { grid-template-columns: 1fr; }
    .upload-panel { padding: 20px; }
    .drop-zone { min-height: 190px; }
    .detail-heading h1, .page-heading h1 { font-size: 36px; }
    .offline-item { grid-template-columns: 1fr; }
    .offline-actions { width: 100%; }
    .offline-actions .button { flex: 1; }
}
