:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --card-2: #eef0f4;
  --text: #16181d;
  --muted: #6b7280;
  --line: #e2e5ea;
  --accent: #3b5bdb;
  --accent-soft: #e5eaff;
  --good: #12a150;
  --good-soft: #e3f6ea;
  --bad: #e03131;
  --bad-soft: #fde8e8;
  --warn: #e8590c;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0,0,0,.05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #16181d; --card: #23262d; --card-2: #2c3038; --text: #f1f3f5; --muted: #9aa1ad;
    --line: #353a44; --accent: #7c95ff; --accent-soft: #2b3358; --good: #40c977; --good-soft: #1e3a2a;
    --bad: #ff6b6b; --bad-soft: #4a2526; --warn: #ffa94d; --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #16181d; --card: #23262d; --card-2: #2c3038; --text: #f1f3f5; --muted: #9aa1ad;
  --line: #353a44; --accent: #7c95ff; --accent-soft: #2b3358; --good: #40c977; --good-soft: #1e3a2a;
  --bad: #ff6b6b; --bad-soft: #4a2526; --warn: #ffa94d; --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font-family: "Pretendard", "Apple SD Gothic Neo", "Malgun Gothic", system-ui, sans-serif;
  font-size: 16px; line-height: 1.5;
  padding-bottom: calc(68px + env(safe-area-inset-bottom));
  -webkit-tap-highlight-color: transparent;
}
button, input, textarea, select { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  height: 54px; padding: 0 16px;
  background: var(--bg); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 800; font-size: 18px; letter-spacing: -.3px; }
.top-actions { display: flex; gap: 4px; }
.icon-btn {
  border: 0; background: transparent; cursor: pointer;
  width: 40px; height: 40px; border-radius: 10px; font-size: 18px; color: var(--muted);
  display: inline-flex; align-items: center; justify-content: center;
}
.icon-btn:hover { background: var(--card-2); color: var(--text); }
.icon-btn.on { color: var(--warn); }

main { max-width: 640px; margin: 0 auto; padding: 16px; outline: none; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center;
  height: 60px; font-size: 12px; color: var(--muted); gap: 2px;
}
.tabbar a .ti { font-size: 20px; line-height: 1; }
.tabbar a.active { color: var(--accent); font-weight: 700; }
.tabbar em {
  position: absolute; top: 6px; left: calc(50% + 6px);
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--bad); color: #fff; font-style: normal; font-size: 11px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}

h1 { font-size: 22px; margin: 4px 0 16px; letter-spacing: -.4px; }
h2 { font-size: 16px; margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

.card {
  background: var(--card); border-radius: var(--radius); padding: 16px;
  margin-bottom: 12px; box-shadow: var(--shadow); border: 1px solid var(--line);
}
.card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.card-head h2 { margin: 0; }

.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.stat { background: var(--card-2); border-radius: 12px; padding: 12px; }
.stat b { display: block; font-size: 22px; letter-spacing: -.5px; }
.stat span { font-size: 13px; color: var(--muted); }

.streak { display: flex; align-items: center; gap: 10px; font-weight: 700; }
.goal { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line); }
.goal-head { display: flex; justify-content: space-between; align-items: baseline; font-size: 14px; margin-bottom: 8px; }
.goal-head span { color: var(--muted); font-size: 13px; }
.goal-bar { height: 10px; border-radius: 5px; background: var(--card-2); overflow: hidden; }
.goal-bar > i { display: block; height: 100%; background: var(--accent); border-radius: 5px; transition: width .3s; }
.goal-bar.done > i { background: var(--good); }

/* 틀린 단어 카드 넘기기 */
.card-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.wc { text-align: center; padding: 28px 16px 20px; touch-action: pan-y; user-select: none; }
.wc-word { font-size: 36px; font-weight: 800; letter-spacing: -.5px; word-break: break-word; }
.wc-mean { font-size: 20px; font-weight: 700; margin-top: 12px; }
.streak .fire { font-size: 26px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line); background: var(--card); color: var(--text);
  min-height: 44px; padding: 0 16px; border-radius: 12px; cursor: pointer; font-weight: 600;
}
.btn:hover { background: var(--card-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.05); }
.btn.good { background: var(--good); border-color: var(--good); color: #fff; }
.btn.bad { background: var(--bad-soft); border-color: transparent; color: var(--bad); }
.btn.block { width: 100%; }
.btn.sm { min-height: 34px; padding: 0 12px; font-size: 14px; border-radius: 10px; }
.btn:disabled { opacity: .45; cursor: default; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-row > .btn { flex: 1 1 130px; }  /* 폰에서 버튼이 좁게 찌그러지지 않고 두 줄로 넘어가게 */

/* Netlify가 자동으로 넣는 "Powered by Netlify" 배지가 폰에서 하단 탭(퀴즈·복습·작문)을 가려서 숨김 */
#nl-badge-frame, iframe[id^="nl-badge"] { display: none !important; }

.seg { display: flex; background: var(--card-2); border-radius: 12px; padding: 4px; margin-bottom: 12px; }
.seg button {
  flex: 1; border: 0; background: transparent; min-height: 38px; border-radius: 9px; cursor: pointer;
  color: var(--muted); font-weight: 600; font-size: 14px;
}
.seg button.on { background: var(--card); color: var(--text); box-shadow: var(--shadow); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1px solid var(--line); background: var(--card); border-radius: 999px;
  min-height: 36px; padding: 0 14px; cursor: pointer; font-size: 14px; font-weight: 600; color: var(--muted);
}
.chip.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.field { margin-bottom: 16px; }
.field > label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 8px; font-weight: 600; }

input[type=text], input[type=search], textarea, select {
  width: 100%; border: 1px solid var(--line); background: var(--card); border-radius: 12px;
  min-height: 46px; padding: 10px 14px; outline: none;
}
input:focus, textarea:focus { border-color: var(--accent); }
textarea { min-height: 90px; resize: vertical; }

.search-row { display: flex; gap: 8px; margin-bottom: 12px; }
.search-row input { flex: 1; }

.list { display: flex; flex-direction: column; gap: 8px; }
.row {
  display: flex; align-items: center; gap: 8px;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 8px 10px 14px;
}
.row-main { flex: 1; min-width: 0; cursor: pointer; }
.row-word { font-weight: 700; font-size: 17px; }
.row-mean { color: var(--muted); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-meta { font-size: 12px; color: var(--muted); display: flex; justify-content: space-between; gap: 8px; margin-bottom: 4px; }
.row-chosen { font-size: 13px; margin-bottom: 6px; }
.row-chosen b { color: var(--bad); font-weight: 600; }
.tag { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 6px; background: var(--card-2); color: var(--muted); font-weight: 600; }

.empty { text-align: center; color: var(--muted); padding: 40px 16px; }
.empty .big { font-size: 40px; display: block; margin-bottom: 8px; }

/* quiz */
.progress { height: 6px; background: var(--card-2); border-radius: 3px; overflow: hidden; margin-bottom: 16px; }
.progress > i { display: block; height: 100%; background: var(--accent); transition: width .2s; }
.q-top { display: flex; justify-content: space-between; color: var(--muted); font-size: 13px; margin-bottom: 8px; }
.q-word { text-align: center; padding: 28px 8px 24px; }
.q-word .w { font-size: 34px; font-weight: 800; letter-spacing: -.5px; word-break: break-word; }
.q-word .m { font-size: 22px; font-weight: 700; }
.q-word .ph { color: var(--muted); margin-top: 4px; }
.choices { display: flex; flex-direction: column; gap: 10px; }
.choice {
  text-align: left; border: 1.5px solid var(--line); background: var(--card); border-radius: 12px;
  min-height: 56px; padding: 12px 16px; cursor: pointer; font-size: 16px; display: flex; gap: 10px; align-items: center;
}
.choice .n { color: var(--muted); font-weight: 700; width: 18px; }
.choice:hover:not(:disabled) { border-color: var(--accent); }
.choice.correct { border-color: var(--good); background: var(--good-soft); }
.choice.wrong { border-color: var(--bad); background: var(--bad-soft); }
.choice:disabled { cursor: default; }
.feedback { margin-top: 14px; padding: 12px 14px; border-radius: 12px; font-weight: 600; }
.feedback.ok { background: var(--good-soft); color: var(--good); }
.feedback.no { background: var(--bad-soft); color: var(--bad); }
.score-big { font-size: 48px; font-weight: 800; text-align: center; letter-spacing: -1px; }

/* 단계 학습 진행 막대: 다 익힘(진한색) + 반쯤 익힘(옅은색) */
.progress.learn { display: flex; }
.progress.learn > b { display: block; height: 100%; background: var(--accent); opacity: .35; transition: width .2s; }

/* 매칭 게임 */
.match-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.tile {
  min-height: 84px; padding: 8px; border-radius: 12px; cursor: pointer;
  border: 1.5px solid var(--line); background: var(--card); color: var(--text);
  font-size: 14px; line-height: 1.35; word-break: keep-all; overflow-wrap: anywhere;
  display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden;
  transition: opacity .25s, transform .25s, border-color .15s;
}
.tile-w { font-weight: 700; font-size: 16px; overflow-wrap: normal; hyphens: auto; }
.tile-w.long { font-size: 14px; }
.tile-w.xlong { font-size: 12px; letter-spacing: -.2px; }
.tile.sel { border-color: var(--accent); background: var(--accent-soft); }
.tile.gone { opacity: 0; transform: scale(.85); pointer-events: none; }
.tile.shake { border-color: var(--bad); background: var(--bad-soft); animation: shake .35s; }
@keyframes shake { 0%, 100% { translate: 0; } 25% { translate: -5px; } 75% { translate: 5px; } }
@media (min-width: 560px) { .match-grid { grid-template-columns: repeat(4, 1fr); } }

/* review */
.stage-bar { display: flex; gap: 4px; margin-bottom: 6px; }
.stage-bar i { flex: 1; height: 5px; border-radius: 3px; background: var(--card-2); }
.stage-bar i.on { background: var(--accent); }
.overdue { color: var(--bad); font-size: 13px; }
.rate-row { display: flex; gap: 6px; margin-left: auto; }
.rate-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.rate-row .btn, .rate-grid .btn { flex-direction: column; gap: 0; line-height: 1.2; padding: 6px 8px; }
.rate-grid .btn { min-height: 58px; }
.btn .ivl { font-size: 11px; font-weight: 500; opacity: .75; }
.ai-btn { border-style: dashed; border-color: var(--accent); color: var(--accent); }
.ai-btn .small { margin-left: 4px; }
.flash { text-align: center; padding: 24px 8px; }
.flash .w { font-size: 32px; font-weight: 800; }
.flash .m { font-size: 20px; margin-top: 12px; }
.flash .ex { color: var(--muted); margin-top: 10px; font-size: 14px; }
.hidden-mean { filter: blur(7px); user-select: none; cursor: pointer; }

/* writing */
.ko-sentence { font-size: 19px; font-weight: 700; line-height: 1.5; margin: 6px 0 10px; }
.diff { line-height: 1.9; }
.diff .ok { color: var(--good); }
.diff .miss { color: var(--bad); text-decoration: underline; text-decoration-style: wavy; }

/* stats */
.bars { display: flex; align-items: flex-end; gap: 3px; height: 110px; padding-top: 6px; }
.bars div { flex: 1; background: var(--accent); border-radius: 3px 3px 0 0; min-height: 2px; opacity: .85; }
.bars div.zero { background: var(--card-2); }
.bars-x { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); margin-top: 4px; }
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; text-align: center; font-size: 12px; }
.cal .dow { color: var(--muted); padding-bottom: 2px; }
.cal .d { aspect-ratio: 1; border-radius: 8px; display: flex; align-items: center; justify-content: center; background: var(--card-2); color: var(--muted); }
.cal .d.l1 { background: var(--accent-soft); color: var(--text); }
.cal .d.l2 { background: var(--accent); color: #fff; opacity: .7; }
.cal .d.l3 { background: var(--accent); color: #fff; }
.cal .d.today { outline: 2px solid var(--accent); outline-offset: 1px; }

/* sheet */
.sheet { position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.sheet[hidden] { display: none; }
.tabbar em[hidden] { display: none; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.45); }
.sheet-panel {
  position: relative; width: 100%; max-width: 640px; max-height: 88vh; overflow: auto;
  background: var(--bg); border-radius: 20px 20px 0 0; padding: 20px 16px calc(24px + env(safe-area-inset-bottom));
}
.sheet-close { position: absolute; top: 10px; right: 10px; }
@media (min-width: 700px) {
  .sheet { align-items: center; }
  .sheet-panel { border-radius: 20px; }
}
.detail-word { font-size: 32px; font-weight: 800; letter-spacing: -.5px; margin: 0; padding-right: 40px; word-break: break-word; }
.detail-ph { display: flex; align-items: center; gap: 8px; color: var(--muted); margin: 4px 0 12px; }
.def-list { margin: 0; padding-left: 20px; }
.def-list li { margin-bottom: 6px; }
.def-list .pos { color: var(--accent); font-size: 12px; font-weight: 700; margin-right: 4px; }
.def-list .ex { display: block; color: var(--muted); font-size: 14px; font-style: italic; }

.toast {
  position: fixed; left: 50%; bottom: calc(80px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: #111; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px; z-index: 60;
  max-width: calc(100% - 32px);
}

@media (min-width: 700px) {
  .stat-grid { grid-template-columns: repeat(4, 1fr); }
}

/* 레벨 학습 */
.lv-stats { grid-template-columns: repeat(3, 1fr) !important; }
.lv-stats .stat { display: block; color: inherit; }
.lv-stats .stat small { font-size: 12px; font-weight: 500; color: var(--muted); }
.lv-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.lv { border: 1.5px solid var(--line); background: var(--card); border-radius: 12px; min-height: 64px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; color: var(--text); }
.lv b { font-size: 15px; }
.lv span { font-size: 11px; color: var(--muted); }
.lv.done { background: var(--good-soft); border-color: transparent; }
.lv.done span { color: var(--good); font-weight: 700; }
.lv.now { border-color: var(--accent); background: var(--accent-soft); }
.lv.now span { color: var(--accent); font-weight: 700; }
.lv.lock { opacity: .55; }
.seg button .small { font-size: 11px; font-weight: 500; }
@media (min-width: 560px) { .lv-grid { grid-template-columns: repeat(6, 1fr); } }

/* 카드 상자 */
.ctabs { display: flex; background: var(--card-2); border-radius: 12px; padding: 4px; margin-bottom: 12px; }
.ctabs a { flex: 1; text-align: center; min-height: 38px; line-height: 38px; border-radius: 9px; color: var(--muted); font-weight: 600; font-size: 14px; text-decoration: none; }
.ctabs a.on { background: var(--card); color: var(--text); box-shadow: var(--shadow); }
.bx-row { display: flex; gap: 4px; align-items: flex-end; }
.bx { display: flex; flex-direction: column; align-items: center; gap: 4px; min-width: 42px; }
.bx-cell { position: relative; width: 100%; height: 64px; border: 2px solid var(--line); border-radius: 6px; overflow: hidden; background: var(--card-2); }
.bx-cell > i { position: absolute; left: 0; right: 0; bottom: 0; background: var(--accent); opacity: .75; transition: height .3s; }
.bx.full .bx-cell { border-color: var(--warn); }
.bx.full .bx-cell > i { background: var(--warn); }
.bx-l { font-size: 10.5px; color: var(--muted); white-space: nowrap; text-align: center; line-height: 1.3; }
.bx-l b { color: var(--text); }
.bx-grad { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; min-width: 34px; height: 96px; font-size: 18px; }
.bx-grad b { font-size: 14px; }
.bx-row.mini .bx-cell { height: 40px; }
.bx-row.mini .bx-grad { height: 72px; }
.bx-hot { color: var(--warn); font-weight: 600; }
.bx-card { position: relative; padding-top: 44px; }
.bx-dir { position: absolute; top: 10px; right: 10px; min-height: 28px; padding: 0 10px; font-size: 12px; }
.bx-front { font-size: 24px; font-weight: 700; margin-top: 0; }
.bx-hr { border: 0; border-top: 1px dashed var(--line); margin: 16px 0; }
.bx-ans { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.bx-ans .btn { flex-direction: column; gap: 0; min-height: 58px; line-height: 1.2; }
.bx-ans .ivl { font-size: 12px; opacity: .85; font-weight: 500; }
.why p { line-height: 1.65; }
.why ul { padding-left: 20px; line-height: 1.65; margin: 8px 0 12px; }
.why h2 { margin-top: 4px; }
.why-svg { display: block; width: 100%; max-width: 420px; margin: 8px auto 4px; }
.why-svg .grid { stroke: var(--line); stroke-width: 1; }
.why-svg .lbl { fill: var(--muted); font-size: 10px; }
.why-svg .val { fill: var(--text); font-size: 10px; font-weight: 700; }
.why-svg .curve { fill: none; stroke: var(--bad); stroke-width: 2.5; stroke-linejoin: round; }
.why-svg .dot { fill: var(--bad); }
.why-svg .boxr { fill: var(--card-2); stroke: var(--muted); stroke-width: 1.2; }
.why-svg .arc { fill: none; stroke-width: 1.8; }
.why-svg .arc.ok { stroke: var(--good); }
.why-svg .arc.no { stroke: var(--bad); stroke-dasharray: 4 3; }
.why-svg .lbl.ok { fill: var(--good); }
.why-svg .lbl.no { fill: var(--bad); }
.why-svg .arrowhead { fill: var(--muted); }
.why .why-points { font-size: 14px; padding-left: 18px; margin: 0 0 12px; }
.why .why-points li { margin-bottom: 6px; }
.why-tip { background: var(--accent-soft); border-radius: 10px; padding: 12px 14px; font-size: 14px; margin: 0; }
.why-core { border: 2px solid var(--accent); }
.core-item { display: flex; gap: 12px; margin: 12px 0; }
.core-item p { margin: 4px 0 0; font-size: 14px; }
.core-n { flex: 0 0 28px; height: 28px; border-radius: 50%; background: var(--accent); color: #fff; font-weight: 800; display: flex; align-items: center; justify-content: center; }
.seg .rec { font-size: 10px; font-weight: 700; color: #fff; background: var(--good); border-radius: 6px; padding: 1px 5px; margin-left: 2px; vertical-align: middle; }
.pick-list { max-height: 420px; overflow-y: auto; border: 1px solid var(--line); border-radius: 10px; }
.pick-row { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-bottom: 1px solid var(--line); cursor: pointer; }
.pick-row:last-child { border-bottom: 0; }
.pick-row.on { background: var(--accent-soft); }
.pick-row input { width: 20px; height: 20px; flex: 0 0 auto; accent-color: var(--accent); }
.pick-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.pick-main .muted { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.new-prev { margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--line); }
.bx-sticky { position: sticky; bottom: calc(64px + env(safe-area-inset-bottom)); padding: 8px 0; background: linear-gradient(transparent, var(--bg) 30%); z-index: 5; }
.why-cap { text-align: center; font-size: 13px; margin: 2px 0 8px; color: var(--text); }
.core-tag { font-size: 11px; font-weight: 700; color: #fff; background: var(--accent); border-radius: 6px; padding: 2px 6px; margin-left: 4px; vertical-align: middle; white-space: nowrap; }
