/* 하루쌤 — 모바일 우선, 최대 폭 560px 카드형 레이아웃 */
:root {
  --primary: #5b7cfa;
  --primary-d: #4a63e0;
  --primary-l: #eef1ff;
  --bg: #f5f7fc;
  --card: #fff;
  --text: #1f2333;
  --muted: #7a8199;
  --line: #e6e9f2;
  --ok: #22b07d;
  --warn: #f2994a;
  --danger: #eb5757;
  --radius: 16px;
  --shadow: 0 2px 10px rgba(40, 52, 110, 0.06);
  --tab-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12141c;
    --card: #1c1f2b;
    --text: #e9ebf3;
    --muted: #9aa1b8;
    --line: #2c3042;
    --primary-l: #252c4d;
    --shadow: none;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: Pretendard, -apple-system, BlinkMacSystemFont, 'Apple SD Gothic Neo', 'Noto Sans KR', 'Malgun Gothic', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  word-break: keep-all;
  overflow-wrap: anywhere;
}
body.noscroll { overflow: hidden; }
a { color: var(--primary); text-decoration: none; }
h1, h2, h3 { margin: 0 0 8px; line-height: 1.3; }
h1 { font-size: 1.35rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: 1rem; }
p { margin: 4px 0; }
code { background: var(--primary-l); padding: 1px 5px; border-radius: 5px; font-size: 0.85em; }
img { max-width: 100%; }

/* 뼈대 */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  max-width: 560px; margin: 0 auto; padding: 10px 16px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 1.15rem; color: var(--text); }
.topnav { display: flex; align-items: center; gap: 12px; font-size: 0.9rem; }
.view { max-width: 560px; margin: 0 auto; padding: 4px 16px calc(var(--tab-h) + 90px); }
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  display: flex; justify-content: space-around;
  height: calc(var(--tab-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--card); border-top: 1px solid var(--line);
}
.tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; color: var(--muted); font-size: 0.72rem; }
.tabbar a i { font-style: normal; font-size: 1.25rem; filter: grayscale(1); opacity: 0.7; }
.tabbar a.on { color: var(--primary); font-weight: 700; }
.tabbar a.on i { filter: none; opacity: 1; }
body.guest .topbar, body.guest .tabbar { display: none; }
body.guest .view { padding-bottom: 40px; }

/* 공통 */
.card { display: block; background: var(--card); border-radius: var(--radius); padding: 16px; margin: 12px 0; box-shadow: var(--shadow); color: inherit; }
.row { display: flex; }
.row.gap { gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.row > label { flex: 1; }
.between { justify-content: space-between; }
.center-v { align-items: center; }
.row.end { justify-content: flex-end; }
.grow { flex: 1; min-width: 0; }
.center { text-align: center; justify-content: center; }
.block { display: block; width: 100%; }
.nowrap { white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.tiny { font-size: 0.75rem; }
.big { font-size: 2.4rem; margin: 0; }
.sec-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 18px 0 6px; }
.sec-head h1, .sec-head h2 { margin: 0; }
.hint { font-size: 0.82rem; color: var(--muted); margin: 2px 0 8px; }
.notice { background: var(--primary-l); border-radius: 12px; padding: 10px 14px; margin: 10px 0; font-size: 0.9rem; }
.notice.warn { background: color-mix(in srgb, var(--warn) 16%, var(--card)); }
.empty { text-align: center; padding: 30px 16px; }
.empty .btn { margin-top: 10px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line); background: var(--card); color: var(--text);
  padding: 10px 16px; border-radius: 12px; font: inherit; font-weight: 600; cursor: pointer;
  transition: transform 0.05s, background 0.15s;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-d); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.danger.ghost { background: transparent; color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, transparent); }
.btn.ghost { background: transparent; }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.sm { padding: 6px 12px; font-size: 0.85rem; border-radius: 10px; }
.btn.lg { padding: 14px 18px; font-size: 1.05rem; }
.link { background: none; border: 0; color: var(--primary); font: inherit; cursor: pointer; padding: 4px; }
.link.danger { color: var(--danger); }
.icon-btn { background: none; border: 0; font-size: 1.4rem; color: var(--text); cursor: pointer; padding: 2px 10px; line-height: 1; }
.icon-btn:disabled { opacity: 0.3; }
.chip { border: 1px solid var(--line); background: var(--card); color: var(--text); border-radius: 999px; padding: 5px 12px; font: inherit; font-size: 0.85rem; cursor: pointer; white-space: nowrap; }
.chip.on { background: var(--primary); color: #fff; border-color: var(--primary); }
.chips, .quick, .quick-dday { display: flex; gap: 6px; overflow-x: auto; padding: 4px 0; }
.badge { display: inline-block; font-size: 0.75rem; padding: 2px 9px; border-radius: 999px; background: var(--primary-l); color: var(--primary); font-weight: 600; }
.badge.ok, .badge.done { background: color-mix(in srgb, var(--ok) 15%, transparent); color: var(--ok); }
.badge.overdue, .badge.k-wrong { background: color-mix(in srgb, var(--danger) 15%, transparent); color: var(--danger); }
.badge.k-weak, .badge.paused { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: var(--primary); flex: none; }
.dot.ok { background: var(--ok); }
.dot.ring { background: transparent; border: 2px solid var(--primary); }

.bar { height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; flex: 1; }
.bar span { display: block; height: 100%; border-radius: 99px; transition: width 0.4s; }

/* 폼 */
.form label, .card label { display: block; font-size: 0.85rem; color: var(--muted); margin: 8px 0; }
input, select, textarea {
  display: block; width: 100%; margin-top: 4px; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--bg); color: var(--text);
  font: inherit; font-size: 1rem;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; }
input[type=checkbox], input[type=radio] { width: auto; display: inline; margin: 0; }
fieldset { border: 0; padding: 0; margin: 10px 0; }
legend { font-size: 0.85rem; color: var(--muted); padding: 0; margin-bottom: 4px; }
.form .btn.block { margin-top: 14px; }
.colors { display: flex; gap: 8px; flex-wrap: wrap; }
.color input { position: absolute; opacity: 0; }
.color span { display: block; width: 30px; height: 30px; border-radius: 50%; border: 3px solid transparent; cursor: pointer; }
.color input:checked + span { border-color: var(--text); }
.scale { display: flex; gap: 6px; flex-wrap: wrap; }
.scale legend { width: 100%; }
.pill { margin: 0 !important; }
.pill input { position: absolute; opacity: 0; }
.pill span { display: inline-block; padding: 6px 10px; border: 1px solid var(--line); border-radius: 999px; cursor: pointer; color: var(--text); }
.pill input:checked + span { background: var(--primary); color: #fff; border-color: var(--primary); }
.switch { display: flex !important; align-items: center; gap: 10px; color: var(--text) !important; }
.switch input { width: 20px; height: 20px; }
.week-inputs { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.week-inputs label { text-align: center; margin: 0; font-weight: 600; color: var(--text); }
.week-inputs label.sun { color: var(--danger); }
.week-inputs label.sat { color: var(--primary); }
.week-inputs input { padding: 8px 2px; text-align: center; font-size: 0.9rem; }
.week-inputs small { color: var(--muted); font-weight: 400; }

/* 로그인 */
.auth { padding-top: 24px; }
.auth-hero { text-align: center; padding: 10px 0 4px; }
.auth-hero h1 { font-size: 2rem; margin: 8px 0 0; }
.auth-hero .sub { color: var(--muted); font-size: 0.85rem; margin: 0; }
.auth-hero .slogan { font-size: 1.15rem; font-weight: 700; color: var(--primary); margin: 10px 0 4px; }
.features { list-style: none; padding: 0; margin: 16px 0; display: grid; gap: 8px; font-size: 0.9rem; }
.features li { background: var(--card); border-radius: 12px; padding: 10px 14px; }
.features b { margin-right: 6px; }

/* 홈 */
.hero {
  --c: var(--primary);
  background: linear-gradient(135deg, var(--c), color-mix(in srgb, var(--c) 65%, #1a1f4a));
  color: #fff; border-radius: 22px; padding: 20px; margin: 8px 0 14px; position: relative;
}
.hero .hello { opacity: 0.9; font-size: 0.9rem; }
.hero .goal { font-weight: 600; }
.hero .dday { font-size: 3rem; font-weight: 800; line-height: 1.1; margin: 6px 0 10px; letter-spacing: -1px; }
.hero .bar { background: rgba(255, 255, 255, 0.3); }
.hero-prog b { font-size: 1.3rem; }
.hero .streak { position: absolute; top: 16px; right: 16px; background: rgba(255, 255, 255, 0.2); padding: 3px 10px; border-radius: 99px; font-size: 0.8rem; }
.goal-card { border-left: 5px solid var(--c, var(--primary)); }
.goal-card.done { opacity: 0.85; }
.goal-top { display: flex; gap: 12px; margin-bottom: 10px; }
.goal-card h3 a { color: inherit; }
.goal-card .range { font-size: 1rem; }
.goal-card .row { margin-top: 8px; }
.cover { width: 58px; height: 78px; border-radius: 8px; object-fit: cover; flex: none; background: var(--primary-l); }
.cover.lg { width: 76px; height: 102px; }
.cover.ph { display: flex; align-items: center; justify-content: center; background: var(--c, var(--primary)); color: #fff; font-weight: 800; font-size: 1.05rem; }
.advice { background: var(--primary-l); }
.advice p { white-space: pre-wrap; }
.review-cta { display: flex; justify-content: space-between; align-items: center; color: var(--text); }
.timeline { list-style: none; padding: 8px 16px; }
.timeline li { display: flex; gap: 12px; align-items: center; padding: 10px 0; border-bottom: 1px dashed var(--line); }
.timeline li:last-child { border-bottom: 0; }
.timeline time { font-weight: 700; font-variant-numeric: tabular-nums; width: 46px; color: var(--primary); }
.timeline .tl-title { flex: 1; }
.timeline .tl-min { color: var(--muted); font-size: 0.85rem; }
.timeline .tl-break { color: var(--muted); }
.timeline .tl-break time { color: var(--muted); }
.timeline .tl-review time, .timeline .tl-quiz time { color: var(--ok); }
.sticky-cta { position: sticky; bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 10px); z-index: 10; margin: 16px 0; }
.sticky-cta .btn { box-shadow: 0 6px 18px rgba(74, 99, 224, 0.35); }
.book-mini { display: flex; justify-content: space-between; align-items: center; border-left: 5px solid var(--c); }
.today-sum .row { margin-bottom: 6px; }

/* 책장 */
.shelf { display: grid; gap: 4px; }
.book-card { display: flex; gap: 14px; border-left: 5px solid var(--c); }
.book-card h3 { margin: 2px 0; }
.book-card .bar { margin: 6px 0 2px; }
.book-head { border-top: 6px solid var(--c); }
.book-head h1 { margin: 2px 0; }
.dday-sm { font-weight: 800; font-size: 1.3rem; color: var(--c); }
.stats3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 14px 0; text-align: center; }
.stats3 div { background: var(--bg); border-radius: 12px; padding: 8px; }
.stats3 b { display: block; font-size: 1.2rem; }
.stats3 span { font-size: 0.75rem; color: var(--muted); }
.chapters, .plan-list, .log-list { list-style: none; margin: 0; padding: 0; }
.chapters li, .plan-list li, .log-list li { display: flex; gap: 10px; align-items: center; padding: 9px 0; border-bottom: 1px solid var(--line); }
.chapters li:last-child, .plan-list li:last-child, .log-list li:last-child { border-bottom: 0; }
.chapters li.done { color: var(--muted); text-decoration: line-through; }
.chapters li.now { font-weight: 700; }
.diff { font-size: 0.72rem; padding: 1px 8px; border-radius: 99px; }
.diff.d1 { background: color-mix(in srgb, var(--ok) 15%, transparent); color: var(--ok); }
.diff.d2 { background: var(--primary-l); color: var(--primary); }
.diff.d3 { background: color-mix(in srgb, var(--danger) 15%, transparent); color: var(--danger); }
.plan-list .date, .log-list .date { width: 92px; flex: none; font-size: 0.85rem; color: var(--muted); }
.plan-list li.today { font-weight: 700; }
.plan-list li.today .date { color: var(--primary); }
.plan-list li.final .grow { color: var(--warn); font-weight: 600; }

/* 캘린더 */
.cal-nav { display: flex; align-items: center; justify-content: space-between; padding: 8px 6px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 3px; }
.cal-grid.head span { text-align: center; font-size: 0.78rem; color: var(--muted); padding: 4px 0; }
.cal-grid.head .sun { color: var(--danger); }
.cal-grid.head .sat { color: var(--primary); }
.cal-day {
  min-height: 56px; border: 0; background: var(--bg); border-radius: 10px; padding: 4px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 2px; font: inherit; color: var(--text);
}
.cal-day .num { font-size: 0.85rem; font-weight: 600; position: relative; }
.cal-day .chk { font-style: normal; color: var(--ok); font-size: 0.7rem; margin-left: 2px; }
.cal-day .dd { font-size: 0.6rem; background: var(--danger); color: #fff; border-radius: 6px; padding: 0 4px; font-weight: 700; }
.cal-day .dots { display: flex; gap: 2px; flex-wrap: wrap; justify-content: center; }
.cal-day .dots i { width: 7px; height: 7px; border-radius: 50%; }
.cal-day .dots i.ring { background: transparent !important; border: 2px solid var(--warn); }
.cal-day.other { opacity: 0.35; }
.cal-day.past .dots { opacity: 0.45; }
.cal-day.today { outline: 2px solid var(--primary); }
.cal-day.sel { background: var(--primary-l); }
.cal-day.off { background: repeating-linear-gradient(45deg, var(--bg), var(--bg) 4px, var(--line) 4px, var(--line) 6px); }
.legend { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 10px; align-items: center; }
.legend span { display: inline-flex; gap: 4px; align-items: center; }
.offmark { padding: 0 6px; border-radius: 4px; background: repeating-linear-gradient(45deg, var(--bg), var(--bg) 4px, var(--line) 4px, var(--line) 6px); }

/* 대화 */
.chat-page { display: flex; flex-direction: column; min-height: calc(100vh - 200px); }
.chat-ctl select { margin: 0 0 4px; }
.chat { flex: 1; display: flex; flex-direction: column; gap: 10px; padding: 12px 0; overflow-y: auto; max-height: calc(100vh - 360px); min-height: 240px; }
.msg { max-width: 86%; padding: 10px 14px; border-radius: 18px; white-space: normal; line-height: 1.6; }
.msg.bot { align-self: flex-start; background: var(--card); border-top-left-radius: 4px; box-shadow: var(--shadow); }
.msg.me { align-self: flex-end; background: var(--primary); color: #fff; border-top-right-radius: 4px; }
.typing span { display: inline-block; width: 7px; height: 7px; margin: 0 2px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite; }
.typing span:nth-child(2) { animation-delay: 0.2s; }
.typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.2; } 40% { opacity: 1; } }
.chat-input { display: flex; gap: 8px; align-items: flex-end; position: sticky; bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 6px); background: var(--bg); padding: 6px 0; }
.chat-input textarea { margin: 0; resize: none; }

/* 집중 */
.focus { text-align: center; }
.ring-wrap { position: relative; width: 240px; height: 240px; margin: 16px auto; }
.ring { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 8; }
.ring .bg { stroke: var(--line); }
.ring .fg { stroke: var(--c, var(--primary)); stroke-linecap: round; transition: stroke-dashoffset 0.5s linear; }
.ring .fg.brk { stroke: var(--ok); }
.ring-text { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.ring-text b { font-size: 3rem; font-variant-numeric: tabular-nums; letter-spacing: -1px; }
.ring-text #phase { font-weight: 700; color: var(--c, var(--primary)); }
.focus .row { margin-top: 10px; }
.focus .link.block { margin-top: 10px; }

/* 복습 */
.tabs { display: flex; gap: 4px; background: var(--card); border-radius: 12px; padding: 4px; margin: 10px 0; }
.tab { flex: 1; border: 0; background: none; padding: 8px 4px; border-radius: 9px; font: inherit; font-size: 0.85rem; color: var(--muted); cursor: pointer; }
.tab.on { background: var(--primary); color: #fff; font-weight: 700; }
.rv { position: relative; border-left: 5px solid var(--c, var(--primary)); }
.rv h3 { margin: 8px 0 4px; }
.rv-content { white-space: pre-wrap; background: var(--bg); border-radius: 10px; padding: 8px 10px; font-size: 0.9rem; }
.rv-del { position: absolute; bottom: 8px; right: 10px; }
.stages { display: flex; gap: 4px; margin: 8px 0; }
.stages span { flex: 1; text-align: center; font-size: 0.7rem; padding: 2px 0; border-radius: 6px; background: var(--bg); color: var(--muted); }
.stages span.on { background: var(--ok); color: #fff; }
.stages span.cur { outline: 2px solid var(--primary); color: var(--primary); font-weight: 700; }
.result-row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--line); padding-right: 40px; }
.quiz-list { padding-left: 20px; margin: 8px 0; }
.quiz-list li { margin-bottom: 10px; }
.quiz-list summary { cursor: pointer; color: var(--primary); font-size: 0.85rem; }

/* 리포트 */
.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin: 12px 0; }
.tile { background: var(--card); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.tile span { display: block; font-size: 0.8rem; color: var(--muted); }
.tile b { font-size: 1.35rem; }
.tile small { display: block; font-size: 0.75rem; color: var(--muted); }
.chart { width: 100%; height: auto; }
.chart .cbar { fill: var(--primary); opacity: 0.85; }
.chart .cbar-ok { fill: var(--ok); }
.chart .future { opacity: 0.3; }
.chart .axis { stroke: var(--line); }
.chart text { font-size: 9px; fill: var(--muted); text-anchor: middle; }
.chart text.v { fill: var(--text); }
.chart text.today { fill: var(--primary); font-weight: 700; }
.chart > text.lbl:first-of-type { text-anchor: start; }
.prog-row { margin: 10px 0; }
.prog-row .bar { margin-top: 4px; }

/* 모달 · 토스트 · 로딩 */
.modal-wrap { position: fixed; inset: 0; z-index: 100; background: rgba(15, 18, 35, 0.5); display: flex; align-items: flex-end; justify-content: center; }
.modal { position: relative; background: var(--card); width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto; border-radius: 22px 22px 0 0; padding: 22px 18px calc(22px + env(safe-area-inset-bottom)); animation: up 0.2s ease-out; }
@media (min-width: 600px) { .modal-wrap { align-items: center; } .modal { border-radius: 22px; } }
@keyframes up { from { transform: translateY(30px); opacity: 0; } }
.modal-x { position: absolute; top: 10px; right: 12px; border: 0; background: none; font-size: 1.6rem; color: var(--muted); cursor: pointer; }
.confirm-msg { margin: 10px 0 18px; }
#toasts { position: fixed; left: 50%; top: 14px; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; width: min(92vw, 420px); pointer-events: none; }
.toast { background: #262b40; color: #fff; padding: 12px 16px; border-radius: 12px; font-size: 0.92rem; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2); transition: opacity 0.4s, transform 0.4s; }
.toast-ok { background: var(--ok); }
.toast-error { background: var(--danger); }
.toast.out { opacity: 0; transform: translateY(-8px); }
.loading { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 60px 0; color: var(--muted); }
.spinner { display: inline-block; width: 16px; height: 16px; border: 2px solid var(--line); border-top-color: var(--primary); border-radius: 50%; animation: spin 0.8s linear infinite; vertical-align: -3px; }
@keyframes spin { to { transform: rotate(360deg); } }
