:root {
  color-scheme: light;
  --bg: #eef1f4;
  --surface: #ffffff;
  --surface-2: #f5f7f9;
  --surface-3: #e8edf2;
  --ink: #182230;
  --muted: #667085;
  --line: #d9e0e8;
  --line-soft: #e7ecf1;
  --blue: #365f7f;
  --blue-dark: #284a64;
  --teal: #3f6f68;
  --green: #2d7a4f;
  --green-soft: #eaf5ee;
  --red: #a0443e;
  --red-soft: #f8e9e7;
  --amber: #9a6a2f;
  --amber-soft: #f7efd9;
  --shadow: 0 10px 28px rgba(24, 34, 48, 0.07);
  --shadow-soft: 0 4px 14px rgba(24, 34, 48, 0.04);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(circle at top left, rgba(63, 111, 104, 0.08), transparent 340px),
    var(--bg);
  color: var(--ink);
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.62;
}

.auth-page {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
  background: var(--bg);
}

.auth-shell {
  width: min(100%, 460px);
}

.auth-panel,
.panel,
.question-panel,
.results-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.auth-panel {
  padding: clamp(22px, 5vw, 34px);
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-lockup.compact {
  gap: 12px;
}

.brand-mark {
  display: grid;
  flex: 0 0 48px;
  width: 48px;
  height: 48px;
  place-items: center;
  border-radius: 8px;
  background: var(--ink);
  color: #fff;
  font-weight: 800;
  letter-spacing: 0;
}

.compact .brand-mark {
  flex-basis: 42px;
  width: 42px;
  height: 42px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--teal);
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(1.45rem, 3vw, 1.9rem);
}

h2 {
  font-size: clamp(1.15rem, 2.2vw, 1.5rem);
}

.auth-form {
  display: grid;
  gap: 16px;
  margin-top: 28px;
}

.auth-form label,
.field {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 700;
}

.auth-form input,
.field input {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
  color: var(--ink);
  padding: 10px 12px;
  font-weight: 600;
}

.auth-form input:focus,
.field input:focus {
  border-color: var(--blue);
  outline: 3px solid rgba(54, 95, 127, 0.14);
}

.primary-button,
.ghost-button,
.mini-button {
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 0 16px;
  font-size: 0.94rem;
  font-weight: 760;
  letter-spacing: 0;
}

.primary-button {
  background: var(--blue);
  color: #fff;
}

.primary-button:hover:not(:disabled) {
  background: var(--blue-dark);
}

.ghost-button {
  border-color: var(--line);
  background: rgba(255, 255, 255, 0.72);
  color: var(--ink);
}

.ghost-button:hover:not(:disabled),
.mini-button:hover:not(:disabled) {
  border-color: #aab5c4;
}

.mini-button {
  min-height: 38px;
  background: var(--surface-2);
  border-color: var(--line);
  color: var(--ink);
  padding: 0 14px;
}

.mini-button.danger {
  background: var(--red-soft);
  color: var(--red);
}

.notice {
  margin-top: 18px;
  border-radius: 8px;
  padding: 12px 14px;
  font-weight: 700;
}

.notice.error {
  background: var(--red-soft);
  color: var(--red);
}

.notice.success {
  background: var(--green-soft);
  color: var(--green);
}

.notice.warning {
  background: var(--amber-soft);
  color: var(--amber);
}

.app-shell {
  width: min(100%, 1180px);
  margin: 0 auto;
  padding: 18px 22px 28px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 10px 0 20px;
}

.app-brand {
  display: flex;
  align-items: center;
  min-width: 0;
}

.app-brand h1 {
  color: var(--teal);
  font-size: clamp(1.05rem, 2vw, 1.28rem);
  font-weight: 780;
  line-height: 1.1;
  text-transform: uppercase;
}

.topbar-actions {
  display: flex;
  align-items: center;
  flex: 0 0 auto;
}

.user-email {
  max-width: min(34vw, 280px);
  overflow: hidden;
  color: var(--muted);
  font-weight: 650;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.page-notice {
  margin: 0 0 18px;
}

.workspace {
  display: grid;
  gap: 16px;
}

.loading-state,
.empty-state {
  color: var(--muted);
  font-weight: 700;
  text-align: center;
}

.loading-state {
  padding: 80px 20px;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  align-items: start;
}

.panel {
  padding: clamp(16px, 3vw, 24px);
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.section-title {
  margin: 0;
  color: var(--teal);
  font-size: 0.92rem;
  font-weight: 780;
  letter-spacing: 0;
  text-transform: uppercase;
}

.selection-actions,
.form-footer,
.question-footer,
.result-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.section-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 12px;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: var(--surface-2);
  padding: 12px;
}

.section-row {
  display: grid;
  grid-template-columns: 20px minmax(0, 1fr);
  gap: 12px;
  align-items: start;
  min-height: 78px;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: #fff;
  padding: 13px 14px;
  transition: border-color 140ms ease, background 140ms ease, box-shadow 140ms ease;
}

.section-row:has(input:checked) {
  border-color: rgba(63, 111, 104, 0.28);
  background: #fbfdfc;
  box-shadow: var(--shadow-soft);
}

.section-row input {
  width: 18px;
  height: 18px;
  margin-top: 3px;
  accent-color: var(--teal);
}

.section-copy {
  display: grid;
  min-width: 0;
  gap: 4px;
}

.section-copy strong {
  overflow-wrap: anywhere;
  line-height: 1.28;
  font-size: 0.98rem;
  font-weight: 760;
}

.section-copy small {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 650;
  line-height: 1.35;
}

.test-form {
  display: grid;
  gap: 16px;
}

.start-controls {
  display: grid;
  grid-template-columns: minmax(130px, 170px) minmax(260px, 1fr) minmax(112px, 132px) minmax(120px, 136px);
  gap: 14px;
  align-items: end;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: #fbfcfd;
  padding: 14px;
}

.form-grid {
  display: grid;
  grid-template-columns: minmax(132px, 190px) minmax(260px, 1fr);
  gap: 16px;
}

.range-pair {
  display: grid;
  grid-template-columns: minmax(160px, 1fr) 82px;
  gap: 12px;
  align-items: center;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--teal);
}

.form-footer {
  justify-content: space-between;
  color: var(--muted);
  font-weight: 800;
}

.available-box {
  display: grid;
  min-height: 44px;
  align-content: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 8px 12px;
}

.available-box span {
  color: var(--ink);
  font-size: 1rem;
  font-weight: 780;
  line-height: 1.1;
}

.available-box small {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 650;
}

.start-controls .primary-button {
  min-height: 44px;
}

.inline-error {
  margin: 0;
  color: var(--red);
  font-weight: 800;
}

.stat-grid,
.result-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.stats-panel .stat-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.stat-grid div,
.result-stats div {
  display: grid;
  gap: 4px;
  min-height: 76px;
  align-content: center;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  padding: 14px;
  background: var(--surface-2);
}

.stat-grid span,
.result-stats span {
  font-size: clamp(1.2rem, 3.4vw, 1.58rem);
  font-weight: 820;
}

.stat-grid small,
.result-stats small {
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 680;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: #fff;
}

table {
  width: 100%;
  min-width: 840px;
  border-collapse: collapse;
}

th,
td {
  padding: 12px 10px;
  border-bottom: 1px solid var(--line-soft);
  text-align: left;
  vertical-align: middle;
}

th {
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.82rem;
  text-transform: uppercase;
}

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

.result-pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border-radius: 999px;
  padding: 0 10px;
  font-size: 0.82rem;
  font-weight: 900;
}

.result-pill.pass {
  background: var(--green-soft);
  color: var(--green);
}

.result-pill.fail {
  background: var(--red-soft);
  color: var(--red);
}

.result-pill.pending {
  background: var(--surface-2);
  color: var(--muted);
}

.history-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.quiz-shell {
  display: grid;
  gap: 14px;
}

.quiz-topline,
.quiz-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.quiz-meta {
  color: var(--muted);
  font-weight: 900;
}

.quiz-meta span {
  min-width: 74px;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.8);
  padding: 8px 10px;
  text-align: center;
}

.progress-track {
  height: 7px;
  overflow: hidden;
  border-radius: 999px;
  background: #dfe6eb;
}

.progress-track div {
  height: 100%;
  border-radius: inherit;
  background: var(--teal);
  transition: width 180ms ease;
}

.question-panel {
  padding: clamp(18px, 4vw, 30px);
}

.question-kicker {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 16px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 900;
}

.question-kicker span {
  border: 1px solid var(--line-soft);
  border-radius: 999px;
  padding: 6px 10px;
  background: var(--surface-2);
}

.question-panel h2 {
  max-width: 980px;
  font-size: clamp(1.12rem, 2.6vw, 1.68rem);
  line-height: 1.35;
}

.answers {
  display: grid;
  gap: 10px;
  margin-top: 24px;
}

.answer-option {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr);
  gap: 12px;
  align-items: start;
  width: 100%;
  min-height: 58px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 13px;
  text-align: left;
  line-height: 1.35;
}

.answer-option:hover:not(:disabled) {
  border-color: var(--blue);
  outline: 3px solid rgba(54, 95, 127, 0.10);
}

.answer-key {
  display: grid;
  width: 32px;
  height: 32px;
  place-items: center;
  border-radius: 8px;
  background: var(--surface-3);
  font-weight: 900;
}

.answer-option.correct {
  border-color: rgba(45, 122, 79, 0.44);
  background: var(--green-soft);
}

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

.answer-option.wrong {
  border-color: rgba(160, 68, 62, 0.44);
  background: var(--red-soft);
}

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

.answer-option.muted {
  color: var(--muted);
  background: var(--surface-2);
}

.question-footer {
  justify-content: space-between;
  margin-top: 18px;
}

.feedback {
  border-radius: 8px;
  padding: 10px 12px;
  font-weight: 900;
}

.feedback.correct {
  background: var(--green-soft);
  color: var(--green);
}

.feedback.wrong {
  background: var(--red-soft);
  color: var(--red);
}

.results-panel {
  display: grid;
  gap: 18px;
  border: 0;
  background: transparent;
  box-shadow: none;
}

.result-hero {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: clamp(22px, 5vw, 36px);
  background: #fff;
  box-shadow: var(--shadow-soft);
}

.result-hero.pass {
  border-color: rgba(21, 128, 61, 0.35);
}

.result-hero.fail {
  border-color: rgba(180, 35, 24, 0.35);
}

.result-hero h2 {
  font-size: clamp(1.9rem, 6vw, 3.4rem);
}

.result-hero p:last-child {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 1.05rem;
  font-weight: 800;
}

.result-stats {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.review-list {
  display: grid;
  gap: 10px;
}

.review-item {
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: #fff;
}

.review-item summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px;
  cursor: pointer;
  font-weight: 800;
}

.review-item.correct summary strong {
  color: var(--green);
}

.review-item.wrong summary strong {
  color: var(--red);
}

.review-item p {
  margin: 0;
  padding: 0 14px 12px;
  line-height: 1.45;
}

.review-options {
  display: grid;
  gap: 8px;
  padding: 0 14px 14px;
}

.review-options div {
  border-radius: 8px;
  padding: 9px 10px;
  background: #f8fafc;
}

.review-options .correct {
  background: var(--green-soft);
  color: var(--green);
  font-weight: 800;
}

.review-options .wrong {
  background: var(--red-soft);
  color: var(--red);
  font-weight: 800;
}

@media (max-width: 900px) {
  .stats-panel .stat-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .start-controls {
    grid-template-columns: minmax(130px, 180px) minmax(260px, 1fr);
  }

  .available-box,
  .start-controls .primary-button {
    grid-column: span 1;
  }

  .topbar {
    align-items: center;
  }
}

@media (max-width: 760px) {
  .history-panel .table-wrap {
    overflow: visible;
    border: 0;
    background: transparent;
  }

  .history-panel table,
  .history-panel tbody,
  .history-panel tr,
  .history-panel td {
    display: block;
    width: 100%;
    min-width: 0;
  }

  .history-panel thead {
    display: none;
  }

  .history-panel tbody {
    display: grid;
    gap: 10px;
  }

  .history-panel tr {
    border: 1px solid var(--line-soft);
    border-radius: 8px;
    background: #fff;
    box-shadow: var(--shadow-soft);
    overflow: hidden;
  }

  .history-panel td {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 14px;
    border-bottom: 1px solid var(--line-soft);
    padding: 11px 12px;
    text-align: right;
  }

  .history-panel td::before {
    content: attr(data-label);
    flex: 0 0 96px;
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 900;
    text-align: left;
    text-transform: uppercase;
  }

  .history-panel td:last-child {
    border-bottom: 0;
  }

  .history-panel td:last-child::before {
    padding-top: 8px;
  }

  .history-actions {
    justify-content: flex-end;
  }
}

@media (max-width: 640px) {
  .app-shell {
    padding: 12px;
  }

  .topbar {
    gap: 10px;
    padding: 6px 0 14px;
  }

  .app-brand {
    min-width: 0;
  }

  .app-brand h1 {
    max-width: calc(100vw - 118px);
    overflow: hidden;
    font-size: 0.98rem;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .topbar-actions {
    gap: 0;
  }

  .topbar-actions .ghost-button {
    min-height: 38px;
    padding: 0 13px;
    font-size: 0.9rem;
  }

  .auth-page {
    padding: 12px;
  }

  .auth-panel,
  .panel,
  .question-panel {
    box-shadow: none;
  }

  .form-grid,
  .range-pair,
  .start-controls,
  .result-stats {
    grid-template-columns: 1fr;
  }

  .start-controls {
    padding: 12px;
  }

  .stats-panel .stat-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .section-list {
    grid-template-columns: 1fr;
    padding: 8px;
  }

  .panel-heading,
  .form-footer,
  .question-footer {
    align-items: stretch;
    flex-direction: column;
  }

  .panel-heading {
    gap: 12px;
  }

  .selection-actions,
  .result-actions {
    width: 100%;
  }

  .selection-actions button,
  .result-actions button,
  .question-footer button,
  .form-footer button,
  .history-actions button,
  .start-controls .primary-button {
    width: 100%;
  }

  .history-actions {
    width: min(100%, 190px);
  }

  .answer-option {
    grid-template-columns: 32px minmax(0, 1fr);
    padding: 11px;
  }

  .answer-key {
    width: 28px;
    height: 28px;
  }

  .quiz-topline {
    align-items: stretch;
    flex-direction: column;
  }

  .quiz-meta {
    width: 100%;
  }

  .quiz-meta span {
    flex: 1;
  }
}
