:root {
  --bg: #eef1f2;
  --paper: #f7f8f8;
  --panel: #ffffff;
  --ink: #050505;
  --muted: #53606a;
  --line: #d4d8dc;
  --line-dark: #8c9398;
  --teal: #007f7f;
  --teal-dark: #006b6b;
  --blue: #1976c9;
  --danger: #b42318;
  --success: #067647;
  --flag: #f59e0b;
  --flag-bg: #fff7ed;
  --top-h: 54px;
  --bottom-h: 58px;
  font-family: Arial, Helvetica, sans-serif;
}

* {
  box-sizing: border-box;
}
html,
body {
  min-height: 100%;
}
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-size: 19px;
  line-height: 1.36;
}
body.is-test-mode {
  padding-bottom: var(--bottom-h);
}
button,
input,
select {
  font: inherit;
}
button {
  font-family: inherit;
}
.hidden {
  display: none !important;
}
h1,
h2,
h3,
p {
  margin-top: 0;
}

/* Generic screens */
.app {
  width: min(1180px, calc(100% - 28px));
  margin: 0 auto;
  padding: 22px 0 34px;
}
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 26px;
  box-shadow: 0 16px 40px rgba(15, 23, 42, 0.08);
}
.hero {
  display: grid;
  gap: 18px;
  max-width: 940px;
  margin: 28px auto;
}
h1 {
  font-size: clamp(2rem, 4vw, 3.1rem);
  line-height: 1.05;
  margin-bottom: 0;
}
.lead {
  color: #344054;
  font-size: 1.05rem;
  max-width: 70ch;
}
.badge {
  display: inline-flex;
  width: fit-content;
  align-items: flex-start;
  border-radius: 999px;
  padding: 7px 12px;
  background: #e6f5f3;
  color: #0f766e;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.badge.danger {
  background: #fee4e2;
  color: var(--danger);
}
.badge.success {
  background: #dcfae6;
  color: var(--success);
}
.warning-card {
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: 16px;
  padding: 18px 20px;
}
.warning-card h2 {
  font-size: 1.15rem;
  margin-bottom: 10px;
}
.warning-card ul {
  margin: 0;
  padding-left: 1.25rem;
}
.warning-card li {
  margin: 6px 0;
}
.student-form {
  display: grid;
  gap: 14px;
}
.student-form label {
  display: grid;
  gap: 7px;
  color: #344054;
  font-weight: 700;
}
.student-form input[type="text"] {
  width: 100%;
  border: 1px solid #b8c1cc;
  border-radius: 12px;
  padding: 13px 14px;
  background: #fff;
}
.confirm-rules {
  display: flex !important;
  align-items: flex-start;
  gap: 10px !important;
}
.confirm-rules input {
  margin-top: 5px;
}
.primary-btn,
.ghost-btn {
  border: 0;
  border-radius: 12px;
  padding: 13px 18px;
  font-weight: 800;
  cursor: pointer;
  text-decoration: none;
  text-align: left;
  display: inline-flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
}
.primary-btn {
  background: var(--teal);
  color: #fff;
}
.primary-btn:hover {
  background: var(--teal-dark);
}
.ghost-btn {
  background: #eef2f6;
  color: #26323f;
}
.wide {
  width: 100%;
}

/* Test shell */
.test-shell {
  min-height: calc(100vh - var(--bottom-h));
}
.test-topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 16px;
  min-height: var(--top-h);
  background: rgba(255, 255, 255, 0.96);
  border-bottom: 1px solid var(--line);
  padding: 8px 18px;
  backdrop-filter: blur(8px);
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  letter-spacing: 0.01em;
}
.brand-mark {
  width: 28px;
  height: 28px;
  border-radius: 7px;
  display: inline-grid;
  place-items: center;
  background: var(--teal);
  color: #fff;
  font-weight: 900;
}
.test-tools {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #111827;
  font-size: 0.9rem;
}
.tool-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--teal);
}
.student-chip {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}
#testScreen.panel {
  width: 100%;
  max-width: none;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  background: transparent;
}
.test-header,
.part-tabs {
  display: none;
}
.exam-stage {
  width: 100%;
  min-width: 960px;
  padding: 18px 18px calc(var(--bottom-h) + 22px);
}
.exam-instruction-box {
  display: grid;
  gap: 4px;
  background: #fff;
  border: 1px solid #cfd4d8;
  border-radius: 4px;
  padding: 10px 14px;
  margin-bottom: 20px;
}
.exam-instruction-box strong {
  font-size: 1.04rem;
}
.exam-instruction-box span {
  font-size: 0.95rem;
}
.exam-paper {
  background: var(--paper);
  color: var(--ink);
  border: 1px solid #cfd4d8;
  border-radius: 2px;
  padding: 22px 28px;
}
.exam-paper--single {
  max-width: none;
  width: 100%;
  margin: 0 auto;
}
.exam-text-title {
  text-align: center;
  font-size: 1.34rem;
  margin-bottom: 18px;
}
.exam-text-flow {
  font-size: 1.04rem;
  line-height: 1.62;
  white-space: pre-wrap;
}
.exam-two-column {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(310px, 0.55fr);
  gap: 0;
  min-height: calc(100vh - var(--top-h) - var(--bottom-h) - 126px);
  padding: 0;
  overflow: hidden;
}
.exam-left,
.exam-right {
  min-width: 0;
  padding: 22px 26px;
}
.exam-left {
  border-right: 1px solid #cbd3da;
}
.exam-right {
  background: #fff;
}
.exam-two-column--wf {
  grid-template-columns: minmax(0, 1fr) 260px;
}
.pulse-target {
  outline: 3px solid rgba(25, 118, 201, 0.35);
  outline-offset: 3px;
}

/* Inline gaps: Parts 1, 2, 3 */
.exam-gap,
.exam-gap-placeholder {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 48px;
  min-height: 30px;
  margin: 0 4px;
  border: 1px solid #6f7a84;
  border-radius: 2px;
  background: #fff;
  color: #111827;
  vertical-align: baseline;
}
select.exam-gap {
  padding: 1px 22px 1px 7px;
}
input.exam-gap {
  width: 92px;
  padding: 2px 7px;
  text-align: center;
}
.exam-gap.is-filled {
  border-color: var(--teal);
  box-shadow: inset 0 -2px 0 rgba(0, 127, 127, 0.25);
}
.wf-flow {
  line-height: 1.8;
}
.keyword-panel h3 {
  margin-bottom: 12px;
  font-size: 1rem;
}
.keyword-item {
  width: 100%;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  border: 1px solid #cfd8e3;
  background: #f9fafb;
  border-radius: 6px;
  padding: 8px 10px;
  margin-bottom: 8px;
  cursor: pointer;
  text-align: left;
  font-size: 0.9rem;
}
.keyword-item:hover {
  border-color: var(--teal);
}

/* Part 4 */
.kwt-list {
  display: grid;
  gap: 18px;
  max-width: none;
  width: 100%;
}
.kwt-item {
  background: #fff;
  border: 1px solid #d7dde4;
  border-radius: 4px;
  padding: 14px 16px;
}
.kwt-prompt {
  margin-bottom: 10px;
}
.kwt-keyword {
  margin-bottom: 10px;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.kwt-answer-line {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 0;
}
.kwt-answer-line .exam-gap {
  flex: 1 1 280px;
  max-width: 460px;
  text-align: left;
}

/* Reading parts 5, 6, 8 */
.reading-passage p {
  margin: 0 0 1em;
}
.reading-questions h2 {
  font-size: 1.02rem;
  margin-bottom: 12px;
}
.annotation-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  background: #eef7f7;
  border: 1px solid #b7dddd;
  border-radius: 6px;
  padding: 8px;
  margin-bottom: 12px;
  font-size: 0.78rem;
}
.annotation-toolbar strong {
  color: var(--teal-dark);
}
.annotation-question-select {
  padding: 4px 8px;
  border: 1px solid #94a3b8;
  border-radius: 6px;
  background: #fff;
}
.annotation-btn {
  border: 1px solid var(--teal);
  background: var(--teal);
  color: #fff;
  border-radius: 6px;
  padding: 5px 8px;
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 700;
}
.annotation-btn--ghost {
  background: #fff;
  color: var(--teal-dark);
}
.student-highlight {
  background: #fff3bf;
  border-bottom: 2px solid #f59e0b;
  position: relative;
  padding: 0 1px;
}
.student-highlight-number {
  color: #92400e;
  font-weight: 900;
  font-size: 0.66em;
  margin-left: 2px;
}
.student-highlight-delete {
  border: 0;
  background: #f59e0b;
  color: #fff;
  border-radius: 999px;
  width: 14px;
  height: 14px;
  padding: 0;
  margin-left: 2px;
  line-height: 1;
  cursor: pointer;
  font-size: 10px;
  vertical-align: super;
}
.reading-question {
  border-bottom: 1px solid #d9dee4;
  background: #fff;
}
.reading-question-trigger {
  width: 100%;
  border: 0;
  background: transparent;
  padding: 10px 0;
  text-align: left;
  display: block;
  cursor: pointer;
}
.reading-question-trigger h3 {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin: 0;
  font-size: 0.92rem;
  line-height: 1.28;
  font-weight: 700;
}
.question-number-box {
  flex: 0 0 auto;
  min-width: 28px;
  height: 24px;
  display: inline-grid;
  place-items: center;
  border: 1px solid #87919c;
  border-radius: 2px;
  font-size: 0.78rem;
}
.reading-choice-summary {
  color: var(--muted);
  font-size: 0.78rem;
  white-space: nowrap;
}
.reading-question.is-filled .reading-choice-summary {
  color: var(--teal-dark);
  font-weight: 800;
}
.reading-answer-panel {
  display: none;
  padding: 0 0 12px 36px;
}
.reading-question.is-open .reading-answer-panel {
  display: block;
}
.radio-list {
  display: grid;
  gap: 7px;
}
.radio-option {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: start;
  gap: 8px;
  border: 1px solid #d8dee6;
  border-radius: 6px;
  padding: 7px 8px;
  font-size: 0.84rem;
  cursor: pointer;
}
.radio-option.is-selected {
  border-color: var(--teal);
  background: #eefafa;
}


/* Reading split layout: keep the text and questions side by side, each with its own scroll. */
.reading-scroll-layout {
  height: calc(100vh - var(--top-h) - var(--bottom-h) - 126px);
  min-height: 420px;
  overflow: hidden;
}
.reading-scroll-layout .exam-left,
.reading-scroll-layout .exam-right {
  height: 100%;
  max-height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
}
.reading-scroll-layout .reading-passage .exam-text-flow {
  font-size: 0.98rem;
  line-height: 1.46;
}

/* Part 7 drag and drop */
.gapped-layout {
  height: calc(100vh - var(--top-h) - var(--bottom-h) - 126px);
  min-height: 420px;
  overflow: hidden;
}
.gapped-layout .exam-left,
.gapped-layout .exam-right {
  height: 100%;
  max-height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
}
.gapped-passage .exam-text-flow {
  font-size: 0.98rem;
  line-height: 1.42;
  white-space: pre-wrap;
}
.gapped-drop-zone {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: auto;
  min-width: 220px;
  min-height: 23px;
  margin: 0 5px;
  padding: 0 6px;
  border: 1px solid #74808b;
  border-radius: 2px;
  background: #fff;
  color: #111827;
  vertical-align: baseline;
  cursor: pointer;
}
.gapped-drop-zone.is-drag-over {
  outline: 3px solid rgba(0, 127, 127, 0.24);
  outline-offset: 2px;
}
.gapped-drop-zone.is-filled {
  display: inline-flex;
  align-items: flex-start;
  justify-content: flex-start;
  text-align: left;
  width: auto;
  max-width: 100%;
  min-height: auto;
  margin: 0 2px;
  padding: 1px 4px;

  border: 1px solid #b8c0cc;
  border-radius: 4px;
  background: #fff;

  vertical-align: baseline;
}
.gapped-drop-zone.is-filled:hover,
.gapped-drop-zone.is-filled:focus-visible {
  outline: 1px solid #98a2b3;
  outline-offset: 2px;
}
.gapped-drop-zone.is-filled .gapped-drop-number {
  display: none;
}
.gapped-drop-content {
  display: inline;
  margin: 0;
  padding: 0;

  font-size: inherit;
  line-height: inherit;
  text-align: left;
  color: #111827;
}
.gapped-remove {
  float: right;
  width: 16px;
  height: 16px;
  margin: 1px 0 2px 6px;
  border: 1px solid #c6ced6;
  border-radius: 50%;
  background: #fff;
  color: #344054;
  font-size: 0.68rem;
  line-height: 1;
  cursor: pointer;
}
.paragraph-bank {
  display: grid;
  align-content: start;
  gap: 8px;
}
.paragraph-bank h3 {
  font-size: 1rem;
  margin: 0 0 4px;
}
.paragraph-bank-help {
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.25;
  margin-bottom: 6px;
}
.paragraph-option {
  display: block;
  width: 100%;
  border: 1px solid #cbd5df;
  border-radius: 5px;
  background: #fff;
  padding: 6px 8px;
  font-size: 0.88rem;
  line-height: 1.22;
  text-align: left;
  cursor: grab;
}
.paragraph-option:active {
  cursor: grabbing;
}
.paragraph-option.is-selected-for-gap {
  outline: 3px solid rgba(0, 127, 127, 0.18);
  border-color: var(--teal);
}
.paragraph-option.is-used {
  display: none;
}

.paragraph-option:disabled {
  cursor: not-allowed;
}

/* Result and correction screens */
.result-box,
.danger-box {
  border-radius: 16px;
  padding: 18px 20px;
  background: #fff;
  border: 1px solid var(--line);
}
.danger-box {
  background: #fff1f0;
  border-color: #f4b3ad;
}
.result-actions,
.bottom-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
.score-breakdown {
  display: grid;
  gap: 6px;
  margin: 12px 0;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #f8fafc;
}
.score-breakdown p {
  margin: 0;
}
.score-breakdown .score-note {
  color: var(--muted);
  font-size: 0.92rem;
}
.part-score-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}
.part-score-list span {
  border-radius: 999px;
  background: #eef2f6;
  padding: 6px 10px;
  font-size: 0.86rem;
}
.corrected-review {
  display: grid;
  gap: 16px;
  margin-top: 22px;
}
.correction-part {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  background: #fff;
}
.correction-item {
  border-left: 5px solid #d0d5dd;
  padding: 10px 12px;
  margin: 10px 0;
  background: #f9fafb;
}
.correction-item.correct {
  border-left-color: var(--success);
}
.correction-item.partial {
  border-left-color: var(--flag);
}
.correction-item.wrong {
  border-left-color: var(--danger);
}
.small-note,
.submit-note {
  color: var(--muted);
  font-size: 0.86rem;
}

/* Footer navigation */
.bottom-navigation {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  height: var(--bottom-h);
  min-height: var(--bottom-h);
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: stretch;
  background: #fff;
  border-top: 1px solid #b9c1c8;
  padding: 5px 8px;
  box-shadow: 0 -8px 24px rgba(15, 23, 42, 0.09);
}
.bottom-parts {
  min-width: 0;
  display: flex;
  gap: 5px;
  align-items: stretch;
  overflow: hidden;
}
.bottom-part {
  min-width: 0;
  flex: 0.74 1 0;
  border: 1px solid #c7d0d8;
  background: #f8fafc;
  border-radius: 5px;
  padding: 4px 5px;
  display: flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  color: #1f2937;
}
.bottom-part.is-active {
  flex: 2.15 1 0;
  background: #eaf7f7;
  border-color: var(--teal);
}
.bottom-part.has-flagged:not(.is-active) {
  background: var(--flag-bg);
  border-color: var(--flag);
}
.bottom-part-meta {
  min-width: 0;
  display: grid;
  gap: 1px;
  line-height: 1.05;
}
.bottom-part strong {
  font-size: 0.72rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.nav-count {
  font-size: 0.64rem;
  color: var(--muted);
  white-space: nowrap;
}
.nav-numbers {
  min-width: 0;
  display: flex;
  gap: 3px;
  align-items: center;
  overflow: hidden;
}
.nav-number-wrap {
  display: inline-flex;
}
.nav-number {
  width: 21px;
  height: 22px;
  min-width: 21px;
  border: 1px solid #a6b0ba;
  border-radius: 3px;
  background: #fff;
  color: #111827;
  padding: 0;
  font-size: 0.62rem;
  font-weight: 800;
  line-height: 1;
  cursor: pointer;
}
.nav-number.is-filled:not(.is-flagged) {
  background: var(--teal);
  color: #fff;
  border-color: var(--teal);
}
.nav-number.is-flagged,
.nav-number.is-filled.is-flagged {
  background: var(--flag-bg);
  color: #92400e;
  border-color: var(--flag);
  box-shadow: inset 0 -3px 0 var(--flag);
}
.bottom-actions {
  align-items: stretch;
  gap: 6px;
}
.nav-arrow,
.nav-submit {
  width: 46px;
  border: 1px solid #b8c1cc;
  border-radius: 5px;
  background: #fff;
  font-weight: 900;
  cursor: pointer;
}
.nav-arrow:disabled {
  opacity: 0.42;
  cursor: not-allowed;
}
.nav-submit {
  background: var(--teal);
  border-color: var(--teal);
  color: #fff;
}

/* Orientation overlay */
.orientation-overlay {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(15, 23, 42, 0.68);
}
.orientation-card {
  max-width: 420px;
  background: #fff;
  border-radius: 18px;
  padding: 22px;
  text-align: center;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.24);
}
.orientation-card h2 {
  margin-bottom: 8px;
}
.phone-rotate {
  font-size: 3rem;
  margin-bottom: 10px;
}
.orientation-actions {
  display: flex;
  justify-content: flex-start;
  gap: 10px;
  margin-top: 16px;
}
.teacher-only {
  opacity: 0.78;
}

/* Responsive rules: preserve exam structure, scale it down. */
@media (max-width: 1100px) {
  body {
    font-size: 17px;
  }
  .exam-stage {
    min-width: 900px;
    padding-left: 12px;
    padding-right: 12px;
  }
  .exam-paper {
    padding: 18px 22px;
  }
  .bottom-part {
    padding: 3px 4px;
  }
  .bottom-part strong {
    font-size: 0.66rem;
  }
  .nav-count {
    font-size: 0.58rem;
  }
  .nav-number {
    width: 18px;
    min-width: 18px;
    height: 20px;
    font-size: 0.55rem;
  }
  .nav-arrow,
  .nav-submit {
    width: 38px;
  }
}
@media (max-width: 820px) {
  :root {
    --top-h: 48px;
    --bottom-h: 52px;
  }
  body {
    font-size: 15px;
  }
  .app {
    width: min(100% - 18px, 960px);
  }
  .test-topbar {
    padding: 6px 10px;
    gap: 8px;
  }
  .brand {
    font-size: 0.82rem;
  }
  .student-chip {
    font-size: 0.72rem;
  }
  .exam-stage {
    min-width: 820px;
    padding: 12px 10px calc(var(--bottom-h) + 16px);
  }
  .exam-instruction-box {
    margin-bottom: 12px;
    padding: 8px 10px;
  }
  .exam-paper {
    padding: 14px 16px;
  }
  .exam-left,
  .exam-right {
    padding: 14px 16px;
  }
  .exam-text-flow {
    font-size: 0.94rem;
    line-height: 1.5;
  }
  .gapped-layout,
  .reading-scroll-layout {
    height: calc(100vh - var(--top-h) - var(--bottom-h) - 98px);
    min-height: 340px;
  }
  .bottom-navigation {
    padding: 4px 5px;
    gap: 5px;
  }
  .bottom-parts {
    gap: 3px;
  }
  .bottom-part {
    padding: 2px 3px;
    gap: 3px;
  }
  .bottom-part.is-active {
    flex: 2.5 1 0;
  }
  .bottom-part strong {
    font-size: 0.56rem;
  }
  .nav-count {
    font-size: 0.5rem;
  }
  .nav-numbers {
    gap: 2px;
  }
  .nav-number {
    width: 16px;
    min-width: 16px;
    height: 18px;
    font-size: 0.48rem;
  }
  .nav-arrow,
  .nav-submit {
    width: 31px;
  }
}
@media print {
  .test-topbar,
  .bottom-navigation,
  .orientation-overlay,
  .result-actions {
    display: none !important;
  }
  body {
    background: #fff;
    padding-bottom: 0;
  }
  .exam-stage {
    min-width: 0;
    padding: 0;
  }
}
