/* 말하기 연습 PWA — 공통 스타일 (모바일 우선 · 밝은 테마 · 외부 리소스 없음) */

:root {
  --bg: #f5f6f1;
  --card: #ffffff;
  --ink: #22302d;
  --muted: #5d6b67;
  --line: #dfe4de;
  --pri: #2f6f68;
  --pri-dark: #255a54;
  --pri-soft: #e2efeb;
  --amber: #d99a2b;
  --amber-ink: #8a5a0b;
  --amber-soft: #fff6e3;
  --ok: #1f7a3d;
  --ok-bg: #dff2e5;
  --bad: #b3362c;
  --bad-bg: #fbe5e2;
  --hdr: 56px;
  --fk: system-ui, -apple-system, "Apple SD Gothic Neo", "Noto Sans KR", "Malgun Gothic", "Segoe UI", Roboto, sans-serif;
  --ft: "Noto Sans Hebrew", "Arial Hebrew", "SF Hebrew", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--fk);
  font-size: 16px;
  line-height: 1.5;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}
body.modal-open { overflow: hidden; }

h1, h2, h3 { line-height: 1.3; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }
button:focus-visible, input:focus-visible, select:focus-visible, summary:focus-visible {
  outline: 3px solid #8cc2b8;
  outline-offset: 2px;
}
[hidden] { display: none !important; }

.small { font-size: 13px; color: var(--muted); }
.block { display: block; }
.msg { text-align: center; color: var(--muted); padding: 32px 8px; }
.msg .btn { margin-top: 12px; }

/* ---------- 음성 안내 배너 ---------- */
#banner { background: var(--amber-soft); border-bottom: 1px solid #f0d9a8; }
.banner-in {
  position: relative;
  max-width: 640px;
  margin: 0 auto;
  padding: 12px 52px 12px 14px;
  font-size: 14px;
}
.banner-x {
  position: absolute; top: 4px; right: 4px;
  width: 44px; height: 44px;
  border: 0; border-radius: 10px;
  background: transparent; font-size: 18px;
}
.banner-x:active { background: rgba(0, 0, 0, .06); }
.vhelp p { margin: 4px 0; }
.vhelp ul { margin: 6px 0; padding-left: 18px; }
.vhelp li { margin: 5px 0; overflow-wrap: anywhere; }

/* ---------- 상단 바 ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  height: var(--hdr);
  display: flex; align-items: center; gap: 4px;
  padding: 0 max(6px, calc((100% - 640px) / 2 + 6px));
  background: rgba(255, 255, 255, .97);
  border-bottom: 1px solid var(--line);
}
.app-title {
  flex: 1; min-width: 0;
  margin: 0 0 0 8px;
  font-size: 20px; font-weight: 800; color: var(--pri);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.top-title {
  flex: 1; min-width: 0;
  font-size: 16px; font-weight: 700; line-height: 1.3;
  overflow: hidden;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow-wrap: anywhere;
}
.icon-btn {
  width: 44px; height: 44px; min-width: 44px;
  display: inline-flex; align-items: center; justify-content: center;
  border: 0; border-radius: 12px;
  background: transparent; font-size: 22px; line-height: 1;
}
.icon-btn:active { background: var(--pri-soft); }

/* ---------- 공통 레이아웃 / 버튼 ---------- */
.wrap { max-width: 640px; margin: 0 auto; padding: 14px 14px 32px; }
.wrap.lesson { padding-bottom: calc(100px + env(safe-area-inset-bottom)); }

.btn {
  min-height: 44px;
  padding: 8px 14px;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line); border-radius: 12px;
  background: #fff;
  font-size: 15px; font-weight: 600; line-height: 1.25; text-align: center;
  max-width: 100%;
}
.btn:active { background: #f0f2ee; }
.btn.primary { background: var(--pri); border-color: var(--pri); color: #fff; }
.btn.primary:active { background: var(--pri-dark); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.danger { color: var(--bad); border-color: #efc4be; }
.btn.wide { width: 100%; }
.btn.listening {
  background: var(--bad-bg); border-color: var(--bad); color: var(--bad);
  animation: pulse 1.2s ease-in-out infinite;
}
@keyframes pulse { 50% { box-shadow: 0 0 0 6px rgba(179, 54, 44, .15); } }

/* ---------- 홈 ---------- */
.today {
  display: block; width: 100%;
  padding: 18px;
  border: 0; border-radius: 18px;
  background: linear-gradient(135deg, #2f6f68, #3f8a80);
  color: #fff; text-align: left;
  box-shadow: 0 6px 18px rgba(47, 111, 104, .25);
}
.today-label { display: block; font-size: 14px; opacity: .92; }
.today-title { display: block; margin: 4px 0; font-size: 22px; font-weight: 800; overflow-wrap: anywhere; }
.today-sub { display: block; font-size: 14px; opacity: .92; overflow-wrap: anywhere; }
.today-go {
  display: inline-block; margin-top: 10px;
  padding: 8px 14px; border-radius: 999px;
  background: rgba(255, 255, 255, .2);
  font-size: 15px; font-weight: 700;
}
.today.all-done { background: var(--pri-soft); color: var(--ink); box-shadow: none; }

.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin: 14px 0; }
.stat { padding: 10px 6px; background: #fff; border: 1px solid var(--line); border-radius: 14px; text-align: center; }
.stat-i { display: block; font-size: 18px; line-height: 1.2; }
.stat-v { display: block; font-size: 18px; font-weight: 800; overflow-wrap: anywhere; }
.stat-l { display: block; font-size: 12.5px; color: var(--muted); }

.recent { width: 100%; justify-content: flex-start; text-align: left; margin-bottom: 12px; }

.jump { margin: 0 0 16px; padding: 12px; background: #fff; border: 1px solid var(--line); border-radius: 14px; }
.jump label { display: block; margin-bottom: 6px; font-weight: 700; }
.jump-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.jump-row input {
  width: 110px; min-height: 44px;
  padding: 8px 10px;
  border: 1px solid var(--line); border-radius: 10px;
  background: #fff; font-size: 17px;
}

.section-title { margin: 18px 2px 8px; font-size: 18px; }

.week { margin-bottom: 8px; background: #fff; border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.week summary {
  list-style: none;
  display: flex; align-items: center; gap: 8px;
  min-height: 48px; padding: 10px 14px;
  font-weight: 700; cursor: pointer;
}
.week summary::-webkit-details-marker { display: none; }
.week summary::before { content: "▸"; color: var(--muted); transition: transform .15s; }
.week[open] summary::before { transform: rotate(90deg); }
.wk-title { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.wk-count { font-size: 13px; color: var(--muted); white-space: nowrap; }
.wk-count.full { color: var(--ok); }
.wk-days { border-top: 1px solid var(--line); }
.day-row {
  display: flex; align-items: center; gap: 10px;
  width: 100%; min-height: 48px;
  padding: 8px 14px;
  border: 0; border-bottom: 1px solid #eef1ec;
  background: #fff; text-align: left;
}
.day-row:last-child { border-bottom: 0; }
.day-row:active { background: var(--pri-soft); }
.day-row.current { background: #f3f9f7; }
.dnum { min-width: 58px; font-weight: 700; color: var(--pri); white-space: nowrap; }
.dtitle { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.dmark { min-width: 18px; color: var(--ok); font-weight: 800; text-align: center; }
.day-row.done .dtitle { color: var(--muted); }

/* ---------- 레슨 ---------- */
.scene { padding: 12px 14px; background: #fff; border: 1px solid var(--line); border-radius: 14px; }
.scene p { margin: 2px 0; overflow-wrap: anywhere; }
.scene-txt { font-size: 15px; }
.partner { font-size: 14px; color: var(--muted); }
.chip {
  margin-top: 8px;
  min-height: 44px; padding: 6px 12px;
  border: 1px solid var(--line); border-radius: 999px;
  background: var(--pri-soft); color: var(--pri-dark);
  font-size: 14px; font-weight: 600;
}

.tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin: 12px 0 8px; }
.tab {
  min-height: 46px;
  border: 1px solid var(--line); border-radius: 12px;
  background: #fff; font-size: 16px; font-weight: 700;
}
.tab.on { background: var(--pri); border-color: var(--pri); color: #fff; }

.seg {
  display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 4px;
  padding: 4px;
  background: #e7ebe5; border-radius: 12px;
}
.seg button {
  min-width: 0; min-height: 44px;
  padding: 6px 4px;
  border: 0; border-radius: 9px;
  background: transparent; color: var(--muted);
  font-size: 14px; font-weight: 600; line-height: 1.2;
  overflow-wrap: anywhere;
}
.seg button.on { background: #fff; color: var(--pri); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }
.seg .sub { display: block; font-size: 11.5px; font-weight: 500; }

.mode-help { margin: 6px 2px 8px; font-size: 13.5px; color: var(--muted); }

.toolbar { padding: 4px 0; background: var(--bg); }
.toolbar.sticky {
  position: sticky; top: var(--hdr); z-index: 20;
  box-shadow: 0 8px 8px -8px rgba(0, 0, 0, .18);
}
.tb-block { margin-bottom: 6px; padding: 10px; background: #fff; border: 1px solid var(--line); border-radius: 14px; }
.tb-label { margin-bottom: 6px; font-size: 14px; font-weight: 700; }
.tb-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.tb-block .seg, .tb-block .switch, .tb-block .seg + .tb-row, .tb-block .switch + .tb-row { margin-top: 8px; }
.tb-status { flex: 1 1 140px; min-width: 0; font-size: 14px; color: var(--muted); overflow-wrap: anywhere; }
.tb-status.big { display: block; margin-bottom: 8px; font-size: 16px; font-weight: 700; color: var(--ink); }
.tb-status.turn { color: var(--amber-ink); }

.hint { margin: 4px 2px 8px; font-size: 12.5px; color: var(--muted); }

.switch {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  min-height: 44px; cursor: pointer;
}
.switch input { width: 24px; height: 24px; flex: none; accent-color: var(--pri); }

/* 문장 카드 */
.lines { margin-top: 4px; }
.line {
  margin: 10px 0;
  padding: 14px;
  background: var(--card);
  border: 2px solid transparent; border-radius: 16px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .06);
  scroll-margin-top: calc(var(--hdr) + 16px);
  scroll-margin-bottom: 100px;
  transition: border-color .15s, background-color .15s;
}
.line.active { border-color: var(--pri); background: #f2f9f7; }
.line.playing .play { background: var(--pri-soft); border-color: var(--pri); }
.line.myturn { border-color: var(--amber); background: var(--amber-soft); }

.who { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; font-size: 13.5px; color: var(--muted); }
.role {
  display: inline-flex; align-items: center; justify-content: center;
  width: 26px; height: 26px; border-radius: 50%;
  font-weight: 800; font-size: 13px; color: #fff;
}
.role-a { background: #6b7f9e; }
.role-b { background: var(--pri); }
.who-name { font-weight: 600; }
.mine-tag, .turn-tag {
  padding: 2px 8px; border-radius: 999px;
  font-size: 12px; font-weight: 700;
}
.mine-tag { background: var(--pri-soft); color: var(--pri-dark); }
.turn-tag { display: none; background: var(--amber); color: #fff; }
.line.myturn .turn-tag { display: inline-block; }

.tgt {
  font-family: var(--ft);
  font-size: 24px; line-height: 1.55; font-weight: 500;
  color: var(--ink);
  overflow-wrap: anywhere;
}
.tgt[dir="rtl"] { text-align: right; }
.ko { margin-top: 6px; font-size: 16px; color: var(--muted); overflow-wrap: anywhere; }
.ko.ko-prompt { margin-top: 0; font-size: 18px; color: var(--ink); font-weight: 600; }
.ko-prompt + .tgt, .ko-prompt + .hidden-box { margin-top: 8px; }
.note {
  margin-top: 10px; padding: 8px 10px;
  background: #f4f5ef; border-radius: 10px;
  font-size: 14px; color: #44514d;
  overflow-wrap: anywhere;
}
.hidden-box {
  display: block; width: 100%; min-height: 56px;
  padding: 10px;
  border: 2px dashed #c6cfc8; border-radius: 12px;
  background: #fafbf8; color: var(--muted);
  font-size: 15px; font-weight: 600;
}
.acts { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.acts .btn { flex: 1 1 auto; }

/* 음성 인식 결과 */
.result { margin-top: 10px; padding: 10px; background: #f7f8f4; border-radius: 12px; font-size: 14px; }
.result.err { background: var(--bad-bg); color: var(--bad); }
.words { font-family: var(--ft); font-size: 20px; line-height: 1.8; overflow-wrap: anywhere; }
.words[dir="rtl"] { text-align: right; }
.w { padding: 1px 4px; border-radius: 6px; }
.w.ok { background: var(--ok-bg); color: var(--ok); }
.w.miss { background: var(--bad-bg); color: var(--bad); text-decoration: underline wavy rgba(179, 54, 44, .5); }
.w.neutral { color: var(--muted); }
.score { margin-top: 4px; font-weight: 700; }
.heard { margin-top: 2px; color: var(--muted); overflow-wrap: anywhere; }
.heard span { font-family: var(--ft); }

/* 하단 바 */
.bottombar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 25;
  display: grid; grid-template-columns: 56px minmax(0, 1fr) 56px; gap: 8px;
  padding: 8px max(12px, calc((100% - 640px) / 2 + 12px)) calc(8px + env(safe-area-inset-bottom));
  background: rgba(255, 255, 255, .97);
  border-top: 1px solid var(--line);
}
.bottombar .btn { min-height: 48px; padding: 6px 8px; font-size: 16px; }
.done-btn { background: var(--pri); border-color: var(--pri); color: #fff; }
.done-btn.is-done { background: var(--ok-bg); border-color: #b8dfc4; color: var(--ok); }

/* ---------- 모달 ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: flex-end; justify-content: center;
  background: rgba(20, 30, 28, .45);
}
.sheet {
  width: 100%; max-width: 560px;
  max-height: 90vh; max-height: 90dvh;
  overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 16px 16px calc(20px + env(safe-area-inset-bottom));
  background: #fff;
  border-radius: 18px 18px 0 0;
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.sheet-head h2 { margin: 0; font-size: 20px; }
.set-row { padding: 12px 0; border-bottom: 1px solid #eef1ec; }
.set-row:last-child { border-bottom: 0; }
.set-label { font-weight: 700; margin-bottom: 6px; }
.switch .set-label { margin-bottom: 0; }
.set-val { color: var(--pri); font-weight: 800; }
.set-row input[type="range"] { width: 100%; height: 44px; margin: 0; accent-color: var(--pri); }
.set-row h3 { margin: 0 0 8px; font-size: 16px; }
.set-row .btn + .btn, .set-row select + .btn { margin-top: 8px; }
.select {
  width: 100%; min-height: 44px;
  padding: 8px 10px;
  border: 1px solid var(--line); border-radius: 10px;
  background: #fff; font-size: 15px;
}

.gender-sheet { text-align: center; }
.gender-sheet h2 { margin: 4px 0 8px; }
.gender-sheet .q { font-size: 17px; margin: 0 0 16px; }
.g-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.btn.big { flex-direction: column; min-height: 88px; font-size: 18px; }
.btn.big .ex { font-family: var(--ft); font-size: 18px; font-weight: 500; color: var(--muted); }

@media (min-width: 600px) {
  .overlay { align-items: center; }
  .sheet { border-radius: 18px; }
}

/* ---------- 토스트 ---------- */
#toast {
  position: fixed; left: 50%; z-index: 60;
  bottom: calc(84px + env(safe-area-inset-bottom));
  max-width: calc(100% - 32px);
  padding: 10px 16px; border-radius: 999px;
  background: rgba(34, 48, 45, .92); color: #fff;
  font-size: 15px; text-align: center;
  transform: translate(-50%, 20px); opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* 음성 안내: 한 줄로 접기 */
details.vhelp summary { cursor: pointer; font-size: 14px; line-height: 1.4; padding-right: 28px; }
details.vhelp ul { margin: 6px 0 0; padding-left: 18px; }
details.vhelp .small { margin: 6px 0 0; }
