:root {
  --navy: #1e3a5f;
  --navy-700: #17304f;
  --navy-100: #e3eaf3;
  --blue: #2563eb;
  --blue-100: #dbeafe;
  --green: #0f766e;
  --green-100: #d1fae5;
  --red: #dc2626;
  --red-100: #fee2e2;
  --amber: #b45309;
  --amber-100: #fef3c7;
  --bg: #f3f5f9;
  --card: #ffffff;
  --fg: #0f172a;
  --muted: #5b6b7f;
  --muted-2: #94a3b8;
  --border: #e4e7eb;
  --border-strong: #cbd5e1;
  --ring: #2563eb;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.06), 0 1px 3px rgba(15, 23, 42, 0.05);
  --shadow-lg: 0 10px 30px rgba(15, 23, 42, 0.12);
  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, Arial, sans-serif;
  --s1: 4px;
  --s2: 8px;
  --s3: 12px;
  --s4: 16px;
  --s5: 24px;
  --s6: 32px;
  --s7: 48px;
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  color: var(--fg);
  background: var(--bg);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

body.is-loading .page {
  opacity: 0.4;
}

a {
  color: var(--blue);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

h1,
h2,
h3 {
  margin: 0;
  line-height: 1.25;
  color: var(--navy);
}

h1 {
  font-size: 1.6rem;
  font-weight: 700;
}

h2 {
  font-size: 1.2rem;
  font-weight: 700;
}

h3 {
  font-size: 1rem;
  font-weight: 600;
}

p {
  margin: 0;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

:focus-visible {
  outline: 3px solid rgba(37, 99, 235, 0.45);
  outline-offset: 2px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.hidden {
  display: none !important;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 0.875rem;
}

.container {
  width: 100%;
  max-width: 800px;
  margin: 0 auto;
  padding: 0 var(--s4);
}

.page {
  padding: var(--s5) 0 var(--s7);
  transition: opacity 0.2s;
}

/* ---------- Topbar ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--card);
  border-bottom: 1px solid var(--border);
}

.topbar__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s3);
  min-height: 60px;
}

.brand {
  font-weight: 800;
  color: var(--navy);
  font-size: 1.1rem;
  letter-spacing: -0.01em;
  display: inline-flex;
  align-items: center;
  gap: var(--s2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.brand:hover {
  text-decoration: none;
}

.brand__mark {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: var(--navy);
  color: #fff;
  display: inline-grid;
  place-items: center;
  flex: none;
}

.topbar__actions {
  display: flex;
  align-items: center;
  gap: var(--s2);
  flex: none;
}

.user-chip {
  display: none;
  align-items: center;
  gap: var(--s2);
  padding: 6px 12px 6px 6px;
  border-radius: 999px;
  background: var(--bg);
  color: var(--fg);
  font-weight: 600;
  font-size: 0.9rem;
  max-width: 260px;
}

.user-chip:hover {
  text-decoration: none;
  background: var(--navy-100);
}

.user-chip__avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--navy);
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 0.75rem;
  font-weight: 700;
  flex: none;
}

.user-chip__name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (min-width: 560px) {
  .user-chip {
    display: inline-flex;
  }
}

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s2);
  min-height: 44px;
  padding: 0 18px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--navy);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, box-shadow 0.15s, transform 0.05s;
  white-space: nowrap;
  text-decoration: none;
}

.btn:hover {
  background: var(--navy-700);
  text-decoration: none;
}

.btn:active {
  transform: translateY(1px);
}

.btn:disabled,
.btn[aria-disabled='true'] {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}

.btn--ghost {
  background: var(--card);
  color: var(--navy);
  border-color: var(--border-strong);
}

.btn--ghost:hover {
  background: var(--bg);
}

.btn--green {
  background: var(--green);
}

.btn--green:hover {
  background: #0b5d57;
}

.btn--danger {
  background: var(--red);
}

.btn--danger:hover {
  background: #b91c1c;
}

.btn--sm {
  min-height: 36px;
  padding: 0 12px;
  font-size: 0.875rem;
}

.btn--icon {
  padding: 0;
  width: 44px;
}

.btn--block {
  width: 100%;
}

.btn svg {
  width: 18px;
  height: 18px;
  flex: none;
}

/* ---------- Cards ---------- */

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: var(--s4) var(--s4);
}

.card + .card {
  margin-top: var(--s3);
}

.card--pad {
  padding: var(--s5);
}

.card-list {
  display: flex;
  flex-direction: column;
  gap: var(--s3);
}

.test-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s4);
  width: 100%;
  text-align: left;
  cursor: pointer;
  transition: box-shadow 0.15s, border-color 0.15s, transform 0.05s;
  color: var(--fg);
  margin: 0;
}

.test-card:hover {
  border-color: var(--border-strong);
  box-shadow: 0 4px 14px rgba(15, 23, 42, 0.08);
  text-decoration: none;
}

.test-card:active {
  transform: translateY(1px);
}

.test-card__body {
  min-width: 0;
}

.test-card__title {
  font-weight: 600;
  font-size: 1.05rem;
  color: var(--fg);
}

.test-card__sub {
  color: var(--muted);
  font-size: 0.875rem;
  margin-top: 2px;
}

.test-card__meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  flex: none;
}

.test-card__count {
  color: var(--green);
  font-weight: 700;
  font-size: 1.1rem;
  white-space: nowrap;
}

.test-card--mixed {
  border-left: 4px solid var(--green);
}

/* ---------- Forms ---------- */

.field {
  display: block;
  margin-bottom: var(--s4);
}

.field__label {
  display: block;
  font-weight: 600;
  font-size: 0.9rem;
  margin-bottom: 6px;
  color: var(--navy);
}

.input {
  width: 100%;
  min-height: 46px;
  padding: 10px 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: #fff;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.input:focus {
  outline: none;
  border-color: var(--ring);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.18);
}

.input[aria-invalid='true'] {
  border-color: var(--red);
}

textarea.input {
  min-height: 90px;
  resize: vertical;
}

select.input {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%235b6b7f' stroke-width='2'%3E%3Cpath d='m4 6 4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

.field__error {
  color: var(--red);
  font-size: 0.85rem;
  margin-top: 6px;
  min-height: 1.2em;
}

.form-alert {
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 0.9rem;
  margin-bottom: var(--s4);
}

.form-alert--error {
  background: var(--red-100);
  color: #991b1b;
}

.form-alert--ok {
  background: var(--green-100);
  color: #065f46;
}

.form-alert--warn {
  background: var(--amber-100);
  color: #92400e;
}

.check {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  cursor: pointer;
}

.check input {
  width: 20px;
  height: 20px;
  accent-color: var(--navy);
}

/* ---------- Login ---------- */

.auth {
  max-width: 440px;
  margin: var(--s6) auto 0;
}

.auth__head {
  text-align: center;
  margin-bottom: var(--s5);
}

.auth__head h1 {
  font-size: 1.5rem;
}

.auth__head p {
  color: var(--muted);
  margin-top: 6px;
}

/* ---------- Home ---------- */

.hero {
  margin-bottom: var(--s5);
}

.hero h1 {
  font-size: 1.7rem;
}

.hero p {
  color: var(--muted);
  margin-top: 4px;
}

.section-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin: var(--s5) 0 var(--s3);
}

/* ---------- Badges ---------- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  white-space: nowrap;
  background: var(--navy-100);
  color: var(--navy);
}

.badge--green {
  background: var(--green-100);
  color: #065f46;
}

.badge--red {
  background: var(--red-100);
  color: #991b1b;
}

.badge--amber {
  background: var(--amber-100);
  color: #92400e;
}

.badge--blue {
  background: var(--blue-100);
  color: #1e40af;
}

.badge--gray {
  background: #e9edf2;
  color: var(--muted);
}

/* ---------- Test screen ---------- */

.quiz-bar {
  position: sticky;
  top: 60px;
  z-index: 10;
  background: var(--card);
  border-bottom: 1px solid var(--border);
}

.quiz-bar__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s3);
  min-height: 52px;
}

.quiz-bar__title {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--navy);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.quiz-bar__right {
  display: flex;
  align-items: center;
  gap: var(--s2);
  flex: none;
}

.counter {
  font-weight: 700;
  color: var(--navy);
  font-variant-numeric: tabular-nums;
}

.timer {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--navy-100);
  color: var(--navy);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  font-size: 0.9rem;
}

.timer--warn {
  background: var(--amber-100);
  color: var(--amber);
}

.timer--danger {
  background: var(--red-100);
  color: var(--red);
}

.timer svg {
  width: 16px;
  height: 16px;
}

.progress {
  height: 4px;
  background: var(--border);
}

.progress__bar {
  height: 100%;
  background: var(--green);
  width: 0;
  transition: width 0.25s;
}

.question {
  margin-top: var(--s4);
}

.question__num {
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 6px;
}

.question__text {
  font-size: 1.12rem;
  font-weight: 600;
  line-height: 1.45;
  color: var(--fg);
}

.options {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: var(--s4);
}

.option {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  width: 100%;
  text-align: left;
  padding: 12px 14px;
  min-height: 52px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--card);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
  line-height: 1.4;
}

.option:hover {
  border-color: var(--border-strong);
  background: #fbfcfe;
}

.option__letter {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  flex: none;
  font-weight: 700;
  font-size: 0.85rem;
  background: var(--bg);
  color: var(--navy);
  border: 1px solid var(--border);
}

.option__text {
  flex: 1;
  padding-top: 3px;
}

.option--selected {
  border-color: var(--navy);
  background: #f4f7fb;
  box-shadow: 0 0 0 1px var(--navy);
}

.option--selected .option__letter {
  background: var(--navy);
  color: #fff;
  border-color: var(--navy);
}

.option--correct {
  border-color: var(--green);
  background: #f0fdf9;
}

.option--correct .option__letter {
  background: var(--green);
  color: #fff;
  border-color: var(--green);
}

.option--wrong {
  border-color: var(--red);
  background: #fff5f5;
}

.option--wrong .option__letter {
  background: var(--red);
  color: #fff;
  border-color: var(--red);
}

.option[disabled] {
  cursor: default;
}

.quiz-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s2);
  margin-top: var(--s5);
}

.quiz-actions .btn {
  flex: 1 1 140px;
}

.hide-sm {
  display: none;
}

@media (min-width: 560px) {
  .hide-sm {
    display: inline;
  }
}

.brand > span:last-child {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.quiz-actions .btn--finish {
  flex: 1.3;
}

.qnav {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(40px, 1fr));
  gap: 6px;
  margin-top: var(--s4);
}

.qnav__item {
  height: 40px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--muted);
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.qnav__item--answered {
  background: var(--navy);
  border-color: var(--navy);
  color: #fff;
}

.qnav__item--current {
  box-shadow: 0 0 0 2px var(--blue);
  border-color: var(--blue);
}

.qnav__item--correct {
  background: var(--green);
  border-color: var(--green);
  color: #fff;
}

.qnav__item--wrong {
  background: var(--red);
  border-color: var(--red);
  color: #fff;
}

.qnav__legend {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s3);
  margin-top: var(--s3);
  font-size: 0.8rem;
  color: var(--muted);
}

.qnav__legend span::before {
  content: '';
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 3px;
  margin-right: 6px;
  vertical-align: middle;
  background: var(--border-strong);
}

.qnav__legend .l-answered::before {
  background: var(--navy);
}

.qnav__legend .l-correct::before {
  background: var(--green);
}

.qnav__legend .l-wrong::before {
  background: var(--red);
}

/* ---------- Result ---------- */

.result-head {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: var(--s3);
  padding: var(--s5) var(--s4);
}

.score-ring {
  --pct: 0;
  --ring-color: var(--green);
  width: 150px;
  height: 150px;
  border-radius: 50%;
  background: conic-gradient(var(--ring-color) calc(var(--pct) * 1%), var(--border) 0);
  display: grid;
  place-items: center;
}

.score-ring__inner {
  width: 118px;
  height: 118px;
  border-radius: 50%;
  background: var(--card);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.score-ring__pct {
  font-size: 2rem;
  font-weight: 800;
  color: var(--navy);
  line-height: 1;
}

.score-ring__sub {
  color: var(--muted);
  font-size: 0.8rem;
  margin-top: 4px;
}

.stat-row {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--s3);
  margin-top: var(--s4);
}

@media (min-width: 560px) {
  .stat-row {
    grid-template-columns: repeat(4, 1fr);
  }
}

.stat {
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: 12px;
  text-align: center;
}

.stat__value {
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--navy);
  line-height: 1.1;
}

.stat__label {
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 4px;
}

.review-item {
  padding: var(--s4) 0;
  border-top: 1px solid var(--border);
}

.review-item:first-child {
  border-top: 0;
}

.review-item .options {
  margin-top: var(--s3);
}

.review-item .option {
  min-height: 44px;
  padding: 9px 12px;
}

/* ---------- Table ---------- */

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
  min-width: 560px;
}

.table th,
.table td {
  padding: 11px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  white-space: nowrap;
}

.table th {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
  background: #f8fafc;
  font-weight: 600;
}

.table tbody tr:last-child td {
  border-bottom: 0;
}

.table tbody tr.is-clickable {
  cursor: pointer;
}

.table tbody tr.is-clickable:hover {
  background: #f8fafc;
}

.table td.wrap {
  white-space: normal;
  min-width: 200px;
}

.table .num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.pct {
  font-weight: 700;
}

.pct--good {
  color: var(--green);
}

.pct--bad {
  color: var(--red);
}

/* ---------- Misc ---------- */

.empty {
  text-align: center;
  color: var(--muted);
  padding: var(--s6) var(--s4);
}

.empty svg {
  width: 40px;
  height: 40px;
  color: var(--muted-2);
  margin-bottom: var(--s2);
}

.toast-host {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(92vw, 420px);
  pointer-events: none;
}

.toast {
  background: var(--navy);
  color: #fff;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  font-size: 0.92rem;
  animation: toast-in 0.2s ease-out;
}

.toast--error {
  background: var(--red);
}

.toast--ok {
  background: var(--green);
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.modal {
  border: 0;
  border-radius: var(--radius);
  padding: 0;
  width: min(94vw, 520px);
  box-shadow: var(--shadow-lg);
}

.modal::backdrop {
  background: rgba(15, 23, 42, 0.45);
}

.modal__body {
  padding: var(--s5);
}

.modal__title {
  margin-bottom: var(--s3);
}

.modal__actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--s2);
  margin-top: var(--s5);
}

.modal--wide {
  width: min(96vw, 860px);
}

.spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--navy);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: var(--s6) auto;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.inline-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s2);
}

.kv {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 6px 16px;
  font-size: 0.92rem;
}

.kv dt {
  color: var(--muted);
}

.kv dd {
  margin: 0;
  font-weight: 500;
  overflow-wrap: anywhere;
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
  }
}

@media print {
  .topbar,
  .quiz-bar,
  .btn,
  .toast-host {
    display: none !important;
  }
}
