:root {
  --bg: #F3F1FF;
  --card: #FFFFFF;
  --ink: #1E1B3A;
  --muted: #4A4668;
  --line: #E2DEFF;
  --line-strong: #C9C3F5;
  --primary: #4B3FD9;
  --primary-ink: #3B30C4;
  --primary-dark: #251C8F;
  --night: #2A2270;
  --night-2: #3A3190;
  --night-3: #463C9E;
  --gold: #FFC77A;
  --orange: #E8730C;
  --orange-soft: #FFE6CC;
  --orange-ink: #8A3D00;
  --green-soft: #D6F2E4;
  --green-ink: #1F6B45;
  --danger: #B42318;
  --title: 'Do Hyeon', 'Noto Sans KR', sans-serif;
  --body: 'Noto Sans KR', system-ui, -apple-system, 'Malgun Gothic', sans-serif;
  --radius-lg: 24px;
  --radius: 16px;
  --radius-sm: 12px;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--body);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--primary-ink); }
:focus-visible { outline: 3px solid var(--orange); outline-offset: 2px; }
img { max-width: 100%; }
.hidden { display: none !important; }

h1, h2, h3, .title { font-family: var(--title); font-weight: 400; margin: 0; line-height: 1.2; }
h1 { font-size: 34px; }
h2 { font-size: 26px; }
h3 { font-size: 21px; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.tiny { font-size: 13px; }

/* ---------- 상단 메뉴 ---------- */
.topbar { background: var(--card); border-bottom: 2px solid var(--line); position: sticky; top: 0; z-index: 20; }
.topbar-inner { max-width: 1200px; margin: 0 auto; padding: 12px 20px; display: flex; flex-wrap: wrap; align-items: center; gap: 10px 28px; }
.logo { font-family: var(--title); font-size: 26px; color: var(--primary); background: none; border: 0; padding: 0; }
.nav { display: flex; gap: 6px; flex-grow: 1; overflow-x: auto; scrollbar-width: none; }
.nav::-webkit-scrollbar { display: none; }
.nav a { text-decoration: none; white-space: nowrap; padding: 10px 14px; border-radius: var(--radius-sm); color: var(--muted); font-weight: 500; }
.nav a.on { background: var(--line); color: var(--primary-dark); font-weight: 700; }
.me-chip { display: flex; align-items: center; gap: 10px; background: none; border: 0; padding: 4px; border-radius: var(--radius-sm); text-align: left; }
.me-chip .lv { font-size: 12px; color: var(--muted); display: block; }
.me-chip b { font-size: 14px; display: block; }

.page { max-width: 1200px; margin: 0 auto; padding: 24px 20px 64px; display: flex; flex-direction: column; gap: 22px; }
.row { display: flex; flex-wrap: wrap; gap: 22px; align-items: flex-start; }
.col-main { flex: 999 1 540px; min-width: 0; display: flex; flex-direction: column; gap: 22px; }
.col-side { flex: 1 1 300px; min-width: 0; display: flex; flex-direction: column; gap: 22px; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.inline { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.between { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; }

.card { background: var(--card); border-radius: var(--radius-lg); padding: 24px; box-shadow: 0 6px 0 var(--line); display: flex; flex-direction: column; gap: 16px; }
.card.night { background: var(--night); color: #fff; box-shadow: none; }
.card.night .muted { color: #E6E3FF; }

/* ---------- 버튼 ---------- */
.btn { border: 0; border-radius: var(--radius-sm); padding: 12px 18px; font-weight: 700; background: var(--primary); color: #fff; box-shadow: 0 4px 0 var(--primary-dark); min-height: 44px; transition: transform .08s; }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--primary-dark); }
.btn.big { font-family: var(--title); font-weight: 400; font-size: 24px; padding: 16px 24px; border-radius: var(--radius); }
.btn.orange { background: #FFB35C; color: var(--ink); box-shadow: 0 4px 0 #A24A00; }
.btn.ghost { background: var(--card); color: var(--primary-ink); border: 2px solid var(--line-strong); box-shadow: none; }
.btn.ghost-dark { background: transparent; color: #fff; border: 2px solid #8F86FF; box-shadow: none; }
.btn.text { background: none; box-shadow: none; color: var(--primary-ink); padding: 8px 10px; min-height: auto; }
.btn.danger { background: var(--card); color: var(--danger); border: 2px solid #F3C7C3; box-shadow: none; }
.btn.small { padding: 8px 12px; font-size: 14px; min-height: 36px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.full { width: 100%; }

.chip { border: 2px solid var(--line); background: var(--card); color: var(--ink); border-radius: 999px; padding: 8px 16px; font-weight: 500; }
.chip.on { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 700; }
.pill { display: inline-block; font-size: 13px; font-weight: 700; padding: 5px 12px; border-radius: 999px; }
.pill.orange { background: var(--orange-soft); color: var(--orange-ink); }
.pill.green { background: var(--green-soft); color: var(--green-ink); }
.pill.gray { background: #ECEAF3; color: #3F3B57; }
.pill.violet { background: var(--line); color: var(--primary-dark); }

/* ---------- 입력 ---------- */
label.field { display: flex; flex-direction: column; gap: 6px; font-weight: 700; font-size: 15px; }
label.field .hint { font-weight: 400; color: var(--muted); font-size: 13px; }
input[type=text], input[type=number], input[type=password], input[type=search], select, textarea {
  border: 2px solid var(--line-strong); border-radius: var(--radius-sm); padding: 12px 14px; background: #FAF9FF; width: 100%; font-weight: 400;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); outline: none; background: #fff; }
textarea { resize: vertical; min-height: 90px; }
.check { display: flex; align-items: center; gap: 10px; font-weight: 700; }
.check input { width: 22px; height: 22px; accent-color: var(--primary); }

/* ---------- 아바타 ---------- */
.avatar { width: 40px; height: 40px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-family: var(--title); font-size: 19px; flex-shrink: 0; }
.avatar.lg { width: 84px; height: 84px; font-size: 36px; }
.avatar.sm { width: 30px; height: 30px; font-size: 14px; }

/* ---------- 로그인 ---------- */
.login { min-height: 100vh; display: flex; flex-direction: column; align-items: center; gap: 32px; padding: 56px 20px; }
.login-hero { text-align: center; display: flex; flex-direction: column; gap: 8px; }
.login-hero h1 { font-size: 52px; color: var(--primary); }
.profiles { width: 100%; max-width: 900px; display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 16px; }
.profile { background: var(--card); border: 3px solid var(--line); border-radius: 20px; padding: 24px 12px; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.profile.on { border-color: var(--primary); }
.profile b { font-size: 20px; }
.pinbox { width: 100%; max-width: 380px; background: var(--card); border-radius: var(--radius-lg); padding: 24px; display: flex; flex-direction: column; gap: 16px; box-shadow: 0 6px 0 var(--line); }
.pin-dots { display: flex; justify-content: center; gap: 14px; }
.pin-dots span { width: 22px; height: 22px; border-radius: 50%; border: 3px solid var(--line-strong); }
.pin-dots span.f { background: var(--primary); border-color: var(--primary); }
.keypad { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.keypad button { font-family: var(--title); font-size: 28px; padding: 12px 0; border-radius: var(--radius-sm); border: 2px solid var(--line); background: #FAF9FF; }
.keypad button:active { background: var(--line); }
.err { color: var(--danger); font-weight: 700; text-align: center; min-height: 24px; }

/* ---------- 홈 ---------- */
.quest-title { font-size: 34px; }
.gauge { height: 34px; background: var(--night-3); border-radius: 17px; overflow: hidden; display: flex; }
.gauge span { height: 100%; transition: width .6s ease; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 18px; font-size: 14px; }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 4px; margin-right: 6px; vertical-align: -1px; }
.reward-box { background: var(--card); color: var(--ink); border-radius: 20px; padding: 20px; display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; flex: 1 1 240px; }
.reward-box .title { font-size: 24px; color: #A24A00; }
.reward-box.open { background: #FFF6E5; outline: 4px solid #FFB35C; }
.ring { width: 150px; height: 150px; border-radius: 50%; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.ring > div { width: 116px; height: 116px; border-radius: 50%; background: #fff; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.ring .title { font-size: 32px; }
.quest { display: flex; align-items: center; gap: 12px; padding: 12px 14px; background: var(--bg); border-radius: 14px; }
.quest .box { width: 26px; height: 26px; border-radius: 8px; border: 2px solid var(--primary); flex-shrink: 0; display: flex; align-items: center; justify-content: center; }
.quest.done .box { background: var(--primary); }
.quest.done .label { text-decoration: line-through; color: var(--muted); }
.quest .label { flex-grow: 1; }
.quest .xp { font-size: 13px; font-weight: 700; color: var(--primary-ink); }
.xpbar { height: 12px; background: var(--line); border-radius: 6px; overflow: hidden; }
.xpbar div { height: 100%; background: var(--orange); }
.feed-item { display: flex; gap: 12px; align-items: flex-start; padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.feed-item:last-child { border-bottom: 0; padding-bottom: 0; }
.feed-item.to-me { background: #FFF6EC; border-radius: 14px; padding: 12px; border: 0; }
.fam-row { display: flex; align-items: center; gap: 12px; }
.fam-row .grow { flex-grow: 1; }
.badge-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 12px; }
.badge { display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; font-size: 12px; }
.badge .tile { width: 60px; height: 60px; border-radius: 18px; display: flex; align-items: center; justify-content: center; font-family: var(--title); font-size: 19px; }
.badge.locked .tile { background: #ECEAF3 !important; color: #8A86A3 !important; }
.badge.locked { color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 20px 10px; }

/* ---------- 독서 ---------- */
.timer-panel { align-items: center; text-align: center; gap: 20px; padding: 32px; }
.timer-big { font-family: var(--title); font-size: clamp(72px, 14vw, 120px); line-height: 1; letter-spacing: 2px; }
.book-mini { display: flex; align-items: center; gap: 14px; background: var(--night-2); padding: 12px 18px 12px 12px; border-radius: var(--radius); text-align: left; }
.cover { width: 56px; height: 78px; border-radius: 6px; object-fit: cover; flex-shrink: 0; background: var(--line); display: flex; align-items: center; justify-content: center; font-family: var(--title); color: var(--primary-dark); font-size: 22px; overflow: hidden; }
.cover.lg { width: 84px; height: 118px; font-size: 30px; }
.cover.xl { width: 120px; height: 168px; font-size: 40px; }
.pick-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }
.pick { display: flex; gap: 12px; align-items: center; text-align: left; background: var(--card); border: 3px solid var(--line); border-radius: var(--radius); padding: 12px; }
.pick.on { border-color: var(--primary); }
.photo-opts { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.photo-opts > * { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 14px 6px; border-radius: var(--radius-sm); border: 2px solid var(--line); background: #FAF9FF; font-size: 14px; text-align: center; cursor: pointer; }
.photo-preview { width: 100%; max-height: 260px; object-fit: contain; border-radius: var(--radius-sm); background: var(--bg); }
.stars { display: flex; gap: 4px; }
.stars button { background: none; border: 0; font-size: 30px; line-height: 1; padding: 2px; color: #D5D1EA; }
.stars button.on { color: #F2A100; }
.pages { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.pages input { width: 96px; text-align: center; }

/* ---------- 책장 ---------- */
.result { display: flex; align-items: center; gap: 14px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.result:last-child { border-bottom: 0; }
.results { border: 2px solid var(--line); border-radius: 14px; overflow: hidden; }
.book-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); gap: 18px; }
.book-card { background: var(--card); border-radius: 20px; padding: 16px; display: flex; gap: 14px; box-shadow: 0 5px 0 var(--line); text-align: left; border: 0; width: 100%; }
.book-card .info { flex-grow: 1; min-width: 0; display: flex; flex-direction: column; gap: 5px; }
.book-card .t { font-weight: 700; font-size: 16px; overflow-wrap: anywhere; }
.rec { font-size: 13px; background: var(--bg); padding: 8px 10px; border-radius: 10px; }
.who { display: flex; flex-wrap: wrap; gap: 4px; }
.stars-text { color: #A24A00; font-weight: 700; font-size: 14px; }

/* ---------- 문장 ---------- */
.quote-grid { columns: 3 280px; column-gap: 18px; }
.quote-card { break-inside: avoid; margin-bottom: 18px; background: var(--card); border-radius: 20px; padding: 20px; box-shadow: 0 5px 0 var(--line); display: flex; flex-direction: column; gap: 10px; }
.quote-card .q { font-size: 18px; line-height: 1.6; white-space: pre-wrap; }

/* ---------- 통계 ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; }
.stat { background: var(--card); border-radius: 20px; padding: 18px; box-shadow: 0 5px 0 var(--line); display: flex; flex-direction: column; gap: 2px; }
.stat .title { font-size: 34px; }
.bars { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 10px; align-items: end; height: 200px; }
.bars .bar { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 6px; height: 100%; font-size: 13px; }
.bars .bar div { width: 100%; max-width: 46px; border-radius: 10px 10px 4px 4px; background: var(--primary); min-height: 4px; }
.bars .bar.goal div { background: var(--orange); }
.hbar { display: flex; align-items: center; gap: 10px; }
.hbar .track { flex-grow: 1; height: 18px; background: var(--bg); border-radius: 9px; overflow: hidden; }
.hbar .track div { height: 100%; border-radius: 9px; }
.log-row { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.log-row:last-child { border-bottom: 0; }

/* ---------- 의견 ---------- */
.fb-card { background: var(--card); border-radius: 20px; padding: 18px 20px; display: flex; flex-direction: column; gap: 10px; box-shadow: 0 5px 0 var(--line); }
.fb-reply { font-size: 14px; background: var(--bg); padding: 10px 14px; border-radius: 12px; }

/* ---------- 모달·토스트 ---------- */
.overlay { position: fixed; inset: 0; background: rgba(30, 27, 58, .55); display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 50; }
.modal { background: var(--card); border-radius: var(--radius-lg); padding: 26px; width: 100%; max-width: 560px; max-height: 90vh; overflow-y: auto; display: flex; flex-direction: column; gap: 16px; }
.modal.center { text-align: center; align-items: center; }
.levelup .title { font-size: 56px; color: var(--primary); }
.toast-wrap { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 60; align-items: center; pointer-events: none; }
.toast { background: var(--night); color: #fff; padding: 12px 20px; border-radius: 14px; font-weight: 700; box-shadow: 0 6px 18px rgba(0,0,0,.2); animation: pop .25s ease-out; }
.toast.xp { background: #FFB35C; color: var(--ink); font-family: var(--title); font-weight: 400; font-size: 22px; }
.toast.bad { background: var(--danger); }
@keyframes pop { from { transform: translateY(12px); opacity: 0; } to { transform: none; opacity: 1; } }
video.cam { width: 100%; border-radius: var(--radius-sm); background: #000; }
.loading { min-height: 100vh; display: flex; align-items: center; justify-content: center; font-family: var(--title); font-size: 28px; color: var(--primary); }

@media (max-width: 640px) {
  h1 { font-size: 28px; }
  .login-hero h1 { font-size: 40px; }
  .card { padding: 18px; }
  .page { padding: 16px 14px 48px; }
  .topbar-inner { padding: 10px 14px; }
  .me-chip .txt { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
