:root {
  --navy: #102b46;
  --navy-2: #173e5f;
  --teal: #0e8f82;
  --mint: #2ec4a6;
  --mint-soft: #ddf8f1;
  --blue-soft: #e9f2f8;
  --amber: #f4b942;
  --red: #c94252;
  --red-soft: #fdebed;
  --ink: #172636;
  --muted: #667789;
  --line: #dce5ec;
  --surface: #ffffff;
  --background: #f3f7fa;
  --shadow: 0 18px 50px rgba(16, 43, 70, .10);
  --radius: 20px;
}

* { box-sizing: border-box; }
html { font-family: "Manrope", system-ui, sans-serif; color: var(--ink); background: var(--background); }
body { margin: 0; min-height: 100vh; font-size: 16px; }
button, input, select { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.muted { color: var(--muted); }

.loading-screen { min-height: 100vh; display: grid; place-content: center; gap: 22px; justify-items: center; background: var(--navy); }
.loader { width: 36px; height: 36px; border: 3px solid rgba(255,255,255,.25); border-top-color: var(--mint); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.brand-mark { width: 62px; height: 62px; display: grid; place-items: center; border-radius: 18px; background: var(--mint); color: var(--navy); font-weight: 800; letter-spacing: -.05em; }
.brand-mark.small { width: 42px; height: 42px; border-radius: 12px; font-size: .82rem; }
.brand-lockup { display: flex; align-items: center; gap: 12px; font-weight: 800; font-size: 1.15rem; color: white; }
.eyebrow { display: inline-block; color: var(--teal); font-size: .75rem; font-weight: 800; text-transform: uppercase; letter-spacing: .12em; }
.eyebrow.light { color: #81e6d4; }

.center-view { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.setup-card { max-width: 560px; padding: 42px; border: 1px solid var(--line); border-radius: var(--radius); background: white; box-shadow: var(--shadow); }
.setup-card h1 { margin: 10px 0; font-size: clamp(1.8rem, 4vw, 2.6rem); }
.setup-card code { display: block; margin-top: 24px; padding: 14px; border-radius: 10px; background: var(--navy); color: white; }

.auth-layout { min-height: 100vh; display: grid; grid-template-columns: minmax(420px, 1.1fr) minmax(420px, .9fr); }
.auth-brand { min-height: 100vh; padding: 38px clamp(38px, 6vw, 90px); color: white; background: radial-gradient(circle at 20% 20%, rgba(46,196,166,.22), transparent 32%), linear-gradient(145deg, #0b2238, #173f5f); display: flex; flex-direction: column; }
.auth-copy { max-width: 680px; margin: auto 0; padding: 70px 0; }
.auth-copy h1 { max-width: 620px; margin: 16px 0 18px; font-size: clamp(2.6rem, 5vw, 5rem); line-height: 1.02; letter-spacing: -.055em; }
.auth-copy > p { max-width: 560px; margin-bottom: 48px; color: #c9d8e5; font-size: 1.1rem; line-height: 1.7; }
.auth-feature { max-width: 560px; display: grid; grid-template-columns: 42px 1fr; align-items: center; gap: 16px; padding: 14px 0; border-top: 1px solid rgba(255,255,255,.14); }
.auth-feature span { color: var(--mint); font-weight: 800; }
.auth-feature p { margin: 0; color: #d9e4ec; }
.auth-panel { display: grid; place-items: center; padding: 34px; background: #f7fafc; }
.login-card { width: min(440px, 100%); padding: 44px; border: 1px solid var(--line); border-radius: 24px; background: white; box-shadow: var(--shadow); }
.login-card h2 { margin: 8px 0; font-size: 2rem; }
.mobile-brand { display: none; align-items: center; gap: 12px; margin-bottom: 32px; }
label { display: grid; gap: 8px; margin: 22px 0; color: #30465a; font-size: .9rem; font-weight: 700; }
input, select { width: 100%; min-height: 48px; padding: 0 14px; border: 1px solid #cdd9e2; border-radius: 11px; background: white; color: var(--ink); outline: none; }
input:focus, select:focus { border-color: var(--teal); box-shadow: 0 0 0 4px rgba(14,143,130,.12); }
.form-error { min-height: 22px; color: var(--red); font-size: .88rem; }

.btn { min-height: 44px; padding: 0 18px; border: 1px solid transparent; border-radius: 11px; font-weight: 800; transition: transform .15s, background .15s; }
.btn:hover { transform: translateY(-1px); }
.btn.primary { background: var(--navy); color: white; }
.btn.primary:hover { background: var(--navy-2); }
.btn.secondary { border-color: #abd9d2; background: var(--mint-soft); color: #08685f; }
.btn.danger { background: var(--red); color: white; }
.btn.ghost { border-color: var(--line); background: white; color: var(--navy); }
.btn.full { width: 100%; }
.btn:disabled { cursor: not-allowed; opacity: .55; transform: none; }

.app-shell { min-height: 100vh; display: grid; grid-template: 72px 1fr / 260px 1fr; }
.topbar { position: sticky; top: 0; z-index: 20; grid-column: 1 / -1; display: flex; align-items: center; justify-content: space-between; padding: 0 24px; background: var(--navy); box-shadow: 0 6px 22px rgba(16,43,70,.13); }
.topbar-actions { display: flex; align-items: center; gap: 18px; }
.user-chip { display: flex; align-items: center; gap: 10px; color: white; }
.user-chip > span { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 12px; background: rgba(46,196,166,.18); color: #8cf1de; font-weight: 800; }
.user-chip div { display: grid; }
.user-chip small { color: #b9c9d7; }
.menu-button { display: none; }
.icon-button { width: 42px; height: 42px; border: 0; border-radius: 10px; background: rgba(255,255,255,.1); color: white; }
.sidebar { position: sticky; top: 72px; height: calc(100vh - 72px); display: flex; flex-direction: column; padding: 24px 18px; background: white; border-right: 1px solid var(--line); }
.sidebar nav { display: grid; gap: 7px; }
.nav-button { width: 100%; display: flex; align-items: center; gap: 12px; padding: 13px 14px; border: 0; border-radius: 12px; background: transparent; color: #526679; text-align: left; font-weight: 700; }
.nav-button.active, .nav-button:hover { background: var(--blue-soft); color: var(--navy); }
.nav-icon { width: 28px; color: var(--teal); text-align: center; }
.sidebar-note { margin-top: auto; display: grid; gap: 6px; padding: 15px; border-radius: 14px; background: var(--mint-soft); color: #17685f; font-size: .8rem; }
.main-content { min-width: 0; padding: clamp(24px, 4vw, 52px); }

.page-header { display: flex; align-items: end; justify-content: space-between; gap: 20px; margin-bottom: 28px; }
.page-header h1 { margin: 5px 0 0; font-size: clamp(1.8rem, 3vw, 2.8rem); line-height: 1.12; letter-spacing: -.04em; }
.page-header p { max-width: 680px; margin: 8px 0 0; color: var(--muted); }
.grid { display: grid; gap: 20px; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.card { padding: 24px; border: 1px solid var(--line); border-radius: var(--radius); background: white; box-shadow: 0 8px 30px rgba(16,43,70,.055); }
.card h2, .card h3 { margin-top: 0; }
.stat-card { min-height: 144px; display: flex; flex-direction: column; justify-content: space-between; }
.stat-card strong { font-size: 2rem; color: var(--navy); }
.stat-card span { color: var(--muted); font-size: .86rem; font-weight: 700; }
.stat-accent { width: 42px; height: 5px; border-radius: 10px; background: var(--mint); }

.welcome-card { position: relative; overflow: hidden; min-height: 220px; padding: 34px; color: white; background: linear-gradient(130deg, var(--navy), #20577c); }
.welcome-card::after { content: ""; position: absolute; width: 240px; height: 240px; right: -70px; top: -90px; border: 45px solid rgba(46,196,166,.16); border-radius: 50%; }
.welcome-card h2 { max-width: 630px; font-size: clamp(1.65rem, 3vw, 2.5rem); }
.welcome-card p { max-width: 660px; color: #d8e4ec; }
.welcome-card .btn { margin-top: 14px; background: var(--mint); color: var(--navy); }

.module-list { display: grid; gap: 14px; }
.module-card { display: grid; grid-template-columns: 54px 1fr auto; gap: 18px; align-items: center; padding: 20px; border: 1px solid var(--line); border-radius: 16px; background: white; }
.module-number { width: 54px; height: 54px; display: grid; place-items: center; border-radius: 15px; background: var(--blue-soft); color: var(--navy); font-weight: 800; }
.module-card h3 { margin: 0 0 6px; }
.module-meta { display: flex; flex-wrap: wrap; gap: 12px; color: var(--muted); font-size: .82rem; }
.progress-track { height: 8px; overflow: hidden; margin-top: 13px; border-radius: 10px; background: #e9eef2; }
.progress-fill { height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--teal), var(--mint)); }
.locked { opacity: .62; }
.badge { display: inline-flex; align-items: center; min-height: 28px; padding: 0 10px; border-radius: 999px; background: var(--blue-soft); color: var(--navy); font-size: .75rem; font-weight: 800; }
.badge.success { background: var(--mint-soft); color: #08685f; }
.badge.warning { background: #fff2d2; color: #805300; }
.badge.danger { background: var(--red-soft); color: #9a2837; }

.question-shell { max-width: 980px; margin: 0 auto; }
.question-top { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 18px; margin-bottom: 20px; }
.question-progress { color: var(--muted); font-weight: 700; }
.timer { min-width: 112px; padding: 11px 15px; border-radius: 12px; background: var(--navy); color: white; text-align: center; font-variant-numeric: tabular-nums; font-weight: 800; }
.question-card { padding: clamp(24px, 5vw, 44px); }
.question-context { margin-bottom: 26px; padding: 22px; border-left: 5px solid var(--mint); border-radius: 0 12px 12px 0; background: #f5f9fb; white-space: pre-wrap; line-height: 1.68; }
.question-card h2 { font-size: clamp(1.25rem, 2.4vw, 1.75rem); line-height: 1.45; }
.options { display: grid; gap: 12px; margin-top: 28px; }
.option { display: grid; grid-template-columns: 38px 1fr; gap: 12px; align-items: start; width: 100%; padding: 16px; border: 1px solid #cad7e0; border-radius: 14px; background: white; color: var(--ink); text-align: left; line-height: 1.5; }
.option:hover { border-color: var(--teal); background: #f5fcfa; }
.option.selected { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(14,143,130,.12); }
.option-key { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 9px; background: var(--blue-soft); color: var(--navy); font-weight: 800; }
.feedback { margin: 22px 0 0; padding: 18px; border-radius: 13px; line-height: 1.55; }
.feedback.error { background: var(--red-soft); color: #862634; }
.feedback.correct { background: var(--mint-soft); color: #08685f; }
.question-actions { display: flex; justify-content: flex-end; gap: 12px; margin-top: 24px; }

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 15px; background: white; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 14px 16px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { background: #f3f7fa; color: #4c6072; font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; }
tr:last-child td { border-bottom: 0; }
.empty-state { padding: 52px 24px; text-align: center; color: var(--muted); }

.admin-form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 18px; }
.admin-form .span-2 { grid-column: 1 / -1; }
.result-score { display: grid; place-items: center; width: 150px; height: 150px; margin: 20px auto; border: 14px solid var(--mint-soft); border-top-color: var(--teal); border-radius: 50%; color: var(--navy); }
.result-score strong { font-size: 2.4rem; }
.result-score small { display: block; color: var(--muted); text-align: center; }
.subject-bars { display: grid; gap: 14px; }
.subject-row { display: grid; grid-template-columns: 180px 1fr 52px; gap: 12px; align-items: center; }

.toast { position: fixed; right: 22px; bottom: 22px; z-index: 100; max-width: 420px; padding: 15px 18px; border-radius: 12px; background: var(--navy); color: white; box-shadow: var(--shadow); opacity: 0; pointer-events: none; transform: translateY(12px); transition: .2s; }
.toast.show { opacity: 1; transform: translateY(0); }

@media (max-width: 980px) {
  .auth-layout { grid-template-columns: 1fr; }
  .auth-brand { display: none; }
  .mobile-brand { display: flex; color: var(--navy); }
  .app-shell { grid-template-columns: 1fr; }
  .menu-button { display: inline-grid; place-items: center; }
  .sidebar { position: fixed; z-index: 19; top: 72px; left: 0; width: 280px; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow); }
  .sidebar.open { transform: translateX(0); }
  .grid.cols-4, .grid.cols-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 680px) {
  .auth-panel { padding: 18px; }
  .login-card { padding: 28px 22px; }
  .topbar { padding: 0 14px; }
  .topbar .brand-lockup > span:last-child, .user-chip div, .topbar .btn { display: none; }
  .main-content { padding: 24px 16px 42px; }
  .grid.cols-2, .grid.cols-3, .grid.cols-4 { grid-template-columns: 1fr; }
  .page-header { align-items: start; flex-direction: column; }
  .module-card { grid-template-columns: 46px 1fr; }
  .module-card > .btn, .module-card > .badge { grid-column: 1 / -1; width: 100%; justify-content: center; }
  .admin-form { grid-template-columns: 1fr; }
  .admin-form .span-2 { grid-column: auto; }
  .subject-row { grid-template-columns: 1fr 48px; }
  .subject-row .progress-track { grid-column: 1 / -1; grid-row: 2; }
  .question-actions { flex-direction: column; }
  .question-actions .btn { width: 100%; }
}
