:root {
  --bg: #f7f4ef;
  --bg-card: #ffffff;
  --bg-sidebar: #ede8df;
  --text: #2c2416;
  --text-muted: #6b5d4d;
  --accent: #5c4a32;
  --accent-light: #8b7355;
  --border: #d9d0c3;
  --highlight: #fff8e7;
  --highlight-border: #c9a962;
  --shadow: 0 2px 12px rgba(44, 36, 22, 0.08);
  --radius: 10px;
  --font-serif: "Noto Serif TC", "Songti TC", serif;
  --font-sans: "Noto Sans TC", "PingFang TC", sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  color: var(--text);
  background: var(--bg);
  line-height: 1.6;
  min-height: 100vh;
}

/* Header */
.site-header {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.5rem;
  gap: 1rem;
  flex-wrap: wrap;
}

.site-title {
  margin: 0;
  font-family: var(--font-serif);
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--accent);
}

.view-tabs {
  display: flex;
  gap: 0.25rem;
  background: var(--bg);
  padding: 0.25rem;
  border-radius: var(--radius);
}

.tab {
  border: none;
  background: transparent;
  padding: 0.45rem 1rem;
  border-radius: 8px;
  font-family: inherit;
  font-size: 0.9rem;
  cursor: pointer;
  color: var(--text-muted);
  transition: background 0.15s, color 0.15s;
}

.tab:hover {
  color: var(--text);
}

.tab.active {
  background: var(--bg-card);
  color: var(--accent);
  font-weight: 600;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.65rem 1rem;
  padding: 0 1.5rem 0.85rem;
}

.search-bar {
  position: relative;
  flex: 0 1 220px;
  min-width: 160px;
  max-width: 280px;
  padding: 0;
}

.search-bar input {
  width: 100%;
  padding: 0.45rem 2rem 0.45rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 0.88rem;
  background: var(--bg);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.search-bar input:focus {
  outline: none;
  border-color: var(--accent-light);
  box-shadow: 0 0 0 3px rgba(92, 74, 50, 0.12);
}

.search-clear {
  position: absolute;
  right: 0.45rem;
  top: 50%;
  transform: translateY(-50%);
  border: none;
  background: var(--text-muted);
  color: white;
  width: 1.25rem;
  height: 1.25rem;
  border-radius: 50%;
  cursor: pointer;
  font-size: 0.9rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.filter-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem 0.55rem;
  min-width: 0;
  flex: 1 1 auto;
}

.filter-group + .filter-group {
  padding-left: 0.85rem;
  border-left: 1px solid var(--border);
}

.filter-row-head {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-shrink: 0;
}

.filter-label {
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  white-space: nowrap;
}

.btn-link {
  border: none;
  background: none;
  padding: 0;
  font-family: inherit;
  font-size: 0.78rem;
  color: var(--accent-light);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
  white-space: nowrap;
}

.btn-link:hover {
  color: var(--accent);
}

.filter-chips {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
}

.category-chip,
.tag-chip {
  border: 1px solid var(--border);
  background: var(--bg-card);
  padding: 0.3rem 0.75rem;
  border-radius: 999px;
  font-family: inherit;
  font-size: 0.82rem;
  cursor: pointer;
  transition: all 0.15s;
  color: var(--text-muted);
}

.category-chip:hover,
.tag-chip:hover {
  border-color: var(--accent-light);
}

.category-chip.active,
.tag-chip.active {
  color: white;
  border-color: transparent;
  font-weight: 500;
}

.manage-toolbar {
  margin-bottom: 0.85rem;
}

.manage-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-height: min(50vh, 360px);
  overflow-y: auto;
}

.manage-item {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
}

.manage-swatch {
  width: 0.85rem;
  height: 0.85rem;
  border-radius: 50%;
  flex-shrink: 0;
}

.manage-item-name {
  flex: 1;
  font-size: 0.92rem;
  color: var(--text);
}

.manage-item-actions {
  display: flex;
  gap: 0.35rem;
}

.manage-item-actions .btn-secondary,
.manage-item-actions .btn-danger {
  padding: 0.3rem 0.55rem;
  font-size: 0.78rem;
}

#meta-form-color {
  width: 3.5rem;
  height: 2.2rem;
  padding: 0.15rem;
  cursor: pointer;
}

/* Layout */
.main-layout {
  max-width: 1400px;
  margin: 0 auto;
  padding: 1rem 1rem 2rem;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

#view-bible.active {
  display: grid;
  grid-template-columns: 200px 1fr 320px;
  gap: 1rem;
  align-items: start;
}

/* Sidebars */
.sidebar {
  background: var(--bg-sidebar);
  border-radius: var(--radius);
  padding: 1rem;
  max-height: calc(100vh - 180px);
  overflow-y: auto;
  position: sticky;
  top: 120px;
}

.sidebar-title {
  margin: 0 0 0.75rem;
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.book-filter {
  width: 100%;
  margin-bottom: 0.75rem;
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: inherit;
  font-size: 0.85rem;
  background: var(--bg-card);
}

.book-filter:focus {
  outline: none;
  border-color: var(--accent-light);
}

.testament-group h3 {
  margin: 0.5rem 0 0.35rem;
  font-size: 0.75rem;
  color: var(--accent-light);
  font-weight: 600;
}

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

.book-list li {
  margin: 0;
}

.book-btn {
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  padding: 0.35rem 0.5rem;
  border-radius: 6px;
  font-family: inherit;
  font-size: 0.88rem;
  cursor: pointer;
  color: var(--text);
  transition: background 0.12s;
}

.book-btn:hover {
  background: rgba(255, 255, 255, 0.6);
}

.book-btn.active {
  background: var(--bg-card);
  font-weight: 600;
  color: var(--accent);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

.badge {
  display: inline-block;
  background: var(--accent);
  color: white;
  font-size: 0.72rem;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  font-weight: 600;
  vertical-align: middle;
}

/* Scripture panel */
.scripture-panel {
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  min-height: 400px;
}

.scripture-header {
  padding: 1.25rem 1.5rem 0.75rem;
  border-bottom: 1px solid var(--border);
}

.scripture-header h2 {
  margin: 0 0 0.75rem;
  font-family: var(--font-serif);
  font-size: 1.5rem;
  color: var(--accent);
}

.chapter-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.chapter-btn {
  border: 1px solid var(--border);
  background: var(--bg);
  width: 2.2rem;
  height: 2.2rem;
  border-radius: 6px;
  font-family: inherit;
  font-size: 0.82rem;
  cursor: pointer;
  transition: all 0.12s;
}

.chapter-btn:hover {
  border-color: var(--accent-light);
  background: var(--highlight);
}

.chapter-btn.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.chapter-btn.has-notes::after {
  content: "";
  display: block;
  width: 4px;
  height: 4px;
  background: var(--highlight-border);
  border-radius: 50%;
  margin: 1px auto 0;
}

.chapter-btn.active.has-notes::after {
  background: #ffe082;
}

.scripture-content {
  padding: 1.25rem 1.5rem 2rem;
  font-family: var(--font-serif);
  font-size: 1.05rem;
  line-height: 1.85;
}

.placeholder {
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-size: 0.95rem;
  text-align: center;
  padding: 3rem 1rem;
}

.verse {
  margin-bottom: 0.5rem;
  padding: 0.15rem 0.35rem;
  border-radius: 4px;
  transition: background 0.12s;
}

.verse.has-note {
  background: var(--highlight);
  border-left: 3px solid var(--highlight-border);
  padding-left: 0.6rem;
}

.verse-num {
  font-size: 0.75rem;
  color: var(--accent-light);
  font-weight: 700;
  margin-right: 0.35rem;
  vertical-align: super;
  font-family: var(--font-sans);
}

.no-text-notice {
  background: var(--bg);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  text-align: center;
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-size: 0.92rem;
}

/* Notes list */
.notes-list {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.notes-list.compact .note-card {
  padding: 0.75rem;
}

.note-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  cursor: pointer;
  transition: box-shadow 0.15s, border-color 0.15s;
}

.note-card:hover {
  box-shadow: var(--shadow);
  border-color: var(--accent-light);
}

.note-card h3 {
  margin: 0 0 0.35rem;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--accent);
  line-height: 1.4;
}

.note-card .note-excerpt {
  margin: 0 0 0.5rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.note-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
}

.note-ref {
  font-size: 0.78rem;
  color: var(--accent-light);
  font-weight: 500;
}

.tag {
  display: inline-block;
  font-size: 0.72rem;
  padding: 0.12rem 0.45rem;
  border-radius: 999px;
  color: white;
  font-weight: 500;
}

.keyword-tag {
  background: var(--bg);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.note-date {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-left: auto;
}

.empty-notes {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.88rem;
  padding: 1.5rem 0.5rem;
}

/* Notes browser view */
.notes-browser {
  max-width: 800px;
  margin: 0 auto;
}

.notes-browser-header {
  margin-bottom: 1rem;
}

.notes-browser-header h2 {
  margin: 0 0 0.25rem;
  font-family: var(--font-serif);
  color: var(--accent);
}

.result-count {
  margin: 0;
  font-size: 0.88rem;
  color: var(--text-muted);
}

/* Modal */
.note-modal {
  border: none;
  padding: 0;
  border-radius: var(--radius);
  max-width: 560px;
  width: calc(100% - 2rem);
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.18);
}

.note-modal::backdrop {
  background: rgba(44, 36, 22, 0.45);
}

.modal-inner {
  padding: 1.5rem;
  position: relative;
}

.modal-close {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  border: none;
  background: var(--bg);
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  font-size: 1.25rem;
  cursor: pointer;
  color: var(--text-muted);
  line-height: 1;
}

.modal-close:hover {
  background: var(--border);
}

.modal-content h2 {
  margin: 0 2rem 0.75rem 0;
  font-family: var(--font-serif);
  font-size: 1.35rem;
  color: var(--accent);
}

.modal-content .note-body {
  font-size: 0.95rem;
  line-height: 1.75;
  margin-bottom: 1rem;
}

.modal-content .note-refs {
  margin-bottom: 0.75rem;
}

.modal-content .ref-link {
  display: inline-block;
  background: var(--highlight);
  color: var(--accent);
  padding: 0.25rem 0.6rem;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid var(--highlight-border);
  margin: 0.15rem 0.25rem 0.15rem 0;
  transition: background 0.12s;
}

.modal-content .ref-link:hover {
  background: #ffecb3;
}

/* Buttons */
.btn-primary,
.btn-secondary,
.btn-text,
.btn-danger {
  font-family: inherit;
  cursor: pointer;
  border-radius: 8px;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}

.btn-primary {
  border: none;
  background: var(--accent);
  color: #fff;
  padding: 0.45rem 0.9rem;
  font-size: 0.88rem;
  font-weight: 600;
  white-space: nowrap;
}

.btn-primary:hover {
  background: var(--accent-light);
}

.btn-secondary {
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  padding: 0.45rem 0.9rem;
  font-size: 0.88rem;
}

.btn-secondary:hover {
  border-color: var(--accent-light);
}

.btn-danger {
  border: 1px solid #c45c5c;
  background: transparent;
  color: #a33;
  padding: 0.4rem 0.75rem;
  font-size: 0.85rem;
}

.btn-danger:hover {
  background: #fdf0f0;
}

.btn-text {
  border: none;
  background: transparent;
  color: var(--accent);
  font-size: 1.25rem;
  line-height: 1;
  padding: 0.15rem 0.35rem;
  font-weight: 600;
}

.btn-text:hover {
  color: var(--accent-light);
}

.sidebar-notes-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.sidebar-notes-header .sidebar-title {
  margin: 0;
}

.notes-browser-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.modal-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

/* Note form */
.note-form-modal {
  max-width: 640px;
}

.form-title {
  margin: 0 2rem 1rem 0;
  font-family: var(--font-serif);
  font-size: 1.25rem;
  color: var(--accent);
}

.note-form {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.form-field.grow {
  flex: 1;
  min-width: 8rem;
}

.form-field input,
.form-field textarea,
.form-field select {
  font-family: inherit;
  font-size: 0.95rem;
  color: var(--text);
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
}

.form-field input:focus,
.form-field textarea:focus,
.form-field select:focus {
  outline: none;
  border-color: var(--accent-light);
  box-shadow: 0 0 0 3px rgba(92, 74, 50, 0.12);
}

.form-field textarea {
  resize: vertical;
  line-height: 1.6;
}

.form-fieldset {
  margin: 0;
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.form-fieldset legend {
  padding: 0 0.35rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.form-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
}

.form-row .form-field:not(.grow) {
  width: 4.5rem;
}

.form-checkboxes {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 0.85rem;
}

.form-checkboxes label {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.88rem;
  color: var(--text);
  cursor: pointer;
}

.inline-add {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem;
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px dashed var(--border);
}

.inline-add input[type="text"] {
  flex: 1 1 8rem;
  min-width: 7rem;
  font-family: inherit;
  font-size: 0.88rem;
  color: var(--text);
  padding: 0.4rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
}

.inline-add input[type="text"]:focus {
  outline: none;
  border-color: var(--accent-light);
}

.inline-add input[type="color"] {
  width: 2.2rem;
  height: 2rem;
  padding: 0.1rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-card);
  cursor: pointer;
}

.inline-add .btn-secondary {
  padding: 0.35rem 0.7rem;
  font-size: 0.82rem;
}

.form-error {
  margin: 0;
  color: #a33;
  font-size: 0.88rem;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 0.25rem;
}

.storage-hint {
  margin: 0.75rem 0 0;
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Responsive */
@media (max-width: 1024px) {
  #view-bible.active {
    grid-template-columns: 1fr;
  }

  .sidebar-books {
    position: static;
    max-height: none;
  }

  .sidebar-notes {
    position: static;
    max-height: none;
  }
}

@media (max-width: 600px) {
  .header-inner {
    flex-direction: column;
    align-items: flex-start;
  }

  .toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .search-bar {
    max-width: none;
    flex: 1 1 auto;
  }

  .filter-group + .filter-group {
    padding-left: 0;
    border-left: none;
    padding-top: 0.35rem;
    border-top: 1px solid var(--border);
  }

  .scripture-content {
    font-size: 1rem;
  }

  .notes-browser-header {
    flex-direction: column;
  }
}
