/* 문제 화면. 짓는 코드는 screens/session.js 다. 영역은 REWORK.md 5장, 모양은 DESIGN.md,
   크기와 움직임은 시제품(spike/web-keyboard/style.css)에서 사용자가 폰으로 쳐 본 것을 옮겼다.
   색, 글자, 간격은 tokens.css 의 것만 쓴다.

   위에서 아래로: 윗줄, (방금 줄, 문제, 쓰는 줄, 안내 줄), 도움, 키보드.
   가운데 넷은 아래에 붙어 있어 쓰는 줄이 키보드 가까이 있고, 쓰는 줄의 아래 끝은 움직이지 않는다.
   시제품에서 찾은 배치 문제 넷을 여기서 막는다:
     1. 세 줄 문장이 판정 순간 내려앉음  → 나가는 문장을 쓰는 줄의 아래 끝에 맞춰 띄우고(session.js turn),
                                           120ms 동안 쓰는 줄의 높이를 잡아 둔다
     2. 방금 줄의 지난 문장은 두 줄까지    → .ss-just-line 을 두 줄에서 자른다
     3. 세션 끝에 버튼이 겹침             → 이 화면에는 끝 버튼이 없다. 끝 화면(session_end)으로 간다
     4. 낮은 화면에서 안내 줄이 두 줄이면 쓰는 줄이 밀림 → 안내 줄의 높이를 늘 두 줄로 잡아 둔다 */
.ss {
  position: relative; /* 오른 숫자(.ss-gain)가 이 안에서 난다 */
  display: flex;
  flex: 1;
  flex-direction: column;
  min-height: 0;
}

/* 맞힌 순간 쓴 문장 끝에 뜨는 "+18". 왕관으로 날아간다(session.js flyGain). */
.ss-gain {
  position: absolute;
  z-index: 5;
  color: var(--success);
  font: var(--type-number);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  pointer-events: none;
  /* 글자 위를 지나가도 읽히게 바탕색 테두리를 두른다 */
  text-shadow: 0 0 3px var(--surface), 0 0 3px var(--surface), 0 0 1px var(--surface);
  opacity: 0;
}

/* 새 내용이 들어올 때. 방금 줄, 문제, 쓰는 줄이 같이 쓴다. */
.ss-in {
  animation: ss-fade-in var(--motion-short) var(--ease-enter) both;
}
@keyframes ss-fade-in {
  from {
    opacity: 0;
  }
}

/* ---------- 윗줄: 닫기, 진행 막대, 왕관과 내 숫자 ---------- */
.ss-top {
  display: flex;
  flex: none;
  align-items: center;
  gap: var(--space-md);
  height: calc(var(--touch) + var(--safe-top));
  padding: var(--safe-top) var(--gutter) 0 var(--space-xs);
}
.ss-close {
  display: flex;
  flex: none;
  align-items: center;
  justify-content: center;
  width: var(--touch);
  height: var(--touch);
  color: var(--text-muted);
}
.ss-close:active {
  color: var(--text);
}
.ss-bar {
  flex: 1;
  height: 8px;
  overflow: hidden;
  border-radius: var(--radius-full);
  background: var(--surface-dim);
}
.ss-bar i {
  display: block;
  width: 0;
  height: 100%;
  border-radius: var(--radius-full);
  background: var(--success);
  transition: width var(--motion-short) var(--ease-move);
}

/* ---------- 가운데 ----------
   내용이 길어지면 위쪽이 잘리고 도움 버튼과 키보드는 밀리지 않는다. 잘리는 곳은 옅어지게 한다. */
.ss-stage {
  display: flex;
  flex: 1 1 0;
  flex-direction: column;
  justify-content: flex-end;
  min-height: 0;
  overflow: hidden;
  -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 14px);
  mask-image: linear-gradient(to bottom, transparent 0, #000 14px);
}
.ss-work {
  flex: none;
  padding: 0 var(--gutter) 6px;
}

/* ---------- 방금 줄 ----------
   바로 앞에 쓴 문장(두 줄까지)과 그때 개구리가 한 말(두 줄까지). 높이를 잡아 두어 아래가 움직이지 않는다. */
.ss-just {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  min-height: 66px;
  padding-bottom: 2px;
}
.ss-just-line,
.ss-just-say {
  display: -webkit-box;
  overflow: hidden;
  word-break: keep-all;
  overflow-wrap: anywhere;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}
.ss-just-line {
  color: var(--success);
  font: var(--type-label);
}
.ss-just.is-unknown .ss-just-line {
  color: var(--text-muted);
}
.ss-just-say {
  color: var(--text-muted);
  font: var(--type-aux);
}
.ss-just-more {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-md);
}
.ss-just-known {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  color: var(--success);
  font: var(--type-label);
  text-overflow: ellipsis;
  white-space: nowrap;
}
/* 확인 못 한 답에 붙는 "내 답도 맞아요". 보이는 크기는 작게, 누르는 영역은 넓게. */
.ss-mine {
  position: relative;
  flex: none;
  color: var(--success);
  font: var(--type-aux);
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.ss-mine::before {
  position: absolute;
  inset: -10px -8px;
  content: '';
}
.ss-mine:disabled {
  color: var(--text-muted);
  text-decoration: none;
}

/* ---------- 문제: 한국어 문장 ----------
   두 줄 높이를 늘 잡아 둔다. 한 줄짜리는 쓰는 줄 바로 위에 붙는다. 낱말 가운데서 줄을 바꾸지 않는다. */
.ss-ko {
  display: flex;
  align-items: flex-end;
  min-height: 64px;
  margin-top: var(--space-sm);
  font: var(--type-prompt);
  letter-spacing: var(--track-prompt);
  text-wrap: balance;
  word-break: keep-all;
  overflow-wrap: anywhere;
}

/* ---------- 쓰는 줄 ----------
   입력칸이 따로 없다. 이 줄이 곧 입력이다. 왼쪽부터 채워져 글자를 쳐도 좌우로 움직이지 않는다.
   두 줄 높이를 늘 잡아 두고, 세 줄이 되면 위쪽이 밀려 올라간다(아래의 안내 줄은 그대로다). */
.ss-write {
  position: relative;
  min-height: 80px;
  margin-top: var(--space-md);
}
.line {
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: var(--space-sm) 7px;
  font: var(--type-english);
}
/* 판정 뒤 새 문장이 들어오기 전까지(120ms). 그 사이에 글쇠를 누르면 session.js 가 바로 보여 준다. */
.line.is-waiting {
  opacity: 0;
}
.slot {
  display: block;
  min-width: 38px;
  height: 32px;
  border-bottom: 2px solid rgba(90, 111, 121, 0.4); /* --text-muted 를 옅게 */
  white-space: pre;
}
/* 다 친 낱말은 밑줄을 걷고 글자 폭만큼만 차지한다. 문장처럼 읽힌다. */
.slot.is-done {
  min-width: 0;
  border-bottom-color: transparent;
}
.slot.is-bad {
  min-width: 0;
  border-bottom-color: var(--error);
}
.slot.is-cur,
.slot.is-empty.has-caret {
  border-bottom-color: var(--text);
}
/* 오타나 아포스트로피가 빠진 낱말. 받아 주는 낱말이라 초록인 채로 노란 밑줄만 긋는다. */
.slot.is-typo {
  border-bottom-color: var(--warning);
}
.slot .ok {
  color: var(--success);
}
.slot .ink {
  color: var(--text);
}
.slot .bad {
  color: var(--error);
}
.slot .ghost {
  color: var(--text-muted); /* 옅게 하지 않는다: 따라 쳐야 하는 글이라 글자 대비 AA(4.73). 2026-11-18 사용자 결정 */
}
/* 커서. 폭을 차지하지 않아 글자가 밀리지 않는다. */
.caret {
  display: inline-block;
  width: 2px;
  height: 25px;
  margin: 0 -3px 0 1px;
  border-radius: 1px;
  background: var(--text);
  vertical-align: -5px;
  animation: ss-caret 1060ms steps(1) infinite;
}
/* 빈칸 맨 앞의 커서는 칸 왼쪽 틈에 둔다. 정답 보기의 흐린 글자와 겹치지 않는다. */
.caret.is-before {
  margin: 0 2px 0 -4px;
}
@keyframes ss-caret {
  50% {
    opacity: 0;
  }
}

/* 보내기를 눌렀는데 틀렸을 때. 좌우로 짧게 흔들리고 밑줄이 잠깐 빨개진다. */
.ss-write.is-shake .line:not(.leaving) {
  animation: ss-shake 320ms linear;
}
.ss-write.is-shake .line:not(.leaving) .slot:not(.is-done) {
  border-bottom-color: var(--error);
}
@keyframes ss-shake {
  12.5% {
    transform: translateX(7px);
  }
  37.5% {
    transform: translateX(-5px);
  }
  62.5% {
    transform: translateX(3px);
  }
  87.5% {
    transform: translateX(-1px);
  }
}

/* 판정이 난 문장. 쓰는 줄 위에 그대로 있다가(맞았으면 전부 초록) 120ms 뒤 위로 올라가며 나간다.
   아래 끝(bottom)은 session.js 가 그 순간의 자리로 정한다. 그 아래에서는 이미 다음 문장을 칠 수 있다. */
.line.leaving {
  position: absolute;
  right: 0;
  left: 0;
  pointer-events: none;
}
.line.leaving .slot {
  min-width: 0;
  border-bottom-color: transparent;
}
.line.leaving.is-going {
  animation: ss-leave var(--motion-micro) var(--ease-exit) both;
}
@keyframes ss-leave {
  to {
    opacity: 0;
    transform: translateY(-14px);
  }
}

/* ---------- 안내 줄 ----------
   지금 문장에 대해 개구리가 하는 한 줄. 높이를 늘 잡아 두어, 말이 길어져도 위의 쓰는 줄이 밀리지 않는다.
   보통은 두 줄, 키 큰 화면(700 이상)은 세 줄, 낮은 화면(600 미만)은 작은 글자로 두 줄이다.
   문구가 이 안에 드는지는 web/qa/lines.mjs 가 잰다(check.sh). */
.ss-say-row {
  display: flex;
  align-items: flex-start;
  gap: var(--space-sm);
  height: 54px;
  margin-top: var(--space-md);
  overflow: hidden;
  transition: opacity var(--motion-micro) var(--ease-exit);
}
.ss-say-row.is-out {
  opacity: 0;
}
.ss-say-row .ui-frog {
  margin-top: 2px;
}
.ss-say {
  display: -webkit-box;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  font: var(--type-note);
  letter-spacing: var(--track-note);
  word-break: keep-all;
  overflow-wrap: anywhere;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  transition: opacity 110ms var(--ease-enter);
}
/* 개구리가 건네는 인사(실력 확인의 "실력을 잠깐 볼게굴"). 개구리의 말이라 주아다. */
.ss-say.is-frog {
  font: var(--type-frog);
  letter-spacing: 0;
}
.ss-say.is-out {
  opacity: 0;
  transition-duration: 70ms;
}

/* ---------- 도움 ---------- */
.ss-help {
  display: flex;
  flex: none;
  align-items: center;
  justify-content: space-between;
  height: 50px;
  padding: 0 var(--gutter) 6px;
}
.ss-chip,
.ss-quiet {
  position: relative;
  display: inline-flex;
  flex: none;
  align-items: center;
  white-space: nowrap;
  height: 36px;
  font: var(--type-label);
}
/* 보이는 크기는 작게, 누르는 영역은 44 로. */
.ss-chip::before,
.ss-quiet::before {
  position: absolute;
  inset: -4px -6px;
  content: '';
}
.ss-chip {
  gap: 6px;
  padding: 0 14px 0 var(--space-md);
  border-radius: var(--radius-full);
  background: var(--card);
  box-shadow: var(--shadow-soft);
}
.ss-chip:active {
  box-shadow: 0 1px 0 rgba(29, 43, 51, 0.22);
  transform: translateY(2px);
}
.ss-quiet {
  gap: 2px;
  padding: 0 2px 0 10px;
  color: var(--text-muted);
  font-weight: 500;
}
.ss-quiet:active {
  color: var(--text);
}
.ss-quiet:disabled {
  opacity: 0.4;
}
/* "내 답도 맞아요". 보낸 답이 틀림으로 남았을 때만 정답 보기와 건너뛰기 사이에 뜬다. 남긴 뒤에는 "남겨 뒀어요"로
   흐리지 않고 그대로 읽히게 둔다(남았다는 것을 알려 주는 글이다). */
.ss-report {
  padding: 0 var(--space-sm);
  color: var(--success);
  text-decoration: underline;
  text-underline-offset: 3px;
}
.ss-report:disabled {
  opacity: 1;
  color: var(--text-muted);
  text-decoration: none;
}

/* 좁은 화면(320)에서 "내 답도 맞아요"까지 셋이 한 줄에 들게 도움 글자를 한 단계(14) 작게, 여백을 좁게. */
@media (max-width: 359px) {
  .ss-chip,
  .ss-quiet {
    font: var(--type-aux);
    font-weight: 600;
  }
  .ss-chip {
    gap: var(--space-xs);
    padding: 0 10px 0 var(--space-sm);
  }
  .ss-quiet {
    padding-left: var(--space-xs);
  }
  .ss-report {
    padding: 0 var(--space-xs);
  }
}

/* ---------- 키보드 ----------
   시스템 키보드(290~330)보다 낮다. 줄 높이는 54 이고 화면이 낮으면 44 까지 줄어든다. */
.ss-kb {
  flex: none;
}
.ss-kb .kb {
  --kb-row: clamp(44px, calc((100vh - 330px) / 6.2), 54px);
  --kb-row: clamp(44px, calc((100dvh - 330px) / 6.2), 54px);
}

/* 가운데가 넘쳐 방금 줄의 위가 잘릴 때(session.js 의 fit). 먼저 그때의 말을, 그래도 모자라면 지난 문장을 한 줄로. */
.ss-just.is-tight .ss-just-say {
  -webkit-line-clamp: 1;
}
.ss-just.is-tighter .ss-just-line {
  -webkit-line-clamp: 1;
}

/* ---------- 키 큰 화면 ----------
   18px 로 296px 폭에서 세 줄이 되는 문구가 있다(May I는 …, 2026-11-18 lines.mjs 로 잰 7종). 빈 곳이 넉넉한
   높이에서는 안내 줄을 세 줄 높이로 잡는다. 높이가 고정이라 쓰는 줄은 그대로다. */
@media (min-height: 700px) {
  .ss-say-row {
    height: 81px;
  }
  .ss-say {
    -webkit-line-clamp: 3;
  }
}

/* ---------- 낮은 화면 ----------
   방금 줄과 문제는 한 줄씩, 글자는 한 단계씩 작게. 안내 줄은 그래도 두 줄 높이를 잡아 둔다. */
@media (max-height: 599px) {
  .ss-top {
    height: calc(36px + var(--safe-top));
  }
  .ss-close {
    position: relative;
    height: 36px;
  }
  /* 보이는 높이는 36 이지만 누르는 영역은 44 로(도움 버튼과 같은 방법). */
  .ss-close::before {
    position: absolute;
    inset: -4px 0;
    content: '';
  }
  .ss-just {
    min-height: 43px;
  }
  .ss-ko {
    min-height: 30px;
    margin-top: var(--space-xs);
    font: var(--type-english);
  }
  .ss-write {
    min-height: 68px;
    margin-top: var(--space-sm);
  }
  /* 가장 긴 문장(p01-07)이 320 폭에서도 세 줄에 들게 한 단계 작게(18). */
  .line {
    row-gap: var(--space-xs);
    font-size: 18px;
  }
  .ss-say-row {
    height: 42px;
    margin-top: 6px;
  }
  .ss-say-row .ui-frog {
    margin-top: 0;
  }
  .ss-say {
    font: var(--type-aux);
  }
  .ss-help {
    height: 42px;
    padding-bottom: var(--space-xs);
  }
}

/* ---------- 움직임을 줄였을 때 ----------
   통째로 끄지 않는다. 이동과 크기 변화, 저절로 되풀이되는 것만 빼고 옅어짐, 색 변화, 시간차는 남긴다. */
@media (prefers-reduced-motion: reduce) {
  /* 진행 막대는 늘어나는 움직임 없이 바로 바뀐다. */
  .ss-bar i {
    transition: none;
  }
  .ss-write.is-shake .line:not(.leaving) {
    animation-name: none;
  }
  .line.leaving.is-going {
    animation-name: ss-leave-still;
  }
  @keyframes ss-leave-still {
    to {
      opacity: 0;
    }
  }
  .caret {
    animation: none;
  }
  .ss-chip:active {
    transform: none;
  }
}
