:root {
  --bg: #f6f3ec;
  --card: #ffffff;
  --ink: #1f2a26;
  --muted: #6b746f;
  --line: #e4dfd3;
  --pine: #2f5d50;
  --pine-2: #3f7a69;
  --pine-soft: #e3eee9;
  --sun: #f2b84b;
  --danger: #b4473a;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(31, 42, 38, .06), 0 4px 14px rgba(31, 42, 38, .05);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141917;
    --card: #1d2421;
    --ink: #eef1ee;
    --muted: #9aa49f;
    --line: #2c3531;
    --pine: #6fb39c;
    --pine-2: #85c4ae;
    --pine-soft: #23332d;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Pretendard", "Noto Sans KR", "Malgun Gothic", sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: .92rem; margin: .3rem 0 .8rem; }
.center { text-align: center; }

/* header */
.top {
  position: sticky; top: 0; z-index: 10;
  background: var(--bg);
  padding: calc(10px + env(safe-area-inset-top)) 16px 8px;
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 1.1rem; color: var(--pine); }
.brand svg { width: 26px; height: 26px; }
.kids { display: flex; gap: 8px; overflow-x: auto; padding: 10px 0 4px; scrollbar-width: none; }
.kids::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border: 1.5px solid var(--line); background: var(--card); color: var(--ink);
  padding: 7px 14px; border-radius: 999px; font-size: .95rem; font-weight: 600; cursor: pointer;
}
.chip.active { background: var(--pine); border-color: var(--pine); color: #fff; }
.chip.add { color: var(--muted); border-style: dashed; }

main { max-width: 560px; margin: 0 auto; padding: 14px 16px; }
.view { display: none; }
.view.active { display: block; }

.card { background: var(--card); border-radius: var(--radius); padding: 18px; margin-bottom: 14px; box-shadow: var(--shadow); border: 1px solid var(--line); }
.card h2 { margin: 0 0 .2rem; font-size: 1.1rem; }
.hero h1 { font-size: 1.25rem; margin: 0; line-height: 1.35; }
.section-title { font-size: 1rem; margin: 20px 4px 8px; color: var(--muted); }

/* buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 0; border-radius: 12px; padding: 11px 16px; font: inherit; font-weight: 700; cursor: pointer;
  background: var(--pine-soft); color: var(--pine); text-decoration: none;
  min-height: 44px; white-space: nowrap;
}
.btn.primary { background: var(--pine); color: #fff; }
.btn.primary:active { background: var(--pine-2); }
.btn.big { width: 100%; padding: 16px; font-size: 1.1rem; border-radius: 14px; }
.btn.big svg { width: 24px; height: 24px; }
.btn.ghost { background: transparent; border: 1.5px solid var(--line); color: var(--ink); }
.btn.small { padding: 8px 12px; font-size: .92rem; min-height: 40px; }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: .5; }
.alt-row { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.alt-row .btn { flex: 1; }

.manual { display: flex; gap: 8px; margin-top: 12px; }
input, textarea {
  font: inherit; font-size: 16px; /* iOS 확대 방지 */
  border: 1.5px solid var(--line); border-radius: 12px; padding: 10px 12px;
  background: var(--bg); color: var(--ink); width: 100%; min-width: 0;
}
input:focus, textarea:focus { outline: 2px solid var(--pine); outline-offset: 1px; }

/* scanner */
#reader { width: 100%; border-radius: 12px; overflow: hidden; background: #000; }
#reader video { border-radius: 12px; }
#scanner-wrap .btn { width: 100%; }

/* book result */
.book { display: flex; gap: 14px; }
.cover {
  flex: none; width: 92px; height: 128px; border-radius: 8px; object-fit: cover; background: var(--pine-soft);
  display: flex; align-items: center; justify-content: center; color: var(--pine); font-weight: 800; font-size: .8rem; text-align: center; padding: 6px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .12);
}
.book h3 { margin: 0 0 4px; font-size: 1.08rem; line-height: 1.35; word-break: break-word; }
.book .meta { font-size: .88rem; color: var(--muted); }
.badge { display: inline-block; background: var(--pine-soft); color: var(--pine); border-radius: 6px; padding: 2px 8px; font-size: .78rem; font-weight: 700; margin-top: 6px; }
.badge.sun { background: #fdf0d3; color: #8a5a00; }
.form-row { margin-top: 14px; }
.form-row > label { display: block; font-weight: 700; font-size: .92rem; margin-bottom: 6px; }
.seg { display: flex; gap: 6px; flex-wrap: wrap; }
.seg button { flex: 1; min-width: 30%; }
.seg button.on { background: var(--pine); color: #fff; border-color: var(--pine); }
.actions { display: flex; gap: 8px; margin-top: 16px; }
.actions .btn { flex: 1; }

/* lists */
.log-list { list-style: none; margin: 0; padding: 0; }
.log-item { display: flex; gap: 12px; align-items: center; padding: 10px 12px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; margin-bottom: 8px; }
.log-item .thumb { width: 40px; height: 56px; border-radius: 4px; object-fit: cover; background: var(--pine-soft); flex: none; }
.log-item .t { flex: 1; min-width: 0; }
.log-item .t b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .96rem; }
.log-item .t span { font-size: .82rem; color: var(--muted); }
.log-item .del { background: none; border: 0; color: var(--muted); font-size: 1.2rem; padding: 8px; cursor: pointer; }
.day-head { font-weight: 800; font-size: .9rem; color: var(--muted); margin: 18px 4px 8px; }
.empty { text-align: center; color: var(--muted); padding: 30px 10px; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px 8px; text-align: center; }
.stat b { display: block; font-size: 1.5rem; color: var(--pine); line-height: 1.2; }
.stat span { font-size: .8rem; color: var(--muted); }
.filter-row { margin-bottom: 4px; }

.kid-admin { list-style: none; margin: 0; padding: 0; }
.kid-admin li { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.kid-admin li span { flex: 1; font-weight: 700; }

/* tab bar */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  display: flex; background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar button {
  flex: 1; border: 0; background: none; color: var(--muted); font: inherit; font-size: .78rem; font-weight: 700;
  padding: 8px 0 10px; display: flex; flex-direction: column; align-items: center; gap: 2px; cursor: pointer;
}
.tabbar svg { width: 24px; height: 24px; }
.tabbar button.active { color: var(--pine); }

/* dialog */
dialog { border: 0; border-radius: 20px; padding: 24px; width: min(92vw, 400px); background: var(--card); color: var(--ink); }
dialog::backdrop { background: rgba(20, 25, 23, .55); }
dialog h2 { margin: 8px 0 0; }
dialog input { margin-bottom: 14px; }
.onboard-mt { width: 120px; display: block; }

#toast {
  position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 999px; font-weight: 700; font-size: .92rem;
  opacity: 0; pointer-events: none; transition: .25s; z-index: 30; max-width: 90vw; text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.spinner { width: 22px; height: 22px; border: 3px solid var(--pine-soft); border-top-color: var(--pine); border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; vertical-align: middle; margin-right: 8px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- 2단계: 로그인 · 모두의 책 · PC 화면 ---- */
.top-inner { display: flex; align-items: center; justify-content: space-between; max-width: 1080px; margin: 0 auto; }
.top .kids { max-width: 560px; margin: 0 auto; }
.topnav { display: none; gap: 4px; }
.topnav button { border: 0; background: none; font: inherit; font-weight: 700; color: var(--muted); padding: 8px 14px; border-radius: 10px; cursor: pointer; }
.topnav button.active { background: var(--pine-soft); color: var(--pine); }
.linkbtn { background: none; border: 0; color: var(--pine); font: inherit; font-weight: 700; cursor: pointer; padding: 8px; text-decoration: underline; text-underline-offset: 3px; }
.notice { border-color: var(--sun); background: color-mix(in srgb, var(--sun) 10%, var(--card)); }
.notice p { margin: 4px 0 0; }
#view-auth h1 { font-size: 1.3rem; margin: 10px 0 0; }

body.is-wide main { max-width: 1080px; }
.community-head h1 { font-size: 1.35rem; margin: 4px 0 0; }
.community-head .stats { margin: 12px 0; }
.book-grid { display: grid; grid-template-columns: 1fr; gap: 10px; margin-top: 10px; }
.book-grid .empty { grid-column: 1 / -1; }
.gbook { display: flex; gap: 12px; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px; }
.gcover { flex: none; width: 64px; height: 90px; border-radius: 6px; object-fit: cover; background: var(--pine-soft); color: var(--pine);
  display: flex; align-items: center; justify-content: center; text-align: center; font-size: .7rem; font-weight: 800; padding: 4px; overflow: hidden; }
.ginfo { min-width: 0; display: flex; flex-direction: column; gap: 2px; flex: 1; }
.ginfo b { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; line-height: 1.3; }
.ginfo .meta { font-size: .82rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gcount { font-size: .84rem; color: var(--ink); }
.gcount strong { color: var(--pine); }
.ginfo .btn { align-self: flex-start; margin-top: auto; }

@media (min-width: 640px) {
  .book-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (min-width: 900px) {
  body { padding-bottom: 24px; }
  .tabbar { display: none; }
  .topnav { display: flex; }
  .community-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; }
  .community-head .stats { min-width: 360px; }
  .book-grid { grid-template-columns: repeat(3, 1fr); }
  .gbook { flex-direction: column; }
  .gcover { width: 100%; height: 220px; font-size: .9rem; }
  img.gcover { object-fit: contain; background: var(--bg); }
  #toast { bottom: 32px; }
}
@media (min-width: 1080px) { .book-grid { grid-template-columns: repeat(4, 1fr); } }
.auth-error { margin: 14px 0 0; padding: 10px 12px; border-radius: 10px; background: color-mix(in srgb, var(--danger) 10%, var(--card)); color: var(--danger); font-size: .9rem; word-break: break-word; }
#reader { position: relative; }
#reader video { display: block; width: 100%; height: auto; }
.scan-strip { position: absolute; left: 4%; top: 28%; width: 92%; height: 44%; border: 3px solid #5fd3a7; border-radius: 10px; box-shadow: 0 0 0 999px rgba(0,0,0,.35); pointer-events: none; }
.scan-strip i { position: absolute; left: 6%; right: 6%; top: 50%; height: 2px; background: #ff5a4e; opacity: .8; }

/* ---- 3단계: 난이도 · 한줄평 ---- */
.gbook { cursor: pointer; transition: border-color .15s; }
.gbook:hover { border-color: var(--pine); }
.lvl { align-self: flex-start; display: inline-block; background: var(--pine); color: #fff; border-radius: 6px; padding: 1px 8px; font-size: .76rem; font-weight: 800; }
.lvl.none { background: var(--pine-soft); color: var(--muted); font-weight: 600; }
.log-item { cursor: pointer; }
.level-filter { display: flex; gap: 6px; overflow-x: auto; padding: 4px 0 10px; scrollbar-width: none; }
.level-filter::-webkit-scrollbar { display: none; }
.level-filter .chip { padding: 6px 12px; font-size: .88rem; }
.back { padding: 4px 0 10px; text-decoration: none; }
.lvl-big { font-size: 1.8rem; font-weight: 800; color: var(--pine); margin: 6px 0 10px; }
.lvl-big small { display: block; font-size: .85rem; color: var(--muted); font-weight: 600; }
.hist { display: grid; grid-template-columns: repeat(12, 1fr); gap: 4px; height: 110px; align-items: end; }
.hcol { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 4px; }
.hbar { width: 100%; background: var(--pine); border-radius: 4px 4px 0 0; min-height: 2px; opacity: .85; }
.hcol span { font-size: .7rem; color: var(--muted); font-weight: 700; }
.level-pick { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 8px; }
.level-pick .chip { padding: 9px 4px; font-size: .9rem; text-align: center; }
.reviews { list-style: none; margin: 8px 0 0; padding: 0; }
.reviews li { border-top: 1px solid var(--line); padding: 10px 0; }
.reviews li:first-child { border-top: 0; }
.reviews p { margin: 4px 0 2px; }
#view-book .book h3 { font-size: 1.2rem; }
.tags { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.lvl.sug { background: var(--pine-soft); color: var(--pine); border: 1px dashed var(--pine); }
.lvl-big.sug { color: var(--pine-2); }
.mini-stars { font-size: .78rem; font-weight: 800; color: #c98a12; }
.stars { color: #f2b84b; letter-spacing: 1px; font-size: .95rem; }
.stars i { font-style: normal; color: var(--line); }
.star-sum { margin-top: 12px; display: flex; align-items: center; gap: 6px; }
.star-sum .stars { font-size: 1.3rem; }
.star-pick { display: flex; gap: 4px; }
.star-pick button { background: none; border: 0; font-size: 2.1rem; line-height: 1; color: var(--line); cursor: pointer; padding: 2px; }
.star-pick button.on { color: #f2b84b; }
