:root {
  --bg: #f4f4f4;
  --panel: #ffffff;
  --panel-soft: #fff4f3;
  --text: #171717;
  --muted: #5f6368;
  --line: #e2e2e2;
  --brand: #20242c;
  --brand-dark: #080808;
  --accent: #e60f00;
  --accent-dark: #cc0d00;
  --danger: #e60f00;
  --ok: #168455;
  --shadow: 0 18px 42px rgba(0, 0, 0, .08);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-width: 320px;
  overflow-x: hidden;
  background: linear-gradient(180deg, #ffffff 0, #f7f7f7 360px, #eeeeee 100%);
  color: var(--text);
  font-family: Poppins, "DM Sans", Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  letter-spacing: 0;
}

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

button {
  cursor: pointer;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 18px;
  min-height: 72px;
  padding: 14px clamp(16px, 3vw, 34px);
  background: rgba(255, 255, 255, .96);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(14px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: var(--text);
  font-weight: 800;
  text-decoration: none;
  white-space: nowrap;
}

.brand-logo {
  display: block;
  width: 126px;
  height: auto;
  border-radius: 6px;
}

.brand span {
  min-height: 28px;
  padding: 5px 10px;
  border: 2px solid var(--accent);
  border-radius: 8px;
  color: var(--accent);
  font-size: 13px;
  line-height: 1.1;
  text-transform: uppercase;
}

.nav {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
}

.nav a {
  color: var(--muted);
  padding: 9px 10px;
  border-radius: 7px;
  font-size: 14px;
  text-decoration: none;
}

.nav a:hover {
  background: rgba(230, 15, 0, .07);
  color: var(--brand);
}

body.teacher-entry .nav,
body.teacher-entry #resetBtn,
body.admin-entry .nav,
body.admin-entry #resetBtn {
  display: none;
}

body.public-version #resetBtn {
  display: none;
}

body.teacher-entry .topbar,
body.admin-entry .topbar {
  justify-content: center;
}

.app-shell {
  width: min(1380px, 100%);
  margin: 0 auto;
  padding: 18px clamp(12px, 3vw, 34px) 42px;
}

.intro-panel {
  display: grid;
  grid-template-columns: minmax(340px, .8fr) minmax(460px, 1.2fr);
  gap: 14px;
  align-items: stretch;
  margin-bottom: 14px;
}

.portal-layout {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.portal-card {
  display: grid;
  gap: 12px;
  align-content: start;
  padding: clamp(20px, 3vw, 28px);
  text-decoration: none;
  color: inherit;
  transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease;
}

.portal-card:hover {
  transform: translateY(-2px);
  border-color: rgba(230, 15, 0, .35);
  box-shadow: 0 22px 48px rgba(0, 0, 0, .10);
}

.portal-card .primary-btn {
  justify-self: start;
  pointer-events: none;
}

.conditional-fields {
  display: grid;
  gap: 10px;
}

.intro-copy,
.intro-brand-card,
.panel {
  min-width: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.intro-copy {
  position: relative;
  overflow: hidden;
  padding: clamp(20px, 3vw, 34px);
  background: #fff;
}

.intro-copy::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 10px;
  background: var(--accent);
}

.intro-copy::after {
  content: "";
  position: absolute;
  right: 22px;
  bottom: 18px;
  width: 118px;
  height: 118px;
  border: 12px solid rgba(230, 15, 0, .08);
  border-radius: 999px;
  pointer-events: none;
}

.eyebrow {
  display: block;
  margin-bottom: 8px;
  color: var(--brand-dark);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  max-width: 660px;
  margin-bottom: 14px;
  font-size: clamp(34px, 3.6vw, 50px);
  line-height: 1.02;
}

h2 {
  margin-bottom: 0;
  font-size: 22px;
  line-height: 1.1;
}

h3 {
  margin-bottom: 10px;
  font-size: 18px;
}

p {
  color: var(--muted);
  line-height: 1.55;
}

.intro-copy > * {
  position: relative;
  z-index: 1;
}

.intro-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
  margin-top: 22px;
}

.intro-badges span {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 7px 12px;
  border: 2px solid var(--accent);
  border-radius: 8px;
  background: #fff;
  color: var(--brand-dark);
  font-size: 13px;
  font-weight: 900;
}

.intro-brand-card {
  display: grid;
  grid-template-rows: minmax(230px, 1fr) auto;
  overflow: hidden;
  background: #fff;
}

.intro-brand-card picture,
.intro-brand-card img {
  display: block;
  width: 100%;
  height: 100%;
}

.intro-brand-card img {
  min-height: 230px;
  object-fit: contain;
  object-position: center;
  background: #fff;
}

.intro-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, .96);
}

.intro-stats div {
  display: grid;
  align-content: center;
  min-height: 78px;
  padding: 12px 16px;
  border-left: 1px solid var(--line);
}

.intro-stats div:first-child {
  border-left: 0;
}

.intro-stats span {
  color: var(--muted);
  font-size: 13px;
}

.intro-stats strong {
  margin-top: 6px;
  color: var(--accent);
  font-size: 26px;
}

.grid-layout {
  display: grid;
  grid-template-columns: minmax(280px, .85fr) minmax(360px, 1.25fr);
  gap: 14px;
  align-items: start;
}

.grid-layout > *,
.intro-panel > * {
  min-width: 0;
}

.panel {
  position: relative;
  overflow: hidden;
  padding: 18px;
  background:
    linear-gradient(#fff, #fff) padding-box,
    linear-gradient(90deg, rgba(230, 15, 0, .2), rgba(0, 0, 0, .04)) border-box;
}

.panel::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 5px;
  background: var(--accent);
}

.test-panel,
.teacher-panel {
  min-height: 480px;
}

body[data-mode="student"] #teacher,
body[data-mode="student"] #admin,
body[data-mode="teacher"] #student,
body[data-mode="teacher"] #test,
body[data-mode="teacher"] #admin,
body[data-mode="admin"] #student,
body[data-mode="admin"] #test,
body[data-mode="admin"] #teacher {
  display: none;
}

body[data-mode="teacher"] .grid-layout,
body[data-mode="admin"] .grid-layout {
  grid-template-columns: 1fr;
}

body.student-entry .topbar,
body.student-entry .intro-panel {
  display: none;
}

body.student-entry {
  background:
    radial-gradient(circle at 12% 12%, rgba(230, 15, 0, .08), transparent 28%),
    linear-gradient(180deg, #ffffff 0, #f6f6f6 100%);
}

body.student-entry .app-shell {
  display: grid;
  align-items: center;
  min-height: 100vh;
  padding-top: clamp(18px, 4vw, 42px);
  padding-bottom: clamp(24px, 5vw, 52px);
}

body.student-entry .grid-layout {
  width: min(1120px, 100%);
  margin: 0 auto;
}

body.student-entry:not(.student-ready) .grid-layout {
  width: min(560px, 100%);
  grid-template-columns: 1fr;
}

body.student-entry:not(.student-ready) #test {
  display: none;
}

body.student-entry.student-ready .grid-layout {
  grid-template-columns: 1fr;
}

body.student-entry.student-ready #student {
  display: none;
}

.student-auth-card {
  padding: clamp(20px, 4vw, 34px);
}

.student-entry-head {
  max-width: 460px;
  margin: 0 auto 22px;
  text-align: center;
}

.student-entry-logo {
  display: block;
  width: min(220px, 72vw);
  height: auto;
  margin: 0 auto 18px;
  border-radius: 6px;
}

.student-entry-head h1 {
  max-width: 100%;
  margin-bottom: 10px;
  font-size: clamp(30px, 5vw, 42px);
}

.student-entry-head p {
  margin-bottom: 0;
}

body.student-entry:not(.student-ready) .student-auth-card .panel-head {
  justify-content: center;
  text-align: center;
}

body.student-entry:not(.student-ready) .student-auth-card .panel-head .eyebrow {
  display: none;
}

body.student-entry:not(.student-ready) .student-auth-card .status-pill {
  display: none;
}

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin: 0 0 16px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f5f7f6;
}

.auth-tab {
  min-height: 38px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}

.auth-tab.active {
  background: #fff;
  color: var(--brand-dark);
  box-shadow: 0 8px 18px rgba(23, 48, 43, .08);
}

.auth-panel[hidden] {
  display: none;
}

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

#test .panel-head {
  align-items: center;
}

#test .panel-head .eyebrow,
#test #attemptStatus {
  display: none;
}

#testTitle {
  max-width: 920px;
  padding-left: 14px;
  border-left: 5px solid var(--accent);
  color: var(--brand-dark);
  font-size: clamp(25px, 3vw, 34px);
  font-weight: 900;
  line-height: 1.12;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  max-width: 100%;
  min-height: 28px;
  padding: 5px 9px;
  border-radius: 999px;
  border: 1px solid rgba(230, 15, 0, .18);
  background: rgba(230, 15, 0, .08);
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  overflow-wrap: anywhere;
}

.participant-summary {
  display: grid;
  grid-template-columns: minmax(160px, 1fr) minmax(220px, 2fr);
  align-items: center;
  gap: 12px;
  margin: -2px 0 16px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f7faf8;
}

.participant-summary strong {
  display: block;
  margin-top: 3px;
  color: var(--brand-dark);
  overflow-wrap: anywhere;
}

.participant-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.participant-meta span {
  min-height: 28px;
  padding: 5px 8px;
  border-radius: 999px;
  background: #fff;
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  overflow-wrap: anywhere;
}

.participant-summary #changeStudentBtn {
  display: none;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.form-grid.compact {
  margin-top: 14px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

[hidden] {
  display: none !important;
}

input,
select,
textarea {
  min-width: 0;
  width: 100%;
  min-height: 42px;
  padding: 10px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  outline: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(230, 15, 0, .12);
}

textarea {
  resize: vertical;
  line-height: 1.4;
}

.checkbox-line {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--text);
}

.checkbox-line input {
  width: 17px;
  min-height: 17px;
}

.wide {
  grid-column: 1 / -1;
}

.primary-btn,
.secondary-btn,
.small-btn,
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  font-weight: 800;
}

.primary-btn {
  background: var(--accent);
  color: #fff;
  padding: 0 16px;
  box-shadow: 0 10px 20px rgba(230, 15, 0, .18);
}

.primary-btn:hover {
  background: var(--accent-dark);
}

.secondary-btn,
.small-btn {
  border: 2px solid var(--brand);
  background: #fff;
  color: var(--brand);
  padding: 0 14px;
}

.secondary-btn:hover,
.small-btn:hover {
  background: var(--brand);
  color: #fff;
}

.small-btn {
  min-height: 34px;
  font-size: 13px;
}

.icon-btn {
  width: 40px;
  min-width: 40px;
  padding: 0;
  background: rgba(230, 15, 0, .08);
  color: var(--accent);
}

.icon-btn svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.progress-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.progress-bar {
  height: 10px;
  margin: 10px 0 16px;
  overflow: hidden;
  border-radius: 999px;
  background: #eef0f6;
}

.progress-bar span {
  display: block;
  width: 0;
  height: 100%;
  background: var(--accent);
  transition: width .2s ease;
}

.question-card {
  min-height: 236px;
  padding: 18px;
  border: 2px solid rgba(0, 0, 0, .08);
  border-left: 6px solid var(--accent);
  border-radius: 8px;
  background: #fff;
}

.option-list {
  display: grid;
  gap: 9px;
  margin-top: 14px;
}

.option {
  display: grid;
  grid-template-columns: 28px 26px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
}

.option-number {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  margin-top: 1px;
  border-radius: 999px;
  background: rgba(230, 15, 0, .08);
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
}

.option:hover {
  border-color: rgba(230, 15, 0, .45);
  background: #fff8f7;
}

.option input {
  width: 18px;
  min-height: 18px;
  margin: 2px 0 0;
}

.test-actions {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 9px;
  margin-top: 12px;
}

.missed-review-btn {
  grid-column: span 2;
  white-space: normal;
  line-height: 1.15;
}

.result-card {
  margin-top: 14px;
  padding: 16px;
  border-radius: 8px;
  background: #fff4f3;
  border: 2px solid rgba(230, 15, 0, .18);
}

.certificate-note {
  margin-top: 14px;
  margin-bottom: 0;
  padding: 12px 14px;
  border-left: 5px solid var(--accent);
  border-radius: 8px;
  background: #fff4f3;
  color: var(--brand-dark);
  font-weight: 700;
}

.certificate-note small {
  color: var(--muted);
  font-weight: 600;
}

.certificate-card {
  margin: 16px 0;
  padding: 18px;
  border: 2px solid rgba(230, 15, 0, .16);
  border-radius: 8px;
  background: #fff;
}

.certificate-card h3 {
  margin-bottom: 8px;
}

.certificate-preview {
  margin: 14px 0;
  overflow: hidden;
  border: 1px solid rgba(0, 0, 0, .08);
  border-radius: 12px;
  background: #f8f8f8;
}

.certificate-preview--filled {
  position: relative;
}

.certificate-preview img {
  display: block;
  width: 100%;
  height: auto;
}

.certificate-overlay {
  position: absolute;
  inset: 0;
}

.certificate-fill {
  position: absolute;
  left: 31.5%;
  width: 49%;
  color: #171717;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(9px, 1.05vw, 15px);
  font-weight: 700;
  line-height: 1.05;
  text-align: left;
  text-shadow: 0 0 0 rgba(0, 0, 0, 0.02);
}

.certificate-fill--name {
  top: 45.2%;
  left: calc(41.5% - 15mm);
  font-size: clamp(11px, 1.34vw, 19px);
  font-weight: 800;
}

.certificate-fill--category {
  top: 52.0%;
  left: calc(41.5% - 15mm);
}

.certificate-fill--study {
  top: 57.4%;
  width: 56%;
  font-size: clamp(9px, 1.0vw, 14px);
  white-space: normal;
}

.certificate-fill--level {
  top: 63.0%;
  left: calc(41.5% - 15mm);
}

.certificate-fill--date {
  top: 70.6%;
  left: 37%;
}

.certificate-fill--number {
  top: 84.0%;
  left: 34.5%;
  width: 18%;
  transform: translateX(-50%);
  text-align: center;
  font-size: clamp(8px, .95vw, 13px);
  white-space: nowrap;
}

.certificate-signature-wrap {
  position: absolute;
  left: auto;
  right: calc(0.5% + 50mm);
  bottom: calc(16% - 20mm);
  width: 18%;
  text-align: center;
}

.certificate-signature {
  display: block;
  width: 100%;
  height: auto;
}

.certificate-signature-name {
  position: relative;
  display: block;
  width: max-content;
  margin: 4px auto 0;
  color: #171717;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(8px, .95vw, 13px);
  font-weight: 700;
  transform: translate(20mm, -15mm);
}

.certificate-card p {
  margin-bottom: 0;
}

.certificate-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin: 14px 0;
}

.certificate-grid div {
  padding: 12px;
  border: 1px solid rgba(22, 132, 85, .18);
  border-radius: 8px;
  background: #fff;
}

.certificate-grid span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.certificate-grid strong {
  display: block;
  color: var(--brand-dark);
}

.certificate-print-btn {
  margin-top: 8px;
}

@media print {
  body * {
    visibility: hidden;
  }
  .certificate-card, .certificate-card * {
    visibility: visible;
  }
  .certificate-card {
    position: absolute;
    inset: 0;
    margin: 0;
    box-shadow: none;
    border: 0;
    padding: 0;
    background: #fff;
    page-break-inside: avoid;
  }
  .certificate-preview {
    margin: 0 0 14px;
    border: 0;
    border-radius: 0;
    background: transparent;
  }

  .certificate-overlay {
    inset: 0;
  }

  .certificate-fill {
    color: #171717;
  }

  .certificate-preview img {
    width: 100%;
  }
  .certificate-print-btn,
  .result-navigation,
  .contact-card,
  .topbar,
  .intro-panel,
  .test-actions,
  .progress-row,
  .progress-bar,
  .question-card {
    display: none !important;
  }
}

.test-panel.result-mode .progress-row,
.test-panel.result-mode .progress-bar,
.test-panel.result-mode .question-card,
.test-panel.result-mode .test-actions {
  display: none;
}

.test-panel.result-mode .result-card {
  margin-top: 0;
}

.result-card strong {
  color: var(--brand-dark);
}

.student-result-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin: 14px 0;
}

.student-result-summary div {
  min-width: 0;
  padding: 12px;
  border: 1px solid rgba(230, 15, 0, .18);
  border-radius: 8px;
  background: #fff;
}

.student-result-summary span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.student-result-summary strong {
  font-size: 22px;
}

.student-level-result {
  margin: 16px 0;
  padding: 18px 20px;
  border: 2px solid rgba(230, 15, 0, .22);
  border-radius: 8px;
  background: linear-gradient(135deg, #fff7f6 0%, #ffffff 72%);
  box-shadow: 0 16px 38px rgba(0, 17, 89, .08);
}

.student-level-result span {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 900;
  text-transform: uppercase;
}

.student-level-result strong {
  display: block;
  color: var(--brand-dark);
  font-size: 32px;
  line-height: 1.12;
}

.result-navigation {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 14px;
}

.result-navigation a {
  text-decoration: none;
}

.contact-card {
  display: grid;
  gap: 8px;
  margin-top: 16px;
  padding: 14px;
  border-radius: 8px;
  background: #fff;
}

.contact-card b {
  font-size: 18px;
}

.contact-card span {
  color: var(--muted);
}

.contact-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
  margin-top: 6px;
}

.contact-actions a {
  min-width: min(100%, 180px);
  text-decoration: none;
}

.filters {
  display: grid;
  grid-template-columns: 1.2fr .8fr .8fr;
  gap: 10px;
  margin-bottom: 12px;
}

.teacher-login {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
  max-width: 620px;
  padding: 14px;
  border: 1px solid var(--line);
  border-left: 5px solid var(--accent);
  border-radius: 8px;
  background: #fff;
}

.teacher-login[hidden],
#teacherContent[hidden] {
  display: none;
}

.attempt-row-certificate td {
  background: rgba(230, 15, 0, .05);
}

.format-badge {
  display: inline-flex;
  align-items: center;
  margin-right: 6px;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .04em;
  vertical-align: middle;
}

.format-badge--certificate {
  background: rgba(230, 15, 0, .12);
  color: var(--accent-dark);
  border: 1px solid rgba(230, 15, 0, .25);
}

.format-badge--standard {
  background: rgba(22, 132, 85, .10);
  color: var(--ok);
  border: 1px solid rgba(22, 132, 85, .18);
}

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

table {
  width: 100%;
  min-width: 720px;
  border-collapse: collapse;
  background: #fff;
}

th,
td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  font-size: 13px;
}

th {
  background: #f7f7f7;
  color: var(--brand);
  font-size: 12px;
  text-transform: uppercase;
}

tbody tr {
  cursor: pointer;
}

tbody tr:hover {
  background: var(--panel-soft);
}

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

.test-chip {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  border-left: 5px solid var(--accent);
  background: #fff;
}

.test-chip span {
  color: var(--muted);
  font-size: 13px;
}

.modal {
  width: min(860px, calc(100vw - 24px));
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.modal::backdrop {
  background: rgba(16, 28, 24, .45);
}

.modal form {
  position: relative;
  padding: 20px;
}

.close {
  position: absolute;
  top: 12px;
  right: 12px;
}

.details-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin: 14px 0;
}

.detail-box,
.answer-row {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdfc;
}

.answer-list {
  display: grid;
  gap: 8px;
}

.retake-btn {
  margin: 2px 0 16px;
}

.answer-row {
  display: grid;
  gap: 5px;
  font-size: 13px;
}

.answer-row b {
  color: var(--brand-dark);
}

.answer-row .wrong {
  color: var(--danger);
}

.answer-row .right {
  color: var(--ok);
}

.toast {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 40;
  max-width: min(420px, calc(100vw - 32px));
  padding: 12px 14px;
  border-radius: 8px;
  background: #1d2c28;
  color: #fff;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity .2s ease, transform .2s ease;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 980px) {
  .intro-panel,
  .grid-layout {
    grid-template-columns: 1fr;
  }

  .intro-brand-card {
    grid-template-rows: auto auto;
  }

  .intro-brand-card img {
    min-height: 0;
  }
}

@media (max-width: 760px) {
  .topbar {
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 10px;
  }

  .nav {
    order: 3;
    width: 100%;
    overflow-x: auto;
  }

  .app-shell {
    padding-top: 14px;
  }

  h1 {
    font-size: 34px;
  }

  .intro-copy::after {
    width: 82px;
    height: 82px;
    border-width: 9px;
  }

  .intro-stats,
  .form-grid,
  .filters,
  .student-result-summary,
  .result-navigation,
  .details-grid,
  .participant-summary {
    grid-template-columns: 1fr;
  }

  .student-level-result strong {
    font-size: 26px;
  }

  .intro-stats div {
    min-height: 68px;
    border-top: 1px solid var(--line);
    border-left: 0;
  }

  .intro-stats div:first-child {
    border-top: 0;
  }

  .test-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  #nextBtn {
    order: -1;
    background: #dff6df;
    border-color: #9ed69e;
    color: #1f5f1f;
  }

  #nextBtn:hover {
    background: #d2f0d2;
  }

  table {
    min-width: 0;
    table-layout: auto;
  }

  thead {
    display: none;
  }

  table,
  tbody,
  tr,
  td {
    display: block;
    width: 100%;
  }

  tbody {
    display: grid;
    gap: 10px;
    padding: 10px;
  }

  tbody tr {
    display: grid;
    gap: 6px;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
  }

  td {
    display: grid;
    grid-template-columns: 86px minmax(0, 1fr);
    gap: 8px;
    padding: 0;
    border-bottom: 0;
    overflow-wrap: anywhere;
    font-size: 12px;
  }

  td::before {
    content: attr(data-label);
    color: var(--muted);
    font-weight: 800;
    text-transform: uppercase;
    font-size: 10px;
  }
}

@media (max-width: 430px) {
  .panel,
  .intro-copy {
    padding: 14px;
  }

  h1 {
    font-size: 31px;
  }

  .test-actions {
    grid-template-columns: 1fr;
  }

  #nextBtn {
    order: -1;
    background: #dff6df;
    border-color: #9ed69e;
    color: #1f5f1f;
  }

  #nextBtn:hover {
    background: #d2f0d2;
  }

  .missed-review-btn {
    grid-column: span 1;
  }
}
