/* 中打只顯示當前詞；寬度與字級各由一個變數調整。 */
.test-zh-input {
  --zh-input-width: 320px;
  --zh-input-font-size: 36px;
  width: min(var(--zh-input-width), 100%);
  margin: 16px auto 0;
  font-size: var(--zh-input-font-size);
  text-align: center;
}

/* ============================================================
   計時測驗（中打測驗 / 英打測驗）— 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;
}

/* ============================================================
   焦點槽 ＋ 進料帶 ＋ 飛出離場（SPEC v3.4「完成即離場」）
   ------------------------------------------------------------
   結構由 js/test.js 的 buildConveyor() 建立，整場測驗只有這一組節點：
     .test-conveyor > .test-belt > .test-belt-past + 焦點槽 + .test-belt-ahead
     左右各 3 槽；已完成槽只含文字，焦點與進料槽保留字元節點
       .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;          /* 飛出殘影的定位基準 */
  --test-past-opacity: .42;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: end;
  gap: 14px 18px;
  width: 100%;
  overflow: visible;           /* 絕不裁切，也不能裁掉飛出殘影 */
}

.test-belt-past,
.test-belt-ahead {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 14px 18px;
  min-width: 0;
}

.test-belt-past { justify-content: flex-end; }
.test-belt-ahead { justify-content: flex-start; }

.test-slot-past { opacity: var(--test-past-opacity); }
.test-slot-past .test-slot-content {
  font-size: 20px;
  color: var(--ok);
  border-color: var(--line);
}
.test-slot-past.is-bad .test-slot-content { color: var(--err); }

.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) {
  .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,
  .test-belt-past,
  .test-belt-ahead {
    gap: 10px;
  }

  .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; }

  .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;
  }
}
