:root {
    --bg: #f2f4f7;
    --panel: #ffffff;
    --ink: #1f2937;
    --muted: #64748b;
    --brand: #111827;
    --brand-accent: #2563eb;
    --line: #dbe2ea;
    --success: #166534;
    --success-bg: #dcfce7;
    --danger: #b91c1c;
    --danger-bg: #fee2e2;
    --shadow: 0 18px 50px rgba(15, 23, 42, 0.08);
    --radius: 18px;
}

* { box-sizing: border-box; }
body { margin: 0; font-family: "Segoe UI", sans-serif; background: var(--bg); color: var(--ink); }
a { color: inherit; text-decoration: none; }
img { max-width: 100%; }
form { margin: 0; }
code { font-family: Consolas, monospace; }

.topbar {
    background: #111;
    color: #fff;
    padding: 0.95rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 20;
}

.topbar-actions, .public-actions { display: flex; align-items: center; gap: 0.75rem; }
.admin-layout { display: grid; grid-template-columns: 260px minmax(0, 1fr); min-height: calc(100vh - 56px); }
.sidebar { background: #1f2937; color: #cbd5e1; padding: 1.5rem 1rem; }
.sidebar nav { display: grid; gap: 0.45rem; }
.sidebar a { padding: 0.85rem 1rem; border-radius: 12px; }
.sidebar a.active, .sidebar a:hover { background: rgba(255,255,255,0.08); color: #fff; }
.admin-content { padding: 1.5rem; display: grid; gap: 1.5rem; }
.page-header, .card-header, .split { display: flex; justify-content: space-between; align-items: center; gap: 1rem; }
.card, .public-card, .lesson-card, .auth-card, .setup-card { background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.5rem; }
.public-shell, .auth-shell { width: min(1100px, calc(100% - 2rem)); margin: 0 auto; padding: 2rem 0 4rem; }
.public-header {
    display: flex; align-items: center; justify-content: space-between; gap: 1rem;
    padding: 1rem 2rem; background: #0f172a; color: white; position: sticky; top: 0; z-index: 20;
}
.public-nav { display: flex; gap: 1rem; flex-wrap: wrap; }
.public-nav a { padding: 0.35rem 0.6rem; border-radius: 999px; }
.public-nav a:hover { background: rgba(255,255,255,0.08); }
.hero {
    background: linear-gradient(135deg, #0f172a, #1d4ed8);
    color: white;
    border-radius: 24px;
    padding: 2rem;
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    align-items: end;
    margin-bottom: 1.5rem;
}
.code-card { width: min(560px, 100%); margin: 0 auto; }
.lesson-card { display: grid; gap: 1rem; }
.lesson-meta { display: flex; gap: 0.75rem; flex-wrap: wrap; }
.video-frame { position: relative; padding-top: 56.25%; overflow: hidden; border-radius: 20px; }
.video-frame iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.editor-output { line-height: 1.7; }
.editor-output img { border-radius: 16px; }
.editor-shell { border: 1px solid var(--line); border-radius: 18px; overflow: hidden; background: #fff; }
.editor-toolbar { display: flex; flex-wrap: wrap; gap: 0.5rem; padding: 0.9rem; background: #f8fafc; border-bottom: 1px solid var(--line); }
.editor-toolbar button {
    border: 1px solid var(--line);
    background: white;
    padding: 0.55rem 0.85rem;
    border-radius: 10px;
    cursor: pointer;
}
.editor-surface { min-height: 220px; padding: 1rem; outline: none; }
.button {
    display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem;
    border-radius: 12px; border: 1px solid transparent; padding: 0.8rem 1.1rem; cursor: pointer; font-weight: 600;
}
.button-primary { background: var(--brand-accent); color: white; }
.button-ghost { background: transparent; border-color: rgba(255,255,255,0.25); color: inherit; }
.auth-card, .setup-card { width: min(720px, 100%); margin: 3rem auto; }
.auth-body, .setup-body { min-height: 100vh; background: radial-gradient(circle at top, #dbeafe, #f8fafc 40%); }
.setup-shell { width: min(860px, calc(100% - 2rem)); margin: 0 auto; padding: 2rem 0 4rem; }
.eyebrow { text-transform: uppercase; letter-spacing: 0.1em; font-size: 0.78rem; color: var(--brand-accent); font-weight: 700; }
.stack, .stack-lg { display: grid; gap: 1rem; }
.grid.two, .admin-grid.two-col { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.span-2 { grid-column: span 2; }
label { display: grid; gap: 0.45rem; font-weight: 600; color: var(--ink); }
input, select, textarea {
    width: 100%; border: 1px solid var(--line); border-radius: 12px; padding: 0.85rem 0.95rem;
    font: inherit; background: white; color: var(--ink);
}
textarea { resize: vertical; }
.code-input { text-transform: uppercase; letter-spacing: 0.35em; text-align: center; font-size: 1.35rem; }
.stats-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1rem; }
.stat-card { background: white; padding: 1.25rem; border-radius: 18px; box-shadow: var(--shadow); display: grid; gap: 0.35rem; }
.stat-card strong { font-size: 2rem; }
.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 0.9rem 0.75rem; border-bottom: 1px solid var(--line); }
.badge, .chip {
    display: inline-flex; align-items: center; border-radius: 999px; background: #e2e8f0; color: #0f172a;
    padding: 0.35rem 0.8rem; font-size: 0.9rem; font-weight: 600;
}
.inline-form { display: flex; gap: 0.75rem; align-items: center; margin-top: 1rem; flex-wrap: wrap; }
.alert { padding: 0.95rem 1rem; border-radius: 14px; margin-bottom: 1rem; }
.alert-success { background: var(--success-bg); color: var(--success); }
.alert-error { background: var(--danger-bg); color: var(--danger); }
.narrow { width: min(520px, 100%); margin: 0 auto; }
.lede { color: var(--muted); font-size: 1.05rem; }

@media (max-width: 980px) {
    .admin-layout, .stats-grid, .grid.two, .admin-grid.two-col { grid-template-columns: 1fr; }
    .span-2 { grid-column: span 1; }
    .public-header, .hero { flex-direction: column; align-items: stretch; }
}
