:root,
.skin-pokapoka {
  --bg: #fff5e9;
  --dot: #f1dcc3;
  --card: #fffdf8;
  --ink: #4b3428;
  --muted: #86695a; /* 4.5:1 넘게: 글자로도 쓰이니까 */
  --line: #f0dfcb;
  --coral: #ff8a65;
  --coral-text: #b8482a; /* 코랄 글씨용. 배경 코랄은 그대로 */
  --peach: #ffcdb5;
  --butter: #ffe39a;
  --sage: #cde5bb;
  --sky: #c6e1f5;
  --pink: #fbcadb;
  --lilac: #ddd2f5;
  --on-pastel: #4b3428;
  --pop: 0 4px 0 var(--ink);
  --pop-lg: 0 6px 0 var(--ink);
  --soft: 0 14px 30px -14px rgb(120 70 40 / 0.35);
  --round: 'Zen Maru Gothic', 'Apple SD Gothic Neo', system-ui, sans-serif;
  --display: 'Jua', 'Zen Maru Gothic', 'Apple SD Gothic Neo', sans-serif;
  --gutter: 18px;
  /* 화면 위아래 안전 여백. Capacitor 가 CSS 변수를 넣는 설정이면 그 값을, 아니면 env() */
  --inset-top: var(--safe-area-inset-top, env(safe-area-inset-top, 0px));
  --inset-bottom: var(--safe-area-inset-bottom, env(safe-area-inset-bottom, 0px));
  color-scheme: light;
}

/* 밤 (기본). html[data-mode] 는 skin.js 가 첫 화면 전에 정한다 */
:root[data-mode='dark'],
[data-mode='dark'] .skin-pokapoka {
  --bg: #2b211c;
  --dot: #3e3029;
  --card: #372a23;
  --ink: #fbeee0;
  --muted: #b49c8a;
  --line: #4a3a31;
  --coral: #ff9a78;
  --coral-text: #ff9a78;
  --peach: #f2b59a;
  --butter: #f3d27c;
  --sage: #b5d29f;
  --sky: #a9cbe6;
  --pink: #eeafc3;
  --lilac: #c6b8ea;
  --on-pastel: #2b211c;
  --pop: 0 4px 0 #170f0b;
  --pop-lg: 0 6px 0 #170f0b;
  --soft: 0 14px 30px -14px rgb(0 0 0 / 0.7);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100dvh;
  background-color: var(--bg);
  background-image: radial-gradient(var(--dot) 1.4px, transparent 1.6px);
  background-size: 22px 22px;
  color: var(--ink);
  font-family: var(--round);
  font-size: 16px;
  font-weight: 500;
  line-height: 1.6;
  -webkit-tap-highlight-color: transparent;
}

main {
  max-width: 680px;
  margin: 0 auto;
  padding: calc(var(--inset-top) + 12px) var(--gutter) 130px;
}

a { color: inherit; text-decoration: none; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px dashed var(--coral); outline-offset: 3px; }

/* ───────── 공용 ───────── */

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 0 0 14px;
  padding: 5px 14px;
  border: 2px solid var(--ink);
  border-radius: 999px;
  background: var(--butter);
  color: var(--on-pastel);
  font-size: 13px;
  font-weight: 700;
  box-shadow: 0 3px 0 var(--ink);
  transform: rotate(-2deg);
}

.home-head { padding: 30px 0 26px; }
.home-head h1 {
  margin: 0;
  font-family: var(--display);
  font-weight: 400;
  font-size: clamp(32px, 9vw, 46px);
  line-height: 1.22;
}
mark {
  padding: 0 4px;
  background: linear-gradient(transparent 58%, color-mix(in srgb, var(--coral) 45%, transparent) 58% 92%, transparent 92%);
  color: inherit;
}
.lead { margin: 14px 0 0; color: var(--muted); font-size: 14px; }

.primary {
  padding: 13px 28px;
  border: 2px solid var(--ink);
  border-radius: 999px;
  background: var(--coral);
  color: var(--on-pastel);
  font-family: var(--display);
  font-size: 17px;
  box-shadow: var(--pop);
  transition: transform 0.12s, box-shadow 0.12s;
}
.primary:active { transform: translateY(4px); box-shadow: 0 0 0 var(--ink); }

.text-btn {
  padding: 8px 6px;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border: 2px solid var(--ink);
  border-radius: 50%;
  background: var(--card);
  font-size: 18px;
  box-shadow: 0 3px 0 var(--ink);
  transition: transform 0.12s, box-shadow 0.12s;
}
.icon-btn:active { transform: translateY(3px); box-shadow: none; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: grid;
  /* 양옆은 같은 폭이라 제목이 화면 정중앙. 좁으면 제목이 말줄임으로 줄어든다 (양옆 버튼은 안 꺾임) */
  grid-template-columns: minmax(max-content, 1fr) minmax(0, max-content) minmax(max-content, 1fr);
  align-items: center;
  gap: 10px;
  margin: 0 calc(var(--gutter) * -1) 22px;
  padding: calc(var(--inset-top) + 8px) var(--gutter) 8px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.topbar-title {
  margin: 0;
  overflow: hidden;
  font-size: 16px;
  font-weight: 700;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ───────── 하단 탭 ───────── */

.tabs,
.pager {
  position: fixed;
  left: 50%;
  bottom: calc(var(--inset-bottom) + 18px);
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 5px;
  border: 2px solid var(--ink);
  border-radius: 999px;
  background: var(--card);
  box-shadow: var(--pop), var(--soft);
  transform: translateX(-50%);
  width: max-content; /* left:50% 상자는 화면 절반 폭에 갇혀 글자가 세로로 꺾인다 */
}
.tabs a {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 9px 20px;
  border-radius: 999px;
  color: var(--muted);
  font-family: var(--display);
  font-size: 16px;
  white-space: nowrap;
  transition: background 0.2s, color 0.2s;
}
@media (max-width: 380px) { .tabs a { padding: 9px 14px; } }
.tabs a span { font-family: var(--round); font-weight: 900; }
body[data-view='home'] .tabs [data-tab='home'],
body[data-view='quiz'] .tabs [data-tab='quiz'],
body[data-view='me'] .tabs [data-tab='me'] { background: var(--butter); color: var(--on-pastel); }
body[data-view='book'] .tabs,
body[data-view='new'] .tabs,
body[data-view='login'] .tabs { display: none; }
body[data-view='login'] main { padding-bottom: calc(var(--inset-bottom) + 12px); } /* 탭이 없으니 아래 여백도 위와 같게 → 인트로가 화면 정중앙 */

/* ───────── 책장 ───────── */

.shelf {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(132px, 1fr));
  gap: 34px 20px;
}

.book { display: flex; flex-direction: column; gap: 6px; }
/* 끌어서 순서 바꾸기 */
.shelf .book:not(.add) { -webkit-touch-callout: none; user-select: none; -webkit-user-select: none; }
.book.dragging { position: relative; z-index: 5; cursor: grabbing; pointer-events: none; }
.book.dragging .cover { transform: rotate(-4deg) scale(1.06); box-shadow: inset 6px 0 0 rgb(0 0 0 / 0.07), 0 14px 0 -4px var(--ink), var(--soft); }
.book.dragging .cover { animation: none; }
/* 집은 동안 다른 책들이 자리를 내주려는 듯 꼼지락 */
.shelf.sorting .book:not(.dragging) .cover { animation: jiggle 0.28s ease-in-out infinite alternate; }
.shelf.sorting .book:nth-child(even):not(.dragging) .cover { animation-delay: -0.14s; }
@keyframes jiggle { from { rotate: -1.2deg; } to { rotate: 1.2deg; } }
@media (prefers-reduced-motion: reduce) { .shelf.sorting .book .cover { animation: none; } }

.cover {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 12 / 17;
  margin-bottom: 8px;
  object-fit: cover;
  border: 2px solid var(--ink);
  border-radius: 10px 18px 18px 10px;
  box-shadow: inset 6px 0 0 rgb(0 0 0 / 0.07), var(--pop-lg);
  transition: transform 0.3s cubic-bezier(0.3, 1.6, 0.5, 1), box-shadow 0.2s;
}
.book:focus-visible .cover { transform: translateY(-6px) rotate(-2.5deg); }
.book:active .cover { transform: translateY(2px); box-shadow: inset 6px 0 0 rgb(0 0 0 / 0.07), 0 1px 0 var(--ink); }

/* 표지 없는 책: 파스텔 표지 + 세로쓰기 라벨 */
.cover-blank {
  display: grid;
  place-items: center;
  min-height: 0;
  overflow: hidden; /* 긴 제목이 표지 비율을 늘리지 않게 */
  padding: 10px;
  background: var(--peach);
  color: var(--on-pastel);
}
.book:nth-child(4n + 2) .cover-blank { background: var(--sky); }
.book:nth-child(4n + 3) .cover-blank { background: var(--sage); }
.book:nth-child(4n + 4) .cover-blank { background: var(--lilac); }
.cover-blank span {
  max-height: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 10px 6px;
  border: 2px solid var(--ink);
  border-radius: 999px;
  background: var(--card);
  color: var(--ink);
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.02em;
  writing-mode: vertical-rl;
}
.has-img span { box-shadow: 0 3px 0 var(--ink); }

.cover-add {
  display: grid;
  place-items: center;
  border: 2.5px dashed var(--muted);
  background: color-mix(in srgb, var(--card) 60%, transparent);
  box-shadow: none;
  color: var(--muted);
  font-size: 34px;
}

.book-title {
  display: -webkit-box;
  overflow: hidden;
  font-weight: 700;
  min-height: 2.7em; /* 항상 2줄 높이 → 1줄 제목이어도 진도 바가 옆 책과 나란히 */
  font-size: 15px;
  line-height: 1.35;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}
.book-meta { color: var(--coral-text); font-size: 13px; font-weight: 700; font-variant-numeric: tabular-nums; }
.book-meta em { color: var(--muted); font-style: normal; font-weight: 500; }
.bar { height: 8px; overflow: hidden; border: 2px solid var(--ink); border-radius: 999px; background: var(--card); }
.bar i { display: block; height: 100%; border-radius: 999px; background: var(--butter); }

.home-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.avatar-link { flex: none; border-radius: 50%; }

/* 아바타: 사진이 있으면 사진, 없으면 이름 첫 글자 */
.avatar {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  object-fit: cover;
  border: 2px solid var(--ink);
  border-radius: 50%;
  background: var(--pink);
  color: var(--on-pastel);
  font-weight: 900;
  font-size: 15px;
  box-shadow: 0 3px 0 var(--ink);
}
.avatar.lg { width: 76px; height: 76px; font-size: 30px; box-shadow: var(--pop); }

/* ───────── 인트로 · 로그인 ───────── */

.intro {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: calc(100dvh - var(--inset-top) - var(--inset-bottom) - 24px);
  text-align: center;
}

/* 本·読·積 = 책을 읽고 쌓는다. 아이콘과 같은 남색 타일이 하나씩 떨어져 놓인다 */
.intro-kanji { display: flex; justify-content: center; gap: 12px; margin-bottom: 30px; }
.kanji-tile {
  display: grid;
  justify-items: center;
  gap: 6px;
  animation: tile-drop 0.5s cubic-bezier(0.3, 1.5, 0.5, 1) both;
}
.kanji-tile:nth-child(2) { animation-delay: 0.3s; }
.kanji-tile:nth-child(3) { animation-delay: 0.6s; }
.kanji-tile img,
.kanji-tile b {
  display: grid;
  place-items: center;
  width: 92px;
  height: 92px;
  border: 3px solid var(--ink);
  border-radius: 24px;
  background: #1f2b4a; /* 아이콘 남색 — 테마와 무관하게 아이콘 색 그대로 */
  box-shadow: 0 5px 0 var(--ink);
}
.kanji-tile:nth-child(1) img { transform: rotate(-5deg); }
.kanji-tile:nth-child(3) b { transform: rotate(5deg); }
.kanji-tile b {
  color: #e3f3ff;
  font-family: var(--round);
  font-size: 54px;
  font-weight: 900;
  line-height: 1;
  -webkit-text-stroke: 3px #e3f3ff;
  paint-order: stroke fill;
  text-shadow: 0 5px 0 #7fb6e6;
}
.kanji-tile i { color: var(--muted); font-size: 12px; font-style: normal; font-weight: 700; }

.intro-title {
  margin: 0;
  font-family: 'Mochiy Pop One', var(--round);
  font-weight: 400;
  font-size: clamp(38px, 11vw, 54px);
  line-height: 1.15;
  letter-spacing: 0.02em;
  animation: stamp 0.5s cubic-bezier(0.3, 1.6, 0.5, 1) 1.4s both;
}
.intro-lead { margin: 14px 0 0; color: var(--muted); font-size: 15px; animation: rise 0.5s ease-out 1.6s both; }
.intro-sso {
  display: grid;
  gap: 12px;
  width: min(100%, 340px);
  margin: 40px auto 0;
  animation: rise 0.6s ease-out 1.85s both;
}

/* 카카오·구글 버튼은 각 사의 색 가이드를 따른다 */
.sso {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 52px;
  border-radius: 14px;
  font-size: 16px;
  font-weight: 700;
  transition: transform 0.12s, box-shadow 0.12s, opacity 0.2s;
}
.sso svg { flex: none; width: 20px; height: 20px; }
.sso.kakao { border: 2px solid var(--ink); background: #fee500; color: rgb(0 0 0 / 0.85); box-shadow: 0 4px 0 var(--ink); }
.sso.google { border: 2px solid var(--ink); background: #fff; color: #1f1f1f; box-shadow: 0 4px 0 var(--ink); }
.sso:active:not(:disabled) { transform: translateY(4px); box-shadow: none; }
.sso:disabled { opacity: 0.6; cursor: progress; }
.intro-fine { margin: 6px 0 0; color: var(--muted); font-size: 12px; }
.intro-fine a { text-decoration: underline; text-underline-offset: 3px; }
.intro-error { margin: 4px 0 0; color: var(--coral-text); font-size: 13px; font-weight: 700; }

@keyframes tile-drop { 0% { opacity: 0; translate: 0 -120px; rotate: -8deg; } 60% { opacity: 1; } 100% { opacity: 1; translate: 0 0; rotate: 0deg; } }
@keyframes stamp { from { opacity: 0; transform: scale(1.35) rotate(-4deg); } }

/* ───────── 마이페이지 ───────── */

.me-card {
  display: flex;
  align-items: center;
  gap: 16px;
  margin: 18px 0 18px;
  padding: 18px;
  border: 2px solid var(--ink);
  border-radius: 26px;
  background: var(--card);
  box-shadow: var(--pop);
}
.me-avatar { position: relative; flex: none; cursor: pointer; border-radius: 50%; }
.me-cam {
  position: absolute;
  right: -4px;
  bottom: -2px;
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border: 2px solid var(--ink);
  border-radius: 50%;
  background: var(--butter);
  color: var(--on-pastel);
  box-shadow: 0 2px 0 var(--ink);
}
.me-cam svg { width: 16px; height: 16px; }
.me-id { flex: 1; min-width: 0; }
.me-id h1 { margin: 0; overflow: hidden; font-family: var(--display); font-weight: 400; font-size: 24px; line-height: 1.25; text-overflow: ellipsis; white-space: nowrap; }
.me-id p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.me-card > .text-btn { flex: none; align-self: flex-start; color: var(--coral-text); font-size: 13px; }
.rename { display: flex; gap: 6px; align-items: center; }
.rename input { flex: 1; min-width: 0; padding: 8px 12px; border: 2px solid var(--ink); border-radius: 12px; background: var(--bg); font-size: 16px; }

/* 모은 단어가 주인공: 큰 노란 칸 하나 + 작은 칸 둘 */
.stats { display: grid; grid-template-columns: 1.25fr 1fr; gap: 10px; }
.stat { display: flex; flex-direction: column; gap: 2px; padding: 14px 16px; border: 2px solid var(--line); border-radius: 20px; background: var(--card); }
.stat.big { grid-row: span 2; justify-content: space-between; border-color: var(--ink); background: var(--butter); color: var(--on-pastel); box-shadow: var(--pop); transform: rotate(-1.5deg); }
.stat-n { font-family: var(--display); font-weight: 400; font-size: 28px; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat-n small { margin-left: 2px; font-family: var(--round); font-size: 14px; font-weight: 700; }
.stat.big .stat-n { font-size: 46px; }
.stat-l { color: var(--muted); font-size: 12.5px; font-weight: 700; }
.stat.big .stat-l { color: inherit; opacity: 0.75; }

.grp { margin: 30px 0 8px 6px; color: var(--muted); font-size: 12px; font-weight: 900; letter-spacing: 0.12em; }
.menu { display: grid; overflow: hidden; border: 2px solid var(--line); border-radius: 20px; background: var(--card); }
.menu > button,
.menu > label,
.menu > a {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  min-height: 52px;
  padding: 12px 18px;
  border: 0;
  background: none;
  font-size: 15px;
  font-weight: 700;
  text-align: left;
  cursor: pointer;
  transition: background 0.2s;
}
.menu > * + * { border-top: 2px solid var(--line); }
.menu em { color: var(--muted); font-size: 12.5px; font-style: normal; font-weight: 500; }
.menu .warn { color: var(--coral-text); }

/* ───────── 개인정보 처리방침 같은 글 페이지 ───────── */

.doc { padding-bottom: 80px; line-height: 1.75; }
.doc h2 { margin: 34px 0 10px; font-family: var(--display); font-weight: 400; font-size: 20px; }
.doc p, .doc li { font-size: 15px; }
.doc ul { padding-left: 20px; }
.doc-lead { margin: 0; }
.doc p a { text-decoration: underline; text-underline-offset: 3px; }
.doc-date { margin: 6px 0 0; color: var(--muted); font-size: 13px !important; }
.doc table { width: 100%; border-collapse: collapse; overflow: hidden; border: 2px solid var(--line); border-radius: 16px; background: var(--card); font-size: 14px; }
.doc th, .doc td { padding: 10px 12px; text-align: left; vertical-align: top; }
.doc th { color: var(--muted); font-size: 12px; }
.doc tr + tr td, .doc thead + tbody tr td { border-top: 1.5px solid var(--line); }
body[data-view='doc'] .tabs { display: none; }

/* 이 기기에 있던 책을 계정으로 옮기는 시트 */
.move-dim {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0 10px calc(var(--inset-bottom) + 10px);
  background: rgb(43 33 28 / 0.45);
  animation: fade-in 0.25s ease-out both;
}
.move-sheet {
  display: grid;
  gap: 14px;
  width: min(100%, 460px);
  padding: 24px 20px 18px;
  border: 2.5px solid var(--ink);
  border-radius: 28px;
  background: var(--card);
  box-shadow: var(--pop-lg);
  animation: rise 0.35s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}
.move-sheet h2 { margin: 0; font-family: var(--display); font-weight: 400; font-size: 23px; line-height: 1.3; }
.move-from { display: flex; align-items: center; gap: 14px; padding: 12px; border-radius: 18px; background: var(--bg); }
.move-covers { display: flex; flex: none; }
.move-covers .cover { width: 34px; margin: 0 -12px 0 0; border-width: 1.5px; box-shadow: none; font-size: 0; }
.move-covers .cover span { display: none; }
.move-from p { margin: 0 0 0 12px; color: var(--muted); font-size: 13px; }
.move-from b { display: block; color: var(--ink); font-size: 15px; }
.move-error { margin: 0; color: var(--coral-text); font-size: 13px; font-weight: 700; }
.move-sheet .primary:disabled { opacity: 0.7; cursor: progress; }
.move-sheet .text-btn { justify-self: center; }
@keyframes fade-in { from { opacity: 0; } }

/* 알림·확인 창 (dialog.js) */
.pop {
  width: min(100% - 32px, 380px);
  padding: 26px 22px 18px;
  border: 2.5px solid var(--ink);
  border-radius: 28px;
  background: var(--card);
  color: var(--ink);
  box-shadow: var(--pop-lg);
  animation: rise 0.3s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}
.pop::backdrop { background: rgb(43 33 28 / 0.45); animation: fade-in 0.2s ease-out both; }
.pop h2 { margin: 0 0 8px; font-family: var(--display); font-weight: 400; font-size: 21px; line-height: 1.35; }
.pop p { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.65; white-space: pre-line; overflow-wrap: anywhere; }
.pop h2 + p { color: var(--muted); }
.pop p:only-of-type:first-child { color: var(--ink); }
.pop-actions { display: flex; justify-content: flex-end; align-items: center; gap: 16px; margin-top: 22px; }
.pop-actions .primary { min-width: 96px; }
.pop-cancel { padding: 10px 4px; border: 0; background: none; color: var(--muted); font-weight: 700; }
.pop-danger { background: var(--ink); color: var(--card); }
.menu > :active { background: color-mix(in srgb, var(--butter) 30%, var(--card)); }

/* ───────── 페이지 ───────── */

.sheet {
  position: relative;
  min-height: 60dvh;
  margin-top: 8px;
  padding: 34px 20px 26px;
  border: 2px solid var(--ink);
  border-radius: 28px;
  background: var(--card);
  box-shadow: var(--pop-lg), var(--soft);
  touch-action: pan-y;
}

.tape {
  position: absolute;
  top: -15px;
  left: 50%;
  width: 116px;
  height: 28px;
  background: repeating-linear-gradient(-45deg, var(--pink) 0 8px, color-mix(in srgb, var(--pink) 55%, #fff) 8px 16px);
  opacity: 0.92;
  transform: translateX(-50%) rotate(-3deg);
  clip-path: polygon(3% 0, 97% 0, 100% 20%, 97% 45%, 100% 70%, 97% 100%, 3% 100%, 0 75%, 3% 50%, 0 25%);
}

.page-badge {
  position: absolute;
  top: -16px;
  right: 16px;
  display: grid;
  place-items: center;
  width: 60px;
  height: 60px;
  border: 2px solid var(--ink);
  border-radius: 50%;
  background: var(--butter);
  color: var(--on-pastel);
  font-family: var(--display);
  font-size: 22px;
  line-height: 1;
  box-shadow: 0 3px 0 var(--ink);
  transform: rotate(8deg);
}
.page-badge small { display: block; margin-bottom: -10px; font-size: 11px; }

.chapter {
  display: inline-block;
  margin: 0 0 4px;
  padding: 3px 12px;
  border-radius: 999px;
  background: var(--sage);
  color: var(--on-pastel);
  font-size: 12px;
  font-weight: 700;
}
.page-no { margin: 0 0 10px; color: var(--muted); font-size: 13px; font-weight: 700; }

.words { margin: 0; padding: 0; list-style: none; }

.word {
  display: grid;
  grid-template-columns: 30px 1fr;
  grid-template-areas: 'idx jp' '. mean';
  column-gap: 12px;
  row-gap: 2px;
  padding: 16px 0;
  border-bottom: 2px dotted var(--line);
}
.word:last-child { border-bottom: 0; }
.sheet .word { animation: rise 0.4s cubic-bezier(0.3, 1.4, 0.5, 1) backwards; animation-delay: calc(var(--i, 0) * 35ms); }

.idx {
  grid-area: idx;
  align-self: end;
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  margin-bottom: 3px;
  border-radius: 50%;
  background: var(--peach);
  color: var(--on-pastel);
  font-size: 13px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}
.word:nth-child(5n + 2) .idx { background: var(--sky); }
.word:nth-child(5n + 3) .idx { background: var(--sage); }
.word:nth-child(5n + 4) .idx { background: var(--butter); }
.word:nth-child(5n + 5) .idx { background: var(--lilac); }

.jp { grid-area: jp; display: flex; flex-direction: column; }
.yomi { color: var(--coral-text); font-size: 13px; font-weight: 700; letter-spacing: 0.05em; }
.yomi:empty { display: none; }
.kanji { font-size: 26px; font-weight: 900; line-height: 1.3; }
.mean { grid-area: mean; margin-left: -8px; padding: 2px 8px; border-radius: 10px; font-size: 15px; line-height: 1.55; transition: color 0.2s, background-color 0.2s; }
.hide .word { cursor: pointer; }
.hide .mean { color: transparent; background: repeating-linear-gradient(-45deg, var(--line) 0 6px, transparent 6px 12px); }
.hide .word.open .mean { color: inherit; background: var(--bg); }

.top-actions { display: flex; align-items: center; gap: 2px; }
.toggle {
  padding: 5px 12px;
  border: 2px solid var(--ink);
  border-radius: 999px;
  background: var(--card);
  font-size: 13px;
  font-weight: 700;
  box-shadow: 0 2px 0 var(--ink);
  transition: transform 0.12s, box-shadow 0.12s, background 0.2s;
}
.toggle:active { transform: translateY(2px); box-shadow: none; }
.toggle[aria-pressed='true'] { background: var(--lilac); color: var(--on-pastel); }
.mean small { display: block; margin-top: 2px; color: var(--muted); font-size: 12px; }

.empty {
  display: grid;
  justify-items: center;
  gap: 4px;
  padding: 70px 0 50px;
  color: var(--muted);
  text-align: center;
}
.empty-face {
  margin-bottom: 12px;
  padding: 10px 18px;
  border: 2px solid var(--ink);
  border-radius: 999px;
  background: var(--lilac);
  color: var(--on-pastel);
  font-size: 18px;
  font-weight: 700;
  box-shadow: 0 3px 0 var(--ink);
  animation: doze 3.2s ease-in-out infinite;
}
.empty p { margin: 0; color: var(--ink); font-family: var(--display); font-size: 24px; }

.pager { padding: 6px; }
.pg-btn {
  width: 46px;
  height: 46px;
  border: 2px solid var(--ink);
  border-radius: 50%;
  background: var(--peach);
  color: var(--on-pastel);
  font-size: 24px;
  font-weight: 900;
  line-height: 1;
  transition: transform 0.12s, background 0.15s;
}
.pg-btn:active:not(:disabled) { transform: scale(0.88); }
.pg-btn:disabled { border-style: dashed; border-color: var(--muted); background: transparent; color: var(--muted); cursor: default; opacity: 0.6; }

.pg-count {
  display: flex;
  align-items: baseline;
  gap: 4px;
  padding: 0 8px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.pg-count span { color: var(--muted); font-size: 14px; font-weight: 700; }
.pg-count input {
  width: 3.4ch;
  padding: 0;
  border: 0;
  border-bottom: 2.5px dashed var(--muted);
  background: none;
  font-family: var(--display);
  font-size: 24px;
  text-align: center;
  appearance: textfield;
  -moz-appearance: textfield;
}
.pg-count input::-webkit-inner-spin-button,
.pg-count input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.pg-count input:focus { outline: none; border-bottom: 2.5px solid var(--coral); }

/* ───────── 편집 ───────── */

.edit { display: grid; gap: 22px; }
.edit-top { display: grid; grid-template-columns: 110px 1fr; gap: 20px; align-items: start; }
.cover-pick { display: grid; gap: 6px; cursor: pointer; text-align: center; }
.cover-pick .cover { margin: 0; }
.cover-hint { color: var(--coral-text); font-size: 12px; font-weight: 700; }
.fields { display: grid; gap: 14px; }

.field { display: grid; gap: 6px; }
.field > span { font-size: 13px; font-weight: 700; }
.field small { color: var(--coral-text); }
.field input,
.field textarea {
  width: 100%;
  padding: 12px 14px;
  border: 2px solid var(--ink);
  border-radius: 16px;
  background: var(--card);
  transition: box-shadow 0.15s;
}
.field input:focus,
.field textarea:focus { outline: none; box-shadow: 0 0 0 5px var(--butter); }
.field textarea[readonly] { opacity: 0.75; }
.field textarea[readonly]:focus { box-shadow: none; }
.notes-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 8px; }
.notes-head .text-btn { margin-left: auto; color: var(--coral-text); font-size: 13px; }
.field textarea {
  min-height: 46dvh;
  resize: vertical;
  font-size: 16px; /* 16px 미만이면 iOS 가 포커스 때 확대한다 */
  line-height: 1.9;
  background-image: radial-gradient(var(--dot) 1.2px, transparent 1.4px);
  background-size: 18px 18px;
  background-attachment: local;
}


/* 화면 언어 고르기 (인트로·마이페이지) */
.lang-switch { display: flex; justify-content: center; gap: 4px; }
.lang-switch button {
  padding: 6px 12px;
  border: 0;
  border-radius: 999px;
  background: none;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  transition: background 0.15s, color 0.15s;
}
.lang-switch button[aria-pressed='true'] { background: var(--butter); color: var(--on-pastel); }
.lang-switch button:focus-visible { outline: 2px dashed var(--coral); outline-offset: 2px; }
.lang-switch.at-intro { margin-top: 6px; }
.lang-switch.at-me {
  justify-content: stretch;
  padding: 5px;
  border: 2px solid var(--ink);
  border-radius: 999px;
  background: var(--card);
  box-shadow: var(--pop);
}
.lang-switch.at-me button { flex: 1; padding: 10px; font-size: 15px; }
.lang-switch.at-me button[aria-pressed='true'] { box-shadow: inset 0 0 0 2px var(--ink); }

/* 책 언어: 두 칸짜리 고르기 */
.lang-pick { display: grid; grid-template-columns: auto 1fr 1fr; align-items: center; gap: 8px; margin: 0; padding: 0; border: 0; }
.lang-pick legend { float: left; margin-right: 6px; font-size: 13px; font-weight: 700; }
.lang-pick label { cursor: pointer; }
.lang-pick input { position: absolute; opacity: 0; pointer-events: none; }
.lang-pick span {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 6px;
  padding: 9px 10px;
  border: 2px solid var(--line);
  border-radius: 14px;
  color: var(--muted);
  font-size: 12px;
  transition: background 0.15s, border-color 0.15s, transform 0.12s;
}
.lang-pick b { font-family: var(--display); font-weight: 400; font-size: 16px; }
.lang-pick input:checked + span { border-color: var(--ink); background: var(--butter); color: var(--on-pastel); box-shadow: var(--pop); }
.lang-pick input:focus-visible + span { outline: 2px dashed var(--coral); outline-offset: 3px; }
.lang-pick label:active span { transform: translateY(2px); }

/* 처음 쓰는 사람을 위한 안내 */
.draft-note {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 0;
  padding: 10px 14px;
  border-radius: 14px;
  background: var(--butter);
  color: var(--on-pastel);
  font-size: 13px;
  font-weight: 700;
}
.draft-note .text-btn { color: inherit; text-decoration: underline; }
.howto {
  position: relative;
  padding: 14px 18px;
  border: 2px solid var(--ink);
  border-radius: 22px;
  background: var(--card);
  box-shadow: var(--pop);
  rotate: -1.4deg; /* 책상에 붙여 둔 포스트잇처럼. 펼치면 반듯해진다 */
  transition: rotate 0.35s cubic-bezier(0.3, 1.4, 0.5, 1);
}
.howto.open { rotate: -0.4deg; }
.howto[hidden] { display: none; }
/* 메모를 붙인 마스킹테이프 */
.howto::before {
  content: '';
  position: absolute;
  top: -11px;
  left: 50%;
  width: 78px;
  height: 20px;
  border-radius: 3px;
  background: color-mix(in srgb, var(--butter) 80%, transparent);
  translate: -50% 0;
  rotate: 2deg;
}
.howto-hi {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  padding: 4px 0;
  border: 0;
  background: none;
  color: var(--ink);
  font-family: var(--display);
  font-size: 18px;
  text-align: left;
  cursor: pointer;
}
.howto-hi span { color: var(--coral-text); }
.howto-hi i { margin-left: auto; color: var(--muted); font-style: normal; transition: rotate 0.35s; }
.howto.open .howto-hi i { rotate: 180deg; }
.howto-hi:focus-visible { outline: 2px dashed var(--coral); outline-offset: 4px; border-radius: 8px; }
/* 0fr → 1fr: 내용 높이를 몰라도 부드럽게 펼친다 */
.howto-body {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows 0.4s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.howto-body > div {
  display: grid;
  gap: 12px;
  min-height: 0;
  overflow: hidden;
  opacity: 0;
  translate: 0 -6px;
  transition: opacity 0.25s, translate 0.35s;
}
.howto.open .howto-body { grid-template-rows: 1fr; }
.howto-body .howto-memo { margin-top: 10px; } /* 접힌 동안엔 overflow 로 같이 숨는다 */
.howto.open .howto-body > div { opacity: 1; translate: 0; transition-delay: 0.08s; }
@media (prefers-reduced-motion: reduce) {
  .howto, .howto-hi i, .howto-body, .howto-body > div { transition: none; }
}
.howto-memo {
  display: grid;
  gap: 6px;
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--bg) radial-gradient(var(--dot) 1.2px, transparent 1.4px) 0 0 / 16px 16px;
  font-size: 16px;
}
.memo-row, .memo-legend { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; min-height: 28px; }
.howto-memo code { font-family: var(--round); font-weight: 700; color: var(--ink); }
.memo-page { color: var(--coral-text) !important; }
.howto-memo mark { padding: 1px 3px; border-radius: 4px; color: var(--on-pastel); }
/* 형광펜 색으로 단어·읽기·뜻을 나눠 보인다 */
.hl-word { background: var(--pink); }
.hl-read { background: var(--sky); }
.hl-mean { background: var(--butter); }
.memo-legend { margin: -2px 0 2px; }
.memo-legend i { padding: 1px 8px; border-radius: 999px; color: var(--on-pastel); font-size: 11px; font-style: normal; font-weight: 700; }
.memo-tip { color: var(--muted); font-size: 12px; font-weight: 700; }
.memo-tip::before { content: '← '; }
.howto-foot { margin: 0; color: var(--muted); font-size: 12px; }

.onboard {
  display: grid;
  gap: 10px;
  margin: 0 0 24px;
  padding: 0;
  list-style: none;
  counter-reset: step;
}
.onboard li {
  display: grid;
  grid-template-columns: 30px 1fr;
  column-gap: 12px;
  align-items: center;
  color: var(--muted);
  font-size: 13px;
  counter-increment: step;
}
.onboard li::before {
  content: counter(step);
  grid-row: span 2;
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border: 2px solid var(--ink);
  border-radius: 50%;
  background: var(--butter);
  color: var(--on-pastel);
  font-weight: 700;
}
.onboard b { color: var(--ink); font-size: 15px; }

.edit-actions { display: flex; justify-content: space-between; align-items: center; }
.danger { padding: 8px 0; border: 0; background: none; color: var(--muted); font-size: 13px; text-decoration: underline wavy; text-underline-offset: 4px; }

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

.picks {
  display: flex;
  gap: 8px;
  margin: 0 calc(var(--gutter) * -1) 26px;
  padding: 4px var(--gutter) 8px;
  overflow-x: auto;
  scrollbar-width: none;
}
.picks::-webkit-scrollbar { display: none; }
.pick {
  flex: none;
  display: flex;
  align-items: center;
  gap: 6px;
  max-width: 220px;
  padding: 8px 14px;
  border: 2px solid var(--ink);
  border-radius: 999px;
  background: var(--card);
  font-size: 14px;
  font-weight: 700;
  white-space: nowrap;
  box-shadow: 0 3px 0 var(--ink);
  transition: transform 0.12s, box-shadow 0.12s, background 0.2s;
}
.pick span { overflow: hidden; text-overflow: ellipsis; }
.pick small { padding: 0 7px; border-radius: 999px; background: var(--bg); color: var(--muted); font-size: 11px; }
.pick:active { transform: translateY(3px); box-shadow: none; }
.pick[aria-pressed='true'] { background: var(--butter); color: var(--on-pastel); }
.pick[aria-pressed='true'] small { background: var(--card); color: var(--ink); }

.modes { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.mode {
  display: grid;
  align-content: space-between;
  gap: 4px;
  min-height: 168px;
  padding: 18px;
  border: 2px solid var(--ink);
  border-radius: 26px;
  background: var(--peach);
  color: var(--on-pastel);
  text-align: left;
  box-shadow: var(--pop-lg);
  transition: transform 0.25s cubic-bezier(0.3, 1.6, 0.5, 1), box-shadow 0.12s;
}
.mode.alt { background: var(--sky); transform: translateY(16px); }
.mode:active { box-shadow: 0 1px 0 var(--ink); }
.mode-face { margin-bottom: auto; font-size: 18px; font-weight: 700; }
.mode-jp { font-size: 20px; font-weight: 900; }
.mode-ko { font-family: var(--display); font-size: 17px; }

.notice { margin-top: 44px; padding: 14px 16px; border: 2px dashed var(--coral); border-radius: 18px; font-size: 14px; }

.quiz { display: grid; gap: 18px; padding-top: 8px; }
.q-top { display: flex; justify-content: space-between; align-items: center; }
.q-count { color: var(--muted); font-weight: 700; font-variant-numeric: tabular-nums; }
.q-count b { color: var(--ink); font-family: var(--display); font-size: 22px; font-weight: 400; }
.q-progress { height: 14px; overflow: hidden; border: 2px solid var(--ink); border-radius: 999px; background: var(--card); }
.q-progress i {
  display: block;
  height: 100%;
  background: repeating-linear-gradient(-45deg, var(--butter) 0 8px, color-mix(in srgb, var(--butter) 60%, var(--coral)) 8px 16px);
  transition: width 0.4s cubic-bezier(0.3, 1.4, 0.5, 1);
}

.q-card {
  position: relative;
  display: grid;
  place-items: center;
  gap: 10px;
  min-height: 220px;
  padding: 32px 20px;
  border: 2px solid var(--ink);
  border-radius: 28px;
  background: var(--card);
  box-shadow: var(--pop-lg);
  text-align: center;
}
.q-word { margin: 0; font-size: clamp(40px, 13vw, 58px); font-weight: 900; line-height: 1.2; }
/* 정답 풀이·다음 버튼은 처음부터 자리를 차지하고 보이기만 바뀐다 → 고를 때 아래가 밀리지 않음 */
.q-reveal { display: grid; gap: 2px; margin: 0; visibility: hidden; }
.done .q-reveal { visibility: visible; animation: pop-in 0.35s cubic-bezier(0.3, 1.6, 0.5, 1); }
.q-reveal .yomi { font-size: 16px; }
.q-reveal small { color: var(--muted); font-size: 12px; }

.stamp {
  position: absolute;
  top: -14px;
  right: 14px;
  padding: 4px 14px;
  border: 2px solid var(--ink);
  border-radius: 999px;
  background: var(--sage);
  color: var(--on-pastel);
  font-size: 14px;
  font-weight: 900;
  box-shadow: 0 3px 0 var(--ink);
  transform: rotate(6deg);
}
.stamp.miss { background: var(--pink); transform: rotate(-6deg); }

.choices { display: grid; gap: 11px; }
.choice {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 13px 16px;
  border: 2px solid var(--ink);
  border-radius: 18px;
  background: var(--card);
  text-align: left;
  line-height: 1.45;
  box-shadow: var(--pop);
  transition: transform 0.12s, box-shadow 0.12s, background 0.2s, opacity 0.25s;
}
.choice .num {
  flex: none;
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--bg);
  color: var(--muted);
  font-size: 13px;
  font-weight: 900;
}
.choice:active:not(:disabled) { transform: translateY(4px); box-shadow: none; }
.choice:disabled { cursor: default; opacity: 0.45; box-shadow: none; transform: translateY(4px); }
.choice.right { opacity: 1; background: var(--sage); color: var(--on-pastel); box-shadow: var(--pop); transform: none; animation: bounce 0.45s cubic-bezier(0.3, 1.4, 0.5, 1); }
.choice.wrong { opacity: 1; background: var(--pink); color: var(--on-pastel); animation: shake 0.35s; }
.choice.right .num,
.choice.wrong .num { background: var(--card); color: var(--ink); }
.q-next { justify-self: center; min-width: 180px; transition: opacity 0.2s, transform 0.25s cubic-bezier(0.3, 1.4, 0.5, 1), box-shadow 0.12s; }
.quiz:not(.done) .q-next { visibility: hidden; opacity: 0; transform: translateY(8px); }

.result { padding-top: 34px; text-align: center; }
.result-face { margin: 0 0 6px; font-size: 26px; font-weight: 700; animation: bounce 0.6s; }
.score {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  margin: 0;
  padding: 18px 34px;
  border: 2px solid var(--ink);
  border-radius: 40px;
  background: var(--butter);
  color: var(--on-pastel);
  box-shadow: var(--pop-lg);
  transform: rotate(-2deg);
}
.score b { font-family: var(--display); font-size: 80px; font-weight: 400; line-height: 1; }
.score span { font-size: 22px; font-weight: 700; }
.score-msg { margin: 22px 0 26px; font-size: 17px; font-weight: 700; }
.result-actions { display: flex; justify-content: center; align-items: center; gap: 18px; }
.wrong-title { margin: 54px 0 6px; font-family: var(--display); font-size: 20px; font-weight: 400; text-align: left; }
.wrong-list { padding: 4px 20px; border: 2px solid var(--ink); border-radius: 24px; background: var(--card); text-align: left; }
.wrong-list .word { grid-template-columns: 1fr; grid-template-areas: 'jp' 'mean'; }

@keyframes rise { from { opacity: 0; transform: translateY(10px); } }
@keyframes pop-in { from { opacity: 0; transform: scale(0.85); } }
@keyframes bounce { 40% { transform: translateY(-6px); } }
@keyframes shake { 25% { transform: translate(-5px, 4px); } 75% { transform: translate(5px, 4px); } }
@keyframes doze { 50% { transform: translateY(-4px) rotate(-2deg); } }

/* ───────── 앱처럼 ───────── */

/* 터치 기기에서 hover 가 눌린 채로 남지 않게 */
@media (hover: hover) {
  .primary:hover { transform: translateY(-2px); box-shadow: var(--pop-lg); }
  .text-btn:hover { color: var(--coral-text); }
  .book:hover .cover { transform: translateY(-6px) rotate(-2.5deg); }
  .book:nth-child(even):hover .cover { transform: translateY(-6px) rotate(2.5deg); }
  .book.add:hover .cover-add { border-color: var(--coral); color: var(--coral-text); box-shadow: none; }
  .menu > :hover { background: color-mix(in srgb, var(--butter) 22%, var(--card)); }
  .sso:hover:not(:disabled) { transform: translateY(-2px); box-shadow: 0 6px 0 var(--ink); }
  .me-avatar:hover .me-cam { transform: rotate(-12deg); }
  .pg-btn:hover:not(:disabled) { background: var(--butter); }
  .cover-pick:hover .cover { transform: rotate(-3deg); }
  .danger:hover { color: var(--coral-text); }
  .mode:hover { transform: translateY(-4px) rotate(-1.5deg); }
  .mode.alt:hover { transform: translateY(12px) rotate(1.5deg); }
  .choice:hover:not(:disabled) { background: color-mix(in srgb, var(--butter) 35%, var(--card)); }
}

body { overscroll-behavior-y: none; }
button, a, label, .tabs, .pager { -webkit-user-select: none; user-select: none; touch-action: manipulation; }

.tabs { view-transition-name: tabs; }
/* 화면 전환은 스르륵 페이드만 — 새 화면이 아주 살짝 떠오르며 자리 잡는다 */
::view-transition-old(root) { animation: 0.2s ease-out both nav-fade-out; }
::view-transition-new(root) { animation: 0.36s ease-out both nav-fade-in; }
@keyframes nav-fade-out { to { opacity: 0; } }
@keyframes nav-fade-in { from { opacity: 0; transform: translateY(6px); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  ::view-transition-group(*),
  ::view-transition-old(*),
  ::view-transition-new(*) { animation: none !important; }
}

@media (min-width: 640px) {
  :root { --gutter: 32px; }
  .sheet { padding: 44px 36px 32px; }
  .word { grid-template-columns: 30px minmax(150px, 0.9fr) 1.1fr; grid-template-areas: 'idx jp mean'; align-items: end; }
  .mean { padding-bottom: 4px; }
}

/* 보이는 크기는 그대로, 누르는 영역만 44px 안팎으로 */
.toggle, .text-btn, .danger { position: relative; }
.toggle::after, .text-btn::after, .danger::after { content: ''; position: absolute; inset: -8px 0; }

/* ───────── 文庫 테마 (html[data-skin='bunko']) ─────────
   볕 드는 방에서 문고본을 펼친 느낌: 누런 종이, 먹색 명조, 주홍 도장·책갈피.
   배치와 기능은 그대로 두고 색·글꼴·테두리만 바꾼다. 글꼴은 이 테마를 고를 때만 받는다 */

:root[data-skin='bunko'],
.skin-bunko {
  --bg: #f2e8d5;
  --dot: transparent;
  --card: #fbf6ea;
  --ink: #2d2925;
  --muted: #6f6355;
  --line: #e0d3b8;
  --coral: #b4432e; /* 朱 */
  --coral-text: #a33a26;
  --peach: #e8d8bd;
  --butter: #ecdcb6;
  --sage: #d9dcc4;
  --sky: #d3dbe0;
  --pink: #ead6cc;
  --lilac: #ddd6df;
  --on-pastel: #2d2925;
  --rule: #cdbd9e; /* 얇은 괘선 */
  --pop: 0 1px 0 rgb(45 41 37 / 0.22);
  --pop-lg: 0 2px 0 rgb(45 41 37 / 0.22);
  --soft: 0 12px 26px -16px rgb(60 40 20 / 0.5);
  --round: 'Gowun Batang', 'Shippori Mincho', 'Hiragino Mincho ProN', 'Yu Mincho', serif;
  --display: 'Shippori Mincho', 'Gowun Batang', 'Hiragino Mincho ProN', 'Yu Mincho', serif;
}

/* 夜の文庫: 등불 아래 먹빛 종이 */
:root[data-skin='bunko'][data-mode='dark'],
[data-mode='dark'] .skin-bunko {
  --bg: #24201b;
  --card: #2e2922;
  --ink: #ece3d0;
  --muted: #b3a690;
  --line: #463e33;
  --coral: #d9694f;
  --coral-text: #e8876c;
  --peach: #d9c3a0;
  --butter: #d8c38f;
  --sage: #b9c09e;
  --sky: #a9b7c2;
  --pink: #cfae9f;
  --lilac: #b9adc0;
  --on-pastel: #24201b;
  --rule: #5a5043;
  --pop: 0 1px 0 rgb(0 0 0 / 0.4);
  --pop-lg: 0 2px 0 rgb(0 0 0 / 0.4);
  --soft: 0 12px 26px -16px rgb(0 0 0 / 0.8);
}

/* 종이결 */
:is([data-skin='bunko'] body, .tp.skin-bunko) {
  background-image:
    repeating-linear-gradient(97deg, rgb(120 90 50 / 0.025) 0 2px, transparent 2px 7px),
    repeating-linear-gradient(8deg, rgb(120 90 50 / 0.02) 0 1px, transparent 1px 11px);
  background-size: auto;
  letter-spacing: 0.01em;
}

/* 굵은 잉크 테두리 → 얇은 괘선 */
[data-skin='bunko'] :is(.sheet, .me-card, .menu, .stat, .move-sheet, .pick, .choice, .mode, .icon-btn, .toggle, .pg-btn,
  .tabs, .pager, .score, .wrong-list, .avatar, .me-cam, .sso, .kanji-tile img, .kanji-tile b, .field input, .field textarea, .rename input) {
  border-width: 1px;
  border-color: var(--rule);
}
[data-skin='bunko'] :is(.primary, .stat.big) { border-width: 1px; border-color: var(--coral); }
[data-skin='bunko'] .primary { background: var(--coral); color: var(--card); }
[data-skin='bunko'] .stat.big { background: var(--card); color: var(--ink); transform: none; }
[data-skin='bunko'] .stat.big .stat-n { color: var(--coral-text); }

/* 형광펜 → 주홍 글씨, 인사 칩 → 도장 */
[data-skin='bunko'] mark { background: none; color: var(--coral-text); }
[data-skin='bunko'] .chip { border: 1.5px solid var(--coral); border-radius: 4px; background: none; color: var(--coral-text); box-shadow: none; }

/* 표지는 진짜 책처럼: 테두리 대신 등 그림자와 바닥 그림자 */
[data-skin='bunko'] .cover {
  border: 0;
  border-radius: 1px 4px 4px 1px;
  box-shadow: inset 4px 0 0 rgb(0 0 0 / 0.12), 2px 4px 9px rgb(60 40 20 / 0.35);
}
[data-skin='bunko'] .cover-blank span { border-width: 1px; border-color: var(--rule); border-radius: 2px; box-shadow: none; }
[data-skin='bunko'] .cover-add { border: 1px dashed var(--muted); box-shadow: none; }
[data-skin='bunko'] .book-title { font-family: var(--display); font-weight: 700; }

/* 진도 바 → 주홍 실선 */
[data-skin='bunko'] .bar { height: 3px; border: 0; border-radius: 0; background: var(--line); }
[data-skin='bunko'] .bar i { border-radius: 0; background: var(--coral); }

/* 하단 탭: 고른 탭은 주홍 */
[data-skin='bunko'] .tabs { box-shadow: var(--soft); }
[data-skin='bunko'] body[data-view='home'] .tabs [data-tab='home'],
[data-skin='bunko'] body[data-view='quiz'] .tabs [data-tab='quiz'],
[data-skin='bunko'] body[data-view='me'] .tabs [data-tab='me'] { background: var(--coral); color: var(--card); }

/* 읽는 페이지: 마스킹테이프 대신 책갈피 끈, 단어는 명조 */
[data-skin='bunko'] .sheet { border-radius: 4px; }
[data-skin='bunko'] .tape { display: none; }
[data-skin='bunko'] .sheet::before {
  content: '';
  position: absolute;
  top: -1px;
  left: 26px;
  width: 12px;
  height: 58px;
  background: var(--coral);
  clip-path: polygon(0 0, 100% 0, 100% 100%, 50% 82%, 0 100%);
}
[data-skin='bunko'] .page-badge { border: 1.5px solid var(--coral); border-radius: 4px; background: var(--card); color: var(--coral-text); box-shadow: none; transform: rotate(-4deg); }
[data-skin='bunko'] .chapter { border-radius: 2px; background: none; color: var(--muted); padding-left: 0; letter-spacing: 0.15em; }
[data-skin='bunko'] .word { border-bottom: 1px solid var(--line); }
[data-skin='bunko'] .word .idx { background: none; color: var(--muted); font-family: var(--display); }
[data-skin='bunko'] .kanji { font-family: var(--display); font-weight: 700; }
[data-skin='bunko'] .yomi { color: #2f4866; } /* 藍: 후리가나 */
[data-skin='bunko'][data-mode='dark'] .yomi { color: #9fb4cf; }


/* 글 페이지는 오른쪽 버튼이 없어서 제목이 왼쪽으로 쏠린다 → 양쪽 칸 폭을 맞춰 가운데로 */
.topbar > :first-child { justify-self: start; }
.topbar > :last-child { justify-self: end; }

/* ───────── 抹茶 테마: 찻집 도자기. 진한 녹색 테두리, 연둣빛 그림자, 말차 거품 같은 두 겹 점 ───────── */
:root[data-skin='matcha'],
.skin-matcha {
  --bg: #eef0e2;
  --dot: #dbe0c4;
  --card: #fbfbf3;
  --ink: #2f3a2a;
  --muted: #636d57;
  --line: #dde2c8;
  --coral: #7c9a3f;
  --coral-text: #4b661f;
  --peach: #ead9b5;
  --butter: #d6e3a0;
  --sage: #b7cd96;
  --sky: #cfe0d4;
  --pink: #edd2c9;
  --lilac: #d9d6e5;
  --on-pastel: #2f3a2a;
  --pop: 0 4px 0 #9fb46e;
  --pop-lg: 0 6px 0 #9fb46e;
  --soft: 0 14px 30px -14px rgb(60 80 30 / 0.35);
  --round: 'Zen Maru Gothic', 'Gowun Dodum', 'Apple SD Gothic Neo', sans-serif;
  --display: 'Gowun Dodum', 'Zen Maru Gothic', 'Apple SD Gothic Neo', sans-serif;
}
:root[data-skin='matcha'][data-mode='dark'],
[data-mode='dark'] .skin-matcha {
  --bg: #1f251c;
  --dot: #2c3527;
  --card: #283023;
  --ink: #eef0dc;
  --muted: #a7b198;
  --line: #39432f;
  --coral: #a6c46a;
  --coral-text: #b9d47e;
  --peach: #cbb88f;
  --butter: #b9c97c;
  --sage: #93ad74;
  --sky: #9fbcad;
  --pink: #c9a69b;
  --lilac: #aaa6bf;
  --on-pastel: #1f251c;
  --pop: 0 4px 0 #11150e;
  --pop-lg: 0 6px 0 #11150e;
  --soft: 0 14px 30px -14px rgb(0 0 0 / 0.7);
  color-scheme: dark;
}
:is([data-skin='matcha'] body, .tp.skin-matcha) {
  background-image: radial-gradient(var(--dot) 1.4px, transparent 1.6px), radial-gradient(var(--dot) 3px, transparent 3.4px);
  background-size: 22px 22px, 61px 61px;
  background-position: 0 0, 9px 13px;
}
:is([data-skin='matcha'], .skin-matcha) .chip { box-shadow: var(--pop); }

/* ───────── 夜空 테마: 별이 뜬 밤. 크기가 다른 두 겹 점이 별밭, 강조는 금빛 하나, 얇은 테두리 ───────── */
:root[data-skin='yozora'],
.skin-yozora {
  --bg: #e9ecf6;
  --dot: #c3cbe6;
  --card: #f8f9fd;
  --ink: #26304f;
  --muted: #57618a;
  --line: #d6dbef;
  --coral: #e0a43a;
  --coral-text: #8f610c;
  --peach: #f3d6b8;
  --butter: #f6e3a1;
  --sage: #c6e0d3;
  --sky: #c3d4f2;
  --pink: #efcfe0;
  --lilac: #d6cdf2;
  --on-pastel: #26304f;
  --pop: 0 4px 0 var(--ink);
  --pop-lg: 0 6px 0 var(--ink);
  --round: 'Zen Kaku Gothic New', 'Sunflower', 'Apple SD Gothic Neo', sans-serif;
  --display: 'Sunflower', 'Zen Kaku Gothic New', 'Apple SD Gothic Neo', sans-serif;
}
:root[data-skin='yozora'][data-mode='dark'],
[data-mode='dark'] .skin-yozora {
  --bg: #151a33;
  --dot: #e9d48f;
  --card: #1f2547;
  --ink: #eef0fb;
  --muted: #a3a9cc;
  --line: #2e3561;
  --coral: #f2c45a;
  --coral-text: #f2c45a;
  --peach: #e8b48f;
  --butter: #f2d27a;
  --sage: #9cc7b4;
  --sky: #8fb0e6;
  --pink: #e3a3c2;
  --lilac: #ad9fe6;
  --on-pastel: #151a33;
  --pop: 0 4px 0 #0a0d1e;
  --pop-lg: 0 6px 0 #0a0d1e;
  --soft: 0 14px 30px -14px rgb(0 0 0 / 0.75);
  color-scheme: dark;
}
:is([data-skin='yozora'] body, .tp.skin-yozora) {
  background-image: radial-gradient(var(--dot) 1px, transparent 1.4px), radial-gradient(var(--dot) 1.8px, transparent 2.2px);
  background-size: 29px 29px, 73px 73px;
  background-position: 0 0, 17px 41px;
}
:is([data-skin='yozora'], .skin-yozora) .chip::before { content: '☾'; }
:is([data-skin='yozora'], .skin-yozora) mark {
  background: linear-gradient(transparent 62%, color-mix(in srgb, var(--coral) 55%, transparent) 62% 90%, transparent 90%);
}

/* ───────── ノート 테마: 학교 공책. 파란 괘선과 빨간 여백선, 손글씨 제목, 형광펜, 마스킹테이프 ───────── */
:root[data-skin='note'],
.skin-note {
  --bg: #fbfaf4;
  --dot: #d5e2ef; /* 괘선 */
  --margin-rule: #f1aaa6;
  --card: #ffffff;
  --ink: #23345c;
  --muted: #58658a;
  --line: #dde6f0;
  --coral: #e2574c;
  --coral-text: #c23b31;
  --peach: #ffd9b8;
  --butter: #fff0a3;
  --sage: #cfeccf;
  --sky: #cfe3f7;
  --pink: #ffd3df;
  --lilac: #e2dcf7;
  --on-pastel: #23345c;
  --pop: 0 2px 0 rgb(35 52 92 / 0.28);
  --pop-lg: 0 3px 0 rgb(35 52 92 / 0.28);
  --round: 'Gowun Dodum', 'Klee One', 'Apple SD Gothic Neo', sans-serif;
  --display: 'Gaegu', 'Klee One', 'Apple SD Gothic Neo', sans-serif;
}
:root[data-skin='note'][data-mode='dark'],
[data-mode='dark'] .skin-note {
  --bg: #1c2230;
  --dot: #2b3549;
  --margin-rule: #6a3a42;
  --card: #252c3d;
  --ink: #e6ecf7;
  --muted: #9da9c2;
  --line: #303a50;
  --coral: #ff8a7e;
  --coral-text: #ff8a7e;
  --peach: #e8b991;
  --butter: #e9d77a;
  --sage: #a3cfa3;
  --sky: #9cc0e8;
  --pink: #e8a9bd;
  --lilac: #b7aee6;
  --on-pastel: #1c2230;
  --pop: 0 2px 0 rgb(0 0 0 / 0.5);
  --pop-lg: 0 3px 0 rgb(0 0 0 / 0.5);
  --soft: 0 14px 30px -14px rgb(0 0 0 / 0.75);
  color-scheme: dark;
}
:is([data-skin='note'] body, .tp.skin-note) {
  background-image:
    linear-gradient(90deg, transparent 22px, var(--margin-rule) 22px 23.5px, transparent 23.5px),
    repeating-linear-gradient(transparent 0 27px, var(--dot) 27px 28px);
  background-size: auto;
}
[data-skin='note'] :is(h1, .topbar-title, .book-title, .stat-n) { font-weight: 700; }
:is([data-skin='note'], .skin-note) mark { padding: 0 3px; border-radius: 2px 6px 3px 5px; background: color-mix(in srgb, var(--butter) 90%, transparent); }
:is([data-skin='note'], .skin-note) .chip { border-radius: 2px; transform: rotate(-3deg); }
/* 표지마다 마스킹테이프 */
[data-skin='note'] .shelf .cover:not(.cover-add),
.skin-note .tp-cover { position: relative; }
[data-skin='note'] .shelf .cover:not(.cover-add)::after,
.skin-note .tp-cover::after {
  content: '';
  position: absolute;
  top: 0;
  left: 50%;
  width: 46%;
  height: 12%;
  background: color-mix(in srgb, var(--lilac) 85%, transparent);
  translate: -50% 0;
  rotate: -3deg;
}
[data-skin='note'] .shelf .book:nth-child(even) .cover::after { background: color-mix(in srgb, var(--pink) 85%, transparent); rotate: 2deg; }
[data-skin='note'] .bar i { background: var(--coral); }

/* 夜空·ノート: 굵은 잉크 테두리 → 가는 선 */
:is([data-skin='yozora'], [data-skin='note']) :is(.sheet, .me-card, .menu, .stat, .move-sheet, .pick, .choice, .mode, .icon-btn, .toggle, .pg-btn,
  .tabs, .pager, .score, .wrong-list, .avatar, .me-cam, .sso, .kanji-tile img, .kanji-tile b, .field input, .field textarea, .rename input,
  .primary, .cover, .chip, .bar, .cover-blank span, .lang-switch.at-me, .pop, .howto) {
  border-width: 1.5px;
}

/* ───────── 테마 페이지 ───────── */

.theme-page { display: grid; gap: 22px; }
.mode-switch { justify-content: stretch; }
.theme-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; }
.theme-card {
  display: grid;
  gap: 8px;
  padding: 8px 8px 12px;
  border: 2px solid var(--line);
  border-radius: 20px;
  background: var(--card);
  color: var(--ink);
  text-align: left;
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.12s;
}
.theme-card[aria-pressed='true'] { border-color: var(--ink); box-shadow: var(--pop); }
.theme-card:active { transform: translateY(2px); }
.theme-card:focus-visible { outline: 2px dashed var(--coral); outline-offset: 3px; }
.theme-card b { padding: 0 4px; font-family: var(--display); font-weight: 400; font-size: 17px; }
.theme-card small { padding: 0 4px; color: var(--muted); font-size: 12px; }
.theme-card[aria-pressed='true'] b::after { content: ' ✓'; color: var(--coral-text); }

/* 미리보기: 그 테마의 토큰(.skin-*)으로 그린 작은 책장 */
.tp {
  position: relative;
  display: grid;
  align-content: start;
  gap: 8px;
  height: 172px;
  padding: 12px 12px 0 14px;
  overflow: hidden;
  border-radius: 14px;
  background-color: var(--bg);
  background-image: radial-gradient(var(--dot) 1.2px, transparent 1.4px);
  background-size: 16px 16px;
  color: var(--ink);
  font-family: var(--round);
}
.tp .chip { justify-self: start; margin: 0; padding: 2px 9px; border-width: 1.5px; font-size: 10px; box-shadow: 0 2px 0 var(--ink); }
.tp-h { margin: 0; font-family: var(--display); font-size: 17px; line-height: 1.2; }
.tp-books { display: flex; gap: 8px; }
.tp-cover {
  display: grid;
  place-items: center;
  width: 38px;
  aspect-ratio: 12 / 17;
  border: 1.5px solid var(--ink);
  border-radius: 4px 7px 7px 4px;
  background: var(--peach);
  box-shadow: var(--pop);
}
.tp-cover:nth-child(2) { background: var(--sky); }
.tp-cover:nth-child(3) { background: var(--sage); }
.tp-cover i { width: 8px; height: 60%; border: 1px solid var(--ink); border-radius: 99px; background: var(--card); }
.tp-tabs {
  position: absolute;
  left: 50%;
  bottom: 8px;
  display: flex;
  gap: 2px;
  padding: 3px;
  border: 1.5px solid var(--ink);
  border-radius: 999px;
  background: var(--card);
  translate: -50% 0;
}
.tp-tabs i { width: 22px; height: 12px; border-radius: 99px; }
.tp-tabs i:first-child { background: var(--butter); }
.skin-bunko .tp-cover { border: 0; border-radius: 1px 3px 3px 1px; box-shadow: inset 3px 0 0 rgb(0 0 0 / 0.12), 1px 3px 6px rgb(60 40 20 / 0.35); }
.skin-bunko .chip { border-color: var(--coral); border-radius: 3px; background: none; color: var(--coral-text); box-shadow: none; }
.skin-bunko .tp-tabs i:first-child { background: var(--coral); }
.skin-bunko mark { background: none; color: var(--coral-text); }
