/* 기능 확인용 최소 스타일 — 디자인은 이후 단계에서 */
:root {
  --bg: #faf8f5;
  --card: #ffffff;
  --ink: #1d1b19;
  --sub: #6b655e;
  --line: #e8e2da;
  --acc: #2f6fdb;
  --ok: #2f7d4f;
  --ok-bg: #e5f4ea;
  --bad: #d9483b;
  --bad-bg: #fbe9e7;
  --hint: #fff1a8;
  --speak: #d8e6ff;
  --font-size: 18px;
  --line-height: 1.8;
  --letter-spacing: 0.01em;
}
:root[data-theme='dark'] {
  --bg: #161514;
  --card: #201f1d;
  --ink: #eeeae4;
  --sub: #a49d94;
  --line: #34312d;
  --acc: #7aa7ff;
  --ok: #5fbf86;
  --ok-bg: #1e3326;
  --bad: #f0705f;
  --bad-bg: #3a2220;
  --hint: #5a4b10;
  --speak: #22365c;
}

* { box-sizing: border-box; }
html, body { margin: 0; overflow-x: hidden; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: 'Pretendard Variable', Pretendard, -apple-system, 'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif;
  font-size: 16px;
  line-height: 1.6;
}
button { font: inherit; color: inherit; cursor: pointer; }

/* 상단 툴바 */
.toolbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 8px;
  padding: 6px 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.app-name { flex: 1; min-width: 0; margin: 0; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.toolbar-right { display: flex; gap: 4px; }
.icon-btn {
  min-width: 44px; min-height: 44px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--card);
  font-size: 15px;
}

main { padding: 16px 16px 40px; max-width: 760px; margin: 0 auto; }
.muted { color: var(--sub); }

/* 홈 */
.passage-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.passage-list button {
  width: 100%; min-height: 56px; padding: 10px 14px;
  text-align: left; border: 1px solid var(--line); border-radius: 12px; background: var(--card);
}
.passage-list small { display: block; color: var(--sub); font-size: 13px; }

/* 단계 선택 */
.stage-bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.stage-label { font-size: 14px; color: var(--sub); }
.stage-buttons { display: flex; gap: 4px; }
.stage-buttons button {
  min-width: 44px; min-height: 44px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--card);
}
.stage-buttons button[aria-pressed='true'] { background: var(--acc); border-color: var(--acc); color: #fff; font-weight: 700; }

/* 읽기 */
.read-title { font-size: 20px; margin: 8px 0 16px; }
.reader {
  width: 100%;
  font-size: var(--font-size);
  line-height: var(--line-height);
  letter-spacing: var(--letter-spacing);
  word-break: keep-all;        /* 한글 어절 중간에서 끊지 않기 */
  overflow-wrap: anywhere;     /* 그래도 넘치는 긴 단어는 끊어서 가로 스크롤 방지 */
}
.reader .para { margin: 0 0 1.4em; }
.reader .line { display: block; }
.reader[data-mode='flow'] .line { display: inline; }

.debug { font-size: 12px; color: var(--sub); white-space: pre-wrap; }

.primary-btn {
  display: block; width: 100%; min-height: 52px; margin-top: 24px;
  border: 0; border-radius: 14px;
  background: var(--acc); color: #fff; font-size: 17px; font-weight: 700;
}

/* 홈 수준 탭 · 핵심어 칩 */
.chip-list { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.chip {
  min-height: 44px; padding: 8px 14px;
  border: 1px solid var(--line); border-radius: 99px; background: var(--card);
}
.chip[aria-pressed='true'] { background: var(--acc); border-color: var(--acc); color: #fff; font-weight: 700; }

/* 읽기 모드 안내 */
.mode-bar { display: flex; align-items: center; gap: 8px; margin: 0 0 8px; padding: 8px 12px; border-radius: 12px; background: var(--card); border: 1px solid var(--line); }
.mode-bar[hidden] { display: none; }
.mode-guide { flex: 1; margin: 0; font-size: 15px; }
.text-btn { min-height: 44px; padding: 0 8px; border: 0; background: none; color: var(--acc); font-size: 14px; white-space: nowrap; text-decoration: underline; }

/* 오답 근거 하이라이트 */
.reader .line.hint { background: var(--hint); border-radius: 4px; box-shadow: 0 0 0 2px var(--hint); }

/* 활동 */
.step-label { margin: 0 0 4px; font-size: 14px; color: var(--acc); font-weight: 700; }
.step-q { margin: 0 0 16px; font-size: 20px; line-height: 1.5; word-break: keep-all; }
.choice-list { display: grid; gap: 10px; }
.choice {
  display: flex; align-items: center; gap: 12px;
  width: 100%; min-height: 52px; padding: 12px 14px;
  text-align: left; font-size: 17px; line-height: 1.5; word-break: keep-all;
  border: 2px solid var(--line); border-radius: 14px; background: var(--card);
}
.scene-choice .emoji { font-size: 28px; flex: none; }
.choice:disabled, .chip:disabled { opacity: 1; cursor: default; }
.is-correct { border-color: var(--ok) !important; background: var(--ok-bg) !important; color: var(--ink) !important; }
.is-wrong { border-color: var(--bad) !important; background: var(--bad-bg) !important; color: var(--ink) !important; }
.feedback { min-height: 1.5em; margin: 14px 0 0; font-size: 16px; font-weight: 600; }
.feedback ol { font-weight: 400; padding-left: 20px; }
.order-answer { min-height: 60px; margin: 0 0 12px; padding: 10px 10px 10px 30px; border: 2px dashed var(--line); border-radius: 14px; display: grid; gap: 8px; }
.order-answer li { padding-left: 4px; }
.order-card.placed { border-color: var(--acc); }
.small { font-size: 14px; }

/* 결과 */
.result-stars { margin: 8px 0; font-size: 48px; text-align: center; letter-spacing: 8px; }
.result-msg { text-align: center; font-size: 18px; font-weight: 700; margin: 0 0 16px; }
.star-list { list-style: none; margin: 0 0 12px; padding: 0; display: grid; gap: 8px; }
.star-list li { display: flex; gap: 12px; align-items: center; padding: 12px 14px; border: 1px solid var(--line); border-radius: 14px; background: var(--card); color: var(--sub); }
.star-list li.got { color: var(--ink); }
.star-list .star { font-size: 26px; }
.star-list small { display: block; font-size: 13px; color: var(--sub); }

/* 홈 상태 카드 · 알림 */
.home-status { display: grid; gap: 4px; margin-bottom: 12px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 14px; background: var(--card); }
.status-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; min-height: 32px; }
.streak { font-size: 20px; font-weight: 800; }
.stage-now { font-weight: 700; }
.banner { margin: 0 0 12px; padding: 12px 14px; border: 2px solid var(--acc); border-radius: 14px; background: var(--card); }
.banner p { margin: 0 0 8px; }
.banner.unlock { font-weight: 700; text-align: center; }
.primary-btn.slim { min-height: 44px; margin-top: 4px; font-size: 16px; }
.scale { display: flex; gap: 6px; }
.scale .chip { flex: 1; padding: 0; }
.scale-labels { display: flex; justify-content: space-between; font-size: 12px; color: var(--sub); margin-top: 4px; }
.privacy { margin-top: 20px; text-align: center; }

/* 안내 화면 */
.plain-list { padding-left: 4px; list-style: none; line-height: 1.9; }
.text-btn.block { display: block; width: 100%; margin-top: 8px; }
.choice.is-current { border-color: var(--acc); }
.big-stage { margin: 8px 0; font-size: 56px; font-weight: 800; text-align: center; color: var(--acc); }
.compare { margin: 12px 0; padding: 12px 14px; border-radius: 14px; background: var(--card); border: 1px solid var(--line); text-align: center; }
.compare p { margin: 4px 0; }
.compare-line { font-size: 18px; font-weight: 700; }

/* 소리로 듣기 */
.tts-bar { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin: 0 0 8px; }
.tts-bar[hidden], .stage-bar[hidden] { display: none; }
.tts-rates { display: flex; gap: 4px; }
.reader .line.speaking { background: var(--speak); border-radius: 4px; box-shadow: 0 0 0 2px var(--speak); }
.stage-buttons button:disabled { opacity: 0.5; cursor: not-allowed; }

/* 홈 화면에 추가 안내 */
.banner-title { font-weight: 700; }
.install-steps { margin: 0 0 6px; padding-left: 22px; line-height: 1.8; }

/* ---------- 5차: 내비게이션 ---------- */
.app-name { border: 0; background: none; padding: 0 4px; min-height: 44px; text-align: left; font-weight: 800; color: var(--ink); cursor: pointer; }
.toolbar .app-name { flex: 1; min-width: 0; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.toolbar [hidden] { display: none !important; }
.exit-btn { font-size: 16px; font-weight: 700; text-decoration: none; color: var(--ink); padding: 0 6px; flex: none; }
.stopwatch { flex: 1; text-align: center; font-variant-numeric: tabular-nums; font-size: 16px; color: var(--sub); }
#btn-timer[aria-pressed='true'] { border-color: var(--acc); color: var(--acc); }
.screen-title { font-size: 20px; margin: 4px 0 14px; }

/* 하단 탭 바 */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(4, 1fr);
  padding: 4px 8px calc(4px + env(safe-area-inset-bottom));
  background: var(--bg); border-top: 1px solid var(--line);
}
.tabbar[hidden] { display: none; }
.tabbar button {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: 52px; border: 0; background: none; color: var(--sub); font-size: 12px; border-radius: 12px;
}
.tabbar .tab-icon { font-size: 20px; line-height: 1; }
.tabbar button[aria-current='true'] { color: var(--acc); font-weight: 700; background: var(--card); }
body.with-tabbar main { padding-bottom: calc(84px + env(safe-area-inset-bottom)); }

/* 확인 창 · 알림 */
.modal { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; padding: 16px; background: rgba(0, 0, 0, 0.45); }
.modal[hidden] { display: none; }
.modal-box { width: 100%; max-width: 360px; padding: 20px 18px 16px; border-radius: 18px; background: var(--bg); border: 1px solid var(--line); }
.modal-box p { margin: 0 0 16px; font-size: 17px; line-height: 1.6; word-break: keep-all; }
.modal-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.modal-actions .primary-btn { margin-top: 0; }
.secondary-btn {
  min-height: 52px; padding: 0 14px; border: 2px solid var(--line); border-radius: 14px;
  background: var(--card); font-size: 16px; font-weight: 700;
}
.secondary-btn.small-btn { min-height: 44px; font-size: 14px; padding: 0 12px; white-space: nowrap; }
.btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.toast {
  position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 60;
  max-width: calc(100% - 32px); padding: 10px 16px; border-radius: 99px; background: var(--ink); color: var(--bg); font-size: 14px; text-align: center;
}
.toast[hidden] { display: none; }

/* 홈: 오늘의 지문 */
.today-card { padding: 16px; border: 2px solid var(--acc); border-radius: 16px; background: var(--card); }
.today-title { margin: 2px 0 4px; font-size: 21px; line-height: 1.4; word-break: keep-all; }
.today-card .primary-btn { margin-top: 14px; }

/* 카드 공통 */
.card { margin: 0 0 12px; padding: 14px 16px; border: 1px solid var(--line); border-radius: 16px; background: var(--card); }
.card-title { margin: 0 0 8px; font-size: 16px; }
.record-msg { margin: 8px 0 0; font-weight: 600; word-break: keep-all; }
.record-msg.good { color: var(--ok); }
.stage-history { margin: 6px 0 2px; font-size: 18px; font-weight: 700; }
.result-time p { margin: 4px 0; }

/* 내 기록 */
.stat-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.stat { padding: 12px 6px; border: 1px solid var(--line); border-radius: 14px; background: var(--card); text-align: center; }
.stat b { display: block; font-size: 20px; }
.stat span { font-size: 13px; color: var(--sub); }
.chart { display: block; width: 100%; height: auto; }
.chart-grid { stroke: var(--line); stroke-width: 1; }
.chart-axis { fill: var(--sub); font-size: 11px; }
.chart-line { fill: none; stroke: var(--acc); stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.chart-dot { fill: var(--bg); stroke: var(--acc); stroke-width: 2.5; }
.chart-stage { fill: var(--ink); font-size: 11px; font-weight: 700; }

/* 설정 */
.setting-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 56px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.card .setting-row:last-child { border-bottom: 0; }
.setting-label { display: flex; flex-direction: column; min-width: 0; }
.setting-label small { color: var(--sub); font-size: 12px; }
.stepper { display: flex; align-items: center; gap: 6px; }
.stepper-value { min-width: 46px; text-align: center; font-variant-numeric: tabular-nums; }
.font-sample { margin: 4px 0 8px; line-height: 1.6; color: var(--sub); }
.switch { position: relative; flex: none; width: 56px; height: 32px; min-height: 44px; padding: 0; border: 0; background: none; }
.switch::before { content: ''; position: absolute; left: 0; right: 0; top: 6px; height: 32px; border-radius: 99px; background: var(--line); transition: background 0.15s; }
.switch-knob { position: absolute; top: 9px; left: 3px; width: 26px; height: 26px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3); transition: left 0.15s; }
.switch[aria-checked='true']::before { background: var(--acc); }
.switch[aria-checked='true'] .switch-knob { left: 27px; }
.card .tts-rates { flex-wrap: wrap; justify-content: flex-end; }
.setting-row.stack { flex-direction: column; align-items: stretch; gap: 8px; padding: 10px 0; }
.setting-row.stack .tts-rates { justify-content: flex-start; }
.setting-label span { word-break: keep-all; }
.toolbar-right { margin-left: auto; }

/* ---------- 6차: 새 버전 알림 · 버전 표시 · 붙여넣기 ---------- */
.update-bar {
  position: sticky; top: 57px; z-index: 9;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 2px 16px; background: var(--card); border-bottom: 1px solid var(--line); font-size: 14px;
}
.update-bar[hidden] { display: none; }
.update-bar .text-btn { font-weight: 700; }
.app-version { margin: 4px 0 0; text-align: center; font-size: 13px; color: var(--sub); font-variant-numeric: tabular-nums; }
.paste-btn { width: 100%; margin-bottom: 14px; }
.paste-text {
  display: block; width: 100%; min-height: 200px; margin: 8px 0 4px; padding: 12px 14px;
  border: 2px solid var(--line); border-radius: 14px; background: var(--card); color: var(--ink);
  font: inherit; font-size: 16px; line-height: 1.6; resize: vertical;
}
.paste-text:focus { outline: none; border-color: var(--acc); }
.paste-count { margin: 0 0 12px; text-align: right; }
.paste-stages { margin: 6px 0 4px; flex-wrap: wrap; }
.paste-stages button { min-width: 44px; min-height: 44px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); }
.paste-stages button[aria-pressed='true'] { background: var(--acc); border-color: var(--acc); color: #fff; font-weight: 700; }
.result-msg.big { font-size: 24px; margin: 8px 0 14px; }
