/*
 * Màn thi. Toạ độ quy đổi từ ảnh 1920×1200 (docs/reference/exam-a1-screenshot.png):
 * 1vh = 12px, 1vw = 19.2px ở độ phân giải đó.
 */
.page-exam { overflow: hidden; background: var(--slate); }

.exam {
  --cell-h: 4.75vh;
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 18.8vw;
  grid-template-rows: minmax(0, 1fr) max(22px, 2.6vh);
  grid-template-areas: "main side" "status status";
  column-gap: 0.4vw;
  padding: 0.5vh 0.4vw 0 0.4vw;
  background: var(--slate);
  user-select: none;
}

/* ---------- Cột trái ---------- */
.exam-main {
  grid-area: main;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding-bottom: 0.4vh;
}

.question-frame {
  flex: 1;
  min-height: 0;
  border: 0.55vh solid;
  border-color: #d4d8d8 #9d9fa0 #9d9fa0 #d4d8d8;
  background: #c9ced0;
}

.question-panel {
  height: 100%;
  border: 2px solid;
  border-color: #8c9192 #eef0f0 #eef0f0 #8c9192;
  background: #fff;
  overflow: hidden;
}

.question-image {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: left top;
  -webkit-user-drag: none;
}

.exam-progress {
  position: relative;
  flex: none;
  height: 3.1vh;
  margin-top: 0.75vh;
  border: 1px solid #5d1c22;
  border-radius: 0.35vh;
  background: linear-gradient(#e9ecef, #c9ced6);
  overflow: hidden;
}

.exam-progress-fill {
  height: 100%;
  background: linear-gradient(#ffb7b3 0%, #ff7f80 28%, #f2160d 55%, #f00900 80%, #d10a05 100%);
  transition: width 0.25s linear;
}

.exam-progress-text {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font: 700 1.8vh/1 var(--sans);
  color: #3b0000;
}

.exam-bottom {
  flex: none;
  height: 17.9vh;
  margin-top: 0.6vh;
  display: flex;
  justify-content: space-between;
  align-items: stretch;
}

.candidate-box {
  width: 34.6%;
  margin: 0.5vh 0 0 0;
  padding: 0.8vh 0.6vw 0;
  border: 1px solid #c2cddd;
  min-width: 0;
}

.candidate-box legend {
  padding: 0 0.2vw;
  font: 700 1.3vh var(--ui);
  color: #101010;
}

.candidate-box p {
  margin: 0 0 2.45vh;
  font: 700 1.85vh/1.2 var(--serif);
  color: #1d2d52;
  white-space: nowrap;
}

.candidate-sbd { display: inline-block; min-width: 6.5vw; }

.promo-box {
  width: 29.2%;
  display: flex;
  flex-direction: column;
  border-radius: 1vh;
  background: linear-gradient(#fde5cc, #fbecd6);
  overflow: hidden;
}

.promo-box p {
  flex: 1;
  display: grid;
  place-items: center;
  margin: 0;
  padding-top: 1.2vh;
  font: 2.85vh/1.15 var(--sans);
  text-align: center;
  color: #1f1d5c;
}

.promo-band {
  height: 5.1vh;
  margin: 0 0.4vw 0.6vh;
  border-radius: 0 0 0.6vh 0.6vh;
  background:
    linear-gradient(160deg, transparent 0 58%, #e8382c 58% 72%, #f38a6a 72% 76%, transparent 76%),
    repeating-linear-gradient(90deg, rgba(200, 170, 120, 0.18) 0 2px, transparent 2px 9px),
    linear-gradient(90deg, #f3e2c2, #f6e9d1);
}

/* ---------- Cột phải ---------- */
.exam-side {
  grid-area: side;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5vh;
  padding: 0.45vh 0.3vw 0.6vh;
  background: #1e9ae9;
}

.timer-box {
  flex: none;
  height: 4.9vh;
  display: flex;
  align-items: center;
  padding: 0 0.5vw;
  border: 1px solid #9fa6a6;
  border-radius: 1vh;
  background: linear-gradient(#fffff2, #fbf9d8);
}

.timer-label {
  width: 47%;
  font: 700 1.6vh/1.15 var(--serif);
  text-align: center;
  color: #302e7b;
}

.timer {
  flex: 1;
  text-align: right;
  font: 4.3vh/1 var(--sans);
  color: #130d9a;
  letter-spacing: 0.02em;
  font-variant-numeric: tabular-nums;
}

.palette {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 0.65vh 0.3vw;
  border-radius: 1.2vh 1.2vh 0.5vh 0.5vh;
  background: linear-gradient(#fdf3e6, #fce8d0);
}

.palette-grid {
  display: grid;
  grid-auto-flow: column;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: repeat(var(--rows), var(--cell-h));
  gap: 0.55vh 0.4vw;
  margin: 0;
  padding: 0;
  list-style: none;
}

.cell {
  display: flex;
  align-items: center;
  min-width: 0;
  border: 0.15vh solid #4d4136;
  border-radius: 0.25vh;
  background: linear-gradient(90deg, #fdebd6, #fef6ec);
  cursor: pointer;
}

.cell-no {
  flex: none;
  min-width: 3.1vw;
  padding-left: 0.85vw;
  font: 700 3vh/1 var(--sans);
  color: #130704;
  white-space: nowrap;
}
.cell:hover .cell-no { color: #1f3fff; }

.cell-opts { display: flex; gap: 0.25vh; padding-bottom: 0.2vh; }

.opt {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15vh;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
}

.opt-no { font: 1.55vh/1 var(--sans); color: #3434c8; }

.opt-box {
  position: relative;
  width: 1.75vh;
  height: 1.75vh;
  border: 1px solid #7b7772;
  border-radius: 0.35vh;
  background: #f2f3ef;
}

.opt.is-checked .opt-box::after {
  content: "✓";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font: 700 1.55vh/1 var(--sans);
  color: #1a1a1a;
}

.cell.is-answered { background: linear-gradient(90deg, #9fe09a, #b6ebb1); }

.cell.is-current { background: #fa8282; }
.cell.is-current .cell-no { color: #fff; }
.cell.is-current .opt-no { color: #d94c4c; }

/* Xem lại bài: xanh đúng, đỏ sai, vàng chưa trả lời; câu đang xem viền xanh dương */
.is-review .cell.is-correct { background: linear-gradient(90deg, #9fe09a, #b6ebb1); }
.is-review .cell.is-wrong { background: linear-gradient(90deg, #f47c7c, #f79a9a); }
.is-review .cell.is-unanswered { background: linear-gradient(90deg, #ffe27a, #ffeca6); }
.is-review .cell.is-current { outline: 0.4vh solid #1640ff; outline-offset: -0.05vh; }
.is-review .cell.is-current .cell-no { color: #130704; }
.is-review .cell.is-current .opt-no { color: #3434c8; }
/* Câu điểm liệt: số đỏ kèm dấu * (chỉ hiện khi xem lại, không lộ lúc đang thi) */
.is-review .cell .cell-no.is-critical { margin-right: 0.25vw; color: #e00000; }
.is-review .cell.is-wrong .cell-no.is-critical { color: #a00000; }
.cell-critical-mark { margin-left: 0.05em; font-size: 0.8em; vertical-align: top; }
.is-review .opt { cursor: default; }
.is-review .opt.is-right .opt-no { color: #087a08; font-weight: 700; }
.is-review .opt.is-right .opt-box { border: 2px solid #0a8a0a; background: #e4f8e1; }

.btn-finish {
  flex: none;
  height: 5.2vh;
  margin-top: 0.3vh;
  border: 1px solid #c8cac9;
  border-radius: 0.7vh;
  background: linear-gradient(#ffffff, #f3f5f5);
  box-shadow: inset 0 0 0 2px #fff;
  font: 700 2.75vh/1 var(--serif);
  color: #c92520;
  cursor: pointer;
}
.btn-finish:hover { background: linear-gradient(#fff, #ffe9e6); }

/* ---------- Thanh trạng thái ---------- */
.exam-status {
  grid-area: status;
  display: flex;
  align-items: center;
  margin: 0 -0.4vw;
  padding: 0 0.6vw;
  border-top: 1px solid #c5d3e8;
  background: #e3ecfb;
  font: max(11px, 1.3vh) var(--ui);
  color: #7a1020;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.exam-status.is-warning { color: #8a4b00; background: #fff4cc; border-top-color: #e6cf7a; }
.exam-status.is-error { color: #fff; background: #c62828; }

/* ---------- Màn hình dọc / điện thoại ---------- */
@media (max-width: 900px), (max-aspect-ratio: 1/1) {
  .page-exam { overflow: auto; }

  /* Xếp dọc: đồng hồ, câu hỏi, bảng câu, nút kết thúc, thanh trạng thái */
  .exam {
    --cell-h: 46px;
    height: auto;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 6px;
  }

  .exam-side { display: contents; }
  .timer-box { order: 1; position: sticky; top: 0; z-index: 2; height: 48px; padding: 0 12px; }
  .timer-label { font-size: 14px; }
  .timer { font-size: 30px; }

  .exam-main { order: 2; padding-bottom: 0; }
  .palette { order: 3; }
  .btn-finish { order: 4; }
  .exam-status { order: 5; }
  .question-frame { flex: none; aspect-ratio: 16 / 9.5; border-width: 4px; }

  .exam-progress { height: 24px; }
  .exam-progress-text { font-size: 14px; }

  .exam-bottom { height: auto; }
  .candidate-box { width: 100%; }
  .candidate-box legend { font-size: 12px; }
  .candidate-box p { margin-bottom: 8px; font-size: 15px; }
  .candidate-sbd { min-width: 90px; }
  .promo-box { display: none; }

  .palette { overflow: visible; padding: 8px; }
  .palette-grid { grid-auto-flow: row; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); grid-template-rows: none; grid-auto-rows: var(--cell-h); gap: 6px; }
  .cell { border-width: 2px; border-radius: 3px; }
  .cell-no { min-width: 44px; padding-left: 10px; font-size: 24px; }
  .cell-opts { gap: 6px; }
  .opt-no { font-size: 13px; }
  .opt-box { width: 22px; height: 22px; border-radius: 4px; }
  .opt.is-checked .opt-box::after { font-size: 16px; }
  .is-review .cell.is-current { outline-width: 3px; }

  .btn-finish { height: 50px; font-size: 22px; border-radius: 6px; }
  .exam-status { margin: 0 -6px -6px; padding: 6px 10px; font-size: 12px; white-space: normal; }
}
