:root {
    --bg: #0f1115;
    --panel: #181b22;
    --panel-2: #1f232c;
    --text: #e6e8eb;
    --muted: #8a93a3;
    --accent: #4f8cff;
    --accent-2: #2563eb;
    --good: #2ecc71;
    --warn: #f39c12;
    --bad: #e74c3c;
    --border: #262b35;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    color: var(--text);
    background: var(--bg);
    min-height: 100vh;
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

header {
    max-width: 880px;
    margin: 0 auto;
    padding: 16px 16px 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}
header h1 { font-size: 20px; margin: 0; }

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

.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--bad); margin: 8px 0 0; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.btn-link {
    display: inline-block;
    min-height: 36px;
    padding: 8px 12px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--panel-2);
    color: var(--text);
    line-height: 1;
}
.btn-link:hover { background: #2a2f3a; text-decoration: none; }

.card {
    max-width: 880px;
    margin: 12px auto;
    padding: 16px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 10px;
}

.warn-banner {
    border-color: var(--warn);
    background: #2a2014;
}
.warn-banner strong { color: var(--warn); display: block; margin-bottom: 4px; }

/* background carousel (login + register pages only) */
#bg-stage {
    position: fixed;
    inset: 0;
    z-index: 0;
    overflow: hidden;
    background: var(--bg);
    transition: opacity 800ms ease;
    pointer-events: none;
}
.bg-img {
    position: absolute;
    inset: 0;
    opacity: 0;
    transition: opacity 1500ms ease-in-out;
    will-change: opacity;
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg);
}
.bg-img.active { opacity: 1; }

/* The photo/video: fully visible, modest margin so it doesn't crowd the form. */
.bg-img > img,
.bg-img > video {
    display: block;
    max-width: 96%;
    max-height: 96%;
    width: auto;
    height: auto;
    object-fit: contain;
}

body.engaged #bg-stage { opacity: 0.25; }   /* dimmed but still visible */
@media (prefers-reduced-motion: reduce) {
    #bg-stage, .bg-img { transition-duration: 400ms; }
}

/* login/register */
body.login { display: flex; align-items: center; justify-content: center; min-height: 100vh; position: relative; }
body.login .card {
    width: 100%;
    max-width: 420px;
    margin: 16px;
    position: relative;
    z-index: 5;
    /* Semi-transparent so background photos/videos peek through. */
    background: rgba(24, 27, 34, 0.55);
    backdrop-filter: blur(10px) saturate(140%);
    -webkit-backdrop-filter: blur(10px) saturate(140%);
    transition: background 300ms ease, backdrop-filter 300ms ease;
}
/* When any input/button in the form gets focus, snap to opaque so typing
   is fully readable. Also when JS sets body.engaged after first interaction. */
body.login .card:focus-within,
body.engaged .card {
    background: var(--panel);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
}
body.login h1 { margin: 0 0 4px; }
body.login p { margin: 0 0 12px; }
body.login label {
    display: block;
    font-size: 13px;
    color: var(--muted);
    margin: 12px 0 4px;
}
body.login input,
body.login button {
    width: 100%;
    padding: 14px 12px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--panel-2);
    color: var(--text);
    font-size: 16px; /* >= 16px stops iOS Safari auto-zoom on focus */
    min-height: 48px;
}
body.login button {
    margin-top: 16px;
    background: var(--accent-2);
    border-color: var(--accent-2);
    cursor: pointer;
    font-weight: 600;
}
body.login button:hover:not([disabled]) { background: var(--accent); }
body.login button[disabled], body.login input[disabled] { opacity: 0.5; cursor: not-allowed; }
.register-link {
    margin-top: 18px;
    text-align: center;
    font-size: 14px;
}

/* pending-payment box */
.pay-box {
    background: var(--panel-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 14px 16px;
    margin: 12px 0;
}
.pay-list {
    margin: 6px 0 12px;
    padding-left: 20px;
}
.pay-box code {
    background: var(--bg);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 14px;
}

/* quota bar */
.quota-label {
    display: flex; justify-content: space-between; align-items: baseline;
    margin-bottom: 8px; gap: 12px; flex-wrap: wrap;
}
.quota-track {
    height: 16px; background: var(--panel-2);
    border-radius: 8px; overflow: hidden; border: 1px solid var(--border);
}
.quota-fill {
    height: 100%; width: 0%;
    background: linear-gradient(90deg, var(--good), var(--accent));
    transition: width 250ms ease, background 250ms ease;
}
.quota-fill.warn { background: linear-gradient(90deg, var(--warn), var(--bad)); }
.quota-fill.danger { background: var(--bad); }
.quota .small { margin: 8px 0 0; }

/* dropzone */
.dropzone {
    text-align: center;
    border: 2px dashed var(--border);
    background: var(--panel);
    padding: 24px 16px;
    transition: background 150ms, border-color 150ms;
}
.dropzone.drag { background: var(--panel-2); border-color: var(--accent); }
.dropzone p { margin: 4px 0; }
.dz-prompt { font-size: 16px; }
.dropzone input[type=file] {
    position: absolute; width: 1px; height: 1px;
    padding: 0; margin: -1px; overflow: hidden;
    clip: rect(0, 0, 0, 0); border: 0;
}
.big-btn {
    display: inline-block;
    margin: 14px 0 6px;
    padding: 14px 22px;
    min-height: 48px;
    background: var(--accent-2);
    color: var(--text);
    border-radius: 10px;
    font-weight: 600; font-size: 16px;
    cursor: pointer; border: 1px solid var(--accent-2);
    user-select: none;
}
.big-btn:hover, .big-btn:active { background: var(--accent); }

/* queue */
#queue h2, .card h2 { margin: 0 0 12px; font-size: 17px; }
#queue ul, .files { list-style: none; margin: 0; padding: 0; }
#queue li { padding: 12px 0; border-top: 1px solid var(--border); }
#queue li:first-child { border-top: 0; }
.q-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.q-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.q-status { font-size: 13px; color: var(--muted); white-space: nowrap; }
.q-status.done { color: var(--good); }
.q-status.err { color: var(--bad); }
.q-bar { height: 8px; margin-top: 8px; background: var(--panel-2); border-radius: 4px; overflow: hidden; }
.q-bar > div {
    height: 100%; width: 0%; background: var(--accent);
    transition: width 120ms linear;
}

/* file list */
.files li {
    padding: 12px 0; border-top: 1px solid var(--border);
    display: flex; justify-content: space-between; align-items: center;
    gap: 12px; flex-wrap: wrap;
}
.files li:first-child { border-top: 0; }
.files .f-meta { color: var(--muted); font-size: 13px; }
.files .f-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.files .actions { display: flex; gap: 8px; }
.files button, .files a.btn {
    background: var(--panel-2); border: 1px solid var(--border);
    color: var(--text); padding: 10px 14px;
    min-height: 40px; border-radius: 8px;
    font-size: 14px; cursor: pointer;
    text-decoration: none; display: inline-flex; align-items: center;
}
.files button:hover, .files a.btn:hover { background: #2a2f3a; }
.files button.danger { color: var(--bad); border-color: #4a2a2a; }
.files button.danger:hover { background: #2a1a1a; }

/* admin table */
.admin-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}
.admin-table th, .admin-table td {
    padding: 8px 10px;
    border-bottom: 1px solid var(--border);
    text-align: left;
    vertical-align: top;
}
.admin-table th {
    color: var(--muted);
    font-weight: 500;
    background: var(--panel-2);
}
.admin-table tbody tr:hover { background: var(--panel-2); }
.row-actions {
    display: flex; gap: 6px; flex-wrap: wrap;
}
.row-actions button {
    background: var(--panel-2);
    color: var(--text);
    border: 1px solid var(--border);
    padding: 6px 10px;
    border-radius: 6px;
    font-size: 13px;
    cursor: pointer;
}
.row-actions button:hover { background: #2a2f3a; }
.row-actions button.ok { color: var(--good); border-color: #1f4731; }
.row-actions button.ok:hover { background: #14271c; }
.row-actions button.warn { color: var(--warn); border-color: #4a3a1a; }
.row-actions button.warn:hover { background: #2a221a; }
.row-actions button.danger { color: var(--bad); border-color: #4a2a2a; }
.row-actions button.danger:hover { background: #2a1a1a; }

.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 12px;
    background: var(--panel-2);
    border: 1px solid var(--border);
}
.badge.ok { color: var(--good); border-color: #1f4731; }
.badge.warn { color: var(--warn); border-color: #4a3a1a; }
.badge.info { color: var(--accent); border-color: #1f3147; }

.chip {
    display: inline-block;
    padding: 1px 8px;
    border-radius: 4px;
    font-size: 12px;
    background: var(--panel-2);
    border: 1px solid var(--border);
}
.chip.ok { color: var(--good); border-color: #1f4731; }

.radio-row {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
    margin: 0 0 8px;
}
.radio {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 15px;
    color: var(--text);
    padding: 6px 4px;
    cursor: pointer;
}
.radio input { width: auto; min-height: 0; margin: 0; }

.status-strip { padding: 10px 16px; }
.status-strip p { margin: 0; }

.pay-amount { font-size: 18px; margin: 0 0 8px; }
.big-dl { font-size: 16px; font-weight: 600; padding: 14px 24px; min-height: 48px; }

.detail-info { margin-bottom: 16px; }
.detail-info p { margin: 4px 0; }
.detail-section {
    background: var(--panel-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px 14px;
    margin: 12px 0;
}
.detail-section h3 { margin: 0 0 8px; font-size: 15px; color: var(--muted); }
.upload-final { margin-top: 14px; }
.upload-final .big-btn { margin: 8px 0; }

.settings-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}
@media (max-width: 480px) {
    .settings-row { grid-template-columns: 1fr; }
}

/* settings form */
.settings label {
    display: block;
    color: var(--muted);
    font-size: 13px;
    margin: 12px 0 4px;
}
.settings input, .settings textarea {
    width: 100%;
    padding: 12px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--panel-2);
    color: var(--text);
    font-size: 15px;
    font-family: inherit;
}
.settings textarea { resize: vertical; min-height: 80px; }
.settings .big-btn { margin-top: 16px; }
#settings-status { margin-left: 12px; }

/* narrow phones */
@media (max-width: 600px) {
    header h1 { font-size: 18px; }
    .card { margin: 10px; padding: 14px; border-radius: 12px; }
    .files li { flex-direction: column; align-items: stretch; }
    .files .actions { justify-content: space-between; }
    .files button, .files a.btn { flex: 1; justify-content: center; min-height: 44px; }

    /* Admin table: switch to "card per row" layout */
    .admin-table thead { display: none; }
    .admin-table, .admin-table tbody, .admin-table tr, .admin-table td { display: block; width: 100%; }
    .admin-table tr {
        background: var(--panel-2);
        border: 1px solid var(--border);
        border-radius: 8px;
        padding: 10px 12px;
        margin-bottom: 10px;
    }
    .admin-table td {
        border: 0;
        padding: 4px 0;
    }
    .admin-table td::before {
        content: attr(data-label);
        display: inline-block;
        color: var(--muted);
        min-width: 80px;
    }
    .row-actions { margin-top: 8px; }
    .row-actions button {
        flex: 1 0 calc(50% - 6px);
        min-height: 40px;
    }
}
