* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg: #FBF6EE;
  --card: #FFFFFF;
  --text: #2B2420;
  --muted: #7A6E66;
  --line: #EADFD2;
  --primary: #B5523B;       /* 붉은 먹색 — 도장 느낌 */
  --primary-text: #FFFFFF;
  --primary-soft: #F6E3DC;
  --ok: #2F8F5B;
  --ok-soft: #DDF2E5;
  --bad: #C8423A;
  --bad-soft: #FBE1DE;
  --shadow: 0 2px 10px rgba(80, 50, 30, 0.08);
  --hanja-font: 'Noto Serif KR', 'Noto Serif CJK KR', 'AppleMyungjo', 'Batang', serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1E1A17;
    --card: #2A2421;
    --text: #F2EAE3;
    --muted: #B3A69C;
    --line: #3E3530;
    --primary: #E07A5F;
    --primary-text: #1E1A17;
    --primary-soft: #4A2E26;
    --ok: #6CCB93;
    --ok-soft: #233D2E;
    --bad: #F08A80;
    --bad-soft: #4A2724;
    --shadow: none;
  }
}

html, body {
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, 'Apple SD Gothic Neo', 'Noto Sans KR', sans-serif;
  font-size: 17px;
  line-height: 1.55;
  -webkit-tap-highlight-color: transparent;
}

[hidden] { display: none !important; }

a { color: var(--primary); text-decoration: none; }

/* ── 레이아웃 ─────────────────────────────── */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.topbar > * { white-space: nowrap; flex: 0 0 auto; }
.topbar-title { font-weight: 800; color: var(--primary); margin-right: auto; }
.topbar-user { color: var(--muted); font-size: 14px; flex: 0 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.topbar-link { color: var(--primary); font-weight: 700; font-size: 18px; padding: 4px 6px; }

.app {
  max-width: 520px;
  margin: 0 auto;
  padding: 16px 16px calc(env(safe-area-inset-bottom) + 32px);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 18px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.card h2 { font-size: 21px; }
.card h3 { font-size: 17px; color: var(--muted); }

/* ── 버튼·입력 ────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 46px;
  padding: 10px 18px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--card);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.btn:disabled { opacity: 0.6; cursor: default; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.btn-text { background: none; border: none; color: var(--primary); min-height: 40px; }
.btn-small { min-height: 32px; padding: 4px 8px; font-size: 14px; }
.btn-block { width: 100%; }
.btn-big { min-height: 58px; font-size: 20px; }
.btn-icon { min-height: 36px; padding: 4px 10px; border-radius: 999px; font-size: 18px; }

input {
  width: 100%;
  min-height: 48px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
}
input:focus { outline: 2px solid var(--primary); outline-offset: 1px; }
.field-label { display: flex; flex-direction: column; gap: 4px; font-size: 14px; color: var(--muted); }

.msg { font-size: 15px; color: var(--muted); }
.msg-error { color: var(--bad); }
.hint { font-size: 14px; color: var(--muted); text-align: center; }
.back-link { font-weight: 600; align-self: flex-start; }

/* ── 로그인 ───────────────────────────────── */

.login-card { margin-top: 8vh; text-align: center; }
.login-logo {
  width: 84px; height: 84px; margin: 0 auto;
  display: grid; place-items: center;
  border-radius: 22px;
  background: var(--primary); color: var(--primary-text);
  font-family: var(--hanja-font); font-size: 52px;
}
.login-title { font-size: 28px; color: var(--primary); }
.login-sub { color: var(--muted); margin-bottom: 6px; }

/* ── 홈 ───────────────────────────────────── */

.greeting { color: var(--muted); font-size: 15px; }
.hero { background: var(--primary-soft); border-color: transparent; }
.hero .btn-big { margin-top: 6px; }
.hero-week { font-size: 14px; color: var(--muted); font-weight: 600; }

.day-row { list-style: none; display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.day > a, .day > span {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 10px 2px; border-radius: 12px;
  background: var(--bg); color: var(--text); min-height: 92px;
}
.day-label { font-weight: 700; }
.day-icon { font-size: 20px; }
.day-idiom { font-size: 11px; color: var(--muted); text-align: center; word-break: keep-all; }
.day-done > * { background: var(--ok-soft); }
.day-open > a { outline: 2px solid var(--primary); }
.day-locked > span { opacity: 0.5; }

.missed-list { list-style: none; display: flex; flex-direction: column; gap: 6px; }

/* ── 학습 카드 ────────────────────────────── */

.hanja { font-family: var(--hanja-font); }
.idiom-card { align-items: center; padding: 22px 12px; }
.idiom-chars { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; width: 100%; }
.idiom-char { display: flex; flex-direction: column; align-items: center; }
.idiom-char .hanja { font-size: clamp(44px, 14vw, 64px); line-height: 1.2; }
.huneum { font-size: 14px; color: var(--muted); }
.idiom-reading { display: flex; align-items: center; gap: 8px; font-size: 24px; font-weight: 800; color: var(--primary); }

.explain dl { display: grid; gap: 4px; }
.explain dt { font-size: 13px; font-weight: 700; color: var(--muted); margin-top: 8px; }
.explain dt:first-child { margin-top: 0; }
.explain .meaning { font-size: 19px; font-weight: 700; }
.explain .example { padding: 10px 12px; border-radius: 10px; background: var(--bg); }

.key-main { display: flex; align-items: center; gap: 16px; }
.key-hanja {
  width: 84px; height: 84px; flex: none;
  display: grid; place-items: center;
  font-size: 58px; border-radius: 16px;
  background: var(--primary-soft);
}
.key-huneum { font-size: 20px; font-weight: 700; display: flex; align-items: center; gap: 6px; }
.key-meta { font-size: 14px; color: var(--muted); }
.key-words { font-size: 15px; }

.sticky-bottom { position: sticky; bottom: calc(env(safe-area-inset-bottom) + 12px); box-shadow: 0 6px 18px rgba(0, 0, 0, 0.15); }

/* ── 퀴즈 ─────────────────────────────────── */

.quiz-progress { text-align: center; color: var(--muted); font-weight: 600; }
.quiz-card { align-items: center; text-align: center; }
.quiz-prompt { font-size: 18px; font-weight: 600; }
.quiz-display { font-family: var(--hanja-font); color: var(--primary); }
.display-idiom { font-size: clamp(40px, 13vw, 58px); letter-spacing: 4px; }
.display-single { font-size: 88px; line-height: 1.1; }
.display-text { font-family: inherit; font-size: 20px; font-weight: 700; color: var(--text); }
.option-idiom { font-size: 19px; }

.options { display: grid; gap: 10px; }
.option { min-height: 58px; text-align: left; justify-content: flex-start; font-weight: 500; line-height: 1.4; }
.option-blank { font-family: var(--hanja-font); font-size: 30px; justify-content: center; }
.option-huneum { font-size: 20px; justify-content: center; }
.option.correct { background: var(--ok-soft); border-color: var(--ok); color: var(--ok); font-weight: 700; }
.option.wrong { background: var(--bad-soft); border-color: var(--bad); color: var(--bad); }
.options:has(.option-blank) { grid-template-columns: 1fr 1fr; }

.result { align-items: center; text-align: center; padding: 28px 18px; }
.result-emoji { font-size: 56px; line-height: 1; }
.result-pass { background: var(--ok-soft); border-color: transparent; }

/* ── 부모 ─────────────────────────────────── */

.child-list { list-style: none; display: flex; flex-direction: column; gap: 10px; }
.child { padding: 12px; border-radius: 12px; background: var(--bg); }
.child-id { color: var(--muted); font-size: 14px; }
.child-weeks { font-size: 14px; color: var(--muted); }
/* 학습 내용 둘러보기 (부모) */
.browse-week h3 { color: var(--text); font-size: 16px; }
.browse-days { list-style: none; display: flex; flex-direction: column; gap: 6px; }
.browse-day {
  display: grid; grid-template-columns: 28px auto 1fr; grid-template-rows: auto auto; column-gap: 10px; align-items: center;
  padding: 8px 10px; border-radius: 12px; background: var(--bg); color: var(--text);
}
.browse-dow { grid-row: span 2; font-size: 13px; font-weight: 700; color: var(--muted); text-align: center; }
.browse-idiom { font-size: 20px; font-weight: 700; }
.browse-reading { font-size: 14px; color: var(--primary); font-weight: 600; }
.browse-meaning { grid-column: 2 / span 2; font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.preview-label { text-align: center; }
.member-list { list-style: none; display: flex; flex-direction: column; gap: 6px; }
.member { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 12px; background: var(--bg); }
.member-name { flex: 1; min-width: 0; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.member-role { font-size: 14px; color: var(--muted); }
.edit-child { width: 100%; }
.row-btns { display: flex; gap: 8px; }
.row-btns .btn { flex: 1; }
.label-select { font: inherit; font-size: 14px; padding: 4px 8px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); color: var(--text); }
.field-label .label-select { font-size: 16px; padding: 10px; }
.invite-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.join-family { margin-top: 8px; padding-top: 12px; border-top: 1px solid var(--line); }
.invite-code { font-size: 24px; letter-spacing: 4px; font-family: ui-monospace, monospace; padding: 4px 10px; border-radius: 10px; background: var(--bg); }

/* ── 주간 테스트 ──────────────────────────── */

.stack { display: flex; flex-direction: column; gap: 8px; }
.muted { color: var(--muted); }
.test-ready, .test-needs-approval { outline: 2px solid var(--primary); }
.test-completed { background: var(--ok-soft); border-color: transparent; }
.week-review { list-style: none; display: flex; flex-direction: column; gap: 2px; font-size: 15px; }

.pin-pad { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.pin-dots { display: flex; gap: 14px; }
.pin-dot { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--primary); }
.pin-dot.filled { background: var(--primary); }
.pin-status { min-height: 22px; }
.pin-keys { display: grid; grid-template-columns: repeat(3, 72px); gap: 10px; }
.pin-key { min-height: 60px; font-size: 24px; border-radius: 50%; padding: 0; }
.approval-row {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px;
  margin-top: 8px; padding: 10px 12px; border-radius: 10px; background: var(--primary-soft);
}

/* ── 기록 ─────────────────────────────────── */

.greeting-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.records-link { white-space: nowrap; }
.page-title { font-size: 22px; }
.child-detail-link { display: inline-block; margin-top: 4px; font-size: 15px; font-weight: 600; }

.stats-row { flex-direction: row; justify-content: space-around; text-align: center; }
.stat { display: flex; flex-direction: column; }
.stat-value { font-size: 24px; font-weight: 800; color: var(--primary); }
.stat-label { font-size: 13px; color: var(--muted); }

.stamp-board, .test-table { width: 100%; border-collapse: collapse; text-align: center; }
.stamp-board th, .test-table th { font-size: 13px; color: var(--muted); font-weight: 600; padding: 4px 2px; }
.stamp-board tbody th { text-align: left; white-space: nowrap; }
.stamp { height: 38px; font-size: 18px; border-radius: 8px; }
.stamp-done { color: var(--primary); font-weight: 800; }
.stamp-missed { color: var(--muted); }
.stamp-board td, .stamp-board tbody th { border-top: 1px solid var(--line); }
.test-table td { padding: 8px 2px; border-top: 1px solid var(--line); }

.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; text-align: center; }
.cal-dow { font-size: 12px; color: var(--muted); }
.cal-day { display: flex; flex-direction: column; align-items: center; min-height: 44px; padding-top: 2px; border-radius: 10px; font-size: 14px; }
.cal-studied { background: var(--primary-soft); }
.cal-today { outline: 2px solid var(--primary); }
.cal-stamp { font-size: 12px; color: var(--primary); }

.wrong-list { list-style: none; display: flex; flex-direction: column; gap: 6px; }
.wrong-list li { display: flex; justify-content: space-between; gap: 8px; }
.wrong-count { color: var(--bad); font-weight: 700; white-space: nowrap; }
