/* 모바일 우선 레이아웃. 데스크톱에서는 가운데 정렬된 넓은 화면으로 확장된다. */
:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surfaceAlt: #eef2f8;
  --text: #16202e;
  --textMuted: #5b6a80;
  --border: #dde4ee;
  --accent: #1f3a5f;
  --accentSoft: #e5edf9;
  --known: #1f7a4d;
  --knownSoft: #e2f4ea;
  --unsure: #a86a12;
  --unsureSoft: #fbf0dc;
  --unknown: #b23a3a;
  --unknownSoft: #fbe4e4;
  --shadow: 0 2px 10px rgba(22, 32, 46, 0.07);
  --radius: 14px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11161f;
    --surface: #1a212d;
    --surfaceAlt: #222b39;
    --text: #e7edf6;
    --textMuted: #9aa8bd;
    --border: #2c3646;
    --accent: #7fb0f0;
    --accentSoft: #1e2c40;
    --known: #6cd39a;
    --knownSoft: #16301f;
    --unsure: #e5b567;
    --unsureSoft: #33280f;
    --unknown: #f08a8a;
    --unknownSoft: #3a1c1c;
    --shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
  }
}

* { box-sizing: border-box; }

/* display를 직접 지정한 요소에서도 hidden 속성이 항상 통하도록 한다. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Pretendard", "Malgun Gothic", "맑은 고딕", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: contain;
}

h1, h2, h3 { margin: 0; line-height: 1.3; }
button { font-family: inherit; cursor: pointer; }

/* ---------- 헤더 ---------- */
.appHeader {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(env(safe-area-inset-top, 0px) + 14px) 16px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.appHeader__title h1 { font-size: 19px; letter-spacing: -0.02em; }
.appHeader__title p { margin: 2px 0 0; font-size: 13px; color: var(--textMuted); }

.syncBadge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 11px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surfaceAlt);
  color: var(--textMuted);
  font-size: 12px;
  white-space: nowrap;
}
.syncBadge__dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--textMuted);
  flex: none;
}
.syncBadge--online .syncBadge__dot { background: var(--known); }
.syncBadge--local .syncBadge__dot { background: var(--unsure); }
.syncBadge--syncing .syncBadge__dot { background: var(--accent); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: 0.3; } }

/* ---------- 레이아웃 ---------- */
.appMain {
  max-width: 760px;
  margin: 0 auto;
  padding: 16px 16px calc(env(safe-area-inset-bottom, 0px) + 88px);
}
.view { display: none; }
.view--active { display: block; animation: fadeIn 0.18s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } }

/* ---------- 난이도 선택 ---------- */
.levelPicker {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}
.levelPicker__item {
  padding: 12px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--textMuted);
  font-size: 15px;
  font-weight: 600;
  transition: all 0.15s;
}
.levelPicker__item--active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
@media (prefers-color-scheme: dark) {
  .levelPicker__item--active { color: #11161f; }
}

/* ---------- 진행 카드 ---------- */
.progressCard {
  padding: 14px 16px;
  margin-bottom: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.progressCard__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 14px;
  font-weight: 600;
}
.progressBar {
  height: 7px;
  margin: 10px 0;
  background: var(--surfaceAlt);
  border-radius: 999px;
  overflow: hidden;
}
.progressBar__fill {
  height: 100%;
  width: 0;
  background: var(--accent);
  border-radius: 999px;
  transition: width 0.3s ease;
}
.progressCard__stats { display: flex; gap: 6px; flex-wrap: wrap; }

.chip {
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  background: var(--surfaceAlt);
  color: var(--textMuted);
}
.chip--known { background: var(--knownSoft); color: var(--known); }
.chip--unsure { background: var(--unsureSoft); color: var(--unsure); }
.chip--unknown { background: var(--unknownSoft); color: var(--unknown); }

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--textMuted);
  cursor: pointer;
}
.toggle--block { display: flex; margin-bottom: 6px; }
.toggle input { width: 16px; height: 16px; accent-color: var(--accent); }

/* ---------- 전체 듣기 ---------- */
.playAll {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 11px 13px;
  margin-bottom: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.playAll__main {
  padding: 10px 18px;
  border: 1px solid var(--accent);
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 14px;
  font-weight: 700;
}
@media (prefers-color-scheme: dark) { .playAll__main { color: #11161f; } }
.playAll__main--active {
  background: var(--unknownSoft);
  border-color: var(--unknown);
  color: var(--unknown);
}
@media (prefers-color-scheme: dark) { .playAll__main--active { color: var(--unknown); } }

.playAll__toggle {
  padding: 9px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--textMuted);
  font-size: 13px;
  font-weight: 600;
}
.playAll__toggle--active {
  background: var(--accentSoft);
  border-color: var(--accent);
  color: var(--accent);
}
.playAll__status {
  flex: 1;
  min-width: 120px;
  font-size: 12.5px;
  color: var(--textMuted);
  text-align: right;
}

/* ---------- 문장 카드 ---------- */
.cardList { display: flex; flex-direction: column; gap: 10px; }

.sentenceCard {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  transition: border-color 0.15s;
}
.sentenceCard--known { border-left-color: var(--known); }
.sentenceCard--unsure { border-left-color: var(--unsure); }
.sentenceCard--unknown { border-left-color: var(--unknown); }

/* 전체 듣기에서 지금 읽고 있는 문장 */
.sentenceCard--playing {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accentSoft), var(--shadow);
}
.sentenceCard--playing .sentenceCard__index {
  background: var(--accent);
  color: #fff;
}
@media (prefers-color-scheme: dark) {
  .sentenceCard--playing .sentenceCard__index { color: #11161f; }
}

.sentenceCard__head {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  width: 100%;
  padding: 14px 15px;
  border: 0;
  background: none;
  text-align: left;
  color: inherit;
}
.sentenceCard__index {
  flex: none;
  width: 24px; height: 24px;
  margin-top: 2px;
  border-radius: 50%;
  background: var(--surfaceAlt);
  color: var(--textMuted);
  font-size: 12px;
  font-weight: 700;
  display: grid;
  place-items: center;
}
.sentenceCard__text { flex: 1; min-width: 0; }
.sentenceCard__en {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 17px;
  line-height: 1.45;
  letter-spacing: -0.005em;
}
.sentenceCard__ko {
  margin: 5px 0 0;
  font-size: 14px;
  color: var(--textMuted);
}
.sentenceCard__ko--hidden {
  filter: blur(5px);
  cursor: pointer;
  user-select: none;
}
.sentenceCard__meta {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  flex-wrap: wrap;
}
.sentenceCard__caret { flex: none; color: var(--textMuted); font-size: 13px; margin-top: 4px; }

.sentenceCard__body {
  display: none;
  padding: 0 15px 15px;
  border-top: 1px solid var(--border);
}
.sentenceCard--open .sentenceCard__body { display: block; }
.sentenceCard--open .sentenceCard__caret { transform: rotate(180deg); }

.detailBlock { margin-top: 14px; }
.detailBlock__label {
  display: inline-block;
  margin-bottom: 5px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--accent);
  text-transform: uppercase;
}
.detailBlock__text { margin: 0; font-size: 14px; color: var(--text); }

.wordCard {
  padding: 11px 13px;
  margin-top: 8px;
  background: var(--surfaceAlt);
  border-radius: 10px;
}
.wordCard__head {
  display: flex;
  align-items: baseline;
  gap: 7px;
  flex-wrap: wrap;
}
.wordCard__word {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 16px;
  font-weight: 700;
}
.wordCard__pos {
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--accentSoft);
  color: var(--accent);
  font-size: 11px;
  font-weight: 600;
}
.wordCard__meaning { font-size: 14px; font-weight: 600; }
.wordCard__line { margin: 5px 0 0; font-size: 13px; color: var(--textMuted); }
.wordCard__line b { color: var(--text); font-weight: 600; }
.wordCard__example {
  margin: 6px 0 0;
  padding-left: 9px;
  border-left: 2px solid var(--border);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 13px;
  color: var(--textMuted);
}

.markRow {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 7px;
  margin-top: 15px;
}
.markButton {
  padding: 11px 6px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--textMuted);
  font-size: 14px;
  font-weight: 600;
  transition: all 0.12s;
}
.markButton--known.markButton--active { background: var(--knownSoft); border-color: var(--known); color: var(--known); }
.markButton--unsure.markButton--active { background: var(--unsureSoft); border-color: var(--unsure); color: var(--unsure); }
.markButton--unknown.markButton--active { background: var(--unknownSoft); border-color: var(--unknown); color: var(--unknown); }

.speakRow { display: flex; gap: 7px; flex-wrap: wrap; }

.speakButton {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--textMuted);
  font-size: 12.5px;
  font-weight: 600;
  transition: all 0.12s;
}
.speakButton:hover { border-color: var(--accent); color: var(--accent); }

/* 반복 재생 중인 버튼은 눈에 띄게 표시한다. */
.speakButton--active {
  background: var(--accentSoft);
  border-color: var(--accent);
  color: var(--accent);
}
.speakButton--active::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse 1.1s infinite;
}

/* ---------- 설정: 라벨과 단계 조절 ---------- */
.settingLabel {
  margin: 14px 0 7px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}
.settingCard .settingLabel:first-of-type { margin-top: 4px; }

.stepper {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 9px;
}
.stepper__button {
  width: 38px;
  height: 38px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font-size: 18px;
  font-weight: 600;
  line-height: 1;
}
.stepper__button:disabled { opacity: 0.35; cursor: default; }
.stepper__value {
  min-width: 66px;
  text-align: center;
  font-size: 15px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* ---------- 복습 / 기록 ---------- */
.reviewHead { margin-bottom: 14px; }
.reviewHead h2 { font-size: 20px; }
.reviewHead p { margin: 4px 0 0; font-size: 14px; color: var(--textMuted); }

.segmented {
  display: grid;
  /* 버튼 개수에 맞춰 칸을 나눈다(복습 탭은 3개, 음성 설정은 2개). */
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 4px;
  padding: 4px;
  margin-bottom: 12px;
  background: var(--surfaceAlt);
  border-radius: 11px;
}
.segmented__item {
  padding: 9px 6px;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--textMuted);
  font-size: 14px;
  font-weight: 600;
}
.segmented__item--active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.flashcardBar { margin-bottom: 12px; }

.streakBoard {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 13px;
  margin-bottom: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.streakBoard__cell {
  width: 15px; height: 15px;
  border-radius: 3px;
  background: var(--surfaceAlt);
}
.streakBoard__cell--low { background: color-mix(in srgb, var(--accent) 30%, var(--surfaceAlt)); }
.streakBoard__cell--mid { background: color-mix(in srgb, var(--accent) 60%, var(--surfaceAlt)); }
.streakBoard__cell--high { background: var(--accent); }

.logList { display: flex; flex-direction: column; gap: 8px; }
.logItem {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  padding: 13px 15px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: inherit;
  text-align: left;
}
.logItem__date { font-size: 15px; font-weight: 600; }
.logItem__meta { font-size: 12px; color: var(--textMuted); }

/* ---------- 설정 ---------- */
.settingCard {
  padding: 15px;
  margin-bottom: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.settingCard h3 { font-size: 15px; margin-bottom: 6px; }
.settingCard__detail { margin: 0 0 11px; font-size: 13px; color: var(--textMuted); }

.addressBox {
  padding: 12px;
  margin-bottom: 11px;
  background: var(--accentSoft);
  border-radius: 10px;
  font-size: 13px;
}
.addressBox p { margin: 0 0 8px; }
.addressBox__list { display: flex; flex-direction: column; gap: 6px; }
.addressBox__item {
  padding: 8px 11px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: "Consolas", "Menlo", monospace;
  font-size: 14px;
  word-break: break-all;
}

.buttonRow { display: flex; gap: 7px; flex-wrap: wrap; }

.primaryButton, .ghostButton, .dangerButton {
  padding: 11px 16px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  border: 1px solid transparent;
}
.primaryButton { width: 100%; background: var(--accent); color: #fff; }
@media (prefers-color-scheme: dark) { .primaryButton { color: #11161f; } }
.ghostButton { background: var(--surface); border-color: var(--border); color: var(--text); }
.dangerButton { background: var(--unknownSoft); border-color: var(--unknown); color: var(--unknown); width: 100%; }

.noteBox { margin-top: 16px; }
.noteBox label { display: block; margin-bottom: 6px; font-size: 13px; font-weight: 600; color: var(--textMuted); }
.noteBox textarea {
  width: 100%;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  resize: vertical;
}
#newSetButton { width: 100%; margin-top: 12px; }

.emptyState {
  padding: 34px 18px;
  text-align: center;
  color: var(--textMuted);
  font-size: 14px;
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

.versionText { text-align: center; font-size: 12px; color: var(--textMuted); }

/* ---------- 탭바 ---------- */
.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: var(--surface);
  border-top: 1px solid var(--border);
}
.tabbar__item {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 9px 4px 10px;
  border: 0;
  background: none;
  color: var(--textMuted);
  font-size: 11px;
  font-weight: 600;
}
.tabbar__item--active { color: var(--accent); }
.tabbar__icon { font-size: 19px; line-height: 1; }
.tabbar__badge {
  position: absolute;
  top: 5px;
  right: calc(50% - 22px);
  min-width: 17px;
  padding: 1px 5px;
  border-radius: 999px;
  background: var(--unknown);
  color: #fff;
  font-size: 10px;
  line-height: 1.5;
}

/* ---------- 모달 ---------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(10, 14, 20, 0.55);
  backdrop-filter: blur(2px);
}
.modal__panel {
  width: 100%;
  max-width: 420px;
  max-height: 86vh;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-radius: 18px;
  overflow: hidden;
}
.modal__panel--wide { max-width: 720px; }
.modal__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  font-weight: 600;
  color: var(--textMuted);
}
.iconButton {
  border: 0;
  background: none;
  color: var(--textMuted);
  font-size: 16px;
  padding: 2px 6px;
}
.modal__actions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 7px;
  padding: 13px;
  border-top: 1px solid var(--border);
}

.flashcard {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 14px;
  min-height: 230px;
  padding: 26px 22px;
  text-align: center;
  cursor: pointer;
}
.flashcard__en {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 21px;
  line-height: 1.5;
}
.flashcard__ko { margin: 0; font-size: 15px; color: var(--textMuted); }
.flashcard__hint { margin: 0; font-size: 12px; color: var(--textMuted); }

.logPreview {
  margin: 0;
  padding: 16px;
  overflow: auto;
  font-family: "Consolas", "Menlo", monospace;
  font-size: 12.5px;
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ---------- 토스트 ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 78px);
  z-index: 60;
  transform: translateX(-50%);
  padding: 10px 18px;
  border-radius: 999px;
  background: var(--text);
  color: var(--bg);
  font-size: 13px;
  font-weight: 600;
  box-shadow: var(--shadow);
  animation: toastIn 0.2s ease;
}
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 8px); } }

/* ---------- 데스크톱 ---------- */
@media (min-width: 720px) {
  /* 탭바를 본문 위로 올려 상단 내비게이션처럼 쓴다. */
  body { display: flex; flex-direction: column; min-height: 100vh; }
  .appHeader { order: 1; position: static; }
  .tabbar { order: 2; }
  .appMain { order: 3; }

  .appHeader {
    width: 100%;
    max-width: 792px;
    margin: 0 auto;
    border-bottom: 0;
    background: transparent;
    padding-top: 22px;
  }

  .tabbar {
    position: sticky;
    top: 0;
    bottom: auto;
    width: 100%;
    max-width: 792px;
    margin: 0 auto 4px;
    padding: 0 16px;
    border-top: 0;
    border-bottom: 1px solid var(--border);
    background: var(--bg);
  }
  .tabbar__item { flex-direction: row; gap: 7px; font-size: 14px; padding: 13px 12px; }
  .tabbar__item--active { box-shadow: inset 0 -2px 0 var(--accent); }
  .tabbar__icon { font-size: 16px; }
  .tabbar__badge { position: static; margin-left: 2px; }

  .appMain { padding-top: 18px; padding-bottom: 48px; }
  .sentenceCard__en { font-size: 19px; }
}
