body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: linear-gradient(180deg, #eef4fb, #f4f7fc);
  color: #1f2a44;
}

.container {
  max-width: 1100px;
  margin: 96px auto 24px;
  padding: 20px;
}

.topbar {
  margin-bottom: 10px;
}

.back-link {
  display: inline-block;
  text-decoration: none;
  color: #2563eb;
  font-weight: 700;
}

.back-link:hover {
  text-decoration: underline;
}

.container h1 {
  text-align: center;
  margin: 12px 0 26px;
  font-size: 2.1rem;
}

.resume-notice {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin: 0 auto 18px;
  max-width: 820px;
  padding: 14px 16px;
  border: 1px solid #cddcf9;
  border-radius: 14px;
  background: #f5f8ff;
  color: #274582;
}

.resume-notice > div {
  display: grid;
  gap: 3px;
}

.resume-notice span {
  color: #60708f;
  font-size: 14px;
}

.resume-notice.hidden {
  display: none;
}

@media (max-width: 640px) {
  .resume-notice {
    align-items: stretch;
    flex-direction: column;
  }
}

.exam-topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

.exam-progress {
  font-size: 16px;
  font-weight: 800;
  color: #334155;
}

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

.timer {
  min-width: 86px;
  text-align: center;
  font-size: 18px;
  font-weight: 800;
  color: #2563eb;
  background: #eef4ff;
  border-radius: 12px;
  padding: 10px 14px;
}

.nav-btn {
  padding: 10px 16px;
  font-size: 15px;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 700;
}

.primary-btn {
  background: #2563eb;
  color: white;
}

.secondary-btn {
  background: #e5e7eb;
  color: #111827;
}

.submit-btn {
  background: #111827;
  color: white;
}

.question-card {
  background: #fff;
  border-radius: 20px;
  padding: 28px;
  margin-bottom: 22px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.06);
}

.speaker-row {
  display: flex;
  align-items: flex-start;
  gap: 18px;
  margin-bottom: 26px;
}

.speaker-row:last-child {
  margin-bottom: 0;
}

.avatar {
  width: 74px;
  height: 74px;
  border-radius: 50%;
  background: #d9f3ef;
  border: 3px solid #12a594;
  flex-shrink: 0;
}

.speech,
.response-area {
  font-size: 20px;
  line-height: 1.8;
  flex: 1;
}

.speech {
  font-weight: 700;
}

.response-area {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  align-content: flex-start;
  gap: 0;
}

.fixed-text {
  display: inline-block;
  margin-right: 6px;
  font-weight: 700;
}

.slot {
  min-width: 92px;
  height: 34px;
  border-bottom: 3px solid #cfcfcf;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 6px;
  margin-right: 6px;
  background: transparent;
  transition: background 0.15s ease;
}

.slot.over {
  background: #eef9f7;
  border-radius: 6px 6px 0 0;
}

.token {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 7px 12px;
  border-radius: 12px;
  background: #fff;
  border: 1px solid #ccc;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: none;
  font-size: 16px;
  line-height: 1.2;
  white-space: nowrap;
}

.token.pointer-dragging {
  cursor: grabbing;
  opacity: 0.68;
}

body.bas-pointer-dragging {
  user-select: none;
  -webkit-user-select: none;
}

.bank.over {
  outline: 2px solid rgba(18, 165, 148, 0.32);
  outline-offset: -2px;
}

.bank {
  min-height: 92px;
  background: #fff;
  border-radius: 20px;
  padding: 20px;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.05);
}

.controls {
  margin-top: 18px;
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

button {
  padding: 10px 18px;
  font-size: 15px;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 700;
}

#resetBtn {
  background: #ddd;
}

.result {
  margin-top: 16px;
  font-size: 15px;
  min-height: 22px;
  color: #64748b;
}

.final-result {
  margin-top: 24px;
  background: #fff;
  border-radius: 20px;
  padding: 24px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.06);
}

.final-result.hidden {
  display: none;
}

.final-score {
  font-size: 28px;
  font-weight: 800;
  margin-bottom: 8px;
}

.final-accuracy {
  font-size: 16px;
  font-weight: 700;
  color: #475569;
  margin-bottom: 14px;
}

.final-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 20px;
}

.final-action-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 0 16px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 800;
  text-decoration: none;
  background: #2563eb;
  color: #ffffff;
}

.final-action-link.secondary {
  background: #eef2f7;
  color: #111827;
}

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

.review-item {
  border: 1px solid #e2e8f0;
  border-radius: 14px;
  padding: 16px;
  background: #fcfdff;
}

.review-item.correct {
  border-left: 6px solid #16a34a;
}

.review-item.wrong {
  border-left: 6px solid #dc2626;
}

.review-title {
  font-weight: 800;
  margin-bottom: 8px;
  line-height: 1.5;
}

.review-line {
  margin: 4px 0;
  line-height: 1.6;
}

.review-line strong {
  color: #111827;
}

/* Writing 页 Set 布局 */
.bs-set-list {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.bs-set-row {
  display: flex;
  align-items: center;
  gap: 18px;
  flex-wrap: nowrap;
}

/* Keep BAS aligned with the Listening compact-card geometry. These are
   product-contract heights, not content-driven minimums: future actions must
   fit inside the existing rhythm instead of silently making cards taller. */
body .writing-bas-set-card.writing-bas-set-card {
  height: 132px;
  flex-wrap: nowrap;
}

.bs-set-title {
  width: 62px;
  flex: 0 0 62px;
  font-size: 16px;
  font-weight: 800;
  color: #222;
}

.bs-grid {
  display: flex;
  gap: 12px;
  flex-wrap: nowrap;
}

.bs-item {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fff;
  border: 1px solid #ccc;
  font-weight: 800;
  text-decoration: none;
  color: #333;
  transition: 0.16s ease;
  flex: 0 0 42px;
}

.bs-item:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(15, 23, 42, 0.08);
}

.bs-item.correct {
  background: #16a34a;
  border-color: #16a34a;
  color: #fff;
}

.bs-item.wrong {
  background: #dc2626;
  border-color: #dc2626;
  color: #fff;
}

.bs-item.locked {
  background: #f8fafc;
  border-color: #d8e0ef;
  color: #64748b;
}

/* A paid lock blocks entry, not visibility of a student's history. Keep the
   outcome colors stronger than the generic locked treatment. */
.bs-item.locked.correct {
  background: #16a34a;
  border-color: #16a34a;
  color: #fff;
}

.bs-item.locked.wrong {
  background: #dc2626;
  border-color: #dc2626;
  color: #fff;
}

.bs-set-score {
  margin-left: 8px;
  font-size: 15px;
  font-weight: 800;
  color: #64748b;
  white-space: nowrap;
}

.bs-set-actions {
  display: inline-flex;
  min-width: max-content;
  flex: 0 0 auto;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: nowrap;
  position: relative;
  z-index: 2;
}

.bs-set-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  position: relative;
  padding: 0;
  border: 0;
  border-radius: 0;
  color: #5752b7;
  background: transparent;
  font-size: 12px;
  font-weight: 700;
  line-height: 18px;
  text-decoration: none;
  white-space: nowrap;
  z-index: 2;
  transition: color 160ms ease,
    transform 160ms cubic-bezier(.23, 1, .32, 1);
}

.bs-set-action::before {
  position: absolute;
  inset: -13px -4px;
  content: '';
}

.bs-set-action:focus-visible {
  border-radius: 4px;
  outline: 2px solid #5752b7;
  outline-offset: 2px;
}

.bs-set-action:active {
  transform: scale(.97);
}

/* The full-width BAS card has a dedicated 38px question band. Keep the two
   set-level actions on that same band instead of leaving them suspended in
   the score row: their top, center and bottom now align with the question
   selector while the card-height contract stays untouched. */
@media (min-width: 761px) {
  body .writing-bas-set-card.writing-bas-set-card .bs-set-actions {
    position: absolute;
    top: 64px;
    right: 16px;
    height: 38px;
  }
}

.bs-set-history-note {
  min-width: 0;
  color: #64748b;
  font-size: 12px;
  font-weight: 700;
  line-height: 18px;
  text-align: right;
  white-space: nowrap;
}

@media (prefers-reduced-motion: reduce) {
  .bs-set-action {
    transition: color 0ms, transform 0ms;
  }

  body .writing-bas-set-card.writing-bas-set-card .bs-set-action:active {
    transform: none;
  }
}

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

.auth-modal.open {
  display: flex;
}

.auth-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.48);
  backdrop-filter: blur(4px);
}

body.auth-practice-locked {
  overflow: hidden;
}

body.auth-practice-locked > :not(#authModal):not(#navbar) {
  pointer-events: none;
  user-select: none;
  filter: blur(2px);
}

body.auth-practice-locked > #navbar {
  pointer-events: none;
  user-select: none;
}

body.auth-practice-locked > #navbar .nav-inner {
  filter: blur(2px);
}

body.auth-practice-locked .auth-close,
body.auth-practice-locked [data-auth-close] {
  display: none;
}

.auth-dialog {
  position: relative;
  width: min(420px, 100%);
  background: #fff;
  border: 1px solid #dbe7f6;
  border-radius: 24px;
  padding: 28px;
  box-shadow: 0 25px 70px rgba(15, 23, 42, 0.25);
}

.auth-close {
  position: absolute;
  right: 16px;
  top: 14px;
  border: 0;
  background: transparent;
  color: #64748b;
  font-size: 26px;
  cursor: pointer;
}

.auth-kicker {
  color: #2563eb;
  font-weight: 900;
  font-size: 13px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.auth-dialog h2 {
  font-size: 30px;
  margin: 8px 0;
}

.auth-intro {
  margin: 0 0 20px;
  color: #64748b;
  line-height: 1.6;
}

.auth-dialog label {
  display: block;
  font-size: 13px;
  font-weight: 800;
  margin: 13px 0;
  color: #1f2a44;
}

.auth-dialog input {
  display: block;
  width: 100%;
  margin-top: 7px;
  border: 1px solid #cbd5e1;
  border-radius: 12px;
  padding: 12px 13px;
  font: inherit;
  outline: none;
  box-sizing: border-box;
}

.auth-dialog input:focus {
  border-color: #2563eb;
  box-shadow: 0 0 0 3px #e7efff;
}

.auth-dialog input:disabled {
  background: #f7f9fd;
  color: #64748b;
}

.auth-submit {
  width: 100%;
  margin-top: 8px;
  border: 0;
  border-radius: 12px;
  padding: 13px;
  background: #2563eb;
  color: #fff;
  font: inherit;
  font-weight: 900;
  cursor: pointer;
}

.auth-submit:disabled {
  opacity: 0.65;
  cursor: wait;
}

.auth-message {
  min-height: 22px;
  margin-top: 12px;
  font-size: 13px;
  text-align: center;
  color: #64748b;
}

.auth-message.success {
  color: #15803d;
}

.auth-message.error {
  color: #b91c1c;
}

.auth-switches {
  display: flex;
  justify-content: center;
  gap: 14px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.auth-switches button {
  border: 0;
  background: transparent;
  color: #2563eb;
  font: inherit;
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
}

.auth-notice {
  position: fixed;
  left: 50%;
  top: 82px;
  z-index: 6000;
  max-width: min(560px, calc(100vw - 28px));
  transform: translate(-50%, -14px);
  opacity: 0;
  border: 1px solid #bbf7d0;
  border-radius: 16px;
  padding: 13px 16px;
  background: #f0fdf4;
  color: #166534;
  font-size: 14px;
  font-weight: 800;
  line-height: 1.5;
  box-shadow: 0 16px 40px rgba(15, 23, 42, 0.14);
  transition: 0.22s ease;
}

.auth-notice.error {
  border-color: #fecaca;
  background: #fef2f2;
  color: #991b1b;
}

.auth-notice.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (max-width: 700px) {
  body .writing-bas-set-card.writing-bas-set-card {
    height: 126px;
  }

  .container {
    padding: 14px;
  }

  .container h1 {
    font-size: 1.7rem;
    margin-bottom: 20px;
  }

  .question-card {
    padding: 18px;
    border-radius: 16px;
  }

  .speaker-row {
    gap: 12px;
    margin-bottom: 20px;
  }

  .avatar {
    width: 58px;
    height: 58px;
  }

  .speech,
  .response-area {
    font-size: 18px;
    line-height: 1.75;
  }

  .slot {
    min-width: 82px;
    height: 30px;
  }

  .token {
    font-size: 15px;
    padding: 6px 10px;
  }

  .bank {
    padding: 16px;
    border-radius: 16px;
  }

  .bs-set-row {
    align-items: flex-start;
    gap: 12px;
    flex-wrap: wrap;
    padding-bottom: 2px;
  }

  .bs-grid {
    gap: 10px;
    flex-wrap: wrap;
  }

  .bs-item {
    width: 38px;
    height: 38px;
    flex-basis: 38px;
  }

  .bs-set-score {
    margin-left: 0;
  }

  .bs-set-actions {
    width: auto;
    flex-wrap: nowrap;
    justify-content: flex-end;
  }

  .bs-set-action {
    flex: 0 0 auto;
  }

  .bs-set-history-note {
    text-align: right;
  }

  .auth-dialog {
    padding: 24px 20px;
  }
}

@media (max-width: 760px) {
  body .writing-bas-set-card.writing-bas-set-card .nonreading-card-meta {
    min-height: 44px;
    grid-template-columns: minmax(0, 1fr) 18px;
    grid-template-rows: 18px 18px;
    align-content: center;
    row-gap: 0;
  }

  body .writing-bas-set-card.writing-bas-set-card .nonreading-card-index {
    grid-column: 1;
    grid-row: 1;
  }

  body .writing-bas-set-card.writing-bas-set-card :is(
    .nonreading-card-context,
    .nonreading-card-frequency
  ) {
    display: none;
  }

  body .writing-bas-set-card.writing-bas-set-card .nonreading-card-lock {
    grid-column: 2;
    grid-row: 1 / span 2;
    align-self: center;
  }

  body .writing-bas-set-card.writing-bas-set-card .nonreading-card-foot {
    display: contents;
    min-height: 0;
  }

  body .writing-bas-set-card.writing-bas-set-card .nonreading-card-foot > span {
    position: absolute;
    top: 31px;
    right: 14px;
    left: 14px;
    height: 18px;
    line-height: 18px;
  }

  body .writing-bas-set-card.writing-bas-set-card.is-completed:not(.is-locked) .nonreading-card-foot > span {
    right: 214px;
  }

  body .writing-bas-set-card.writing-bas-set-card .bs-set-actions {
    position: absolute;
    top: 12px;
    right: 14px;
    height: 44px;
  }

  body .writing-bas-set-card.writing-bas-set-card .bs-set-action {
    margin: 0;
  }
}

@media (max-width: 581px) {
  body .writing-bas-set-card.writing-bas-set-card {
    height: 164px;
  }
}

@media (max-width: 341px) {
  body .writing-bas-set-card.writing-bas-set-card {
    height: 212px;
  }
}
