:root {
  --bg: #f6f4ef;
  --card: #ffffff;
  --ink: #1f2a24;
  --sub: #5f6b64;
  --line: #e3e0d8;
  --brand: #2f6b4f;
  --brand-ink: #ffffff;
  --brand-soft: #e3efe8;
  --accent: #d9463b;
  --mark: #d8f37a;
  --ok: #2e8b57;
  --bad: #c0392b;
  --shadow: 0 1px 2px rgba(20,40,30,.05), 0 6px 20px rgba(20,40,30,.06);
  --hero: linear-gradient(135deg, #2f6b4f 0%, #3d8a65 100%);
  --hero-ink: #ffffff;
  --radius: 18px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #151a17; --card: #1f2622; --ink: #e8ece9; --sub: #9aa6a0; --line: #2f3833;
    --brand: #5fb58a; --brand-ink: #0e1511; --brand-soft: #243a2f; --accent: #ff7a6e;
    --mark: #4b5e17; --ok: #5fcf8f; --bad: #ff7a6e; --shadow: none; color-scheme: dark;
    --hero: linear-gradient(135deg, #1f4a36 0%, #2a6048 100%); --hero-ink: #eaf5ef;
  }
}
:root[data-theme="dark"] {
  --bg: #151a17; --card: #1f2622; --ink: #e8ece9; --sub: #9aa6a0; --line: #2f3833;
  --brand: #5fb58a; --brand-ink: #0e1511; --brand-soft: #243a2f; --accent: #ff7a6e;
  --mark: #4b5e17; --ok: #5fcf8f; --bad: #ff7a6e; --shadow: none; color-scheme: dark;
  --hero: linear-gradient(135deg, #1f4a36 0%, #2a6048 100%); --hero-ink: #eaf5ef;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--ink);
  font: 16px/1.55 "Pretendard Variable", "Pretendard", "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", "Noto Sans JP", "PingFang SC", "Microsoft YaHei", "Noto Sans SC", system-ui, sans-serif;
  padding-bottom: calc(96px + env(safe-area-inset-bottom));
  letter-spacing: -0.01em;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand); }
/* .btn 등의 display 지정이 hidden 속성을 덮어쓰지 않게 한다 */
[hidden] { display: none !important; }

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 8px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--bg); border-bottom: 1px solid var(--line);
}
.topbar h1 { font-size: 18px; font-weight: 800; margin: 0; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: flex; align-items: center; gap: 8px; }
/* 위쪽 언어 선택: 보이는 건 알약 버튼, 누르면 기기 기본 선택창이 열린다 */
.lang-pick { position: relative; display: inline-flex; align-items: center; gap: 4px; flex: none; border: 1px solid var(--line); background: var(--card); color: var(--ink); border-radius: 999px; padding: 5px 10px; font-size: 13px; font-weight: 700; cursor: pointer; }
.lang-pick select { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; font-size: 16px; padding: 0; border: 0; }
.brand-mark { width: 28px; height: 28px; border-radius: 9px; background: var(--brand); color: var(--brand-ink); display: inline-flex; align-items: center; justify-content: center; flex: none; }
.back { border: 0; background: none; line-height: 0; padding: 4px 4px 4px 0; margin-left: -6px; cursor: pointer; color: var(--ink); }

main { max-width: 720px; margin: 0 auto; padding: 16px; }

.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0; font-size: 12px; font-weight: 600; color: var(--sub); text-decoration: none; }
.tabbar .ti { width: 56px; height: 30px; border-radius: 999px; display: flex; align-items: center; justify-content: center; transition: background-color .2s; }
.tabbar a.on { color: var(--brand); font-weight: 800; }
.tabbar a.on .ti { background: var(--brand-soft); }
.tabbar a.on .ic { stroke-width: 2.4; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; box-shadow: var(--shadow); }
.muted { color: var(--sub); font-size: 14px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }
h2 { font-size: 17px; margin: 22px 0 10px; }
h2:first-child { margin-top: 4px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line); background: var(--card); border-radius: 12px;
  padding: 9px 14px; cursor: pointer; font-weight: 600; font-size: 15px; text-decoration: none; color: var(--ink);
}
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.btn.big { width: 100%; padding: 15px; font-size: 16px; border-radius: 14px; gap: 8px; }
.btn.danger-fill { background: var(--bad); color: #fff; border-color: var(--bad); }
.btn.small { padding: 5px 10px; font-size: 13px; border-radius: 8px; }
.btn.danger { color: var(--bad); }
.btn:disabled { opacity: .5; cursor: default; }
.chip-btn { display: inline-flex; align-items: center; gap: 4px; flex: none; border: 1px solid var(--brand); color: var(--brand); background: transparent; border-radius: 999px; padding: 5px 12px; font-size: 13px; font-weight: 700; cursor: pointer; }
.icon-btn { border: 0; background: var(--brand-soft); color: var(--ink); border-radius: 999px; width: 38px; height: 38px; font-size: 17px; cursor: pointer; flex: none; display: inline-flex; align-items: center; justify-content: center; }
.icon-btn.star.on { background: #ffe9a8; }

.upload-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 8px; }
.upload-grid label { cursor: pointer; }
.upload-grid input { display: none; }

.ic { display: block; flex: none; }

/* 홈: 배너 */
.banner-link { display: flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; }
.banner-link .ic { color: var(--brand); }

/* 홈: 오늘의 학습 카드 */
.hero { background: var(--hero); color: var(--hero-ink); border-radius: 22px; padding: 18px; margin: 2px 0 26px; box-shadow: 0 10px 28px rgba(47,107,79,.22); }
.hero-top { display: flex; align-items: center; gap: 12px; }
.streak { width: 44px; height: 44px; border-radius: 14px; background: rgba(255,255,255,.16); display: flex; align-items: center; justify-content: center; flex: none; }
.streak.on { background: #ffb547; color: #7a3d00; }
.hero-title { font-size: 19px; font-weight: 800; line-height: 1.3; }
.hero-sub { font-size: 13px; opacity: .85; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); margin: 16px 0 14px; background: rgba(255,255,255,.1); border-radius: 14px; padding: 10px 0; }
.stats div { display: flex; flex-direction: column; align-items: center; }
.stats div + div { border-left: 1px solid rgba(255,255,255,.18); }
.stats b { font-size: 20px; font-weight: 800; line-height: 1.2; }
.stats span { font-size: 12px; opacity: .8; }
.hero-btn { width: 100%; padding: 13px; gap: 8px; background: #fff; color: #1f4a36; border: 0; border-radius: 14px; font-size: 15px; font-weight: 800; }

/* 홈: 목록 */
.list-head { display: flex; align-items: center; gap: 4px; margin: 0 0 6px; }
.list-head h2 { flex: 1; margin: 0; font-size: 18px; font-weight: 800; }
.count { color: var(--brand); font-weight: 800; margin-left: 4px; }
.text-btn { display: inline-flex; align-items: center; gap: 4px; border: 0; background: none; color: var(--sub); font-size: 14px; font-weight: 600; padding: 6px 8px; border-radius: 8px; cursor: pointer; }
.text-btn:active { background: var(--brand-soft); }
.chips { display: flex; gap: 6px; overflow-x: auto; margin: 8px -16px 0; padding: 0 16px 2px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; border: 1px solid var(--line); background: var(--card); color: var(--sub); border-radius: 999px; padding: 6px 14px; font-size: 14px; font-weight: 600; cursor: pointer; }
.chip.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.day { margin-top: 18px; }
.day:last-of-type { margin-bottom: 76px; }
.day-head { display: flex; align-items: baseline; gap: 6px; font-size: 15px; font-weight: 800; margin: 0 4px 8px; }
.day-head small { font-size: 13px; font-weight: 500; color: var(--sub); }
.day-head .count { margin-left: auto; font-size: 13px; color: var(--sub); font-weight: 600; }
.day-list { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.page-item { display: flex; gap: 14px; align-items: center; padding: 12px 12px 12px 14px; text-decoration: none; color: inherit; }
.page-item + .page-item { border-top: 1px solid var(--line); }
.page-item:active { background: var(--bg); }
.page-item img { width: 52px; height: 68px; object-fit: cover; border-radius: 10px; border: 1px solid var(--line); flex: none; background: var(--line); }
.pi-body { flex: 1; min-width: 0; }
.page-item .t { font-weight: 700; font-size: 16px; line-height: 1.4; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; word-break: keep-all; overflow-wrap: anywhere; }
.pi-meta { display: flex; align-items: center; gap: 6px; margin-top: 5px; font-size: 13px; color: var(--sub); }
.pi-time { margin-left: auto; font-variant-numeric: tabular-nums; }
.pi-go { color: var(--sub); opacity: .5; flex: none; }
.page-item.error .t { color: var(--sub); }
.badge { display: inline-block; font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--brand-soft); color: var(--brand); }
.badge.err { background: #fde2df; color: #b3261e; }
:root[data-theme="dark"] .badge.err { background: #4a2320; color: #ff9d94; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .badge.err { background: #4a2320; color: #ff9d94; } }

/* 홈: 처음 화면 */
.empty-hero { text-align: center; padding: 36px 8px 8px; }
.empty-icon { width: 88px; height: 88px; margin: 0 auto 18px; border-radius: 28px; background: var(--brand-soft); color: var(--brand); display: flex; align-items: center; justify-content: center; }
.empty-hero h2 { font-size: 20px; font-weight: 800; margin: 0 0 8px; }
.empty-hero p { color: var(--sub); font-size: 15px; margin: 0 0 24px; }
.empty-hero .upload-grid { grid-template-columns: 1fr; }

/* 떠 있는 올리기 버튼 */
.fab { position: fixed; right: max(18px, calc(50vw - 342px)); bottom: calc(84px + env(safe-area-inset-bottom)); z-index: 11; width: 60px; height: 60px; border-radius: 20px; border: 0; background: var(--brand); color: var(--brand-ink); display: flex; align-items: center; justify-content: center; box-shadow: 0 8px 22px rgba(47,107,79,.38); cursor: pointer; }
.fab:active { transform: scale(.95); }

/* 아래에서 올라오는 메뉴 */
.sheet-wrap { position: fixed; inset: 0; z-index: 30; background: rgba(0,0,0,0); display: flex; align-items: flex-end; justify-content: center; transition: background-color .2s; }
.sheet-wrap.show { background: rgba(0,0,0,.4); }
.sheet { width: 100%; max-width: 720px; background: var(--card); border-radius: 24px 24px 0 0; padding: 8px 16px calc(20px + env(safe-area-inset-bottom)); transform: translateY(100%); transition: transform .25s ease-out; }
.sheet-wrap.show .sheet { transform: none; }
.sheet-handle { width: 40px; height: 4px; border-radius: 99px; background: var(--line); margin: 4px auto 14px; }
.sheet h3 { margin: 0 4px 10px; font-size: 18px; font-weight: 800; }
.sheet-item { display: flex; align-items: center; gap: 14px; padding: 12px 8px; border-radius: 14px; cursor: pointer; }
.sheet-item:active { background: var(--bg); }
.sheet-item input { display: none; }
.sheet-item b { display: block; font-size: 16px; }
.sheet-item small { display: block; color: var(--sub); font-size: 13px; }
.si-icon { width: 48px; height: 48px; border-radius: 14px; background: var(--brand-soft); color: var(--brand); display: flex; align-items: center; justify-content: center; flex: none; }
.si-icon.primary { background: var(--brand); color: var(--brand-ink); }
.sheet-tip { margin: 8px 8px 0; font-size: 13px; color: var(--sub); }

/* 선택 삭제 막대 */
.sel-bar { position: fixed; left: 0; right: 0; bottom: calc(62px + env(safe-area-inset-bottom)); z-index: 11; padding: 10px 16px; background: linear-gradient(transparent, var(--bg) 30%); }
.sel-bar .btn { max-width: 688px; margin: 0 auto; display: flex; }
.spinner { width: 18px; height: 18px; border: 3px solid var(--brand-soft); border-top-color: var(--brand); border-radius: 50%; animation: spin 1s linear infinite; display: inline-block; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }

.toolbar { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.toggle { border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 5px 12px; font-size: 13px; cursor: pointer; }
.toggle.on { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }

.sent .num { font-size: 12px; color: var(--sub); font-weight: 700; }
.sent .fl { font-size: 23px; line-height: 1.45; font-weight: 600; word-break: keep-all; overflow-wrap: anywhere; }
.sent .reading { font-size: 14px; color: var(--sub); }
.sent .pron { font-size: 16px; color: var(--brand); font-weight: 600; margin-top: 2px; }
.sent .ko { font-size: 15px; margin-top: 4px; }
.sent .note { font-size: 13px; color: var(--sub); background: var(--bg); border-radius: 8px; padding: 6px 10px; margin-top: 8px; }
.sent .actions { display: flex; gap: 6px; margin-top: 10px; }
mark { background: var(--mark); color: inherit; border-radius: 3px; padding: 0 1px; }
.hide-pron .pron, .hide-reading .reading, .hide-ko .ko, .hide-ko .w-mean { display: none; }
.cover-ko .ko, .cover-ko .w-mean { filter: blur(6px); cursor: pointer; user-select: none; }
.cover-ko .ko.shown, .cover-ko .w-mean.shown { filter: none; }

.words { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.word { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); border-radius: 10px; padding: 4px 4px 4px 10px; background: var(--bg); }
.word .w { font-weight: 700; cursor: pointer; }
.word .w small { font-weight: 400; color: var(--sub); }
.word .w-mean { font-size: 13px; }
.word .icon-btn { width: 28px; height: 28px; font-size: 13px; }

.vocab { width: 100%; border-collapse: collapse; }
.vocab td { padding: 9px 4px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.vocab tr:last-child td { border-bottom: 0; }
.vocab .w { font-weight: 700; font-size: 17px; }
.vocab .hl { display: inline-block; background: var(--mark); border-radius: 3px; padding: 0 3px; }

.page-img { width: 100%; border-radius: 10px; border: 1px solid var(--line); display: block; }
details summary { cursor: pointer; font-weight: 600; }

.tabs { display: flex; gap: 6px; margin-bottom: 12px; }
input[type=text], input[type=password], input[type=search], select, textarea {
  width: 100%; border: 1px solid var(--line); background: var(--card); border-radius: 10px; padding: 10px 12px;
}
textarea { min-height: 70px; resize: vertical; }
label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: 14px; font-weight: 600; margin-bottom: 4px; }

.quiz .prompt { font-size: 24px; font-weight: 700; line-height: 1.45; margin: 6px 0 4px; word-break: keep-all; overflow-wrap: anywhere; }
.quiz .answer { border-top: 1px dashed var(--line); margin-top: 12px; padding-top: 12px; }
.quiz .answer .fl { font-size: 22px; font-weight: 700; }
.score { font-weight: 800; font-size: 18px; }
.score.good { color: var(--ok); } .score.mid { color: #c98a00; } .score.low { color: var(--bad); }
.progress { height: 6px; background: var(--line); border-radius: 99px; overflow: hidden; margin-bottom: 12px; }
.progress > div { height: 100%; background: var(--brand); }
.mic.on { background: var(--accent); color: #fff; animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .6; } }

.choice { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.choice .btn { width: 100%; }
.seg { display: flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button { flex: 1; border: 0; background: var(--card); padding: 9px 4px; cursor: pointer; font-size: 14px; }
.seg button.on { background: var(--brand); color: var(--brand-ink); font-weight: 700; }

.empty { text-align: center; padding: 30px 10px; color: var(--sub); }
.banner { background: var(--brand-soft); border-radius: 14px; padding: 12px 14px; margin-bottom: 12px; font-size: 14px; }

#toast { position: fixed; left: 50%; bottom: calc(86px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: #222; color: #fff; padding: 9px 16px; border-radius: 999px; font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .2s; max-width: 90vw; z-index: 20; }
#toast.show { opacity: .95; }
.sel-box { width: 22px; height: 22px; flex: none; accent-color: var(--bad); }
label.page-item { cursor: pointer; }
.page-item:has(.sel-box:checked) { background: var(--brand-soft); }

/* 읽는 부분 표시 */
.card.playing { border-color: var(--brand); box-shadow: 0 0 0 2px var(--brand); transition: box-shadow .2s; }
.fl .ch { transition: color .15s, background-color .15s; border-radius: 3px; }
.fl .ch.said { color: var(--brand); }
.fl .ch.now { background: #ffd54f; color: #1f2a24; box-shadow: 0 2px 0 #e0a800; }
