/* 타이핑 화면 — 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;
  flex-wrap: wrap;
  margin-bottom: var(--sp-5);
  transition: opacity .2s ease;
}
body.typing-active .tp-config {
  opacity: .08;
  pointer-events: none;
}
.tp-config-label {
  font-size: var(--fs-xs);
  color: var(--text-muted);
  margin-right: var(--sp-1);
  white-space: nowrap;
}
.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-hangul {
  color: var(--text);
  background: color-mix(in srgb, var(--warn) 22%, transparent);
  border-color: var(--warn);
  font-weight: 700;
}
.tp-hangul[hidden] { display: none; }
p.tp-hangul { display: table; margin: 0 auto var(--sp-3); }

/* ---- 실시간 미터 / 프로그레스 ---- */
.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;
}

/* 타자 화면 타이머(devplan005): 남은 초 숫자(좌) + 실시간 wpm(우), 두꺼운 골드 진행바. 마지막 10초 .tp-warn = 빨강 */
.tp-meter-timer {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: var(--sp-3);
  min-height: 28px;
}
.tp-countdown {
  display: inline-block;
  font-size: 1.75rem;
  font-weight: 700;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  color: var(--brand-gold);
  transform-origin: left bottom;
}
.tp-countdown-unit {
  margin-left: 2px;
  font-size: var(--fs-sm);
  font-weight: 400;
  color: var(--text-muted);
}
.tp-progress-timer { height: 6px; }
.tp-progress-timer .tp-progress-bar { background: var(--brand-gold); }
.tp.tp-warn .tp-countdown { color: var(--brand-red); }
.tp.tp-warn .tp-progress-timer .tp-progress-bar { background: var(--brand-red); }
.tp-countdown.tick { animation: tp-tick .25s ease-out; }
@keyframes tp-tick {
  from { transform: scale(1.15); }
  to { transform: scale(1); }
}
@media (prefers-reduced-motion: reduce) {
  .tp-countdown.tick { animation: none; }
}
@media (max-width: 640px) {
  .tp-countdown { font-size: 1.5rem; }
  .tp-meter-timer { min-height: 24px; }
}

/* ---- 타이핑 영역: 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); }

/* ---- 타자 화면 전용 레이아웃 (devplan004) — renderer.setLayout('line'|'sentence') 가 .tp-area 에 클래스를 붙임.
   레슨/챌린지는 클래스가 없어 위의 3줄 롤링 그대로. 높이는 고정(레이아웃 점프 없음), 폭 좁으면 글자 크기만 줄임. ---- */
.tp-area.tp-layout-line,
.tp-area.tp-layout-sentence {
  font-size: clamp(20px, 5.4vw, var(--fs-typing));
}

/* 단어 모드: 한 줄 가운데 — 현재 단어를 가로 가운데에 두고 stream 을 translateX. 지나간 단어는 흐리게. */
.tp-layout-line .tp-lines {
  height: calc(1em * var(--lh-typing) + 6px);
  -webkit-mask-image: linear-gradient(90deg, transparent 0, #000 14%, #000 86%, transparent 100%);
  mask-image: linear-gradient(90deg, transparent 0, #000 14%, #000 86%, transparent 100%);
}
.tp-layout-line .tp-stream {
  display: flex;
  flex-wrap: nowrap;
  align-items: flex-start;
  width: max-content;
  white-space: nowrap;
  transition: transform .14s ease-out;
  will-change: auto; /* 폭이 큰 스트림 — 별도 합성 레이어 강제 금지 */
}
.tp-layout-line .tp-word {
  flex: 0 0 auto;
  margin-right: 1.1ch;
  transition: opacity .15s ease;
}
.tp-layout-line .tp-word.committed { opacity: .38; }
.tp-layout-line .tp-caret { transition-duration: .14s; transition-timing-function: ease-out; }

/* 문장 모드: 한 문장만 가운데 정렬(길면 줄바꿈). 높이는 3줄분 고정(더 길면 늘어남). 현재 문장의 단어만 .on */
.tp-layout-sentence .tp-lines {
  height: auto;
  min-height: calc(1em * var(--lh-typing) * 3 + 6px);
  display: flex;
  align-items: center;
  justify-content: center;
}
.tp-layout-sentence .tp-stream {
  width: 100%;
  text-align: center;
  transition: none;
  will-change: auto;
}
.tp-layout-sentence .tp-word { display: none; margin: 0 .3ch; }
.tp-layout-sentence .tp-word.on { display: inline-block; }

/* 글자 상태 — 색 + 밑줄 스타일 이중 부호화 (색각 대응) */
.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-case {
  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-pause {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  align-content: center;
  column-gap: var(--sp-3);
  row-gap: 2px;
  padding: 0 var(--sp-3);
  text-align: center;
  font-family: var(--font-ui);
  font-size: var(--fs-sm);
  line-height: 1.35;
  color: var(--text-muted);
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  border: 1px dashed var(--border);
  border-radius: var(--radius-md);
  cursor: pointer;
}
.tp-pause[hidden] { display: none; }
.tp-pause-title { font-weight: 700; color: var(--text); font-size: var(--fs-md); }
.tp.paused .tp-lines,
.tp.paused .tp-caret { visibility: hidden; }
.tp.paused .tp-trans { visibility: hidden; }
.tp.paused .tp-progress-bar { background: var(--text-muted); }
.tp.paused .tp-countdown { color: var(--text-muted); }
.tp.paused .tp-progress-timer .tp-progress-bar { background: var(--text-muted); }

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

/* ---- 번역줄 (타자 영역 바로 아래, 높이 고정 2줄 — 내용이 비어도 레이아웃 유지) ---- */
.tp-trans {
  --tp-trans-lh: 1.5;
  height: calc(var(--fs-md) * var(--tp-trans-lh) * 2);
  margin: var(--sp-3) auto 0;
  max-width: 100%;
  text-align: center;
  font-family: var(--font-ui);
  font-size: var(--fs-md);
  line-height: var(--tp-trans-lh);
  color: var(--text-muted);
  overflow: hidden;
  transition: opacity .2s ease;
}
.tp-trans[hidden] { display: none; }
/* 타자 중에는 헤더·설정이 흐려져도 번역줄은 읽을 수 있게 70% 유지 */
body.typing-active .tp-trans { opacity: .7; }
.tp-trans-text {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  overflow: hidden;
  text-overflow: ellipsis;
  overflow-wrap: anywhere;
  transition: opacity .15s ease;
}
/* devplan004: 타자 화면에선 말풍선 아이콘 삭제 — 챌린지(.dc-trans)만 기존 아이콘 유지 */
.dc-trans .tp-trans-text:not(:empty)::before { content: "\1F4AC\00a0"; }
.tp-trans.swap .tp-trans-text { opacity: 0; }
@media (prefers-reduced-motion: reduce) {
  .tp-trans, .tp-trans-text { transition: none; }
}

/* 타자 영역 아래 상시 표시 — 타자 중에도 흐려지지 않음 */
.tp-restart-row {
  text-align: center;
  margin-top: var(--sp-5);
}

/* 번역: 단어 모드 = 현재 단어 바로 아래(가운데), 문장 모드 = 문장 바로 아래(최대 3줄) */
.tp .tp-trans { margin-top: var(--sp-2); }
.tp[data-kind="sent"] .tp-trans { height: calc(var(--fs-md) * var(--tp-trans-lh) * 3); }
.tp[data-kind="sent"] .tp-trans-text { -webkit-line-clamp: 3; line-clamp: 3; }

/* ---- 결과 패널 ---- */
.tp-results:focus { outline: none; }   /* 결과 영역은 프로그램 포커스만(tabindex=-1) */
.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-mode-chip {
  display: inline-block;
  margin: 0 0 var(--sp-3);
  padding: 4px 14px;
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--text-muted);
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
}
.tp-mode-chip[hidden] { display: none; }

.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-wpm-help { color: var(--text-muted); font-size: var(--fs-sm, 14px); margin: var(--sp-1, 4px) 0 0; }   /* WPM 뜻 한 줄 설명 */
.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-case 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-config { gap: var(--sp-2); }
  .tp-trans { font-size: var(--fs-sm); height: calc(var(--fs-sm) * var(--tp-trans-lh) * 2); }
  .tp[data-kind="sent"] .tp-trans { height: calc(var(--fs-sm) * var(--tp-trans-lh) * 3); }
  .tp-pause-title { font-size: var(--fs-sm); }
  .tp-stats { grid-template-columns: repeat(2, 1fr); }
  .tp-hero-num { font-size: var(--fs-2xl); }
}
