/* Typing practice, scoped to .typing-root so it shares the shell without
   leaking styles into other views. Palette follows the portal tokens. */

.typing-root {
  --typing-surface: #fcfefd;
  --typing-ink: #203b32;
  --typing-muted: #566e63;
  --typing-pending: #93a49a;
  --typing-line: #cbd9d0;
  --typing-accent: #21684b;
  --typing-tint: #dcece3;
  --typing-error: #a43243;
  --typing-error-bg: #fbe4e7;

  --typing-kb-bg: #1e293b;
  --typing-kb-text: #f1f5f9;
  --typing-kb-next: #6ec39a;
  --typing-kb-bad: #e5737d;
  --typing-heat: #6ec39a;

  padding: 24px max(20px, calc((100% - 1060px) / 2)) 48px;
  color: var(--typing-ink);
}

.typing-root button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  cursor: pointer;
}

.typing-root .topbar {
  padding-bottom: 8px;
}

/* ---------- 练习区 ---------- */
.practice-head {
  display: flex;
  align-items: center;
  gap: 18px;
  margin-top: 8px;
}

.duration {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 13px;
  color: var(--typing-muted);
}

.seg {
  display: flex;
  gap: 2px;
  padding: 3px;
  background: var(--typing-tint);
  border-radius: 10px;
}

.seg button {
  padding: 5px 11px;
  border-radius: 7px;
  font-size: 12.5px;
  color: var(--typing-muted);
  transition: background 0.15s, color 0.15s;
}

.seg button[aria-pressed="true"] {
  background: var(--typing-surface);
  color: var(--typing-accent);
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(16, 40, 29, 0.12);
}

.status {
  margin-left: auto;
  padding: 4px 11px;
  border-radius: 999px;
  font-size: 12px;
  color: var(--typing-muted);
  background: var(--typing-tint);
}

.status.running,
.status.done {
  color: #ffffff;
  background: var(--typing-accent);
}

.status.paused {
  color: var(--typing-error);
  background: var(--typing-error-bg);
}

.typing-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 9px;
  color: var(--typing-muted);
  transition: background 0.15s, color 0.15s, transform 0.3s;
}

.typing-icon-btn:hover {
  color: var(--typing-accent);
  background: var(--typing-tint);
}

.typing-icon-btn:active {
  transform: rotate(-90deg);
}

.typing-icon-btn svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ---------- 指标 ---------- */
.workspace {
  padding-top: 22px;
}

.metrics {
  display: flex;
  align-items: baseline;
  gap: 34px;
  margin-bottom: 8px;
}

.metrics > div {
  display: flex;
  flex-direction: column;
}

.metrics b {
  font-size: clamp(23px, 2.5vw, 38px);
  font-weight: 600;
  line-height: 1.15;
  color: var(--typing-accent);
  font-variant-numeric: tabular-nums;
}

.metrics b small {
  font-size: 0.5em;
  font-weight: 500;
  margin-left: 2px;
}

.metrics span {
  font-size: 12px;
  color: var(--typing-muted);
  margin-top: 2px;
}

.metrics > .motto {
  margin-left: auto;
  font-size: 13px;
  font-style: italic;
  color: var(--typing-muted);
  transition: color 0.15s;
}

.metrics > .motto:hover {
  color: var(--typing-accent);
}

/* ---------- 单行滚动文稿 ---------- */
.typing-surface {
  position: relative;
  margin-top: clamp(14px, 1.6vw, 24px);
  /* 字号驱动高度：2.7em 正好是文稿一行的行高，随窗口一起缩放 */
  font-size: clamp(25px, 2.6vw, 42px);
  height: 2.7em;
  cursor: text;
}

.passage {
  height: 100%;
  overflow: hidden;
  -webkit-mask-image: linear-gradient(90deg, transparent 0, #000 14px, #000 86%, transparent 99%);
  mask-image: linear-gradient(90deg, transparent 0, #000 14px, #000 86%, transparent 99%);
}

.passage-track {
  display: inline-block;
  width: max-content;
  padding-left: 50%;
  padding-right: 60%;
  font-family: "Cascadia Code", "JetBrains Mono", Consolas, monospace;
  font-size: 1em;
  line-height: 2.7;
  white-space: pre;
  color: var(--typing-pending);
  will-change: transform;
}

.passage-track span {
  transition: color 0.08s, background-color 0.12s;
}

.passage-track .ok {
  color: var(--typing-ink);
}

.passage-track .bad {
  color: var(--typing-error);
  background: var(--typing-error-bg);
  border-radius: 4px;
}

.passage-track .caret {
  position: relative;
  color: var(--typing-accent);
}

.passage-track .caret::before {
  content: "";
  position: absolute;
  left: -1px;
  top: 14%;
  width: 2px;
  height: 72%;
  background: var(--typing-accent);
  border-radius: 2px;
  animation: typing-caret-blink 1.1s steps(2, jump-none) infinite;
}

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

.typing-input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  padding: 0;
  border: 0;
  resize: none;
  opacity: 0;
  cursor: text;
  font-size: 1em;
}

/* 屏幕键盘开关与指法提示同一行 */
.keyboard-bar {
  position: relative;
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 22px;
}

.keyboard-bar .typing-icon-btn[aria-pressed="true"] {
  color: var(--typing-accent);
}

.keyboard-bar .typing-icon-btn[data-open] {
  margin-left: auto;
}

.finger-tip {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  display: inline-flex;
  align-items: center;
  margin: 0;
  font-size: 12.5px;
  color: var(--typing-muted);
  white-space: nowrap;
}

.finger-tip b {
  font-weight: 600;
  color: var(--typing-accent);
}

.finger-tip .tip-key {
  display: inline-block;
  min-width: 1.5em;
  margin-left: 9px;
  padding: 1px 8px;
  font-family: "Cascadia Code", Consolas, monospace;
  font-size: 0.95em;
  text-align: center;
  color: var(--typing-ink);
  background: var(--typing-tint);
  border-radius: 5px;
}

.finger-tip .tip-extra {
  margin-left: 7px;
  opacity: 0.75;
}

.tip-idle {
  opacity: 0.6;
}

/* ---------- 进度 ---------- */
.progress-row {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-top: 16px;
}

.bar {
  flex: 1;
  height: 5px;
  background: var(--typing-tint);
  border-radius: 6px;
  overflow: hidden;
}

.bar i {
  display: block;
  height: 100%;
  width: 0;
  background: var(--typing-accent);
  border-radius: 6px;
  transition: width 0.14s linear;
}

.progress-row span {
  font-size: 12px;
  color: var(--typing-muted);
  font-variant-numeric: tabular-nums;
  min-width: 96px;
  text-align: right;
}

/* ---------- 提示条 ---------- */
.notice {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin-top: 14px;
  padding: 11px 16px;
  font-size: 13.5px;
  border-radius: 11px;
  background: var(--typing-tint);
  color: var(--typing-ink);
}

.notice[hidden] {
  display: none;
}

.notice button {
  padding: 6px 15px;
  border-radius: 8px;
  font-size: 12.5px;
  font-weight: 600;
  color: #ffffff;
  background: var(--typing-accent);
}

.notice button:hover {
  filter: brightness(1.08);
}

/* ---------- 屏幕键盘 ---------- */
.kb-panel {
  margin-top: 12px;
  padding: clamp(11px, 1.2vw, 18px) clamp(12px, 1.3vw, 18px) clamp(8px, 0.9vw, 12px);
  background: var(--typing-kb-bg);
  border: 1px solid rgba(241, 245, 249, 0.08);
  border-radius: clamp(10px, 1.1vw, 16px);
  transition: box-shadow 0.3s;
}

.kb-panel[data-tier="1"] {
  box-shadow: inset 0 0 0 1px rgba(110, 195, 154, 0.18);
}

.kb-panel[data-tier="2"] {
  box-shadow: inset 0 0 0 1px rgba(110, 195, 154, 0.34);
}

.kb-panel[data-tier="3"] {
  box-shadow: inset 0 0 0 1px rgba(110, 195, 154, 0.55), 0 0 26px -6px rgba(110, 195, 154, 0.35);
}

.kb-panel.is-hidden {
  display: none;
}

.kb-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.tier {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.tier b {
  font-size: 13px;
  font-weight: 600;
  color: var(--typing-kb-text);
}


.heat {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  color: rgba(241, 245, 249, 0.55);
  font-variant-numeric: tabular-nums;
}

.heat em {
  font-style: normal;
  margin-right: 6px;
}

.heat i {
  width: 5px;
  height: 13px;
  border-radius: 2px;
  background: rgba(241, 245, 249, 0.16);
  transition: background 0.16s;
}

.heat i.lit {
  background: var(--typing-heat);
}

.kb-stage {
  position: relative;
  padding-bottom: 2px;
}

.keyboard {
  display: flex;
  flex-direction: column;
  gap: clamp(3px, 0.3vw, 5px);
}

.kb-row {
  display: flex;
  gap: clamp(3px, 0.3vw, 5px);
}

.key {
  position: relative;
  flex: 1 1 0;
  min-width: 0;
  height: clamp(30px, 3.2vw, 52px);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: "Segoe UI", "Microsoft YaHei", sans-serif;
  font-size: clamp(11px, 0.95vw, 14px);
  font-weight: 500;
  color: var(--typing-kb-text);
  background: var(--fg, #445566);
  border-radius: 7px;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.14);
  text-shadow: 0 1px 1px rgba(15, 23, 42, 0.35);
  transition: background 0.1s, color 0.1s, box-shadow 0.15s, transform 0.06s;
  user-select: none;
  overflow: hidden;
}

.key[data-w="1.5"] {
  flex: 1.5 1 0;
}

.key[data-w="1.75"] {
  flex: 1.75 1 0;
}

.key[data-w="2"] {
  flex: 2 1 0;
}

.key[data-w="2.25"] {
  flex: 2.25 1 0;
}

.key[data-w="2.75"] {
  flex: 2.75 1 0;
}

/* 空格键按真实比例居中，不铺满整行 */
.kb-row:last-child {
  justify-content: center;
}

.key[data-w="space"] {
  flex: 0 0 56%;
}

/* 手指分界：换手指的地方拉开一道缝，同手指的键贴在一起 */
.key.finger-gap {
  margin-left: clamp(12px, 1.15vw, 20px);
}

/* 功能键文字小一号、压暗，避免和字母键抢视线 */
.key-fn {
  font-size: clamp(9px, 0.76vw, 11px);
  letter-spacing: 0.02em;
}

/* F / J 盲打定位凸起 */
.key-home::before {
  content: "";
  position: absolute;
  left: 50%;
  bottom: 9px;
  width: clamp(8px, 0.8vw, 11px);
  height: 2px;
  margin-left: calc(clamp(8px, 0.8vw, 11px) / -2);
  border-radius: 2px;
  background: rgba(241, 245, 249, 0.5);
}

/* 下一个要按的键：整键压亮 + 白边 + 外发光，在彩色键帽里也能一眼跳出来 */
.key.next {
  color: #103026;
  font-weight: 700;
  background: var(--typing-kb-next);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.9), 0 0 18px -2px rgba(110, 195, 154, 0.5), 0 2px 6px rgba(0, 0, 0, 0.35);
  text-shadow: none;
  transform: translateY(-1px);
}

.key.held {
  transform: translateY(1px) scale(0.985);
}

.key.hit-ok {
  background: var(--typing-kb-next);
  color: #103026;
  text-shadow: none;
}

.key.hit-bad {
  background: var(--typing-kb-bad);
  color: #ffffff;
}

.key-fx {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* ---------- 说明 ---------- */
.notes {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px 24px;
  margin-top: 16px;
  font-size: 12px;
  color: var(--typing-muted);
}

.notes p {
  margin: 0;
  display: flex;
  align-items: center;
  gap: 7px;
}

.keycap {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 19px;
  height: 19px;
  padding: 0 4px;
  font-size: 11px;
  font-weight: 600;
  color: var(--typing-muted);
  background: var(--typing-tint);
  border-radius: 5px;
  box-shadow: inset 0 -1px 0 var(--typing-line);
}

/* ---------- 弹窗 ---------- */
.typing-dialog {
  width: min(760px, calc(100% - 32px));
  max-height: calc(100dvh - 48px);
  overflow-y: auto;
  padding: 22px 24px;
  border: 0;
  border-radius: 16px;
  background: var(--typing-surface);
  color: var(--typing-ink);
  box-shadow: 0 24px 60px -12px rgba(10, 30, 22, 0.45);
}

.typing-dialog::backdrop {
  background: rgba(14, 30, 24, 0.45);
}

.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}

.dialog-head h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}

.records-sort {
  margin: 0 8px 0 auto;
  padding: 4px 10px;
  border-radius: 8px;
  font-size: 12.5px;
  color: var(--typing-muted);
  background: var(--typing-tint);
  transition: color 0.15s;
}

.records-sort:hover {
  color: var(--typing-accent);
}

.passage-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 12px;
}

.passage-item {
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 12px 14px;
  border-radius: 12px;
  text-align: left;
  background: var(--typing-tint);
  transition: background 0.15s;
}

.passage-item:hover {
  background: var(--typing-line);
}

.passage-item.current {
  background: var(--typing-surface);
  box-shadow: inset 0 0 0 1px var(--typing-accent);
}

.passage-item b {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--typing-ink);
}

.passage-item.current b {
  color: var(--typing-accent);
}

.passage-item span {
  font-size: 12.5px;
  line-height: 1.65;
  color: var(--typing-muted);
}

.typing-dialog table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.typing-dialog th {
  padding: 8px 10px;
  font-size: 11.5px;
  font-weight: 500;
  text-align: left;
  color: var(--typing-muted);
  border-bottom: 1px solid var(--typing-line);
}

.typing-dialog td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--typing-line);
}

.typing-dialog tr:last-child td {
  border-bottom: 0;
}

.typing-dialog .rank-best {
  color: var(--typing-accent);
  font-weight: 700;
}

.typing-dialog .empty {
  padding: 34px 0 26px;
  text-align: center;
  font-size: 13px;
  color: var(--typing-muted);
}

.typing-dialog .empty button {
  margin-top: 14px;
  padding: 7px 16px;
  border-radius: 8px;
  font-size: 12.5px;
  color: #ffffff;
  background: var(--typing-accent);
}

/* ---------- 矮窗口：压缩纵向间距，去掉次要说明，保证一屏放得下 ---------- */
@media (max-height: 760px) {
  .typing-root {
    padding-top: 14px;
    padding-bottom: 16px;
  }

  .workspace {
    padding-top: 14px;
  }

  .typing-surface {
    margin-top: 10px;
  }

  .progress-row {
    margin-top: 12px;
  }

  .keyboard-bar {
    margin-top: 14px;
  }

  .notes {
    display: none;
  }
}

/* ---------- 窄屏：只调布局，尺寸交给 clamp 自动缩放 ---------- */
@media (max-width: 760px) {
  .typing-root {
    padding: 16px 14px 26px;
  }

  .practice-head {
    flex-wrap: wrap;
    gap: 10px;
  }

  .duration {
    width: 100%;
    justify-content: space-between;
  }

  .status {
    margin-left: 0;
  }

  .metrics {
    gap: 18px;
  }


  .keyboard-bar .typing-icon-btn {
    width: 30px;
    height: 30px;
  }

  .finger-tip {
    font-size: 12px;
  }

  .key {
    border-radius: 5px;
  }
}
