/* ============================================================
   計時測驗（中打測驗 / 英打測驗）— SPEC v3.0 第 2-3 節
   只用 css/style.css :root 既有 tokens，不新增色票。
   打字區沿用 .play-target / .play-bar / .zh-input 既有語彙。
   ============================================================ */

.test-card {
  max-width: var(--content-max);
}

.test-topline {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}

.test-exit {
  justify-self: start;
}

.test-heading {
  min-width: 0;
  text-align: center;
}

.test-heading h2 {
  margin: 0;
}

.test-unit-note {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.test-clock {
  display: flex;
  align-items: baseline;
  justify-self: end;
  gap: 4px;
  padding: 4px 12px;
  border: 1.5px solid var(--line-strong);
  border-radius: 999px;
  background: var(--panel2);
}

.test-timer {
  min-width: 2.2ch;
  color: var(--primary-deep);
  font-family: var(--font-mono);
  font-size: 26px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.test-timer.urgent {
  color: var(--err-deep);
}

.test-clock small {
  color: var(--muted);
  font-size: 12px;
}

/* --- 開始前的時長選擇 ------------------------------------------------- */
.test-setup {
  margin-bottom: 14px;
  padding: 12px 14px;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-card);
  background: var(--panel2);
}

.test-setup-label {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .08em;
}

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

.duration-btn {
  font-size: 14px;
  white-space: nowrap;
}

.duration-btn.ranked::before {
  content: "🏆 ";
}

.test-rank-note {
  margin: 10px 0 0;
}

.test-bar {
  margin-bottom: 14px;
}

/* --- 打字區（沿用 .play-target，去掉寵物留白）-------------------------- */
.test-target {
  min-height: 200px;
  padding: 22px 22px 22px 22px;
}

/* 中打測驗的輸入區（2026-09-04）：
   它的角色是「注音的組字視窗」，不是閱讀區 —— 學生要讀的是上面的焦點槽。
   原本是整條 100% 寬的 textarea，字一路往右長、游標一路右移，
   超過一行還會換行後垂直捲動，整場的視覺重心都在飄（使用者實地回報）。

   **游標要停在框的正中間，手感才對**（使用者 2026-09-04 裁示）。
   做法：看得到的框是外層的 .test-zh-field，textarea 本身只佔它的左半邊、靠右對齊，
   所以 textarea 的右緣（＝游標）就落在框的正中間，右半邊永遠留白。
   舊字往左滑出去，游標一格都不動。

   為什麼不能只靠 padding-right 把游標推到中間：Chrome 對水平捲動的文字控制項
   **會把右內距吃掉**——實測字一旦超過框寬，游標就跳回右緣（padding-right 18px
   與 230px 的結果完全一樣）。所以一定要靠「元素本身只有一半寬」來達成。

   已打的字必須留著看得到：中打的 correctCount() 仍是逐位置比對（沒有英打那套
   重新對齊），退格是學生修正錯位的唯一手段，不能改成「上屏後就清掉」。 */
.test-zh-field {
  --zh-caret-split: 50%;         /* textarea 佔框的比例 → 游標落點 */
  display: flex;
  width: min(460px, 100%);
  margin: 16px auto 0;
  border: 2px solid var(--line-strong);
  border-radius: var(--radius-button);
  background: var(--panel);
  transition: border-color .12s, box-shadow .12s;
}

/* 焦點環畫在外框上（textarea 自己的框線已經拿掉）。
   組字中一定是 focus 狀態，所以 :focus-within 一條就夠，不必另外掛 .is-composing。 */
.test-zh-field:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
  outline: 0;
}

/* 蓋掉 .zh-input 的框線／底色／焦點環 —— 那些現在由 .test-zh-field 負責。
   :focus 與 .is-composing 都要一起蓋，否則 .zh-input:focus 的權重會贏過來。 */
.test-zh-input,
.test-zh-input:focus,
.test-zh-input.is-composing {
  width: var(--zh-caret-split);
  min-height: 46px;
  margin: 0;
  padding: 11px 0 11px 14px;
  border: 0;
  background: transparent;
  box-shadow: none;
  outline: 0;
  text-align: right;             /* 最後一個字永遠貼在 textarea 的右緣＝框的中線 */
  white-space: pre;              /* 不換行 —— 絕不變成兩行後垂直捲動 */
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;         /* Firefox */
}

.test-zh-input::-webkit-scrollbar {
  display: none;                 /* Chrome / Safari / Edge */
}

/* ============================================================
   焦點槽 ＋ 進料帶 ＋ 飛出離場（SPEC v3.4「完成即離場」）
   ------------------------------------------------------------
   結構由 js/test.js 的 buildConveyor() 建立，整場測驗只有這一組節點：
     .test-conveyor > .test-belt > .test-slot ×4
       .test-slot > .test-slot-label + .test-slot-content > .test-unit-char ×16
   角色：current（焦點槽，最大最清楚）／next／after／after2（進料帶，遞減）
   槽型：.test-pill-slot —— 自足宣告 width:auto，**不是**覆寫任何固定寬度的 class。
   任何一層都不得 overflow:hidden 或 text-overflow:ellipsis（多字元單位絕不裁切）。
   測驗不用注音專用的田字格十字線。
   ============================================================ */
.play-target.test-conveyor {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 200px;
  padding: 24px 20px;
  letter-spacing: normal;
  word-break: normal;
}

.test-belt {
  position: relative;          /* 飛出殘影的定位基準 */
  display: flex;
  flex-wrap: wrap;             /* 放不下就換行 —— 絕不裁切、也不橫向捲動 */
  align-items: flex-end;
  align-content: center;
  justify-content: center;
  gap: 14px 18px;
  width: 100%;
  overflow: visible;           /* 絕不裁切，也不能裁掉飛出殘影 */
}

.test-slot {
  display: flex;
  flex: 0 0 auto;              /* 不得被壓縮 */
  flex-direction: column;
  align-items: center;
  gap: 7px;
  min-width: 0;
  overflow: visible;
}

/* 字流打完後多出來的空槽：保留版位，不顯示空框 */
.test-slot.is-vacant {
  visibility: hidden;
}

.test-slot-label {
  color: var(--muted);
  font-family: var(--font-ui);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: .06em;
  white-space: nowrap;
}

.test-slot-content {
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-weight: 700;
  line-height: 1;
  white-space: nowrap;         /* 單位內不換行 */
  overflow: visible;           /* 絕不裁切 */
  text-overflow: clip;         /* 明確禁止 ellipsis */
}

/* 槽型：寬度自適應的膠囊（英打單字、中打詞語都用這一種） */
.test-pill-slot .test-slot-content {
  width: auto;
  padding: .2em .46em;
  border: 2px solid var(--line-strong);
  border-radius: 999px;
  background: var(--panel);
}

/* --- 四個角色的視覺層級 ----------------------------------------------- */
.test-slot-current .test-slot-content {
  font-size: 46px;
  border-color: var(--amber-ink);
  background: var(--white);
  box-shadow: 0 4px 0 var(--amber);
}

.test-slot-current .test-slot-label {
  color: var(--amber-ink);
  font-weight: 700;
}

.test-slot-next .test-slot-content {
  font-size: 28px;
  opacity: .82;
}

.test-slot-after .test-slot-content {
  font-size: 23px;
  opacity: .55;
  border-color: var(--line);
}

.test-slot-after2 .test-slot-content {
  font-size: 20px;
  opacity: .36;
  border-color: var(--line);
}

/* 中文字比拉丁字母寬，字級略降 */
.test-zh-conveyor .test-slot-current .test-slot-content { font-size: 42px; }
.test-zh-conveyor .test-slot-next    .test-slot-content { font-size: 26px; }

/* --- 單位內的字元狀態（沿用既有打字區配色語彙）------------------------ */
.test-unit-char {
  display: inline-block;
  border-radius: 4px;
  color: var(--ink);
}

.test-unit-char.is-empty { display: none; }
.test-unit-char.is-pending { color: var(--ink); }
.test-unit-char.is-done { color: var(--ok); }

.test-unit-char.is-bad {
  color: var(--err);
  text-decoration: underline;
  text-decoration-thickness: 2px;
}

.test-unit-char.is-current {
  min-width: .6em;
  background: var(--amber);
  box-shadow: inset 0 0 0 2px var(--amber-ink);
  color: var(--ink);
  text-align: center;
}

/* --- 飛出離場（純裝飾，不在文件流內、不站在輸入路徑上）---------------- */
.test-flyout {
  position: absolute;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--ok);
  border-radius: 999px;
  background: var(--panel);
  color: var(--ok);
  font-family: var(--font-mono);
  font-size: 38px;
  font-weight: 700;
  line-height: 1;
  white-space: nowrap;
  pointer-events: none;
  animation: test-flyout-away 420ms ease-out forwards;
}

.test-flyout.is-bad {
  border-color: var(--err);
  color: var(--err);
}

@keyframes test-flyout-away {
  0%   { transform: translate3d(0, 0, 0) scale(1); opacity: .9; }
  100% { transform: translate3d(-52px, -62px, 0) scale(.6); opacity: 0; }
}

/* reduce 時 js/test.js 根本不會建立這個元素；這條只是保險 */
@media (prefers-reduced-motion: reduce) {
  .test-flyout {
    display: none;
    animation: none;
  }
}

/* --- 即時回饋列（速度／正確率／已輸入／連擊）-------------------------- */
.play-progress.test-live {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: center;
  gap: 6px 20px;
}

.test-live-cell {
  display: inline-flex;
  align-items: baseline;
  gap: 4px;
}

.test-live-value {
  color: var(--primary-deep);
  font-family: var(--font-mono);
  font-size: 20px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.test-live-label {
  color: var(--muted);
  font-size: 12px;
}

/* --- 結算 -------------------------------------------------------------- */
.test-result-card {
  max-width: 560px;
}

.test-result-grid {
  margin-bottom: 4px;
}

.test-detail {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 14px 0 0;
  padding: 12px 14px;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-card);
  background: var(--panel2);
}

.test-detail > div {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.test-detail dt {
  color: var(--muted);
  font-size: 13px;
}

.test-detail dd {
  margin: 0;
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 15px;
  font-weight: 700;
}

.test-result-card .test-unit-note {
  margin-top: 10px;
  text-align: center;
}

.tres-rank {
  margin-top: 12px;
}

.tres-rank-line {
  margin: 0;
  padding: 10px 12px;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-button);
  background: var(--panel2);
  color: var(--ink);
  font-size: 14px;
  font-weight: 500;
  text-align: center;
}

.tres-rank-line.good-line {
  border-color: var(--ok);
  background: var(--ok-soft);
}

.tres-rank-line.muted-line {
  color: var(--muted);
}

.tres-combo {
  margin: 8px 0 0;
  color: var(--amber-ink);
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 700;
  text-align: center;
}

.tres-combo:empty {
  display: none;
}

/* 低重玩摩擦：「再測一次」整列獨佔、字最大（js/test.js 掛上 .tres-again-hero） */
.test-result-actions {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.test-result-actions .tres-again-hero {
  grid-column: 1 / -1;
  padding: 16px 18px;
  font-size: 18px;
}

/* --- 首頁「挑戰與訓練」入口卡 ----------------------------------------- */
.challenge-panel {
  margin-bottom: 16px;
}

.board-entry {
  white-space: nowrap;
}

.challenge-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 16px;
}

.challenge-btn {
  display: grid;
  gap: 2px;
  padding: 16px 14px;
  border: 1.5px solid var(--line-strong);
  border-radius: var(--radius-card);
  background: var(--panel);
  box-shadow: 0 4px 0 var(--line-strong);
  color: var(--primary-deep);
  text-align: left;
  transition: transform .06s, box-shadow .06s;
}

.challenge-btn:hover {
  border-color: var(--primary);
}

.challenge-btn:active:not(:disabled) {
  transform: translateY(2px);
  box-shadow: 0 2px 0 var(--line-strong);
}

.challenge-icon {
  font-size: 22px;
  line-height: 1.1;
}

.challenge-title {
  color: var(--primary-deep);
  font-size: 17px;
  font-weight: 700;
}

.challenge-sub {
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
}

.challenge-best {
  margin-top: 6px;
  color: var(--amber-ink);
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 700;
}

/* --- topbar 線上人數 --------------------------------------------------- */
.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.online-badge {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary-deep);
  font-variant-numeric: tabular-nums;
}

/* --- 中尺寸：561–900px -------------------------------------------------- */
@media (min-width: 561px) and (max-width: 900px) {
  .challenge-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

/* --- 小尺寸：≤560px ---------------------------------------------------- */
@media (max-width: 560px) {
  /* 小螢幕本來就窄：框吃滿寬，游標落點往右挪到 65%，
     否則可視字數會少到看不出自己打了什麼 */
  .test-zh-field {
    --zh-caret-split: 65%;
    width: 100%;
  }

  .test-zh-input,
  .test-zh-input:focus,
  .test-zh-input.is-composing {
    padding: 10px 0 10px 12px;
  }

  .test-topline {
    grid-template-columns: auto minmax(0, 1fr);
    row-gap: 8px;
  }

  .test-heading {
    text-align: left;
  }

  .test-clock {
    grid-column: 1 / -1;
    justify-self: stretch;
    justify-content: center;
  }

  .test-target {
    min-height: 170px;
    padding: 16px;
    font-size: 19px;
  }

  .play-target.test-conveyor {
    min-height: 170px;
    padding: 16px 10px;
  }

  .test-belt {
    gap: 10px;
  }

  /* 手機上焦點槽自己佔一整列，進料帶排在下一列 —— 版位固定，不會隨字長跳動 */
  .test-belt .test-slot-current {
    flex-basis: 100%;
  }

  .test-slot-current .test-slot-content { font-size: 32px; }
  .test-slot-next    .test-slot-content { font-size: 21px; }
  .test-slot-after   .test-slot-content { font-size: 18px; }
  .test-slot-after2  .test-slot-content { font-size: 16px; }
  .test-zh-conveyor .test-slot-current .test-slot-content { font-size: 30px; }
  .test-zh-conveyor .test-slot-next    .test-slot-content { font-size: 20px; }

  /* 英文單字比中文詞語寬得多；手機上帶子放不下四格就少顯示一格預備位
     （SPEC v3.4 允許進料帶 2–3 個）。寧可少一格，也絕不裁字。 */
  .test-en-conveyor .test-slot-after2 {
    display: none;
  }

  .test-flyout {
    font-size: 26px;
  }

  .play-progress.test-live {
    gap: 4px 14px;
  }

  .test-live-value {
    font-size: 17px;
  }

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

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

  .challenge-grid {
    grid-template-columns: 1fr;
  }

  .challenge-btn {
    grid-template-columns: 34px minmax(0, 1fr);
    align-items: center;
    column-gap: 12px;
    padding: 12px 14px;
  }

  .challenge-icon {
    grid-row: 1 / 4;
  }

  .topbar-right {
    gap: 5px;
  }

  .online-badge {
    max-width: 30vw;
    padding-inline: 6px;
    white-space: nowrap;
  }
}
