:root {
  --bg: #f5f1ec;
  --surface: #ffffff;
  --text: #1f1d2c;
  --muted: #8a8696;
  --accent: #5a3e8c;
  --accent-soft: #f1ebff;
  --pali: #2d4a7c;
  --line: #e7e2db;
  --base: clamp(15px, 4.2vw, 18px);
  --safe-bottom: env(safe-area-inset-bottom, 0);
  --safe-top: env(safe-area-inset-top, 0);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0;
  height: 100%; height: 100dvh;
  overflow: hidden;
}
body {
  font-family: "Noto Serif KR", "Noto Sans KR", -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", serif;
  font-size: var(--base);
  line-height: 1.55;
  background: var(--bg);
  color: var(--text);
  -webkit-text-size-adjust: 100%;
  display: flex;
  flex-direction: column;
}

#topbar {
  display: flex; align-items: center;
  padding: 0.4rem 0.6rem;
  padding-top: calc(0.4rem + var(--safe-top));
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
#topbar button {
  background: none; border: none;
  font-size: 1.4rem;
  padding: 0.2rem 0.6rem;
  color: var(--text);
  cursor: pointer;
}
#page-info {
  flex: 1; text-align: center;
  font-size: 0.82em; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

#page {
  flex: 1;
  display: flex; flex-direction: column;
  padding: 0.7rem;
  overflow: hidden;
  min-height: 0;
}

.card {
  background: var(--surface);
  border-radius: 18px;
  box-shadow: 0 2px 12px rgba(40, 30, 60, 0.06);
  padding: 1rem;
  display: flex; flex-direction: column;
  gap: 0.6rem;
  flex: 1; min-height: 0;
  overflow: hidden;
}

.badge {
  display: inline-block;
  font-size: 0.85em; font-weight: 700;
  color: white; background: var(--accent);
  border-radius: 999px;
  padding: 0.2em 0.85em;
  align-self: flex-start;
}
.hint {
  font-size: 0.78em; color: var(--muted);
  text-align: center;
  margin-top: auto;
  padding-top: 0.5rem;
}
.section-label {
  font-size: 0.75em; font-weight: 600;
  color: var(--muted); letter-spacing: 0.05em;
  margin-top: 0.2rem;
}

/* COVER */
.kind-cover { justify-content: center; align-items: center; text-align: center; }
.cover-ko { font-size: 2rem; font-weight: 700; color: var(--accent); margin-bottom: 0.3rem; }
.cover-pali { font-size: 1.3rem; font-style: italic; color: var(--pali); margin-bottom: 0.2rem; }
.cover-ref { font-size: 0.9em; color: var(--muted); }

/* MAIN: 빠알리 원문 */
.kind-main { justify-content: center; }
.pali-main {
  background: linear-gradient(180deg, #f7f4ff 0%, #f1ebff 100%);
  border-radius: 14px;
  padding: 1.5rem 1rem;
  text-align: center;
  margin: auto 0;
}
.pali-line {
  color: var(--pali);
  font-size: 1.2em;
  line-height: 1.9;
  font-weight: 500;
  font-style: italic;
}

/* Pali tappable token */
.pali-tok {
  text-decoration: underline dotted;
  text-decoration-color: rgba(90, 62, 140, 0.45);
  text-underline-offset: 4px;
  cursor: pointer;
}
.pali-tok:active {
  background: rgba(90, 62, 140, 0.12);
  border-radius: 3px;
}

/* WORDS / TRANS 헤더 */
.verse-header {
  background: var(--accent-soft);
  border-radius: 12px;
  padding: 0.75rem 0.9rem;
  flex-shrink: 0;
}
.verse-header-num {
  display: inline-block;
  background: var(--accent); color: white;
  font-weight: 700;
  border-radius: 999px;
  padding: 0.15em 0.7em;
  font-size: 0.78em;
  margin-bottom: 0.45rem;
}
.verse-header-pali {
  display: block;
  color: var(--pali);
  font-style: italic;
  font-size: 1em;
  line-height: 1.7;
  font-weight: 500;
}

/* WORDS */
.kind-words { gap: 0.5rem; }
.words-card {
  display: flex; flex-direction: column;
  gap: 0.5rem;
  flex: 1; min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.word {
  background: #fbfaf6;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.65rem 0.8rem;
  flex-shrink: 0;
  display: flex; flex-direction: column;
  gap: 0.25rem;
}
.word.clickable { cursor: pointer; transition: background 0.1s, border-color 0.1s; }
.word.clickable:active { background: var(--accent-soft); border-color: var(--accent); }
.word-term {
  font-size: 1.1em; font-weight: 700;
  color: var(--pali);
  font-style: italic;
}
.word-grammar-chip {
  align-self: flex-start;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.78em;
  font-weight: 500;
  padding: 0.15em 0.6em;
  border-radius: 999px;
}
.word-meaning {
  color: var(--text);
  font-size: 0.95em;
  line-height: 1.5;
}
.word-more {
  font-size: 0.76em;
  color: var(--muted);
  margin-top: 0.1rem;
}

/* TRANS */
.kind-trans { gap: 0.5rem; }
.trans-list {
  display: flex; flex-direction: column;
  gap: 0.45rem;
  flex: 1; min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.tr-row {
  background: #fbfaf6;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.55rem 0.75rem;
  flex-shrink: 0;
}
.tr-author {
  font-size: 0.78em; font-weight: 600;
  color: var(--accent);
  margin-bottom: 0.2rem;
}
.tr-body {
  font-size: 0.92em;
  white-space: pre-line;
  transition: filter 0.2s;
}
.tr-body.hidden {
  filter: blur(6px);
  cursor: pointer;
  user-select: none;
}

/* Dictionary popup */
.dict-overlay {
  position: fixed; inset: 0;
  background: rgba(20, 15, 30, 0.5);
  display: flex; align-items: flex-end;
  z-index: 100;
  animation: fadein 0.18s;
}
.dict-sheet {
  position: relative;
  background: var(--surface);
  width: 100%;
  max-height: 85dvh;
  border-radius: 18px 18px 0 0;
  padding: 1.2rem 1.1rem;
  padding-bottom: calc(1.2rem + var(--safe-bottom));
  display: flex; flex-direction: column;
  gap: 0.5rem;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  animation: slideup 0.22s ease-out;
}
.dict-close {
  position: absolute;
  right: 0.5rem; top: 0.4rem;
  background: none; border: none;
  font-size: 1.3rem;
  color: var(--muted);
  cursor: pointer;
  padding: 0.4rem 0.6rem;
}
.dict-term {
  font-size: 1.7rem; font-weight: 700;
  color: var(--pali);
  font-style: italic;
  padding-right: 2.5rem;
}
.dict-section-label {
  font-size: 0.78em; color: var(--muted);
  font-weight: 600; letter-spacing: 0.05em;
  margin-top: 0.6rem;
}
.dict-grammar {
  background: var(--accent-soft);
  color: var(--accent);
  padding: 0.55rem 0.75rem;
  border-radius: 8px;
  font-size: 0.95em;
  font-weight: 500;
  line-height: 1.5;
}
.dict-meaning {
  color: var(--text);
  font-size: 1em;
  line-height: 1.6;
}
.dict-extras {
  background: #faf7f1;
  padding: 0.7rem 0.85rem;
  border-radius: 8px;
  font-size: 0.88em;
  color: #444;
  white-space: pre-line;
  line-height: 1.65;
}
@keyframes fadein { from { opacity: 0 } to { opacity: 1 } }
@keyframes slideup { from { transform: translateY(20%); opacity: 0 } to { transform: translateY(0); opacity: 1 } }

#nav {
  display: flex; justify-content: space-between; align-items: center;
  padding: 0.3rem 1rem;
  padding-bottom: calc(0.3rem + var(--safe-bottom));
  background: var(--surface);
  border-top: 1px solid var(--line);
  flex-shrink: 0;
}
#nav button {
  background: none; border: none;
  font-size: 1.8rem;
  padding: 0.1rem 1.2rem;
  color: var(--accent);
  cursor: pointer;
}
#nav button:disabled { color: var(--muted); opacity: 0.4; }
#page-num {
  font-size: 0.85em; color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* ===== QUIZ ===== */
.quiz-overlay {
  position: fixed; inset: 0;
  background: rgba(20, 15, 30, 0.6);
  display: flex; align-items: stretch;
  z-index: 200;
  animation: fadein 0.18s;
}
.quiz-sheet {
  background: var(--surface);
  width: 100%;
  display: flex; flex-direction: column;
  padding: 1rem 1.1rem;
  padding-top: calc(0.6rem + var(--safe-top));
  padding-bottom: calc(1rem + var(--safe-bottom));
  gap: 0.7rem;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.quiz-top {
  display: flex; align-items: center;
  border-bottom: 1px solid var(--line);
  padding-bottom: 0.5rem;
}
.quiz-progress {
  flex: 1;
  font-size: 0.95em;
  color: var(--accent);
  font-weight: 700;
}
.quiz-prompt {
  font-size: 0.9em;
  color: var(--muted);
  margin-top: 1rem;
  text-align: center;
}
.quiz-term {
  font-size: 2.2rem;
  font-weight: 700;
  color: var(--pali);
  font-style: italic;
  text-align: center;
  margin: 0.6rem 0 0.2rem;
}
.quiz-context {
  text-align: center;
  font-size: 0.78em;
  color: var(--muted);
  margin-bottom: 1rem;
}
.quiz-options {
  display: flex; flex-direction: column;
  gap: 0.55rem;
}
.quiz-option {
  text-align: left;
  background: #fbfaf6;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  padding: 0.75rem 0.9rem;
  font: inherit;
  font-size: 0.98em;
  color: var(--text);
  cursor: pointer;
  transition: background 0.1s, border-color 0.1s;
  line-height: 1.45;
}
.quiz-option:active { background: var(--accent-soft); }
.quiz-option:disabled { cursor: default; }
.quiz-option.correct {
  background: #e9f5e2;
  border-color: #4d9a4d;
  color: #1d5b1d;
  font-weight: 600;
}
.quiz-option.wrong {
  background: #fbeaea;
  border-color: #c44a4a;
  color: #882828;
}
.btn-primary {
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 12px;
  padding: 0.85rem 1rem;
  font: inherit;
  font-size: 1em;
  font-weight: 600;
  cursor: pointer;
  margin-top: 0.6rem;
}
.btn-primary:active { opacity: 0.8; }
.btn-secondary {
  background: transparent;
  color: var(--accent);
  border: 1.5px solid var(--accent);
  border-radius: 12px;
  padding: 0.85rem 1rem;
  font: inherit;
  font-size: 1em;
  font-weight: 600;
  cursor: pointer;
  margin-top: 0.6rem;
}

/* QUIZ RESULT */
.quiz-result-emoji {
  font-size: 3.5rem;
  text-align: center;
  margin-top: 1rem;
}
.quiz-result-title {
  text-align: center;
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 0.4rem;
}
.quiz-result-score {
  text-align: center;
  font-size: 2rem;
  font-weight: 700;
  color: var(--pali);
}
.quiz-result-pct {
  text-align: center;
  font-size: 0.9em;
  color: var(--muted);
  margin-bottom: 1rem;
}
.quiz-wrong-list {
  display: flex; flex-direction: column;
  gap: 0.45rem;
  margin-top: 0.4rem;
}
.quiz-wrong {
  background: #fbeaea;
  border: 1px solid #e8b8b8;
  border-radius: 10px;
  padding: 0.55rem 0.75rem;
}
.quiz-wrong-term {
  font-weight: 700;
  color: #882828;
  font-style: italic;
  font-size: 1em;
}
.quiz-wrong-answer {
  color: #444;
  font-size: 0.88em;
  margin-top: 0.2rem;
}
.quiz-actions {
  display: flex; flex-direction: column;
  gap: 0.4rem;
  margin-top: 1rem;
}

/* Badge on quiz button */
#quiz-btn { position: relative; }
.quiz-badge {
  position: absolute;
  top: 0.05rem;
  right: 0.05rem;
  background: #c44a4a;
  color: white;
  font-size: 0.55em;
  font-weight: 700;
  border-radius: 999px;
  padding: 0.1em 0.4em;
  min-width: 1.3em;
  line-height: 1.2;
  text-align: center;
}

/* Quiz chooser sheet */
.quiz-chooser { gap: 0.5rem; }
.btn-text {
  background: none; border: none;
  color: var(--muted);
  font: inherit;
  font-size: 0.88em;
  cursor: pointer;
  margin-top: 0.6rem;
  padding: 0.5rem;
  text-decoration: underline;
}

/* MEMO FAB + sheet */
.memo-fab {
  position: fixed;
  right: 0.9rem;
  bottom: calc(3.8rem + var(--safe-bottom));
  background: var(--accent);
  color: white;
  border: none;
  width: 3rem; height: 3rem;
  border-radius: 50%;
  font-size: 1.2rem;
  box-shadow: 0 4px 14px rgba(40,30,60,0.25);
  cursor: pointer;
  z-index: 50;
  display: flex; align-items: center; justify-content: center;
  transition: transform 0.12s;
}
.memo-fab:active { transform: scale(0.94); }
.memo-fab.has-memo { background: #4d9a4d; }
.memo-fab.has-memo::after {
  content: "";
  position: absolute;
  top: 0.15rem; right: 0.15rem;
  width: 0.55rem; height: 0.55rem;
  background: #ffd84d;
  border-radius: 50%;
  border: 1.5px solid white;
}
.memo-sheet { gap: 0.4rem; }
.memo-page-info {
  font-size: 0.82em;
  color: var(--muted);
  margin-bottom: 0.5rem;
}
.memo-textarea {
  width: 100%;
  min-height: 9rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.7rem 0.8rem;
  font: inherit;
  font-size: 0.95em;
  line-height: 1.55;
  resize: vertical;
  -webkit-appearance: none;
  background: #fbfaf6;
}
.memo-textarea:focus { outline: none; border-color: var(--accent); background: white; }
.memo-updated {
  font-size: 0.76em;
  color: var(--muted);
  margin-top: 0.3rem;
}
.memo-actions {
  display: flex; gap: 0.5rem; align-items: center;
  margin-top: 0.8rem;
}
.memo-actions .btn-primary { flex: 1; margin-top: 0; }
.memo-actions .btn-text { margin-top: 0; }
.memo-loading {
  text-align: center; color: var(--muted);
  padding: 0.8rem;
  font-size: 0.85em;
}

/* ===== MEMO IMAGES (sheet) ===== */
.memo-image-add-row {
  margin: 0.4rem 0 0.2rem;
}
.memo-image-add-btn {
  background: none;
  border: 1px dashed var(--line);
  color: var(--accent);
  padding: 0.45rem 0.9rem;
  border-radius: 8px;
  font: inherit;
  font-size: 0.88em;
  cursor: pointer;
  font-weight: 500;
}
.memo-image-add-btn:active { background: var(--accent-soft); }
.memo-images-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.4rem;
}
.memo-images-grid.empty { display: none; }
.memo-image-item {
  position: relative;
  aspect-ratio: 1 / 1;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--line);
  background: #f5f3ed;
}
.memo-image-thumb {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
  cursor: zoom-in;
}
.memo-image-order {
  position: absolute;
  top: 0.25rem; left: 0.25rem;
  background: var(--accent);
  color: white;
  font-size: 0.72em;
  font-weight: 700;
  width: 1.25rem; height: 1.25rem;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}
.memo-image-remove {
  position: absolute;
  top: 0.25rem; right: 0.25rem;
  background: rgba(196, 74, 74, 0.92);
  color: white;
  border: none;
  width: 1.4rem; height: 1.4rem;
  border-radius: 50%;
  font-size: 0.95em;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.memo-image-remove:active { transform: scale(0.92); }

/* ===== MEMO THUMB STRIP (list/preview) ===== */
.memo-item-thumbs,
.memo-preview-thumbs {
  display: flex;
  gap: 0.35rem;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-top: 0.4rem;
  padding-bottom: 0.15rem;
}
.memo-item-thumb,
.memo-preview-thumb {
  width: 3.2rem;
  height: 3.2rem;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--line);
  flex-shrink: 0;
  cursor: zoom-in;
  background: #f5f3ed;
}
.memo-preview-thumb-more {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 3.2rem;
  height: 3.2rem;
  font-size: 0.85em;
  color: var(--muted);
  border-radius: 6px;
  border: 1px dashed var(--line);
  flex-shrink: 0;
}

/* ===== MEMO LIGHTBOX ===== */
.memo-lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.92);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
}
.memo-lightbox-img {
  max-width: 95vw;
  max-height: 90vh;
  object-fit: contain;
  user-select: none;
  -webkit-user-select: none;
}
.memo-lightbox-counter {
  position: absolute;
  top: max(0.8rem, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  color: white;
  font-size: 0.9em;
  background: rgba(0, 0, 0, 0.45);
  padding: 0.25rem 0.7rem;
  border-radius: 999px;
}
.memo-lightbox-close {
  position: absolute;
  top: max(0.8rem, env(safe-area-inset-top));
  right: 0.8rem;
  background: rgba(255, 255, 255, 0.12);
  color: white;
  border: none;
  width: 2.4rem;
  height: 2.4rem;
  border-radius: 50%;
  font-size: 1.15em;
  cursor: pointer;
}
.memo-lightbox-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(255, 255, 255, 0.12);
  color: white;
  border: none;
  width: 2.6rem;
  height: 3.4rem;
  font-size: 1.6em;
  cursor: pointer;
  border-radius: 6px;
}
.memo-lightbox-prev { left: 0.6rem; }
.memo-lightbox-next { right: 0.6rem; }
.memo-lightbox-nav:active,
.memo-lightbox-close:active { background: rgba(255, 255, 255, 0.22); }


/* ===== TEXT SELECTION ===== */
body {
  user-select: text;
  -webkit-user-select: text;
}
button, .badge, .verse-header-num, .word-grammar-chip,
.quiz-badge, .memo-fab, .quiz-option {
  user-select: none;
  -webkit-user-select: none;
}
.pali-main, .pali-line, .pali-tok, .verse-header-pali,
.tr-body, .word-meaning, .word-extras, .dict-term, .dict-meaning,
.dict-extras, .dict-grammar, .memo-item-preview, .cover-pali,
.cover-ref, .word-term, .quiz-term {
  user-select: text;
  -webkit-user-select: text;
  -webkit-touch-callout: default;
}

/* ===== MEMO LIST ===== */
.memo-list-sheet { gap: 0.4rem; }
.memo-count {
  font-size: 0.82em;
  color: var(--muted);
  margin-bottom: 0.3rem;
}
.memo-empty {
  text-align: center;
  color: var(--muted);
  white-space: pre-line;
  padding: 2rem 1rem;
  line-height: 1.7;
}
.memo-list {
  display: flex; flex-direction: column;
  gap: 0.5rem;
  max-height: 55vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.memo-item {
  background: #fbfaf6;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.6rem 0.75rem;
}
.memo-item-head {
  display: flex; align-items: center;
  justify-content: space-between;
  margin-bottom: 0.3rem;
}
.memo-item-id {
  font-weight: 700;
  color: var(--accent);
  font-size: 0.88em;
}
.memo-item-go {
  background: none; border: none;
  color: var(--accent);
  font-size: 0.82em;
  cursor: pointer;
  padding: 0.2rem 0.4rem;
  font-weight: 600;
}
.memo-item-preview {
  font-size: 0.92em;
  color: var(--text);
  white-space: pre-line;
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.memo-item-date {
  font-size: 0.74em;
  color: var(--muted);
  margin-top: 0.25rem;
}
.memo-item-actions {
  display: flex; gap: 0.3rem;
  margin-top: 0.5rem;
  border-top: 1px dashed var(--line);
  padding-top: 0.4rem;
}
.btn-text-small {
  background: none; border: none;
  color: var(--accent);
  font: inherit;
  font-size: 0.82em;
  cursor: pointer;
  padding: 0.35rem 0.7rem;
  border-radius: 6px;
  font-weight: 500;
}
.btn-text-small.btn-danger { color: #c44a4a; }
.btn-text-small:active { background: var(--accent-soft); }
.memo-list-sheet .btn-secondary { margin-top: 1rem; }

/* Memo source indicators */
.memo-item-id-group {
  display: flex; align-items: center; gap: 0.4rem;
  flex-wrap: wrap;
}
.memo-item-source {
  font-size: 0.7em;
  padding: 0.15em 0.5em;
  border-radius: 999px;
  font-weight: 500;
}
.memo-item-source.src-github {
  background: #e3f2fd;
  color: #1976d2;
}
.memo-item-source.src-local {
  background: #fff8e1;
  color: #b78a00;
}
.memo-source-note {
  background: #e3f2fd;
  color: #1976d2;
  font-size: 0.82em;
  padding: 0.5rem 0.7rem;
  border-radius: 8px;
  margin-bottom: 0.5rem;
}
.memo-fab.has-memo:not(.has-local-memo) { background: #1976d2; }
.memo-fab.has-memo:not(.has-local-memo)::after {
  content: "";
  position: absolute;
  top: 0.15rem; right: 0.15rem;
  width: 0.55rem; height: 0.55rem;
  background: #fff;
  border-radius: 50%;
  border: 1.5px solid white;
}

/* ===== LOTUS ROW ===== */
.lotus-row {
  display: flex;
  align-items: center;
  gap: 0.05rem;
  margin-right: 0.4rem;
  user-select: none;
  -webkit-user-select: none;
}
.lotus {
  font-size: 0.9rem;
  line-height: 1;
  opacity: 0.35;
  filter: grayscale(0.6);
  min-width: 1em;
  text-align: center;
}
.lotus.filled {
  opacity: 1;
  filter: none;
}

/* ===== INLINE QUIZ (in-flow) ===== */
.quiz-prompt-inline {
  text-align: center;
  font-size: 0.88em;
  color: var(--muted);
  margin-top: 0.6rem;
}
.quiz-term-inline {
  text-align: center;
  font-size: 1.7rem;
  font-weight: 700;
  color: var(--pali);
  font-style: italic;
  margin: 0.4rem 0 0.8rem;
  padding: 0.4rem 0.6rem;
  background: var(--accent-soft);
  border-radius: 10px;
}
.quiz-options-inline {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  flex-shrink: 0;
}
.quiz-option-inline {
  text-align: left;
  background: #fbfaf6;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  padding: 0.7rem 0.85rem;
  font: inherit;
  font-size: 0.95em;
  color: var(--text);
  cursor: pointer;
  transition: background 0.1s;
  line-height: 1.4;
}
.quiz-option-inline:active { background: var(--accent-soft); }
.quiz-option-inline:disabled { cursor: default; }
.quiz-option-inline.correct {
  background: #e9f5e2;
  border-color: #4d9a4d;
  color: #1d5b1d;
  font-weight: 600;
}
.quiz-option-inline.wrong {
  background: #fbeaea;
  border-color: #c44a4a;
  color: #882828;
}
.quiz-feedback {
  text-align: center;
  font-weight: 600;
  margin-top: 0.5rem;
  padding: 0.6rem;
  border-radius: 8px;
}
.quiz-feedback.correct { color: #4d9a4d; background: #e9f5e2; }
.quiz-feedback.wrong { color: #c44a4a; background: #fbeaea; }

/* ===== SETTINGS SHEET ===== */
.settings-sheet { gap: 0.4rem; }
.settings-radio {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  margin-bottom: 0.2rem;
}
.settings-radio-btn {
  background: white;
  border: 1.5px solid var(--line);
  border-radius: 8px;
  padding: 0.5rem 1rem;
  font: inherit;
  font-size: 0.92em;
  cursor: pointer;
  color: var(--text);
  flex: 1;
  min-width: 4rem;
}
.settings-radio-btn.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
  font-weight: 600;
}
.settings-actions {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  margin-top: 0.4rem;
}
.settings-actions .btn-secondary {
  margin-top: 0;
  text-align: left;
  font-size: 0.92em;
  padding: 0.7rem 0.9rem;
}

/* Memo inline preview on page */
.memo-preview-box {
  background: #fff8e1;
  border-left: 3px solid #fbc02d;
  border-radius: 6px;
  padding: 0.5rem 0.7rem;
  margin-top: 0.6rem;
  cursor: pointer;
  font-size: 0.85em;
  flex-shrink: 0;
}
.memo-preview-box:active { background: #fff3c4; }
.memo-preview-label {
  font-size: 0.75em;
  color: #b78a00;
  font-weight: 600;
  margin-bottom: 0.2rem;
}
.memo-preview-text {
  color: #5a4a00;
  white-space: pre-line;
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.memo-preview-date {
  font-size: 0.72em;
  color: #b78a00;
  margin-top: 0.2rem;
  text-align: right;
}

/* Exposure suppression note */
.exposure-note {
  text-align: center;
  font-size: 0.78em;
  color: var(--muted);
  padding: 0.6rem;
  background: #f5f1ec;
  border-radius: 8px;
  cursor: pointer;
  margin-top: 0.4rem;
}
.exposure-note:active { background: var(--accent-soft); }

/* Exposure suppression note */
.exposure-note {
  text-align: center;
  font-size: 0.78em;
  color: var(--muted);
  padding: 0.6rem;
  background: #f5f1ec;
  border-radius: 8px;
  cursor: pointer;
  margin-top: 0.4rem;
}
.exposure-note:active { background: var(--accent-soft); }

/* TOC */
.toc-sheet { gap: 0.45rem; }
.toc-list {
  display: flex; flex-direction: column;
  gap: 0.3rem;
  max-height: 50vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.toc-item {
  display: flex; align-items: center; gap: 0.55rem;
  background: #fbfaf6;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  padding: 0.55rem 0.75rem;
  font: inherit;
  text-align: left;
  cursor: pointer;
  color: var(--text);
}
.toc-item:active { background: var(--accent-soft); }
.toc-item.current { border-color: var(--accent); background: var(--accent-soft); }
.toc-num {
  display: inline-block;
  background: var(--accent);
  color: white;
  border-radius: 999px;
  padding: 0.1em 0.55em;
  font-size: 0.78em;
  font-weight: 700;
  min-width: 1.7em;
  text-align: center;
}
.toc-pali {
  font-size: 0.9em;
  color: var(--pali);
  font-style: italic;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Calendar */
.calendar-sheet { gap: 0.5rem; }
.calendar-stats {
  font-size: 0.85em;
  color: var(--muted);
  text-align: center;
  padding: 0.3rem 0;
}
.calendar-grid {
  display: flex; flex-direction: column;
  gap: 0.18rem;
  margin: 0.3rem 0;
}
.calendar-row {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 0.18rem;
}
.calendar-labels .calendar-label {
  font-size: 0.7em;
  color: var(--muted);
  text-align: center;
  padding: 0.25rem 0;
}
.calendar-cell {
  aspect-ratio: 1;
  background: #f5f1ec;
  border-radius: 4px;
  font-size: 0.7em;
  color: var(--muted);
  display: flex; align-items: center; justify-content: center;
  font-variant-numeric: tabular-nums;
}
.calendar-cell.future { opacity: 0.3; }
.calendar-cell.active { color: white; font-weight: 600; }
.calendar-cell.intensity-1 { background: #c8d8b3; color: #1d5b1d; }
.calendar-cell.intensity-2 { background: #8fc070; color: white; }
.calendar-cell.intensity-3 { background: #5a9a3d; color: white; }
.calendar-cell.intensity-4 { background: #2d6a1a; color: white; }
.calendar-cell.today { outline: 2px solid var(--accent); outline-offset: 0; }

/* Memo source note */
.memo-source-note {
  background: #e3f2fd;
  color: #1976d2;
  font-size: 0.82em;
  padding: 0.5rem 0.7rem;
  border-radius: 8px;
  margin-bottom: 0.5rem;
}

/* Exposure suppression note */
.exposure-note {
  text-align: center; font-size: 0.78em;
  color: var(--muted);
  padding: 0.6rem;
  background: #f5f1ec;
  border-radius: 8px;
  cursor: pointer;
  margin-top: 0.4rem;
}
.exposure-note:active { background: var(--accent-soft); }

.toc-sheet { gap: 0.45rem; }
.toc-list {
  display: flex; flex-direction: column; gap: 0.3rem;
  max-height: 50vh; overflow-y: auto; -webkit-overflow-scrolling: touch;
}
.toc-item {
  display: flex; align-items: center; gap: 0.55rem;
  background: #fbfaf6;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  padding: 0.55rem 0.75rem;
  font: inherit; text-align: left;
  cursor: pointer; color: var(--text);
}
.toc-item:active { background: var(--accent-soft); }
.toc-item.current { border-color: var(--accent); background: var(--accent-soft); }
.toc-num {
  display: inline-block;
  background: var(--accent); color: white;
  border-radius: 999px;
  padding: 0.1em 0.55em;
  font-size: 0.78em; font-weight: 700;
  min-width: 1.7em; text-align: center;
}
.toc-pali {
  font-size: 0.9em; color: var(--pali);
  font-style: italic; flex: 1;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.calendar-sheet { gap: 0.5rem; }
.calendar-stats {
  font-size: 0.85em; color: var(--muted);
  text-align: center; padding: 0.3rem 0;
}
.calendar-grid {
  display: flex; flex-direction: column; gap: 0.18rem;
  margin: 0.3rem 0;
}
.calendar-row {
  display: grid; grid-template-columns: repeat(7, 1fr); gap: 0.18rem;
}
.calendar-labels .calendar-label {
  font-size: 0.7em; color: var(--muted);
  text-align: center; padding: 0.25rem 0;
}
.calendar-cell {
  aspect-ratio: 1;
  background: #f5f1ec;
  border-radius: 4px;
  font-size: 0.7em; color: var(--muted);
  display: flex; align-items: center; justify-content: center;
  font-variant-numeric: tabular-nums;
}
.calendar-cell.future { opacity: 0.3; }
.calendar-cell.active { color: white; font-weight: 600; }
.calendar-cell.intensity-1 { background: #c8d8b3; color: #1d5b1d; }
.calendar-cell.intensity-2 { background: #8fc070; color: white; }
.calendar-cell.intensity-3 { background: #5a9a3d; color: white; }
.calendar-cell.intensity-4 { background: #2d6a1a; color: white; }
.calendar-cell.today { outline: 2px solid var(--accent); }

.memo-source-note {
  background: #e3f2fd; color: #1976d2;
  font-size: 0.82em;
  padding: 0.5rem 0.7rem;
  border-radius: 8px;
  margin-bottom: 0.5rem;
}

/* Exposure suppression note */
.exposure-note {
  text-align: center; font-size: 0.78em;
  color: var(--muted);
  padding: 0.6rem;
  background: #f5f1ec;
  border-radius: 8px;
  cursor: pointer;
  margin-top: 0.4rem;
}
.exposure-note:active { background: var(--accent-soft); }

.toc-sheet { gap: 0.45rem; }
.toc-list {
  display: flex; flex-direction: column; gap: 0.3rem;
  max-height: 50vh; overflow-y: auto; -webkit-overflow-scrolling: touch;
}
.toc-item {
  display: flex; align-items: center; gap: 0.55rem;
  background: #fbfaf6;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  padding: 0.55rem 0.75rem;
  font: inherit; text-align: left;
  cursor: pointer; color: var(--text);
}
.toc-item:active { background: var(--accent-soft); }
.toc-item.current { border-color: var(--accent); background: var(--accent-soft); }
.toc-num {
  display: inline-block;
  background: var(--accent); color: white;
  border-radius: 999px;
  padding: 0.1em 0.55em;
  font-size: 0.78em; font-weight: 700;
  min-width: 1.7em; text-align: center;
}
.toc-pali {
  font-size: 0.9em; color: var(--pali);
  font-style: italic; flex: 1;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.calendar-sheet { gap: 0.5rem; }
.calendar-stats {
  font-size: 0.85em; color: var(--muted);
  text-align: center; padding: 0.3rem 0;
}
.calendar-grid {
  display: flex; flex-direction: column; gap: 0.18rem;
  margin: 0.3rem 0;
}
.calendar-row {
  display: grid; grid-template-columns: repeat(7, 1fr); gap: 0.18rem;
}
.calendar-labels .calendar-label {
  font-size: 0.7em; color: var(--muted);
  text-align: center; padding: 0.25rem 0;
}
.calendar-cell {
  aspect-ratio: 1;
  background: #f5f1ec;
  border-radius: 4px;
  font-size: 0.7em; color: var(--muted);
  display: flex; align-items: center; justify-content: center;
  font-variant-numeric: tabular-nums;
}
.calendar-cell.future { opacity: 0.3; }
.calendar-cell.active { color: white; font-weight: 600; }
.calendar-cell.intensity-1 { background: #c8d8b3; color: #1d5b1d; }
.calendar-cell.intensity-2 { background: #8fc070; color: white; }
.calendar-cell.intensity-3 { background: #5a9a3d; color: white; }
.calendar-cell.intensity-4 { background: #2d6a1a; color: white; }
.calendar-cell.today { outline: 2px solid var(--accent); }

.memo-source-note {
  background: #e3f2fd; color: #1976d2;
  font-size: 0.82em;
  padding: 0.5rem 0.7rem;
  border-radius: 8px;
  margin-bottom: 0.5rem;
}

/* === NEW TOPBAR LAYOUT === */
#topbar {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.4rem 0.5rem;
  padding-top: calc(0.4rem + var(--safe-top));
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
#topbar #prev-btn,
#topbar #next-btn {
  background: none;
  border: none;
  font-size: 1.6rem;
  color: var(--accent);
  padding: 0.15rem 0.5rem;
  cursor: pointer;
  font-weight: 600;
}
#topbar #prev-btn:disabled,
#topbar #next-btn:disabled {
  color: var(--muted);
  opacity: 0.35;
}
#topbar-center {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.05rem;
  min-width: 0;
}
#topbar-center #page-info {
  font-size: 0.78em;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
  font-weight: 500;
}
#topbar-center #page-num {
  font-size: 0.65em;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* === BOTTOM TABS (suttalog2 style) === */
#bottom-tabs {
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding-bottom: var(--safe-bottom);
  flex-shrink: 0;
  box-shadow: 0 -2px 8px rgba(40, 30, 60, 0.04);
}
#bottom-tabs button {
  flex: 1;
  background: none;
  border: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.1rem;
  padding: 0.45rem 0.2rem;
  cursor: pointer;
  color: var(--muted);
  font: inherit;
  transition: color 0.15s;
}
#bottom-tabs button:active {
  background: var(--accent-soft);
}
#bottom-tabs button.active {
  color: var(--accent);
}
#bottom-tabs .tab-icon {
  font-size: 1.25rem;
  line-height: 1;
}
#bottom-tabs .tab-label {
  font-size: 0.62rem;
  font-weight: 500;
  letter-spacing: 0.02em;
}

/* Memo FAB moves up since no bottom nav with prev/next */
.memo-fab {
  bottom: calc(4.5rem + var(--safe-bottom));
}

/* Hide old #nav if present (legacy) */
#nav { display: none !important; }

/* Calendar month indicators */
.calendar-today-banner {
  background: var(--accent);
  color: white;
  text-align: center;
  font-weight: 700;
  font-size: 0.95em;
  padding: 0.5rem 0.7rem;
  border-radius: 10px;
  margin-bottom: 0.4rem;
}
.calendar-month-row {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.03em;
  margin: 0.45rem 0 0.15rem;
  padding-left: 0.2rem;
}
.calendar-cell.month-start {
  font-size: 0.62em;
  font-weight: 700;
  border-left: 2px solid var(--accent);
}
.calendar-cell.today {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  font-weight: 800;
}

/* === COVER (home screen) === */
.kind-cover {
  justify-content: flex-start;
  align-items: stretch;
  text-align: left;
  background: linear-gradient(180deg, #fdfaf3 0%, #f5f1ec 60%, #ede5dc 100%);
  padding: 1.4rem 1.2rem;
  gap: 0;
}
.cover-hero {
  text-align: center;
  padding: 1.5rem 0 1rem;
}
.cover-emoji {
  font-size: 4.5rem;
  line-height: 1;
  margin-bottom: 1rem;
  filter: drop-shadow(0 6px 14px rgba(90, 62, 140, 0.25));
}
.cover-hero .cover-ko {
  font-size: 2.1rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: -0.02em;
  margin: 0;
  line-height: 1.2;
}
.cover-hero .cover-pali {
  font-size: 1.15rem;
  color: var(--pali);
  font-style: italic;
  margin: 0.3rem 0 0;
}
.cover-hero .cover-ref {
  font-size: 0.78em;
  color: var(--muted);
  letter-spacing: 0.12em;
  margin: 0.4rem 0 0;
  font-weight: 500;
}

.cover-actions {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  margin-top: 1.5rem;
}
.cover-btn {
  background: var(--surface);
  border: 1.5px solid var(--line);
  border-radius: 14px;
  padding: 0.85rem 1rem;
  font: inherit;
  font-size: 0.98em;
  color: var(--text);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.2rem;
  text-align: center;
  font-weight: 500;
  transition: transform 0.1s, box-shadow 0.15s;
}
.cover-btn:active { transform: scale(0.98); }
.cover-btn-main { font-weight: 600; font-size: 1em; }
.cover-btn-sub {
  font-size: 0.72em;
  opacity: 0.7;
  font-weight: 400;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.05em;
}
.cover-btn-primary {
  background: linear-gradient(135deg, var(--accent) 0%, #7b5cb5 100%);
  color: white;
  border-color: var(--accent);
  box-shadow: 0 4px 14px rgba(90, 62, 140, 0.3);
}
.cover-btn-primary .cover-btn-sub { opacity: 0.85; }

.cover-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.45rem;
  margin-top: 1.5rem;
  padding-bottom: 0.5rem;
}
.cover-stat {
  background: var(--surface);
  border-radius: 12px;
  padding: 0.75rem 0.4rem;
  text-align: center;
  border: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
  box-shadow: 0 1px 3px rgba(40, 30, 60, 0.03);
}
.cover-stat-icon {
  font-size: 1.2rem;
  line-height: 1;
}
.cover-stat-value {
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}
.cover-stat-label {
  font-size: 0.65em;
  color: var(--muted);
  letter-spacing: 0.02em;
  font-weight: 500;
}

/* === CARD-NAV (inline prev/next at bottom of card) === */
.card-nav {
  display: flex;
  gap: 0.5rem;
  margin-top: auto;
  padding-top: 0.8rem;
  border-top: 1px dashed var(--line);
  flex-shrink: 0;
}
.card-nav-btn {
  padding: 0.75rem 0.6rem;
  border-radius: 12px;
  font: inherit;
  font-size: 0.95em;
  font-weight: 600;
  cursor: pointer;
  border: 1.5px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  transition: transform 0.1s;
}
.card-nav-btn:active { transform: scale(0.97); }
.card-nav-btn:disabled { opacity: 0.35; cursor: default; }
.card-nav-prev { flex: 1; }
.card-nav-next {
  flex: 2;
  background: var(--accent);
  color: white;
  border-color: var(--accent);
  box-shadow: 0 3px 10px rgba(90, 62, 140, 0.22);
}
.card-nav-next:disabled {
  background: var(--surface);
  color: var(--muted);
  box-shadow: none;
}

/* === SUTTALOG PALETTE (warm cream + terracotta) === */
:root {
  --bg: #f7f1e6;
  --surface: #fdfaf3;
  --text: #2c2c2c;
  --muted: #9a8e7d;
  --accent: #c46d2c;
  --accent-soft: #fcefdf;
  --line: #e5dfd2;
  --pali: #6a4a30;
  --burgundy: #9c4a3a;
  --tan: #b89968;
}

/* === COVER (SuttaLog style) === */
.kind-cover {
  background: var(--bg);
  text-align: center;
  padding: 1.2rem 1.4rem 1rem;
  gap: 0;
  justify-content: flex-start;
  align-items: stretch;
  font-family: "Noto Serif KR", "Noto Serif", serif;
}
.cover-hero {
  text-align: center;
  padding: 1.5rem 0 0.8rem;
}
.cover-lotus {
  font-size: 5rem;
  line-height: 1;
  margin: 0.5rem 0 1.8rem;
  filter: drop-shadow(0 6px 14px rgba(156, 74, 58, 0.18));
}
.cover-mantra-1 {
  font-style: italic;
  font-weight: 700;
  font-size: 1.5rem;
  color: var(--burgundy);
  letter-spacing: 0.02em;
  margin-bottom: 0.7rem;
}
.cover-mantra-2 {
  font-style: italic;
  font-size: 1.1rem;
  color: var(--tan);
  letter-spacing: 0.01em;
  line-height: 1.4;
  margin-bottom: 2rem;
  padding: 0 0.5rem;
}
.cover-welcome {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.45;
  white-space: pre-line;
  margin-bottom: 0.7rem;
  font-family: "Noto Sans KR", sans-serif;
}
.cover-subtitle {
  font-size: 0.92em;
  color: var(--muted);
  line-height: 1.6;
  white-space: pre-line;
  margin-bottom: 1.5rem;
  font-family: "Noto Sans KR", sans-serif;
}
.cover-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.5rem 1rem;
  font-size: 0.88em;
  color: var(--text);
  font-weight: 500;
  font-family: "Noto Sans KR", sans-serif;
}
.cover-chip .chip-icon { font-size: 1em; line-height: 1; }

.cover-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.45rem;
  margin: 1.5rem 0 1.2rem;
  padding: 0 0.2rem;
}
.cover-stat {
  background: var(--surface);
  border-radius: 12px;
  padding: 0.75rem 0.4rem;
  text-align: center;
  border: 1px solid var(--line);
  font-family: "Noto Sans KR", sans-serif;
}
.cover-stat-value {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--accent);
}

.cover-cta {
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 14px;
  padding: 1.1rem 1.2rem;
  font: inherit;
  font-family: "Noto Sans KR", sans-serif;
  font-size: 1.08em;
  font-weight: 700;
  cursor: pointer;
  margin-top: auto;
  margin-bottom: 0.6rem;
  box-shadow: 0 4px 16px rgba(196, 109, 44, 0.3);
  letter-spacing: 0.02em;
}
.cover-cta:active { transform: scale(0.98); box-shadow: 0 2px 8px rgba(196, 109, 44, 0.25); }

.cover-links {
  display: flex; justify-content: center; gap: 1.5rem;
  margin-bottom: 0.3rem;
}
.cover-link {
  background: none; border: none;
  color: var(--accent);
  font: inherit;
  font-family: "Noto Sans KR", sans-serif;
  font-size: 0.88em;
  font-weight: 500;
  cursor: pointer;
  padding: 0.4rem 0.6rem;
}
.cover-link:active { opacity: 0.7; }

/* Update memo FAB to warm accent */
.memo-fab { background: var(--accent); }
.memo-fab.has-memo { background: #6ba253; }
.memo-fab.has-memo:not(.has-local-memo) { background: #5a8aa8; }
