:root {
    --bg: #f5f5f7;
    --surface: #ffffff;
    --surface-2: #f5f5f7;
    --ink: #1d1d1f;
    --muted: #6e6e73;
    --primary: #0071e3;
    --primary-dark: #0077ed;
    --border: #d2d2d7;
    --border-soft: #e8e8ed;
    --success-bg: #e3f6ea;
    --success-ink: #1a7f3c;
    --error-bg: #fdecec;
    --error-ink: #c22f2f;
    --info-bg: #eef4ff;
    --info-ink: #0057c7;
    --code-bg: #1d1d1f;
    --radius: 18px;
    --radius-sm: 12px;
    --shadow: 0 1px 3px rgba(0,0,0,.04), 0 6px 24px rgba(0,0,0,.06);
    --shadow-sm: 0 1px 2px rgba(0,0,0,.05);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, system-ui, sans-serif;
    background: var(--bg);
    color: var(--ink);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

/* Remove the blue tap flash on iOS and give deliberate feedback instead. */
a, button, input, textarea, select, label[role] {
    -webkit-tap-highlight-color: transparent;
}

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

/* ---- Header ---- */
.site-header {
    background: rgba(255,255,255,.8);
    backdrop-filter: saturate(180%) blur(20px);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    border-bottom: 1px solid var(--border-soft);
    position: sticky; top: 0; z-index: 50;
}
.header-inner {
    display: flex; align-items: center; justify-content: space-between;
    flex-wrap: wrap; gap: 12px;
    padding-top: 12px; padding-bottom: 12px;
}
.brand { font-weight: 600; font-size: 1.1rem; text-decoration: none; color: var(--ink); letter-spacing: -0.01em; }
.nav { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.nav a { color: var(--primary); text-decoration: none; font-size: 0.95rem; }
.nav a:hover { color: var(--primary-dark); }
.nav-user { color: var(--muted); font-size: 0.9rem; }

main.container { padding-top: 28px; padding-bottom: 56px; }

/* ---- Typography ---- */
h1 { font-size: 1.9rem; margin: 0 0 8px; letter-spacing: -0.02em; font-weight: 600; }
h2 { font-size: 1.3rem; margin: 30px 0 14px; letter-spacing: -0.01em; font-weight: 600; }
.subtitle { color: var(--muted); margin-top: 0; }

/* ---- Cards ---- */
.card {
    background: var(--surface);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius);
    padding: 24px;
    margin-bottom: 18px;
    box-shadow: var(--shadow-sm);
}
.card-narrow { max-width: 440px; margin-left: auto; margin-right: auto; }
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }

/* ---- Auth centering (student landing, teacher login) ---- */
.auth-wrap {
    min-height: calc(100vh - 230px);
    display: flex; align-items: center; justify-content: center;
    padding: 20px 0 40px;
}
.auth-card {
    background: var(--surface);
    border: 1px solid var(--border-soft);
    border-radius: 24px;
    box-shadow: var(--shadow);
    padding: 36px 32px;
    width: 100%; max-width: 440px;
    text-align: center;
}
.auth-card h1 { font-size: 1.7rem; }
.auth-card .subtitle { margin-bottom: 22px; }
.auth-foot { margin-top: 22px; font-size: 0.92rem; }
.auth-foot a { color: var(--primary); text-decoration: none; }

/* ---- Buttons ---- */
.btn {
    display: inline-flex; align-items: center; justify-content: center;
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: var(--radius-sm);
    padding: 12px 20px;
    min-height: 46px;
    font-size: 1rem; font-weight: 500;
    text-decoration: none; cursor: pointer;
    transition: transform .08s ease, background-color .15s ease, box-shadow .15s ease, opacity .15s ease;
    user-select: none;
}
.btn:hover { background: var(--primary-dark); }
.btn:active { transform: scale(0.97); opacity: .92; }
.btn:focus-visible { outline: 3px solid rgba(0,113,227,.35); outline-offset: 2px; }
.btn-block { width: 100%; }
.btn-secondary { background: var(--surface-2); color: var(--ink); border: 1px solid var(--border); }
.btn-secondary:hover { background: #ececef; }
.btn-danger { background: #fff0f0; color: var(--error-ink); border: 1px solid #f3c9c9; }
.btn-danger:hover { background: #ffe4e4; }
.btn-small { padding: 7px 12px; min-height: 36px; font-size: 0.86rem; }
.link-button {
    background: none; border: none; color: var(--primary);
    cursor: pointer; padding: 0; font: inherit;
}
.link-button:hover { text-decoration: underline; }
.inline-form { display: inline; margin: 0; }

/* ---- Forms ---- */
form p { margin: 0 0 16px; }
label { display: block; font-weight: 600; margin-bottom: 6px; font-size: 0.92rem; }
input[type=text], input[type=email], input[type=password], input[type=number],
input[type=datetime-local], textarea, select {
    width: 100%;
    padding: 13px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 16px;            /* 16px prevents iOS auto-zoom */
    font-family: inherit;
    background: var(--surface);
    color: var(--ink);
    transition: border-color .15s ease, box-shadow .15s ease;
    -webkit-appearance: none; appearance: none;
}
input:focus, textarea:focus, select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(0,113,227,.15);
}
.helptext { display: block; color: var(--muted); font-size: 0.82rem; margin-top: 5px; }
.errorlist { color: var(--error-ink); list-style: none; padding: 0; margin: 6px 0; font-size: 0.88rem; }
.form-actions { margin-top: 10px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

/* Big single-field code input for the student login */
.code-input {
    text-align: center;
    font-size: 1.6rem !important;
    letter-spacing: 0.18em;
    padding: 16px 14px !important;
    font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

/* ---- Messages ---- */
.messages { list-style: none; padding: 0; margin: 0 0 20px; }
.message { padding: 13px 16px; border-radius: var(--radius-sm); margin-bottom: 10px; font-size: 0.95rem; }
.message.success { background: var(--success-bg); color: var(--success-ink); }
.message.error { background: var(--error-bg); color: var(--error-ink); }
.message.info, .message.debug { background: var(--info-bg); color: var(--info-ink); }

/* ---- Tables ---- */
table.data { width: 100%; border-collapse: collapse; }
table.data th, table.data td {
    text-align: left; padding: 13px 10px; border-bottom: 1px solid var(--border-soft);
    vertical-align: middle;
}
table.data th { font-size: 0.74rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); font-weight: 600; }
table.data tr:last-child td { border-bottom: none; }

/* ---- Access code display ---- */
.code {
    font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
    background: var(--code-bg);
    color: #f5f5f7;
    padding: 4px 9px;
    border-radius: 7px;
    letter-spacing: 0.1em;
    font-size: 0.9rem;
}
.code-big {
    display: inline-block;
    font-family: ui-monospace, Menlo, Consolas, monospace;
    font-size: 2rem; letter-spacing: 0.25em;
    background: var(--code-bg); color: #f5f5f7;
    padding: 12px 22px; border-radius: 14px;
}

.muted { color: var(--muted); }
.badge {
    font-size: 0.74rem; padding: 3px 9px; border-radius: 999px;
    background: var(--surface-2); color: var(--muted); border: 1px solid var(--border-soft);
    white-space: nowrap;
}
.badge.inactive { background: var(--error-bg); color: var(--error-ink); border-color: #f3c9c9; }
.actions-cell { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---- Footer ---- */
.site-footer {
    border-top: 1px solid var(--border-soft);
    background: var(--surface);
    padding: 20px 0;
    margin-top: 24px;
}
.site-footer p { margin: 0; color: var(--muted); font-size: 0.86rem; }
.site-footer a { color: var(--primary); text-decoration: none; }
.site-footer a:hover { text-decoration: underline; }

/* ---- Hero / feature list (landing extras) ---- */
.hero { text-align: center; padding: 40px 0 12px; }
.hero h1 { font-size: 2.3rem; }
.hero .lead { font-size: 1.15rem; color: var(--muted); max-width: 620px; margin: 0 auto 24px; }
.hero-actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
.feature-list { list-style: none; padding: 0; }
.feature-list li { padding: 8px 0 8px 28px; position: relative; }
.feature-list li::before { content: "✓"; position: absolute; left: 0; color: var(--success-ink); font-weight: 700; }

/* ---- iPad / tablet & phone ---- */
@media (max-width: 820px) {
    main.container { padding-top: 20px; }
    h1 { font-size: 1.7rem; }
    .card { padding: 20px; }
    /* Comfortable tap targets on touch devices */
    .btn-small { min-height: 40px; padding: 9px 14px; font-size: 0.9rem; }
    .actions-cell { gap: 10px; }
}
@media (max-width: 560px) {
    .auth-card { padding: 28px 20px; border-radius: 20px; }
    table.data th, table.data td { padding: 12px 8px; }
}

/* Honor reduced-motion preferences */
@media (prefers-reduced-motion: reduce) {
    * { transition: none !important; }
    .btn:active { transform: none; }
}
