html,
body {
  height: 100%;
}

:root {
  --primary: #2f4fc1;
  --primary-dark: #2443ae;
  --page: #f4f7fb;
  --text: #06152d;
  --muted: #4d6078;
  --border: #d8e1ec;
  --not-visited: #cbd7e4;
  --not-answered: #f8a5b6;
  --answered: #86dfbf;
  --review: #dcc8ff;
  --answered-review: #86dfbf;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--page);
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
  overflow-x: hidden;
}

body.is-test-mode {
  overflow: hidden;
}

button,
a {
  font: inherit;
}

.test-shell {
  height: 100dvh;
  overflow: hidden;
}

.instructions-view,
.exam-view,
.result-view {
  display: none;
}

.instructions-view.is-active,
.exam-view.is-active,
.result-view.is-active {
  display: flex;
}

.instructions-view {
  min-height: 100%;
  align-items: center;
  justify-content: center;
  padding: 16px;
  position: relative;
}

.instructions-brand {
  position: absolute;
  top: 18px;
  left: 18px;
  z-index: 2;
}

.instructions-brand img {
  display: block;
  width: 58px;
  height: 58px;
  object-fit: contain;
}

.instructions-card {
  width: min(100%, 1120px);
  margin: 0 auto;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 24px 26px 22px;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
}

.test-details {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.test-detail {
  border: 1px solid #dbe5f2;
  border-radius: 12px;
  background: #f7faff;
  padding: 12px 14px;
}

.test-detail span {
  display: block;
  margin-bottom: 3px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.test-detail strong {
  display: block;
  color: var(--primary);
  font-size: 18px;
  line-height: 1.2;
}

.instructions-card h1 {
  margin: 0 0 10px;
  font-size: 30px;
  line-height: 1.15;
  font-weight: 700;
}

.instruction-intro {
  margin: 0 0 18px;
  border-left: 4px solid rgba(47, 79, 193, 0.42);
  border-radius: 10px;
  background: #f3f7ff;
  padding: 12px 14px;
  color: #31435f;
  font-size: 15px;
  line-height: 1.55;
}

.instruction-sections {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(280px, 0.65fr);
  gap: 18px;
  margin-bottom: 24px;
}

.instruction-section h2 {
  margin: 0 0 10px;
  color: var(--text);
  font-size: 17px;
  line-height: 1.2;
}

.instruction-section ul {
  margin: 0;
  padding-left: 20px;
  color: #1a2945;
  font-size: 15px;
  line-height: 1.65;
}

.instruction-section li + li {
  margin-top: 5px;
}

.marking-list {
  padding-left: 0;
  list-style: none;
}

.marking-list li {
  display: flex;
  align-items: center;
  gap: 8px;
}

.mark-icon {
  width: 20px;
  display: inline-flex;
  justify-content: center;
  font-weight: 700;
}

.mark-icon--correct {
  color: #168457;
}

.mark-icon--wrong {
  color: #b4233d;
}

.mark-icon--empty {
  color: #56667f;
}

.instruction-actions {
  display: flex;
  gap: 15px;
  align-items: center;
  justify-content: flex-end;
}

.test-btn,
.submit-btn,
.nav-btn,
.action-btn,
.close-btn {
  border: 0;
  cursor: pointer;
  text-decoration: none;
  transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.12s ease, border-color 0.12s ease;
}

.test-btn {
  min-width: 94px;
  min-height: 46px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  padding: 12px 20px;
  font-weight: 700;
  font-size: 15px;
}

.test-btn--light {
  color: #1f2937;
  background: #fff;
  border: 1px solid #cbd7e5;
}

.test-btn--primary {
  color: #fff;
  background: var(--primary);
}

.exam-topbar {
  min-height: 76px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 0 0 20px 20px;
  padding: 14px 16px;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
}

.exam-topbar h1 {
  margin: 0;
  color: var(--primary);
  font-size: 28px;
  line-height: 1;
}

.exam-topbar__actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.timer-pill,
.submit-btn {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  background: var(--primary);
  color: #fff;
  font-size: 16px;
  font-weight: 700;
}

.timer-pill {
  min-width: 112px;
  padding: 0 18px;
}

.submit-btn {
  min-width: 118px;
  padding: 0 26px;
}

.exam-view {
  min-height: 100%;
  flex-direction: column;
  overflow: hidden;
  padding: 0 8px 8px;
}

.exam-layout {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 400px;
  gap: 14px;
  padding-top: 10px;
  min-height: 0;
}

.exam-main {
  display: grid;
  gap: 12px;
  grid-template-rows: auto minmax(0, 1fr);
  min-height: 0;
}

.question-card,
.answer-card,
.legend-card,
.palette-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
}

.question-card {
  min-height: 0;
  padding: 14px 16px 12px;
}

.question-card h2 {
  margin: 0 0 10px;
  font-size: 22px;
  line-height: 1.2;
}

.question-text {
  min-height: 44px;
  display: flex;
  align-items: center;
  border-radius: 12px;
  background: #eef2f7;
  padding: 10px 14px;
  font-size: 16px;
  line-height: 1.35;
  font-weight: 700;
}

.answer-card {
  min-height: 0;
  padding: 14px 16px 14px;
}

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

.option-btn {
  min-height: 48px;
  border: 1px solid #c8d4e3;
  border-radius: 10px;
  background: #fff;
  color: var(--text);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  padding: 8px 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.option-btn.is-selected {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.option-btn--media {
  min-height: 86px;
}

.option-content {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
  text-align: center;
}

.option-btn--media .option-content {
  flex-direction: column;
  align-items: flex-start;
  justify-content: flex-start;
  text-align: left;
}

.option-label,
.option-text {
  display: inline-flex;
}

.option-media-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
}

.option-media {
  display: block;
  max-width: 100%;
  max-height: 72px;
  object-fit: contain;
}

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

.action-btn {
  min-height: 42px;
  border-radius: 8px;
  font-size: 15px;
}

.action-btn--save {
  background: #99e2c7;
  color: #0f5132;
}

.action-btn--clear {
  background: #f8b3c1;
  color: #8a1f38;
}

.action-btn--review {
  background: #f7e08c;
  color: #6b5300;
}

.action-btn--review-next {
  background: #9fdcf2;
  color: #0b4d66;
}

.nav-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 12px;
}

.nav-btn {
  min-width: 118px;
  min-height: 42px;
  border-radius: 9px;
  background: #fff;
  border: 1px solid #cbd7e5;
  color: #000;
  font-size: 15px;
}

.exam-sidebar {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 12px;
  min-height: 0;
}

.legend-card {
  min-height: 0;
  padding: 14px 16px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 11px;
  color: #1a2945;
  font-size: 14px;
  line-height: 1;
  margin-bottom: 17px;
}

.dot {
  width: 21px;
  height: 21px;
  border-radius: 999px;
  display: inline-block;
  flex: 0 0 auto;
}

.dot--not-visited {
  background: var(--not-visited);
}

.dot--not-answered {
  background: var(--not-answered);
}

.dot--answered {
  background: var(--answered);
}

.dot--review {
  background: var(--review);
}

.dot--answered-review {
  background: var(--review);
  border: 3px solid #00b982;
}

.palette-card {
  min-height: 0;
  padding: 16px 18px;
}

.question-palette {
  display: grid;
  grid-template-columns: repeat(5, 44px);
  gap: 12px;
  justify-content: center;
}

.palette-btn {
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 999px;
  color: #06152d;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  background: var(--not-visited);
}

.palette-btn.status-not-answered {
  background: var(--not-answered);
}

.palette-btn.status-answered {
  background: var(--answered);
}

.palette-btn.status-review {
  background: var(--review);
}

.palette-btn.status-answered-review {
  background: var(--review);
  border: 3px solid #00b982;
}

.palette-btn.is-current {
  outline: 3px solid #06152d;
  outline-offset: 0;
}

.result-view {
  min-height: 100%;
  align-items: stretch;
  padding: 8px;
}

.result-card {
  width: 100%;
  max-width: 100%;
  height: calc(100dvh - 16px);
  margin: 0 auto;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: #fff;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.12);
  padding: 18px;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.result-header {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr auto;
  align-items: center;
  gap: 10px;
  min-height: 58px;
  border-radius: 14px;
  background: var(--primary);
  color: #fff;
  padding: 10px 12px 10px 14px;
}

.result-header__cell {
  font-size: 18px;
  font-weight: 700;
}

.result-header__cell--center {
  text-align: center;
}

.result-header__cell--right {
  text-align: right;
}

.close-btn {
  min-height: 42px;
  padding: 10px 18px;
  border-radius: 12px;
  border: 1px solid rgba(47, 79, 193, 0.35);
  background: #fff;
  color: var(--primary);
  font-size: 15px;
  font-weight: 700;
  justify-self: end;
}

.review-list {
  flex: 1;
  min-height: 0;
  margin-top: 15px;
  overflow-y: auto;
  padding-right: 9px;
}

.review-item {
  border-radius: 8px;
  padding: 17px 15px 16px;
  margin-bottom: 10px;
  border: 1px solid transparent;
}

.review-item--correct {
  background: #eafff5;
  border-color: #9af0c4;
}

.review-item--wrong {
  background: #fff0f2;
  border-color: #ffc3ca;
}

.review-item--not-attempted {
  background: #fff9e7;
  border-color: #ffdb62;
}

.review-question {
  margin: 0 0 8px;
  font-size: 16px;
  line-height: 1.3;
  font-weight: 700;
}

.review-answer-line {
  margin: 3px 0;
  font-size: 14px;
}

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

.review-option {
  min-height: 42px;
  display: flex;
  align-items: center;
  border: 1px solid #bfd0e3;
  border-radius: 5px;
  background: #fff;
  padding: 8px 10px;
  font-weight: 700;
  font-size: 14px;
  gap: 8px;
  flex-wrap: wrap;
}

.review-option__label,
.review-option__text {
  display: inline-flex;
}

.review-option__media {
  display: block;
  max-width: 120px;
  max-height: 56px;
  object-fit: contain;
}

.review-status {
  margin-top: 12px;
  color: #365f87;
  font-size: 12px;
  text-transform: uppercase;
}

.register-modal {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 2000;
}

.register-modal.is-open {
  display: flex;
}

.register-modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(6, 21, 45, 0.38);
  backdrop-filter: blur(3px);
}

.register-modal__panel {
  position: relative;
  width: min(100%, 480px);
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: 0 18px 60px rgba(15, 23, 42, 0.22);
  padding: 24px 24px 22px;
}

.register-modal__close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 34px;
  height: 34px;
  border: 1px solid rgba(47, 79, 193, 0.14);
  border-radius: 999px;
  background: #fff;
  color: var(--primary);
  font-size: 22px;
  line-height: 1;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
}

.register-modal__badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px 10px;
  border-radius: 999px;
  background: #eef3ff;
  color: var(--primary);
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 12px;
}

.register-modal__panel h2 {
  margin: 0 0 10px;
  font-size: 22px;
  line-height: 1.25;
  color: var(--text);
}

.register-modal__panel p {
  margin: 0 0 18px;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.6;
}

.register-modal__actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.register-modal__primary,
.register-modal__secondary {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  padding: 10px 16px;
  font-size: 15px;
  font-weight: 700;
  text-decoration: none;
  border: 1px solid transparent;
}

.register-modal__primary {
  background: var(--primary);
  color: #fff;
}

.register-modal__secondary {
  background: #fff;
  color: var(--primary);
  border-color: rgba(47, 79, 193, 0.28);
  cursor: pointer;
}

.register-modal__secondary:hover,
.register-modal__primary:hover,
.register-modal__close:hover {
  transform: translateY(-1px);
}

button:hover,
.test-btn:hover {
  transform: translateY(-1px);
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}

@media (max-width: 1180px) {
  .exam-layout {
    grid-template-columns: 1fr;
    height: auto;
  }

  .exam-sidebar {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto;
  }

  .palette-card {
    min-height: auto;
  }
}

@media (max-width: 980px) {
  .instructions-card {
    padding: 20px 20px 18px;
  }

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

  .instruction-sections {
    grid-template-columns: 1fr;
  }

  .exam-layout {
    gap: 12px;
  }

  .exam-sidebar {
    grid-template-columns: 1fr;
  }

  .result-header {
    grid-template-columns: 1fr 1fr;
  }

  .result-header__cell--right {
    text-align: left;
  }

  .close-btn {
    justify-self: start;
  }
}

@media (max-width: 760px) {
  html,
  body {
    height: auto;
    min-height: 100%;
  }

  body.is-test-mode {
    overflow-y: auto;
  }

  .test-shell {
    height: auto;
    min-height: 100dvh;
    overflow: visible;
  }

  .instructions-view,
  .exam-view,
  .result-view {
    min-height: 100dvh;
    height: auto;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    padding: 12px;
  }

  .instructions-view {
    align-items: flex-start;
    justify-content: flex-start;
  }

  .instructions-brand {
    top: 12px;
    left: 12px;
  }

  .instructions-brand img {
    width: 44px;
    height: 44px;
  }

  .instructions-card h1,
  .exam-topbar h1 {
    font-size: 24px;
  }

  .test-details,
  .instruction-sections {
    grid-template-columns: 1fr;
  }

  .instruction-section ul {
    font-size: 14px;
  }

  .instruction-intro {
    font-size: 14px;
    padding: 11px 12px;
  }

  .instruction-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .test-btn {
    width: 100%;
    min-width: 0;
  }

  .exam-topbar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 10px;
    height: auto;
    border-radius: 0 0 16px 16px;
    padding: 12px;
  }

  .exam-topbar h1 {
    min-width: 0;
    font-size: 22px;
    line-height: 1.05;
  }

  .exam-view {
    padding: 0 8px 8px;
  }

  .exam-view.is-active {
    display: flex;
  }

  .exam-topbar__actions {
    justify-content: flex-end;
    align-items: center;
    gap: 8px;
    width: auto;
    flex-wrap: nowrap;
  }

  .exam-layout {
    padding-top: 12px;
    gap: 12px;
    height: auto;
    align-content: start;
  }

  .exam-main {
    gap: 10px;
  }

  .question-card,
  .answer-card,
  .legend-card,
  .palette-card {
    border-radius: 14px;
  }

  .question-card {
    padding: 12px 12px 10px;
  }

  .question-card h2 {
    font-size: 20px;
  }

  .question-text {
    min-height: 40px;
    padding: 10px 12px;
    font-size: 14px;
  }

  .answer-card {
    padding: 12px;
  }

  .question-text,
  .option-btn {
    font-size: 15px;
  }

  .options-grid,
  .action-grid,
  .review-options {
    grid-template-columns: 1fr;
  }

  .action-grid {
    gap: 8px;
    margin-top: 10px;
  }

  .action-btn {
    min-height: 40px;
    font-size: 14px;
  }

  .nav-row {
    margin-top: 10px;
  }

  .nav-btn {
    min-height: 40px;
    min-width: 104px;
  }

  .exam-sidebar {
    gap: 10px;
  }

  .legend-card,
  .palette-card {
    padding: 12px;
  }

  .legend-item {
    margin-bottom: 12px;
    font-size: 13px;
  }

  .dot {
    width: 18px;
    height: 18px;
  }

  .question-palette {
    grid-template-columns: repeat(5, 40px);
    gap: 9px;
  }

  .palette-btn {
    width: 40px;
    height: 40px;
    font-size: 13px;
  }

  .timer-pill {
    min-width: 96px;
    padding: 0 14px;
    font-size: 13px;
  }

  .submit-btn {
    min-width: 88px;
    padding: 0 16px;
    font-size: 13px;
  }

  .result-view {
    padding: 10px;
  }

  .result-card {
    height: auto;
    min-height: calc(100dvh - 20px);
    padding: 10px;
    overflow: visible;
  }

  .question-palette {
    grid-template-columns: repeat(5, 40px);
    gap: 8px;
  }

  .palette-btn {
    width: 40px;
    height: 40px;
    font-size: 13px;
  }

  .close-btn {
    min-height: 40px;
    font-size: 14px;
  }

  .review-list {
    height: auto;
    overflow: visible;
    padding-right: 0;
  }

  .result-header {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "score close"
      "title title"
      "time time";
    gap: 6px 10px;
    padding: 12px 12px 10px;
  }

  .result-header__cell,
  .result-header__cell--center,
  .result-header__cell--right {
    text-align: left;
    font-size: 15px;
    line-height: 1.2;
  }

  .result-header__cell:first-child {
    grid-area: score;
  }

  .result-header__cell--center {
    grid-area: title;
    font-size: 16px;
  }

  .result-header__cell--right {
    grid-area: time;
  }

  .close-btn {
    grid-area: close;
    justify-self: end;
    min-height: 38px;
    padding: 8px 14px;
    font-size: 13px;
    border-radius: 10px;
  }

  .register-modal__panel {
    width: min(92vw, 420px);
    padding: 22px 20px 18px;
    border-radius: 16px;
  }

  .register-modal__panel h2 {
    margin-right: 34px;
    font-size: 19px;
    line-height: 1.2;
  }

  .register-modal__panel p {
    margin-bottom: 16px;
    font-size: 14px;
    line-height: 1.55;
  }

  .register-modal__actions {
    gap: 10px;
  }

  .register-modal__primary,
  .register-modal__secondary {
    min-height: 42px;
    padding: 10px 14px;
    font-size: 14px;
  }
}

@media (max-width: 420px) {
  .instructions-view {
    align-items: flex-start;
    padding-top: 72px;
  }

  .instructions-brand {
    top: 10px;
    left: 10px;
  }

  .instructions-brand img {
    width: 40px;
    height: 40px;
  }

  .instructions-card {
    padding: 16px 14px 14px;
  }

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

  .test-detail strong {
    font-size: 16px;
  }

  .instruction-sections h2 {
    font-size: 16px;
  }

  .instruction-section ul,
  .instruction-intro {
    font-size: 13px;
  }

  .question-text {
    font-size: 13px;
  }

  .question-palette {
    grid-template-columns: repeat(5, 36px);
  }

  .palette-btn {
    width: 36px;
    height: 36px;
  }

  .exam-topbar h1 {
    font-size: 18px;
  }

  .question-card h2 {
    font-size: 18px;
  }

  .timer-pill {
    min-width: 88px;
    padding: 0 12px;
  }

  .submit-btn {
    min-width: 78px;
    padding: 0 14px;
  }

  .question-text {
    min-height: 38px;
    font-size: 13px;
  }
}
