:root {
    --bg: #0f172a;
    --bg-soft: #1e293b;
    --surface: #ffffff;
    --text: #1e293b;
    --muted: #64748b;
    --border: #e2e8f0;
    --primary: #4f46e5;
    --primary-dark: #4338ca;
    --success: #16a34a;
    --success-bg: #dcfce7;
    --error: #dc2626;
    --error-bg: #fee2e2;
    --warn-bg: #fef9c3;
    --radius: 12px;
    --shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 8px 24px rgba(15, 23, 42, .06);
}

* { box-sizing: border-box; }

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

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.container { width: 100%; max-width: 960px; margin: 0 auto; padding: 0 20px; }

/* ---------- Header ---------- */
.site-header {
    background: var(--bg);
    color: #fff;
    box-shadow: var(--shadow);
}
.header-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 14px 20px;
}
.brand { color: #fff; font-weight: 700; font-size: 1.15rem; }
.brand:hover { text-decoration: none; }
.nav { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.nav a { color: #cbd5e1; font-size: .95rem; }
.nav a:hover { color: #fff; text-decoration: none; }
.nav-user { color: #94a3b8; font-size: .9rem; }
.nav-toggle {
    display: none;
    background: none; border: 0; color: #fff;
    font-size: 1.4rem; cursor: pointer;
}

/* ---------- Layout ---------- */
.page { padding: 32px 20px 64px; }
.site-footer {
    color: var(--muted);
    text-align: center;
    padding: 32px 0;
    font-size: .85rem;
}
.site-footer p { margin: 4px 0; }
.site-footer .credit a { font-weight: 600; }

/* Install app banner */
.install-banner {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 60;
    display: flex; align-items: center; justify-content: space-between;
    gap: 12px; flex-wrap: wrap;
    padding: 12px 16px;
    background: var(--bg);
    color: #fff;
    box-shadow: 0 -4px 16px rgba(15, 23, 42, .25);
}
.install-banner .install-text { font-size: .92rem; }
.install-banner .install-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Cards ---------- */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 28px;
    margin-bottom: 24px;
}
.auth-card { max-width: 420px; margin: 40px auto; }
.auth-card--wide { max-width: 560px; }

h1 { font-size: 1.6rem; margin: 0 0 16px; }
h2 { font-size: 1.25rem; margin: 0 0 12px; }
.form-section {
    margin: 24px 0 8px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
    font-size: 1rem;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .04em;
}
.form-section:first-of-type { border-top: 0; padding-top: 0; }

.muted { color: var(--muted); }
small.muted { font-weight: 400; }

/* ---------- Forms ---------- */
.form label {
    display: block;
    margin-bottom: 16px;
    font-weight: 600;
    font-size: .92rem;
}
.form input[type=text],
.form input[type=email],
.form input[type=password],
.form input[type=url],
.form input[type=number],
.form select,
.form textarea {
    display: block;
    width: 100%;
    margin-top: 6px;
    padding: 10px 12px;
    font: inherit;
    font-weight: 400;
    color: var(--text);
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 8px;
}
.form textarea { min-height: 90px; resize: vertical; }
.form input:focus, .form select:focus, .form textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, .15);
}
.inline-checkbox {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-weight: 400;
}

/* ---------- Buttons ---------- */
.btn {
    display: inline-block;
    padding: 10px 18px;
    font: inherit;
    font-weight: 600;
    color: var(--text);
    background: #e2e8f0;
    border: 0;
    border-radius: 8px;
    cursor: pointer;
    transition: background .15s, opacity .15s;
}
.btn:hover { text-decoration: none; opacity: .92; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { background: var(--error-bg); color: var(--error); }
.btn-success { background: var(--success-bg); color: var(--success); }
.btn-sm { padding: 6px 12px; font-size: .85rem; }
.btn-block { display: block; width: 100%; text-align: center; }

/* ---------- Flash / alerts ---------- */
.flash {
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 16px;
    font-size: .95rem;
}
.flash-success { background: var(--success-bg); color: #166534; }
.flash-error   { background: var(--error-bg);   color: #991b1b; }
.flash-info    { background: #dbeafe;           color: #1e40af; }
.flash-warning { background: var(--warn-bg);    color: #854d0e; }

/* ---------- Grid / stats ---------- */
.grid { display: grid; gap: 20px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }

.stat {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    text-align: center;
    box-shadow: var(--shadow);
}
.stat .num { font-size: 2rem; font-weight: 700; color: var(--primary); }
.stat .label { color: var(--muted); font-size: .9rem; }

/* ---------- Tables ---------- */
.table {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
    border-radius: var(--radius);
    overflow: hidden;
}
.table th, .table td {
    text-align: left;
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
    font-size: .92rem;
    vertical-align: middle;
}
.table th { background: #f8fafc; color: var(--muted); font-weight: 600; }
.table tr:last-child td { border-bottom: 0; }
.table .actions { white-space: nowrap; text-align: right; }

.badge {
    display: inline-block;
    padding: 2px 9px;
    font-size: .78rem;
    font-weight: 600;
    border-radius: 999px;
    background: #e2e8f0;
    color: var(--muted);
}
.badge-admin { background: #ede9fe; color: var(--primary-dark); }
.badge-ok { background: var(--success-bg); color: #166534; }

/* ---------- Quiz ---------- */
.question-block {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 22px;
    margin-bottom: 18px;
    box-shadow: var(--shadow);
}
.question-block .qnum { color: var(--muted); font-size: .85rem; font-weight: 600; }
.question-block .qtext { font-size: 1.1rem; font-weight: 600; margin: 6px 0 16px; }
.question-image {
    display: block;
    max-width: 100%;
    height: auto;
    margin: 0 0 16px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fff;
}
.option {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-bottom: 8px;
    cursor: pointer;
}
.option:hover { border-color: var(--primary); }
.option input { margin-top: 3px; }
.option.correct { border-color: var(--success); background: var(--success-bg); }
.option.incorrect { border-color: var(--error); background: var(--error-bg); }
.explanation {
    margin-top: 12px;
    padding: 12px 14px;
    background: #f8fafc;
    border-left: 3px solid var(--primary);
    border-radius: 6px;
    font-size: .92rem;
}
.result-summary { text-align: center; padding: 12px 0 4px; }
.result-summary .score { font-size: 3rem; font-weight: 800; color: var(--primary); }

/* Quiz progress bar + matching rows */
.quiz-progress {
    height: 8px;
    background: var(--border);
    border-radius: 999px;
    overflow: hidden;
    margin-bottom: 18px;
}
.quiz-progress > div { height: 100%; background: var(--primary); transition: width .25s; }
.match-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 10px;
    flex-wrap: wrap;
}
.match-row .match-prompt { min-width: 150px; font-weight: 600; }
.match-row select {
    flex: 1;
    min-width: 160px;
    padding: 10px 12px;
    font: inherit;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 8px;
}
.match-row .match-input {
    width: 90px;
    padding: 8px 10px;
    font: inherit;
    text-align: center;
    text-transform: uppercase;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 8px;
}
.match-row .match-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, .15);
}

/* ---------- Answer editor (admin) ---------- */
.answer-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
}
.answer-row input[type=text] { flex: 1; margin-top: 0; }
.answer-row .correct-toggle {
    display: inline-flex; align-items: center; gap: 6px;
    white-space: nowrap; font-size: .85rem; font-weight: 600;
}
.answer-row .remove-row {
    background: var(--error-bg); color: var(--error);
    border: 0; border-radius: 6px; padding: 8px 10px; cursor: pointer;
}

.toolbar {
    display: flex; align-items: center; justify-content: space-between;
    gap: 16px; margin-bottom: 18px; flex-wrap: wrap;
}
.toolbar h1 { margin: 0; }

/* Bulk add-questions cards */
.bulk-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 18px 20px;
    margin-bottom: 16px;
}
.bulk-card-head {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    margin-bottom: 10px;
}
.bulk-card-head h3 { margin: 0; font-size: 1.05rem; }
.bulk-card textarea,
.bulk-card .bulk-type {
    display: block; width: 100%; margin: 0 0 10px;
    padding: 10px 12px; font: inherit; color: var(--text);
    background: #fff; border: 1px solid var(--border); border-radius: 8px;
}
.bulk-card textarea { min-height: 60px; resize: vertical; }
.bulk-card .answer-row input[type=text] { margin-top: 0; }

.hero {
    text-align: center;
    padding: 48px 24px;
}
.hero h1 { font-size: 2rem; }
.hero p { color: var(--muted); font-size: 1.05rem; max-width: 520px; margin: 0 auto 24px; }

/* ---------- Responsive ---------- */
@media (max-width: 720px) {
    .grid-3, .grid-4 { grid-template-columns: repeat(2, 1fr); }
    .nav-toggle { display: block; }
    .nav {
        display: none;
        width: 100%;
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
        padding-top: 12px;
    }
    .nav.open { display: flex; }
    .header-inner { flex-wrap: wrap; }

    /* Wide tables scroll sideways instead of overflowing the screen. */
    .table { display: block; overflow-x: auto; white-space: nowrap; }
    .table .actions { text-align: left; }
    /* Stack toolbar actions on small screens. */
    .toolbar { align-items: flex-start; }
}
@media (max-width: 480px) {
    .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
    .btn { padding: 9px 14px; }            /* comfortable tap targets */
    .match-row { gap: 8px; }
    .match-row .match-prompt { min-width: 0; }
}
