/* 타이핑 화면 — docs/14 §3.1, §4. tokens.css 변수만 사용. transform 만 애니메이션. */

.tp {
  max-width: 960px;
  margin: 0 auto;
  padding-top: var(--sp-6);
}

/* ---- 설정 바 ---- */
.tp-config {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  justify-content: center;
  margin-bottom: var(--sp-5);
  transition: opacity .2s ease;
}
body.typing-active .tp-config,
body.typing-active .tp-restart-row {
  opacity: .08;
  pointer-events: none;
}
.tp-config-sep {
  width: 1px;
  height: 16px;
  background: var(--border);
}
.tp-ime {
  margin-left: var(--sp-3);
  font-size: var(--fs-xs);
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  padding: 2px 10px;
}

/* ---- 실시간 미터 / 프로그레스 ---- */
.tp-meter {
  min-height: 22px;
  font-size: var(--fs-sm);
  color: var(--text-muted);
}
.tp-progress {
  height: 2px;
  background: var(--surface-sunken);
  border-radius: var(--radius-full);
  overflow: hidden;
  margin: var(--sp-2) 0 var(--sp-4);
}
.tp-progress-bar {
  height: 100%;
  width: 100%;
  background: var(--text-muted);
  transform-origin: left center;
  transform: scaleX(1);
  will-change: transform;
}
.tp-progress.warn .tp-progress-bar { background: var(--warn); }
.tp-countdown {
  font-size: var(--fs-sm);
  font-weight: 700;
  color: var(--warn);
}

/* ---- 타이핑 영역: 3줄 롤링 ---- */
.tp-area {
  position: relative;
  font-family: var(--font-mono);
  font-size: var(--fs-typing);
  line-height: var(--lh-typing);
  cursor: text;
  user-select: none;
  -webkit-user-select: none;
}
.tp-lines {
  overflow: hidden;
  height: calc(var(--fs-typing) * var(--lh-typing) * 3);
}
.tp-stream {
  position: relative;
  transform: translateY(0);
  transition: transform .15s ease;
  will-change: transform;
}
@media (prefers-reduced-motion: reduce) {
  .tp-stream { transition: none; }
}

.tp-word {
  display: inline-block;
  margin-right: .6ch;
  border-bottom: 2px solid transparent;
}
.tp-word.active { border-bottom-color: var(--border); }
.tp-word.active.typing { border-bottom-color: var(--text-muted); }

/* 글자 상태 — 색 + 밑줄 스타일 이중 부호화 (색각 대응) */
.tp-ch { color: var(--text-faint); }
.tp-ch.pending { color: var(--text-faint); }
.tp-ch.correct { color: var(--text); }
.tp-ch.dead { color: var(--text); }
.tp-ch.incorrect-letter {
  color: var(--err);
  text-decoration: underline;
  text-decoration-style: solid;
  text-decoration-color: var(--err);
  text-decoration-thickness: 2px;
  text-underline-offset: 4px;
}
.tp-ch.incorrect-tone {
  color: var(--warn);
  text-decoration: underline;
  text-decoration-style: dotted;
  text-decoration-color: var(--warn);
  text-decoration-thickness: 2px;
  text-underline-offset: 4px;
}
.tp-ch.extra { opacity: .75; }
.tp-word.committed.err .tp-ch.pending { color: var(--text-faint); }

/* 캐럿 — transform 만, 1s 블링크 */
.tp-caret {
  position: absolute;
  top: 0;
  left: 0;
  width: 2px;
  background: var(--caret);
  border-radius: 1px;
  transform: translate(0, 0);
  transition: transform 90ms ease-out;
  will-change: transform;
  pointer-events: none;
}
.tp-caret.blink { animation: tpBlink 1s steps(1) infinite; }
@keyframes tpBlink { 50% { opacity: 0; } }
@media (prefers-reduced-motion: reduce) {
  .tp-caret { transition: none; }
  .tp-caret.blink { animation: none; }
}

/* 숨김 입력 필드 — 화면 밖이 아니라 영역 내 투명 1px (포커스 스크롤 점프 방지) */
.tp-input {
  position: absolute;
  top: 0;
  left: 0;
  width: 1px;
  height: 1px;
  opacity: 0;
  border: 0;
  padding: 0;
  background: none;
  color: transparent;
}

.tp-focus-hint {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-ui);
  font-size: var(--fs-md);
  color: var(--text-muted);
  background: color-mix(in srgb, var(--bg) 55%, transparent);
  pointer-events: none;
}

.tp-restart-row {
  text-align: center;
  margin-top: var(--sp-5);
  transition: opacity .2s ease;
}

/* ---- 결과 패널 ---- */
.tp-results {
  max-width: 640px;
  margin: var(--sp-7) auto 0;
  text-align: center;
  animation: tpUp .3s ease-out;
}
@media (prefers-reduced-motion: reduce) {
  .tp-results { animation: none; }
}
@keyframes tpUp {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}

.tp-hero { display: flex; align-items: baseline; justify-content: center; gap: var(--sp-3); }
.tp-hero-num {
  font-size: var(--fs-hero);
  font-weight: 800;
  line-height: 1.1;
  letter-spacing: -.02em;
}
.tp-hero-label {
  font-size: var(--fs-xl);
  font-weight: 700;
  color: var(--brand-red);
}
.tp-sub { color: var(--text-muted); margin: var(--sp-2) 0 var(--sp-6); }

.tp-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--sp-3);
  margin: 0 0 var(--sp-5);
}
.tp-stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--sp-3) var(--sp-2);
  box-shadow: var(--shadow-1);
}
.tp-stat dt {
  font-size: var(--fs-xs);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .06em;
}
.tp-stat dd { margin: var(--sp-1) 0 0; font-size: var(--fs-lg); font-weight: 700; }
/* 성조/자모 오타 — 결과에서도 색+선 이중 부호화 유지 */
.tp-stat-tone dd {
  color: var(--warn);
  text-decoration: underline dotted var(--warn) 2px;
  text-underline-offset: 4px;
}
.tp-stat-letter dd {
  color: var(--err);
  text-decoration: underline solid var(--err) 2px;
  text-underline-offset: 4px;
}

.tp-note { font-size: var(--fs-sm); margin: var(--sp-3) 0; }
.tp-note-ok { color: var(--ok); }
.tp-note-warn { color: var(--warn); }
.tp-note-err { color: var(--err); }
.tp-myrank { font-size: var(--fs-sm); color: var(--text-muted); }

.tp-result-actions {
  display: flex;
  gap: var(--sp-3);
  justify-content: center;
  margin-top: var(--sp-5);
}

/* 접근성: 시각적 숨김 (aria-live 안내) */
.tp-sronly {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

@media (max-width: 720px) {
  .tp-stats { grid-template-columns: repeat(2, 1fr); }
  .tp-hero-num { font-size: var(--fs-2xl); }
}
