:root {
    --bg: #0f0f0f;
    --bg-elev: #1c1c1c;
    --bg-elev2: #272727;
    --text: #f1f1f1;
    --text-dim: #aaa;
    --accent: #ff4040;
    --border: #303030;
    --radius: 10px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
}

a { color: inherit; text-decoration: none; }
a:hover { color: var(--accent); }

/* ----- Top bar ----- */
.topbar {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    padding: 0.75rem 1.5rem;
    background: var(--bg-elev);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 10;
}

.logo {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--accent);
}

#topnav { display: flex; gap: 1rem; flex: 1; }
#topnav a {
    padding: 0.4rem 0.8rem;
    border-radius: 6px;
}
#topnav a:hover { background: var(--bg-elev2); color: var(--text); }

#userbox { display: flex; gap: 0.5rem; align-items: center; }

/* ----- Main ----- */
main {
    max-width: 1280px;
    margin: 0 auto;
    padding: 1.5rem;
}

h1, h2, h3 { line-height: 1.2; }
h1 { font-size: 1.6rem; margin-top: 0; }
h2 { font-size: 1.3rem; }

.loading { color: var(--text-dim); }

/* ----- Buttons ----- */
.btn {
    display: inline-block;
    background: var(--bg-elev2);
    color: var(--text);
    border: 1px solid var(--border);
    padding: 0.5rem 1rem;
    border-radius: 6px;
    cursor: pointer;
    font: inherit;
    text-align: center;
}
.btn:hover { background: #353535; color: var(--text); }
.btn-primary {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
}
.btn-primary:hover { background: #d63232; }
.btn-danger {
    background: transparent;
    border-color: #6a1f1f;
    color: #ff7878;
}
.btn-danger:hover { background: #2a1010; color: #ff9090; }

/* ----- Forms ----- */
form { display: flex; flex-direction: column; gap: 0.75rem; max-width: 420px; }
.form-wide { max-width: 720px; }
label {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    font-size: 0.9rem;
    color: var(--text-dim);
}
input[type=text], input[type=password], textarea, input[type=file] {
    background: var(--bg-elev);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 0.6rem 0.8rem;
    border-radius: 6px;
    font: inherit;
}
input:focus, textarea:focus {
    outline: none;
    border-color: var(--accent);
}
textarea { min-height: 100px; resize: vertical; }

.form-error {
    background: #3a1414;
    color: #ffb0b0;
    padding: 0.6rem 0.8rem;
    border-radius: 6px;
    border: 1px solid #6a1f1f;
}
.form-ok {
    background: #143a14;
    color: #b0ffb0;
    padding: 0.6rem 0.8rem;
    border-radius: 6px;
    border: 1px solid #1f6a1f;
}
.form-info {
    background: #142a3a;
    color: #b0d0ff;
    padding: 0.6rem 0.8rem;
    border-radius: 6px;
    border: 1px solid #1f456a;
    margin-bottom: 1rem;
}
/* Inline checkbox with label text on its right, used in admin settings. */
.checkbox-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
}
.checkbox-row input[type="checkbox"] {
    width: auto;
    margin: 0;
}
.caps-warn {
    margin-top: 0.3rem;
    margin-bottom: 0.3rem;
    color: #ffcc66;
    font-size: 0.85rem;
}
.caps-warn[hidden] { display: none; }

/* "Your password was reset by admin X" banner */
.reset-notice-banner {
    margin: 0 auto 1rem auto;
    max-width: 1100px;
    background: #3a2a14;
    color: #ffe0b0;
    border: 1px solid #6a4a1f;
    border-radius: 6px;
    padding: 0.75rem 1rem;
    display: flex;
    gap: 1rem;
    align-items: center;
}
.reset-notice-banner .reset-notice-body { flex: 1; }
.reset-notice-banner .reset-notice-body p { margin: 0.25rem 0 0 0; font-size: 0.9rem; }
.reset-notice-banner .btn { white-space: nowrap; }

/* Account-deletion "danger zone" */
.danger-zone {
    border: 1px solid #6a1f1f;
    border-radius: 8px;
    padding: 1rem 1.25rem;
    background: rgba(58, 20, 20, 0.25);
}
.danger-zone h2 { color: #ffb0b0; margin-top: 0; }

/* When the ALTCHA proof-of-work hasn't completed yet, the submit button on
   signup/forgot-password is disabled. The 'altcha-gated-disabled' class lets
   us soften the visual without making the button look broken. */
.btn.altcha-gated-disabled {
    opacity: 0.5;
    cursor: progress;
}

/* ALTCHA widget theming: match the dark site palette via the widget's own
   custom-property hooks. The widget renders into a shadow DOM; these vars
   reach inside it because Shadow DOM lets css custom properties pass through. */
altcha-widget,
.altcha-mount {
    display: block;
    margin: 0.75rem 0;
    --altcha-color-base: var(--bg-elev);
    --altcha-color-border: var(--border);
    --altcha-color-text: var(--text);
    --altcha-color-border-focus: var(--accent);
    --altcha-border-radius: 6px;
    --altcha-max-width: 420px;
}

/* External-video player and metadata */
.iframe-wrap {
    position: relative;
    width: 100%;
    background: #000;
    border-radius: var(--radius);
    overflow: hidden;
    aspect-ratio: 16 / 9;
}
.iframe-wrap iframe {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border: 0;
}
.source-badge {
    margin-top: 0.5rem;
    padding: 0.4rem 0.6rem;
    background: var(--bg-elev2);
    border-radius: 6px;
    font-size: 0.85rem;
    color: var(--text-dim);
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
}
.source-badge a { color: var(--text); text-decoration: underline; }
.btn-link {
    background: none;
    border: 0;
    color: var(--accent);
    cursor: pointer;
    padding: 0;
    font: inherit;
    text-decoration: underline;
    margin-left: 0.5rem;
}
.btn-link:hover { opacity: 0.8; }

/* ----- Video grid ----- */
.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 1.25rem;
}

.video-card {
    background: transparent;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    position: relative;
}
.video-card .thumb {
    width: 100%;
    aspect-ratio: 16 / 9;
    background: #000 center/cover no-repeat;
    border-radius: var(--radius);
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-dim);
    font-size: 2rem;
    border: 1px solid var(--border);
}
.video-card h3 {
    font-size: 0.95rem;
    margin: 0;
    line-height: 1.3;
    /* clamp to 2 lines */
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.video-card .meta {
    font-size: 0.8rem;
    color: var(--text-dim);
}
/* "NEW since previous login" corner badge on subscription-feed video cards. */
.card-new-badge {
    position: absolute;
    top: 0.5rem;
    left: 0.5rem;
    background: var(--accent);
    color: #fff;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    padding: 0.2rem 0.45rem;
    border-radius: 3px;
    z-index: 1;
    pointer-events: none;
}
/* Subscription-count badge appended to the Subscriptions nav button. */
.nav-badge {
    display: inline-block;
    margin-left: 0.4rem;
    background: var(--accent);
    color: #fff;
    font-size: 0.7rem;
    font-weight: 700;
    padding: 0.05rem 0.4rem;
    border-radius: 999px;
    min-width: 1.2rem;
    text-align: center;
    line-height: 1.4;
}

/* ----- Watch page ----- */
.watch {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 1.25rem;
}
.watch video {
    width: 100%;
    max-height: 70vh;
    background: #000;
    border-radius: var(--radius);
}
.watch .info {
    padding: 1rem;
    background: var(--bg-elev);
    border-radius: var(--radius);
}
.channel-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin: 0.75rem 0;
    padding: 0.5rem 0;
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
}
.avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--accent);
    color: white;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    flex-shrink: 0;
}
.avatar.lg { width: 80px; height: 80px; font-size: 1.8rem; }
.avatar.sm { width: 24px; height: 24px; font-size: 0.8rem; }

/* User button in topbar with embedded avatar */
.user-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
}
.user-btn .avatar { background-size: cover; background-position: center; }

/* Subscribe / Subscribed button */
.btn.subscribed {
    background: var(--bg-elev2);
    color: var(--text-dim);
}
.btn.subscribed:hover { background: #3a1c1c; color: var(--accent); }

/* Subscription chips on the subscriptions page */
.subscriptions-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
}
.channel-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.35rem 0.75rem 0.35rem 0.35rem;
    background: var(--bg-elev);
    border-radius: 999px;
    font-size: 0.9rem;
    border: 1px solid var(--border);
}
.channel-chip:hover { border-color: var(--accent); color: var(--accent); }

.desc { white-space: pre-wrap; color: var(--text-dim); margin-top: 0.5rem; }

/* ----- Channel page ----- */
.channel-header {
    display: flex;
    gap: 1rem;
    align-items: center;
    padding: 1rem;
    background: var(--bg-elev);
    border-radius: var(--radius);
    margin-bottom: 1.5rem;
}
.channel-header h1 { margin: 0 0 0.25rem 0; }
.channel-header .username { color: var(--text-dim); font-size: 0.9rem; }
.channel-header .bio { color: var(--text-dim); margin-top: 0.5rem; }

/* ----- Channels list ----- */
.channel-card {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem;
    background: var(--bg-elev);
    border-radius: var(--radius);
}

/* ----- Dashboard ----- */
.dashboard-grid {
    display: grid;
    grid-template-columns: 280px 1fr;
    gap: 1.5rem;
}
.side-card {
    background: var(--bg-elev);
    border-radius: var(--radius);
    padding: 1rem;
    height: fit-content;
}
.side-card h3 { margin-top: 0; }
.side-card nav { display: flex; flex-direction: column; gap: 0.25rem; }
.side-card nav a {
    padding: 0.5rem 0.75rem;
    border-radius: 6px;
    color: var(--text-dim);
}
.side-card nav a:hover { background: var(--bg-elev2); color: var(--text); }

.video-row {
    display: flex;
    gap: 1rem;
    padding: 0.75rem;
    background: var(--bg-elev);
    border-radius: var(--radius);
    margin-bottom: 0.75rem;
    align-items: center;
}
.video-row .thumb-sm {
    width: 140px;
    aspect-ratio: 16 / 9;
    background: #000;
    border-radius: 6px;
    flex-shrink: 0;
}
.video-row .row-body { flex: 1; min-width: 0; }
.video-row .row-body h4 { margin: 0 0 0.25rem 0; }
.video-row .row-body small { color: var(--text-dim); }
.video-row .row-actions { display: flex; gap: 0.5rem; flex-shrink: 0; }

.progress {
    width: 100%;
    height: 8px;
    background: var(--bg-elev2);
    border-radius: 4px;
    overflow: hidden;
    margin-top: 0.5rem;
}
.progress-bar {
    height: 100%;
    width: 0;
    background: var(--accent);
    transition: width 0.2s;
}

/* Drag-and-drop upload zone */
.upload-dropzone {
    border: 2px dashed var(--border);
    border-radius: 8px;
    background: var(--bg-elev);
    padding: 2rem 1rem;
    text-align: center;
    transition: border-color 0.15s, background 0.15s;
    margin: 0.5rem 0;
}
.upload-dropzone-active {
    border-color: var(--accent);
    background: var(--bg-elev2);
}
.upload-dropzone-has-file {
    border-style: solid;
}
.upload-dropzone-prompt > div:first-child {
    color: var(--text);
    font-size: 1rem;
}
.upload-selected-name {
    font-weight: 600;
    word-break: break-all;
}
.upload-selected-meta {
    color: var(--text-dim);
    font-size: 0.85rem;
    margin-top: 0.25rem;
}

footer {
    text-align: center;
    padding: 2rem 1rem;
    color: var(--text-dim);
    border-top: 1px solid var(--border);
    margin-top: 3rem;
}

@media (max-width: 720px) {
    .dashboard-grid { grid-template-columns: 1fr; }
    .topbar { gap: 0.75rem; padding: 0.5rem 1rem; }
    .video-row { flex-direction: column; align-items: stretch; }
    .video-row .thumb-sm { width: 100%; }
}

/* ============ Additions for new features ============ */

/* Language selector */
.lang-select {
    background: var(--bg-elev);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 0.4rem 0.6rem;
    border-radius: 6px;
    font: inherit;
    cursor: pointer;
}
.lang-select:focus { outline: none; border-color: var(--accent); }

/* Badge for "Admin" tag */
.badge {
    display: inline-block;
    font-size: 0.65rem;
    padding: 0.15rem 0.45rem;
    border-radius: 999px;
    background: var(--accent);
    color: white;
    vertical-align: middle;
    margin-left: 0.4rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 700;
}

/* Thumbnail picker */
.thumb-picker {
    background: var(--bg-elev);
    border-radius: var(--radius);
    padding: 1rem;
    margin: 1rem 0;
}
.thumb-options {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 0.75rem;
    margin: 0.75rem 0;
}
.thumb-option {
    position: relative;
    cursor: pointer;
    border-radius: 6px;
    overflow: hidden;
    border: 3px solid transparent;
    transition: border-color 0.15s;
    display: block;
    aspect-ratio: 16 / 9;
    background: #000;
}
.thumb-option img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
.thumb-option input { position: absolute; opacity: 0; pointer-events: none; }
.thumb-option:hover { border-color: var(--text-dim); }
.thumb-option.selected { border-color: var(--accent); }
.thumb-option.selected::after {
    content: '✓';
    position: absolute;
    top: 4px;
    right: 4px;
    background: var(--accent);
    color: white;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.9rem;
}

/* Admin tabs */
.tabs {
    display: flex;
    gap: 0.25rem;
    border-bottom: 1px solid var(--border);
    margin-bottom: 1rem;
}
.tab {
    background: transparent;
    border: none;
    color: var(--text-dim);
    padding: 0.6rem 1rem;
    cursor: pointer;
    font: inherit;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }

/* Admin tables */
.admin-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--bg-elev);
    border-radius: var(--radius);
    overflow: hidden;
}
.admin-table th, .admin-table td {
    padding: 0.6rem 0.8rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}
.admin-table th {
    background: var(--bg-elev2);
    font-weight: 600;
    color: var(--text-dim);
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.admin-table tr:last-child td { border-bottom: none; }
/* Action cell stays as a normal table cell (display:table-cell), so it
   participates in the table's column layout. The inner wrapper is the flex
   container that arranges the buttons. Putting flex directly on the <td>
   removes it from the table layout and the column drifts out of alignment
   with the header. */
.admin-table .row-actions-inner { display: flex; gap: 0.4rem; flex-wrap: wrap; align-items: center; }
.admin-table .row-actions-inner .btn { padding: 0.3rem 0.6rem; font-size: 0.85rem; }
/* Minimum width so the column doesn't collapse when every visible row has
   no actions. The JS emits &nbsp; in non-actionable cells to keep the cell's
   line-height matching its neighbours. */
.admin-table td.row-actions { min-width: 7rem; }

/* Modal */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: 1rem;
}
.modal {
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    max-width: 600px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
}
.modal h2 { margin-top: 0; }
.modal input[type=text] { width: 100%; margin-top: 0.5rem; }

/* Make thumbnail backgrounds cover */
.video-row .thumb-sm {
    background-size: cover;
    background-position: center;
    background-color: #000;
}

@media (max-width: 720px) {
    .admin-table { font-size: 0.85rem; }
    .admin-table th, .admin-table td { padding: 0.4rem 0.5rem; }
    .topbar #langbox { order: 2; }
    .topbar #userbox { flex-wrap: wrap; gap: 0.25rem; }
}
