/* aikc-typing-r1.css —— 打字训练营 50 关（r17-3 / r17-5 UI 重做）
 *
 * 设计策略：本脚本刻意复用原生 class 名（.typing-level-grid / .typing-target /
 * .typing-workbench / .typing-dashboard / .typing-current-level / .typing-set-tabs），
 * 因此绝大部分样式直接继承站点既有 CSS。这里只补：
 *   ① 新增元素（页签内 strong/small、状态条、操作按钮、空态）
 *   ② r17-5 工作台 UI：字符舞台 + 逐字符高亮 + 隐藏输入框 + 进度条 + 失焦遮罩
 *   ③ 无障碍与减弱动效
 */

/* ---------- ① 套件页签：原生是 .typing-set-tabs，这里补标题与进度 ---------- */
.aikc-typing-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
  margin-bottom: 17px;
}

.aikc-typing-tabs button {
  min-height: 41px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: 1px;
  padding: 6px 15px;
  border: 2px solid var(--ink, #26332e);
  border-radius: 9px;
  background: #fff;
  cursor: pointer;
  line-height: 1.25;
}

.aikc-typing-tabs button strong {
  font-size: 13px;
  font-weight: 900;
  color: var(--ink, #26332e);
}

.aikc-typing-tabs button small {
  font-size: 11px;
  color: #7a8780;
}

.aikc-typing-tabs button.active {
  background: var(--orange, #f6ad2f);
  box-shadow: 3px 3px 0 var(--ink, #26332e);
}

.aikc-typing-tabs button.active small {
  color: #5c4a1e;
}

/* ---------- ② 关卡网格：50 关用同一网格，窄屏自动降列 ---------- */
.aikc-typing-grid {
  grid-template-columns: repeat(5, minmax(0, 1fr));
}

/* ---------- ③ 仪表盘状态条 ---------- */
.aikc-typing-dash {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.aikc-typing-flag {
  grid-column: 1 / -1;
  margin: 0;
  padding: 10px 15px;
  border-radius: 10px;
  font-size: 13px;
  font-style: normal;
  font-weight: 600;
  text-align: center;
}

.aikc-typing-flag-idle {
  display: none;
}

.aikc-typing-flag.ok {
  background: #d8f5e3;
  border: 1.5px solid #7ed3a4;
  color: #14713f;
}

.aikc-typing-flag.todo {
  background: #ffe9cf;
  border: 1.5px solid #f0b071;
  color: #a8531a;
}

.aikc-typing-flag-err {
  background: #ffe1e1;
  border: 1.5px solid #f09a9a;
  color: #a32626;
}

/* ---------- ④ 工作台（r17-5 UI）：卡片容器 ---------- */
.aikc-typing-workbench {
  margin-bottom: 20px;
  border: 2.5px solid var(--ink, #26332e);
  border-radius: 14px;
  background: #fff;
  box-shadow: 5px 6px 0 rgba(38, 51, 46, 0.14);
  overflow: hidden;
}

/* 顶部进度条 */
.aikc-typing-wb-head {
  padding: 14px 18px 0;
}

.aikc-typing-bar {
  height: 9px;
  border-radius: 999px;
  background: #edf1ee;
  border: 1.5px solid #d9e0db;
  overflow: hidden;
}

.aikc-typing-bar-fill {
  display: block;
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, #ffd166, var(--orange, #f6ad2f));
  transition: width 0.18s ease;
}

/* 打字舞台 */
.aikc-typing-stage {
  position: relative;
  padding: 26px 26px 22px;
  cursor: text;
}

/* 逐字符目标区：超长内容内部滚动 */
.aikc-typing-target {
  position: relative;
  max-height: 230px;
  overflow-y: auto;
  font: 600 22px/2.1 Consolas, "Microsoft YaHei", monospace;
  word-break: break-all;
  outline: none;
  scrollbar-width: thin;
}

/* 每个字符的基础态：浅灰待输入 */
.aikc-typing-target .ch {
  color: #b7c1ba;
  border-radius: 3px;
  padding: 0 1px;
  transition: color 0.1s ease, background 0.1s ease;
}

/* 已输入正确：绿色 */
.aikc-typing-target .typed-correct {
  color: #1e9e57;
}

/* 已输入错误：红底白字 */
.aikc-typing-target .typed-wrong {
  color: #fff;
  background: #e35d5d;
}

/* 待输入的空格：虚线下划线，方便识别 */
.aikc-typing-target .ch-space:not(.typed-correct):not(.typed-wrong) {
  border-bottom: 2px dotted #cfd8d2;
}

/* 当前光标字符：橙色闪烁竖条 */
.aikc-typing-target .typing-current {
  position: relative;
}

.aikc-typing-target .typing-current::after {
  content: "";
  position: absolute;
  left: -2px;
  top: 8%;
  bottom: 6%;
  width: 3px;
  border-radius: 2px;
  background: var(--orange, #f6ad2f);
  animation: aikc-blink 1s steps(1, end) infinite;
}

@keyframes aikc-blink {
  50% { opacity: 0; }
}

/* 失焦 / 完成遮罩 */
.aikc-typing-focus-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.88);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease;
  z-index: 3;
}

.aikc-typing-stage.is-blurred .aikc-typing-focus-overlay,
.aikc-typing-stage.is-done .aikc-typing-focus-overlay {
  opacity: 1;
}

/* 遮罩两张卡按状态切换 */
.aikc-typing-focus-card {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  text-align: center;
  padding: 0 20px;
}

.aikc-typing-stage.is-blurred:not(.is-done) .aikc-typing-focus-card-start {
  display: flex;
}

.aikc-typing-stage.is-done .aikc-typing-focus-card-done {
  display: flex;
}

.aikc-typing-focus-card strong {
  font-size: 17px;
  color: var(--ink, #26332e);
}

.aikc-typing-focus-card small {
  font-size: 12.5px;
  color: #6f7b76;
}

/* 隐藏输入框：只负责捕获按键（含输入法），不参与视觉 */
.aikc-typing-input {
  position: absolute;
  right: 10px;
  bottom: 8px;
  width: 2px;
  height: 2px;
  min-height: 0;
  padding: 0;
  border: 0;
  opacity: 0;
  resize: none;
  overflow: hidden;
  pointer-events: none;
}

/* 底栏 */
.aikc-typing-workbench footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  padding: 11px 18px;
  border-top: 1px solid #e1e5e2;
  background: #f7faf7;
  font-size: 13px;
  color: #4a5a54;
}

.aikc-typing-actions {
  display: flex;
  gap: 9px;
}

.aikc-typing-ghost,
.aikc-typing-primary {
  min-height: 36px;
  padding: 0 16px;
  border: 2px solid var(--ink, #26332e);
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 800;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.aikc-typing-ghost {
  background: #fff;
  color: var(--ink, #26332e);
}

.aikc-typing-primary {
  background: var(--orange, #f6ad2f);
  color: var(--ink, #26332e);
  box-shadow: 2px 3px 0 var(--ink, #26332e);
}

.aikc-typing-ghost:hover,
.aikc-typing-primary:hover {
  transform: translate(-1px, -1px);
}

.aikc-typing-primary:hover {
  box-shadow: 3px 4px 0 var(--ink, #26332e);
}

.aikc-typing-ghost:active,
.aikc-typing-primary:active {
  transform: translate(1px, 1px);
  box-shadow: none;
}

/* ---------- ⑤ 空态 ---------- */
.aikc-typing-empty-hint {
  display: block;
  padding: 16px;
  color: #6f7b76;
  font-size: 13px;
  line-height: 1.7;
}

/* ---------- ⑥ 原生页被接管后彻底隐藏 ---------- */
main.typing-page[hidden] {
  display: none !important;
}

/* ---------- ⑦ 移动端 ---------- */
@media (max-width: 900px) {
  .aikc-typing-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 640px) {
  .aikc-typing-tabs button {
    flex: 1 1 46%;
  }

  .aikc-typing-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .aikc-typing-dash {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .aikc-typing-stage {
    padding: 18px 14px 16px;
  }

  .aikc-typing-target {
    font-size: 17px;
    line-height: 2;
    max-height: 180px;
  }

  .aikc-typing-actions {
    width: 100%;
  }

  .aikc-typing-ghost,
  .aikc-typing-primary {
    flex: 1;
  }
}

/* ---------- ⑧ 无障碍：减弱动效 ---------- */
@media (prefers-reduced-motion: reduce) {
  .aikc-typing-ghost,
  .aikc-typing-primary,
  .aikc-typing-bar-fill,
  .aikc-typing-focus-overlay {
    transition: none;
  }

  .aikc-typing-target .typing-current::after {
    animation: none;
  }
}
