:root {
  --bg: #f4f6f8;
  --paper: #ffffff;
  --ink: #172033;
  --muted: #607086;
  --line: #d7dee8;
  --line-strong: #aeb9c8;
  --navy: #112a46;
  --blue: #1f5f9f;
  --blue-soft: #e9f2fb;
  --green: #0f7a5b;
  --red: #b3261e;
  --shadow: 0 14px 34px rgba(24, 39, 75, 0.08);
  --radius: 6px;
}

* { box-sizing: border-box; }

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Arial, "Helvetica Neue", Helvetica, sans-serif;
  line-height: 1.5;
}

button, input, textarea {
  font: inherit;
}

button, .top-actions a {
  min-height: 36px;
  border: 1px solid var(--blue);
  background: var(--blue);
  color: white;
  padding: 8px 14px;
  border-radius: 4px;
  cursor: pointer;
  text-decoration: none;
  font-size: 14px;
  font-weight: 700;
}

button.ghost, .top-actions a {
  background: white;
  color: var(--blue);
}

button:hover, .top-actions a:hover {
  filter: brightness(0.96);
}

.login-screen,
.completion-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 28px;
  background: #f7f9fc;
}

.login-card,
.completion-card {
  width: min(100%, 520px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
  box-shadow: var(--shadow);
  padding: 36px;
}

.login-card h1,
.completion-card h1 {
  margin: 0;
  color: #07162e;
  font-size: 30px;
  line-height: 1.25;
}

.login-copy {
  margin: 12px 0 24px;
  color: var(--muted);
  font-size: 15px;
}

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

.login-form button {
  min-height: 48px;
  margin-top: 6px;
}

.login-error {
  min-height: 22px;
  margin: 14px 0 0;
  color: var(--red);
  font-size: 14px;
  font-weight: 800;
}

.completion-card {
  display: grid;
  justify-items: center;
  text-align: center;
  gap: 22px;
}

.completion-card .section-kicker {
  margin: 0;
}

.completion-qr {
  width: min(100%, 360px);
  height: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
}

.login-mode .topbar,
.login-mode .exam-shell,
.login-mode .exam-bottom-bar,
.completed-mode .topbar,
.completed-mode .exam-shell,
.completed-mode .exam-bottom-bar,
.teacher-login-mode .topbar,
.teacher-login-mode .teacher-shell {
  display: none !important;
}

body:not(.teacher-login-mode) #teacherLoginScreen {
  display: none !important;
}

.topbar {
  height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  background: var(--paper);
  border-bottom: 4px solid var(--navy);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  color: var(--ink);
  font-size: 18px;
  font-weight: 800;
  text-decoration: none;
  letter-spacing: 0;
}

.meta-line {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.top-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

.exam-shell {
  display: grid;
  grid-template-columns: 288px minmax(0, 1fr);
  gap: 20px;
  max-width: 1480px;
  margin: 22px auto;
  padding: 0 22px;
}

.exam-sidebar {
  display: flex;
  flex-direction: column;
  gap: 16px;
  position: sticky;
  top: 94px;
  height: calc(100vh - 116px);
}

.candidate-card, .exam-sidebar section, .panel, .score-summary {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.candidate-card, .exam-sidebar section {
  padding: 16px;
}

.exam-sidebar h2, .panel h2 {
  margin: 0 0 12px;
  font-size: 15px;
  color: var(--navy);
}

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

input, textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  background: white;
  color: var(--ink);
  padding: 9px 10px;
  outline: none;
  appearance: none;
  -webkit-appearance: none;
}

input:focus, textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px var(--blue-soft);
}

input[type="date"] {
  min-height: 43px;
  text-align: left;
}

input[type="date"]::-webkit-date-and-time-value {
  min-height: 1.5em;
  text-align: left;
}

.candidate-card {
  display: grid;
  gap: 12px;
}

.nav-item {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  border-color: var(--line);
  background: white;
  color: var(--ink);
  text-align: left;
}

.nav-item.active {
  border-color: var(--blue);
  background: var(--blue-soft);
  color: var(--navy);
}

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

#progressBar {
  height: 100%;
  width: 0%;
  background: var(--green);
}

.status-panel p {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.exam-main {
  min-width: 0;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
  padding: 22px 26px;
  border-bottom: 1px solid var(--line);
  background: #fbfcfe;
}

.section-kicker {
  margin: 0 0 4px;
  color: var(--blue);
  font-size: 12px;
  text-transform: uppercase;
  font-weight: 800;
}

h1 {
  margin: 0;
  font-size: 24px;
  line-height: 1.2;
  letter-spacing: 0;
}

.timer {
  border: 1px solid var(--line);
  background: white;
  border-radius: 4px;
  padding: 8px 12px;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

#content {
  padding: 24px 26px 34px;
}

.level-block {
  margin-bottom: 26px;
}

.level-title {
  margin: 0 0 14px;
  padding: 9px 12px;
  border-left: 4px solid var(--blue);
  background: #f7f9fc;
  font-size: 17px;
}

.question-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  background: white;
}

.question-head {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 8px;
}

.qid {
  min-width: 42px;
  font-weight: 800;
  color: var(--navy);
}

.tag {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 2px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.prompt {
  margin: 0 0 12px;
  font-size: 16px;
}

.options {
  display: grid;
  gap: 8px;
}

.option {
  display: grid;
  grid-template-columns: 22px 1fr;
  gap: 8px;
  align-items: start;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 4px;
  font-size: 15px;
  color: var(--ink);
  font-weight: 400;
}

.option input {
  width: 16px;
  height: 16px;
  margin-top: 3px;
}

.written-answer {
  min-height: 86px;
  resize: vertical;
}

.short-answer {
  width: 100%;
  min-height: 54px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  font: inherit;
  color: var(--ink);
  background: #ffffff;
}

.short-answer:focus {
  outline: 2px solid rgba(38, 102, 168, 0.2);
  border-color: var(--blue);
}

.listening-part {
  display: grid;
  gap: 16px;
}

.listening-sheet {
  max-width: 1180px;
  margin: 0 auto 24px;
}

.listening-player-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(260px, 420px);
  gap: 18px;
  align-items: center;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fbfcfe;
}

.listening-player-card audio {
  width: 100%;
}

.listening-countdown {
  display: grid;
  gap: 8px;
  margin-top: 14px;
  max-width: 520px;
}

.listening-countdown > div:first-child {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  color: var(--navy);
  font-size: 14px;
}

.countdown-track {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: #dfe6f0;
}

.countdown-track span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--blue);
  transition: width 0.3s ease;
}

.listening-autoplay-note {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.listening-autoplay-note.needs-tap {
  display: inline-flex;
  cursor: pointer;
  color: var(--blue);
  font-weight: 800;
}

.listening-answer-sheet {
  margin-top: 16px;
  border: 2px solid #111827;
  background: #ffffff;
}

.listening-answer-sheet header {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  padding: 14px 18px;
  border-bottom: 1px solid #111827;
  font-size: 18px;
}

.listening-notes,
.listening-choices {
  padding: 16px 22px 18px;
}

.listening-notes h3,
.listening-choices h3 {
  margin: 0 0 12px;
  text-align: center;
  font-size: 22px;
  letter-spacing: 0;
}

.listening-note-row {
  display: grid;
  grid-template-columns: 34px 1fr;
  gap: 10px;
  align-items: center;
  min-height: 38px;
  padding: 5px 0;
  font-size: 16px;
}

.note-number {
  font-weight: 800;
  color: var(--navy);
}

.listening-blank {
  width: min(220px, 46vw);
  min-height: 30px;
  margin: 0 4px;
  border: 0;
  border-bottom: 2px dotted #111827;
  border-radius: 0;
  padding: 2px 8px;
  font: inherit;
  color: var(--navy);
  background: transparent;
}

.listening-blank:focus {
  outline: 0;
  border-bottom-color: var(--blue);
  background: #f7fbff;
}

.listening-choice-row {
  padding: 10px 0;
  border-top: 1px solid var(--line);
}

.listening-choice-row:first-of-type {
  border-top: 0;
}

.listening-choice-row p {
  margin: 0 0 8px;
  font-weight: 700;
}

.listening-choice-options {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.listening-choice-options label {
  display: grid;
  grid-template-columns: 28px 1fr;
  gap: 10px;
  align-items: center;
  min-height: 46px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 4px;
  cursor: pointer;
  color: #5f6d82;
  font-weight: 700;
  transition: border-color 0.16s ease, background 0.16s ease, color 0.16s ease;
}

.listening-choice-options label:hover {
  border-color: var(--blue);
  background: #f6faff;
}

.listening-choice-options label:has(input:checked) {
  border-color: var(--blue);
  background: var(--blue-soft);
  color: var(--blue);
  box-shadow: inset 0 0 0 1px rgba(38, 102, 168, 0.2);
}

.listening-choice-options input {
  appearance: none;
  width: 22px;
  height: 22px;
  margin: 0;
  border: 2px solid #aeb9c8;
  border-radius: 50%;
  background: #ffffff;
  position: relative;
}

.listening-choice-options input:checked {
  border-color: var(--blue);
  background: var(--blue);
}

.listening-choice-options input:checked::after {
  content: "";
  position: absolute;
  inset: 5px;
  border-radius: 50%;
  background: #ffffff;
}

.listening-choice-options span {
  min-width: 0;
  line-height: 1.35;
}

.reading-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(360px, 0.95fr);
  gap: 18px;
  align-items: start;
}

.passage {
  max-height: calc(100vh - 190px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  background: #fff;
}

.passage h2 {
  margin-top: 0;
  color: var(--navy);
}

.passage p {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 17px;
  line-height: 1.72;
}

.writing-box {
  min-height: 250px;
  resize: vertical;
}

.speaking-note {
  min-height: 120px;
}

.recording-panel {
  display: grid;
  gap: 10px;
  margin: 18px 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fbfcfe;
}

.recording-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.record-btn {
  min-width: 178px;
}

.record-btn.recording {
  border-color: var(--red);
  background: var(--red);
}

.recording-status {
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.recording-player {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.recording-player audio {
  max-width: 360px;
  width: 100%;
  height: 38px;
}

.download-link {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 7px 12px;
  border: 1px solid var(--blue);
  border-radius: 4px;
  color: var(--blue);
  background: #ffffff;
  font-size: 14px;
  font-weight: 800;
  text-decoration: none;
}

.recording-hint {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.teacher-shell {
  max-width: 1340px;
  margin: 22px auto 40px;
  padding: 0 22px;
  display: grid;
  gap: 18px;
}

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

.submission-row {
  width: 100%;
  display: grid;
  grid-template-columns: minmax(160px, 1fr) minmax(120px, 0.5fr) minmax(150px, 0.7fr) minmax(110px, 0.4fr);
  gap: 12px;
  align-items: center;
  border: 1px solid var(--line);
  background: #ffffff;
  color: var(--ink);
  text-align: left;
  box-shadow: none;
}

.submission-row.active {
  border-color: var(--blue);
  background: var(--blue-soft);
}

.submission-row strong,
.submission-row span,
.submission-row small {
  display: block;
}

.submission-row small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

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

.analytics-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  background: #fbfcfe;
}

.analytics-card-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.analytics-card-head h3 {
  margin: 0;
  color: var(--navy);
  font-size: 18px;
}

.analytics-card-head p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.analytics-card-head strong {
  color: var(--blue);
  font-size: 34px;
  line-height: 1;
}

.analytics-bars {
  display: grid;
  gap: 9px;
}

.analytics-metric {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) 42px;
  gap: 10px;
  align-items: center;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.analytics-metric div {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: #e3e9f1;
}

.analytics-metric i {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--blue);
}

.analytics-metric strong {
  color: var(--ink);
  text-align: right;
}

.level-distribution {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.level-chip {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 4px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #ffffff;
  color: var(--navy);
  font-size: 12px;
  font-weight: 800;
}

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

.analytics-note {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.recording-review {
  display: grid;
  gap: 8px;
  margin: 12px 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fbfcfe;
}

.recording-review audio {
  width: 100%;
  max-width: 420px;
}

.score-summary {
  padding: 22px 24px;
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: center;
}

.score-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(96px, 1fr));
  gap: 10px;
  min-width: 720px;
}

.score-grid div {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  background: #fbfcfe;
}

.score-grid span {
  display: block;
  font-size: 28px;
  font-weight: 800;
  color: var(--navy);
  line-height: 1;
}

.score-grid small {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
}

.score-grid .total {
  border-color: var(--blue);
  background: var(--blue-soft);
}

.panel {
  padding: 20px;
}

.info-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

.two-column {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(380px, 0.8fr);
  gap: 18px;
}

.import-box {
  min-height: 92px;
  resize: vertical;
  margin-bottom: 12px;
}

.hint {
  color: var(--muted);
  font-size: 14px;
}

.review-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.review-table th, .review-table td {
  border-bottom: 1px solid var(--line);
  padding: 9px 8px;
  text-align: left;
}

.review-table th {
  color: var(--navy);
  background: #f7f9fc;
}

.correct { color: var(--green); font-weight: 800; }
.wrong { color: var(--red); font-weight: 800; }

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

.rubric-row {
  display: grid;
  grid-template-columns: 1fr 86px;
  gap: 12px;
  align-items: center;
}

.advice-grid, .rubric-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.advice-grid article, .rubric-grid article {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  background: #fbfcfe;
}

.advice-grid h3, .rubric-grid h3 {
  margin: 0 0 8px;
  font-size: 16px;
  color: var(--navy);
}

.advice-grid p, .rubric-grid p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

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

.radar-layout {
  display: grid;
  grid-template-columns: minmax(360px, 640px) minmax(260px, 1fr);
  gap: 18px;
  align-items: center;
}

#radarChart {
  width: 100%;
  max-width: 640px;
  height: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
}

.radar-legend {
  display: grid;
  gap: 10px;
}

.radar-legend article {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  background: #fbfcfe;
}

.radar-legend h3 {
  margin: 0 0 5px;
  color: var(--navy);
  font-size: 15px;
}

.radar-legend p {
  margin: 0;
  color: var(--ink);
  font-size: 14px;
  font-weight: 800;
}

.radar-legend small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%) translateY(18px);
  background: var(--navy);
  color: white;
  border-radius: 4px;
  padding: 10px 14px;
  opacity: 0;
  pointer-events: none;
  transition: 180ms ease;
  z-index: 30;
  font-size: 14px;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.exam-progress-meta,
.exam-bottom-bar,
#endSectionBtn {
  display: none;
}

.top-progress {
  width: 320px;
  height: 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.85);
  overflow: hidden;
}

#topProgressBar {
  width: 0%;
  height: 100%;
  background: #4c9dff;
}

body.exam-mode {
  background: #ffffff;
}

.exam-mode .topbar {
  height: 58px;
  padding: 0 24px;
  background: #061b3d;
  border-bottom: 0;
  color: #ffffff;
  box-shadow: none;
}

.exam-mode .brand {
  color: #ffffff;
  font-size: 18px;
  font-weight: 800;
}

.exam-mode .meta-line {
  display: none;
}

.exam-mode .exam-progress-meta {
  display: flex;
  align-items: center;
  gap: 14px;
  color: #ffffff;
  font-size: 15px;
  font-weight: 700;
}

.exam-mode .top-actions a,
.exam-mode #resetBtn,
.exam-mode #exportBtn {
  display: none;
}

.exam-mode #endSectionBtn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 170px;
  border-color: rgba(255, 255, 255, 0.22);
  background: rgba(255, 255, 255, 0.06);
  color: #ffffff;
  white-space: nowrap;
}

.exam-mode .exam-shell {
  display: block;
  max-width: none;
  height: calc(100vh - 58px);
  margin: 0;
  padding: 0;
}

.exam-mode .exam-sidebar,
.exam-mode .section-head {
  display: none;
}

.exam-mode .exam-main {
  height: 100%;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  overflow: hidden;
}

.exam-mode #content {
  height: calc(100vh - 58px - 70px);
  padding: 26px;
  overflow-y: auto;
  background: #ffffff;
}

.exam-mode .level-block {
  max-width: 1040px;
  margin: 0 auto 28px;
}

.exam-mode .listening-sheet {
  max-width: 1180px;
  margin: 0 auto;
}

.exam-mode .listening-player-card {
  padding: 14px 18px;
}

.exam-mode .listening-player-card .level-title {
  margin-bottom: 8px;
  font-size: 22px;
}

.exam-mode .listening-answer-sheet {
  margin-top: 14px;
}

.exam-mode .listening-notes,
.exam-mode .listening-choices {
  padding-top: 12px;
  padding-bottom: 12px;
}

.exam-mode .listening-note-row {
  min-height: 34px;
  padding: 3px 0;
}

.exam-mode .listening-choice-row {
  padding: 8px 0;
}

.exam-mode .level-title {
  margin-bottom: 18px;
  border-left: 0;
  background: transparent;
  padding: 0;
  color: #05142c;
  font-size: 24px;
}

.exam-mode .question-card {
  margin-bottom: 18px;
  padding: 24px 26px;
  border: 1px solid #d8dee8;
  border-radius: 6px;
  box-shadow: none;
}

.exam-mode .question-head {
  gap: 12px;
  margin-bottom: 14px;
}

.exam-mode .qid {
  min-width: 46px;
  font-size: 26px;
  color: #07162e;
}

.exam-mode .tag {
  min-height: 32px;
  padding: 4px 14px;
  border-color: #d8dee8;
  color: #6b778a;
  font-size: 14px;
}

.exam-mode .prompt {
  margin-bottom: 18px;
  font-size: 18px;
  color: #121a2c;
}

.exam-mode .options {
  gap: 12px;
}

.exam-mode .option {
  grid-template-columns: 26px 1fr;
  min-height: 56px;
  align-items: center;
  padding: 12px 16px;
  border-color: #d8dee8;
  font-size: 17px;
  color: #172033;
}

.exam-mode .option input {
  width: 18px;
  height: 18px;
  margin-top: 0;
}

.exam-mode .writing-box {
  min-height: 360px;
}

.exam-mode .written-answer,
.exam-mode .speaking-note {
  min-height: 150px;
  font-size: 17px;
}

body.reading-mode {
  overflow: hidden;
  background: #ffffff;
}

.reading-mode .topbar {
  height: 58px;
  padding: 0 24px;
  background: #061b3d;
  border-bottom: 0;
  color: #ffffff;
  box-shadow: none;
}

.reading-mode .brand {
  color: #ffffff;
  font-size: 18px;
  font-weight: 800;
}

.reading-mode .meta-line {
  display: none;
}

.reading-mode .exam-progress-meta {
  display: flex;
  align-items: center;
  gap: 14px;
  color: #ffffff;
  font-size: 15px;
  font-weight: 700;
}

.reading-mode .top-actions a,
.reading-mode #resetBtn,
.reading-mode #exportBtn {
  display: none;
}

.reading-mode #endSectionBtn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 170px;
  border-color: rgba(255, 255, 255, 0.22);
  background: rgba(255, 255, 255, 0.06);
  color: #ffffff;
  white-space: nowrap;
}

.reading-mode .exam-shell {
  display: block;
  max-width: none;
  height: calc(100vh - 58px);
  margin: 0;
  padding: 0;
}

.reading-mode .exam-sidebar,
.reading-mode .section-head {
  display: none;
}

.reading-mode .exam-main {
  height: 100%;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  overflow: hidden;
}

.reading-mode #content {
  height: calc(100vh - 58px - 70px);
  padding: 0;
  overflow: hidden;
}

.reading-exam-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  height: 100%;
  background: #ffffff;
}

.reading-left,
.reading-right {
  min-width: 0;
  height: 100%;
  overflow-y: auto;
  padding: 26px;
}

.reading-left {
  border-right: 1px solid #d7dee8;
}

.reading-instructions {
  margin-bottom: 18px;
}

.reading-instructions h2,
.questions-heading h2 {
  margin: 0 0 12px;
  color: #05142c;
  font-size: 22px;
  line-height: 1.2;
}

.reading-instructions p,
.questions-heading p {
  margin: 8px 0;
  color: #0f203d;
  font-size: 15px;
}

.reading-mode .passage.exam-passage {
  max-height: none;
  overflow: visible;
  border: 1px solid #d8dee8;
  border-radius: 6px;
  padding: 30px 36px;
  background: #ffffff;
}

.reading-mode .passage h2 {
  margin: 0 0 24px;
  color: #07162e;
  font-size: 30px;
  line-height: 1.18;
}

.reading-mode .passage p {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 20px;
  line-height: 1.72;
  color: #101b2f;
}

.questions-heading {
  margin-bottom: 22px;
}

.question-pills {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 16px;
}

.question-pills button {
  width: 42px;
  min-height: 42px;
  padding: 0;
  border: 1px solid #cdd6e2;
  background: #ffffff;
  color: #172033;
  border-radius: 6px;
}

.question-pills button.done {
  border-color: #0c6fd8;
  background: #0c6fd8;
  color: #ffffff;
}

.reading-mode .question-card {
  margin-bottom: 18px;
  padding: 24px 26px;
  border: 1px solid #d8dee8;
  border-radius: 6px;
  box-shadow: none;
}

.reading-mode .question-head {
  gap: 12px;
  margin-bottom: 14px;
}

.reading-mode .qid {
  min-width: 46px;
  font-size: 28px;
  color: #07162e;
}

.reading-mode .tag {
  min-height: 34px;
  padding: 4px 14px;
  border-color: #d8dee8;
  color: #6b778a;
  font-size: 14px;
}

.reading-mode .prompt {
  margin-bottom: 18px;
  font-size: 18px;
  color: #121a2c;
}

.reading-mode .options {
  gap: 12px;
}

.reading-mode .option {
  grid-template-columns: 26px 1fr;
  min-height: 56px;
  align-items: center;
  padding: 12px 16px;
  border-color: #d8dee8;
  font-size: 17px;
  color: #172033;
}

.reading-mode .option input {
  width: 18px;
  height: 18px;
  margin-top: 0;
}

.exam-bottom-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: 70px;
  z-index: 20;
  align-items: center;
  justify-content: space-between;
  padding: 0 30px;
  border-top: 1px solid #d7dee8;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 -8px 24px rgba(12, 26, 48, 0.08);
}

.exam-bottom-bar.show {
  display: flex;
}

.bottom-center {
  display: flex;
  align-items: center;
  gap: 18px;
}

.exam-bottom-bar button {
  min-width: 154px;
  min-height: 46px;
  white-space: nowrap;
}

.exam-bottom-bar #reviewBtn {
  min-width: 230px;
}

.exam-bottom-bar button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

@media (max-width: 980px) {
  .topbar {
    height: auto;
    align-items: flex-start;
    flex-direction: column;
    gap: 12px;
    padding: 16px;
  }

  .top-actions {
    width: 100%;
    flex-wrap: wrap;
  }

  .exam-shell {
    grid-template-columns: 1fr;
    padding: 0 14px;
  }

  .exam-sidebar {
    position: static;
    height: auto;
  }

  .reading-layout,
  .listening-player-card,
  .two-column,
  .info-grid,
  .analytics-grid,
  .advice-grid,
  .rubric-grid {
    grid-template-columns: 1fr;
  }

  .passage {
    max-height: none;
  }

  .score-summary {
    align-items: stretch;
    flex-direction: column;
  }

  .score-grid {
    min-width: 0;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .radar-layout,
  .report-head {
    grid-template-columns: 1fr;
    display: grid;
  }

  .reading-mode {
    overflow: auto;
  }

  .reading-mode .topbar {
    height: auto;
  }

  .reading-mode .exam-progress-meta {
    width: 100%;
    justify-content: space-between;
  }

  .top-progress {
    flex: 1;
    width: auto;
  }

  .reading-mode #content {
    height: auto;
    overflow: visible;
  }

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

  .reading-left,
  .reading-right {
    height: auto;
    overflow: visible;
    padding: 18px;
  }

  .reading-left {
    border-right: 0;
    border-bottom: 1px solid #d7dee8;
  }

  .exam-bottom-bar.show {
    position: sticky;
    height: auto;
    flex-wrap: wrap;
    gap: 10px;
    padding: 10px 14px;
  }

  .bottom-center {
    flex: 1 1 100%;
    justify-content: center;
  }

  .listening-choice-options {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  body.exam-mode,
  body.reading-mode {
    overflow: hidden;
  }

  .login-screen,
  .completion-screen {
    align-items: start;
    padding: 72px 18px 28px;
  }

  .login-card,
  .completion-card {
    width: 100%;
    padding: 28px 22px;
  }

  .login-card h1,
  .completion-card h1 {
    font-size: 30px;
  }

  .login-form input {
    display: block;
    width: 100%;
    height: 48px;
    padding: 9px 12px;
    line-height: 1.4;
  }

  .login-form input[type="date"] {
    text-align: center;
  }

  .login-form input[type="date"]::-webkit-date-and-time-value {
    text-align: center;
  }

  .listening-player-card {
    padding: 14px;
  }

  .listening-answer-sheet header {
    align-items: flex-start;
    flex-direction: column;
    padding: 12px 14px;
  }

  .listening-notes,
  .listening-choices {
    padding: 14px;
  }

  .listening-note-row {
    grid-template-columns: 28px 1fr;
    font-size: 14px;
  }

  .listening-blank {
    width: min(180px, 54vw);
  }

  .exam-mode .topbar,
  .reading-mode .topbar {
    min-height: 82px;
    padding: 10px 14px;
    align-items: stretch;
    flex-direction: column;
    gap: 8px;
  }

  .exam-mode .brand,
  .reading-mode .brand {
    display: block;
    max-width: 100%;
    overflow: hidden;
    color: #ffffff;
    font-size: 18px;
    line-height: 1.18;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .exam-mode .exam-progress-meta,
  .reading-mode .exam-progress-meta {
    display: grid;
    grid-template-columns: auto minmax(72px, 1fr) auto;
    width: 100%;
    gap: 10px;
    font-size: 14px;
  }

  .top-progress {
    width: auto;
    height: 6px;
  }

  .exam-mode #endSectionBtn,
  .reading-mode #endSectionBtn {
    display: none;
  }

  .exam-mode .exam-shell,
  .reading-mode .exam-shell {
    height: calc(100dvh - 82px);
    padding: 0;
  }

  .exam-mode .exam-main,
  .reading-mode .exam-main {
    overflow: hidden;
  }

  .exam-mode #content,
  .reading-mode #content {
    height: 100%;
    padding: 18px 14px 220px;
    overflow-y: auto;
  }

  .exam-mode .level-block {
    margin-bottom: 22px;
  }

  .exam-mode .level-title,
  .reading-mode .level-title {
    font-size: 20px;
  }

  .exam-mode .question-card,
  .reading-mode .question-card {
    margin-bottom: 14px;
    padding: 18px 16px;
  }

  .exam-mode .question-head,
  .reading-mode .question-head {
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
  }

  .exam-mode .qid,
  .reading-mode .qid {
    min-width: auto;
    font-size: 28px;
    line-height: 1;
  }

  .exam-mode .tag,
  .reading-mode .tag {
    min-height: 28px;
    padding: 3px 10px;
    font-size: 13px;
  }

  .exam-mode .prompt,
  .reading-mode .prompt {
    margin-bottom: 14px;
    font-size: 18px;
    line-height: 1.48;
  }

  .exam-mode .option,
  .reading-mode .option {
    grid-template-columns: 24px minmax(0, 1fr);
    min-height: 54px;
    padding: 12px 12px;
    gap: 10px;
    font-size: 16px;
    line-height: 1.42;
  }

  .exam-mode .option input,
  .reading-mode .option input {
    width: 18px;
    height: 18px;
  }

  .reading-exam-layout {
    display: grid;
    grid-template-columns: 1fr;
    height: auto;
  }

  .reading-left,
  .reading-right {
    height: auto;
    overflow: visible;
    padding: 0;
  }

  .reading-left {
    margin-bottom: 18px;
    border-right: 0;
    border-bottom: 1px solid #d7dee8;
    padding-bottom: 18px;
  }

  .reading-mode .passage.exam-passage {
    padding: 20px 18px;
  }

  .reading-mode .passage h2 {
    font-size: 24px;
  }

  .reading-mode .passage p {
    font-size: 17px;
    line-height: 1.68;
  }

  .exam-bottom-bar.show {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    display: grid;
    grid-template-columns: 1fr;
    height: auto;
    gap: 8px;
    padding: 10px 14px calc(12px + env(safe-area-inset-bottom));
  }

  .exam-bottom-bar button {
    width: 100%;
    min-width: 0;
    min-height: 44px;
    padding: 8px 10px;
    font-size: 15px;
  }

  .exam-bottom-bar #reviewBtn {
    min-width: 0;
  }

  .bottom-center {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
    width: 100%;
    gap: 8px;
  }

  #bottomPosition {
    display: grid;
    min-width: 48px;
    place-items: center;
    color: #172033;
    font-size: 14px;
    font-weight: 800;
    line-height: 1.15;
    text-align: center;
  }
}

@media print {
  .topbar, .exam-sidebar, .top-actions, .toast {
    display: none;
  }

  body {
    background: white;
  }

  .exam-shell, .teacher-shell {
    display: block;
    max-width: none;
    margin: 0;
    padding: 0;
  }

  .exam-main, .panel, .score-summary {
    box-shadow: none;
    border-color: #bbb;
  }
}
