:root {
  --bg: #f4f1eb;
  --panel: #fffdf8;
  --panel-strong: #eee8dc;
  --ink: #25221d;
  --muted: #716b61;
  --line: #d9d0c1;
  --accent: #2f675f;
  --accent-dark: #234e49;
  --gold: #a8762e;
  --danger: #9d3a34;
  --chip: #e2f3ee;
  --shadow: 0 18px 48px rgba(37, 34, 29, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  color: var(--ink);
  background: var(--bg);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

[hidden] {
  display: none !important;
}

.auth-screen {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
}

.auth-card {
  display: flex;
  width: min(460px, 100%);
  flex-direction: column;
  gap: 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 28px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.auth-card h1,
.brand h1,
.empty-state h2,
.topbar h2,
.dialog-card h2 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  line-height: 1.05;
  letter-spacing: 0;
}

.auth-card h1 {
  font-size: 42px;
}

.auth-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.app-shell {
  display: grid;
  grid-template-columns: 112px minmax(0, 1fr);
  height: 100vh;
  overflow: hidden;
}

.library-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
  position: relative;
  padding: 10px;
  border-right: 1px solid var(--line);
  background: var(--panel);
}

.brand,
.topbar,
.pane-header,
.guide-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.brand h1 {
  font-size: 18px;
}

.eyebrow {
  margin: 0 0 7px;
  color: var(--gold);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.primary-action,
.secondary-action,
.danger-action,
.icon-button {
  min-height: 30px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 0 8px;
  font-weight: 750;
  font-size: 12px;
}

.primary-action {
  color: #fff;
  background: var(--accent);
}

.primary-action:hover {
  background: var(--accent-dark);
}

.secondary-action {
  color: var(--ink);
  border-color: var(--line);
  background: var(--panel);
}

.danger-action {
  color: #fff;
  background: var(--danger);
}

.icon-button {
  width: 40px;
  padding: 0;
  border-color: var(--line);
  background: var(--panel-strong);
}

.field-label {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 750;
}

.text-input,
.select-input,
.file-input,
.large-textarea,
.template-box {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #fff;
  outline: none;
}

.text-input,
.select-input,
.file-input {
  min-height: 30px;
  padding: 0 8px;
  font-size: 12px;
}

.file-input {
  padding-top: 9px;
}

.select-input {
  width: auto;
  min-width: 118px;
}

.text-input:focus,
.select-input:focus,
.file-input:focus,
.large-textarea:focus,
.template-box:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(47, 103, 95, 0.14);
}

.library-list,
.mini-list,
.terms-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow: auto;
  min-height: 0;
}

.library-list {
  flex: 1;
  padding-bottom: 28px;
}

.library-item,
.mini-item,
.term-item,
.result-item {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px;
  text-align: left;
  color: var(--ink);
  background: #fff;
}

.library-item.active,
.library-item:hover,
.mini-item.active,
.mini-item:hover,
.term-item:hover,
.result-item:hover {
  border-color: var(--accent);
  background: #f2faf7;
}

.library-item strong,
.library-item span,
.mini-item span,
.term-item strong,
.term-item span,
.result-item strong,
.result-item span {
  display: block;
}

.library-item span,
.mini-item span,
.term-item span,
.result-item span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 11px;
}

.library-item strong {
  font-size: 12px;
  line-height: 1.2;
}

.logout-link {
  position: absolute;
  left: 10px;
  bottom: 8px;
  align-self: flex-start;
  border: 0;
  padding: 4px 0;
  color: var(--muted);
  background: transparent;
  font-size: 12px;
  text-decoration: underline;
}

.search-input-wrap {
  position: relative;
}

.search-input-wrap .text-input {
  padding-left: 26px;
}

.search-placeholder-icon {
  position: absolute;
  left: 9px;
  top: 50%;
  width: 10px;
  height: 10px;
  transform: translateY(-56%);
  border: 1.6px solid #aaa39a;
  border-radius: 50%;
  pointer-events: none;
}

.search-placeholder-icon::after {
  content: "";
  position: absolute;
  right: -5px;
  bottom: -4px;
  width: 6px;
  height: 1.6px;
  transform: rotate(45deg);
  border-radius: 999px;
  background: #aaa39a;
}

.workspace {
  min-width: 0;
  height: 100vh;
  overflow: hidden;
  padding: 10px;
}

.empty-state {
  display: grid;
  min-height: calc(100vh - 48px);
  max-width: 760px;
  margin: 0 auto;
  place-content: center;
  text-align: center;
}

.empty-state h2 {
  font-size: clamp(36px, 5vw, 68px);
}

.empty-state p:last-child {
  color: var(--muted);
  font-size: 18px;
  line-height: 1.6;
}

.editor-view {
  display: flex;
  flex-direction: column;
  gap: 10px;
  height: calc(100vh - 20px);
  min-height: 0;
  overflow: hidden;
}

.topbar {
  align-items: center;
  min-height: 72px;
  max-height: 90px;
  overflow: hidden;
}

.series-heading {
  min-width: 260px;
  max-width: 420px;
}

.inline-title-row,
.book-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.inline-title-input,
.book-title-input {
  width: min(280px, 100%);
  min-width: 0;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 3px 6px;
  color: var(--ink);
  background: transparent;
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 700;
  line-height: 1.1;
  outline: none;
}

.inline-title-input {
  font-size: 24px;
}

.book-title-input {
  width: min(240px, 100%);
  font-size: 15px;
}

.inline-title-input:focus,
.book-title-input:focus {
  border-color: var(--line);
  background: #fff;
}

.compact-action {
  min-height: 28px;
  padding: 0 7px;
  font-size: 11px;
}

.meta-line,
.count-pill {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 11px;
}

.count-pill {
  margin: 0;
  white-space: nowrap;
}

.topbar-actions,
.pane-actions,
.dialog-actions,
.search-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.topbar .search-row,
.topbar .topbar-actions {
  flex-wrap: nowrap;
  overflow-x: auto;
  padding-bottom: 1px;
}

.topbar .search-row {
  flex: 1 1 320px;
  min-width: 280px;
}

.topbar .topbar-actions {
  flex: 0 1 auto;
}

.search-row .text-input {
  flex: 1 1 260px;
}

.split-workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 10px;
  min-height: 0;
  flex: 1;
  overflow: hidden;
}

.split-workspace.split-open {
  grid-template-columns: minmax(0, 1fr) minmax(0, 0.82fr);
}

.work-pane {
  display: flex;
  min-width: 0;
  min-height: 0;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.pane-header {
  flex: 0 0 auto;
  padding: 10px;
  border-bottom: 1px solid var(--line);
}

.pane-header h3 {
  margin: 0;
  font-size: 18px;
}

.pane-body {
  min-height: 0;
  flex: 1;
  overflow: hidden;
}

.manuscript-grid,
.canon-grid {
  display: grid;
  grid-template-columns: 190px minmax(0, 1fr);
}

.mini-list {
  height: 100%;
  max-height: 100%;
  padding: 10px;
  border-right: 1px solid var(--line);
  background: #fbf8f1;
}

.mini-item {
  border-color: transparent;
  background: transparent;
  line-height: 1.25;
}

.editor-stack {
  display: flex;
  min-width: 0;
  min-height: 0;
  flex-direction: column;
  gap: 9px;
  overflow: auto;
  padding: 14px 18px;
}

.large-textarea {
  min-height: 360px;
  padding: 13px;
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 14px;
  line-height: 1.55;
}

.chapter-textarea,
.canon-textarea {
  min-height: 520px;
}

.markdown-body {
  overflow: visible;
  color: var(--ink);
  line-height: 1.7;
  font-size: 16px;
}

.edit-panel {
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3 {
  font-family: Georgia, "Times New Roman", serif;
  line-height: 1.15;
}

.markdown-body blockquote {
  margin: 16px 0;
  padding-left: 16px;
  border-left: 4px solid var(--accent);
  color: #4e4942;
}

.markdown-body code,
.guide-section code {
  border-radius: 5px;
  padding: 2px 5px;
  background: var(--panel-strong);
}

.markdown-body mark,
.result-item mark {
  border-radius: 4px;
  padding: 1px 3px;
  background: #ffe08a;
}

.canon-chip {
  display: inline;
  border: 0;
  border-bottom: 1px dotted var(--accent);
  border-radius: 4px;
  padding: 0 2px;
  color: var(--accent-dark);
  background: var(--chip);
  font-weight: 650;
}

.search-results {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 260px;
  overflow: auto;
  border-bottom: 1px solid var(--line);
  padding-bottom: 10px;
}

.result-item p {
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.45;
}

dialog {
  width: min(900px, calc(100vw - 32px));
  border: 0;
  border-radius: 10px;
  padding: 0;
  background: transparent;
}

dialog::backdrop {
  background: rgba(37, 34, 29, 0.48);
}

.dialog-card {
  display: flex;
  max-height: calc(100vh - 36px);
  flex-direction: column;
  gap: 14px;
  overflow: auto;
  border-radius: 10px;
  padding: 22px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.dialog-card h2 {
  font-size: 32px;
}

.dialog-card h3 {
  margin: 0 0 10px;
  font-size: 16px;
}

.dialog-copy {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.dialog-actions {
  justify-content: flex-end;
}

.guide-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.guide-section,
.term-form {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fff;
}

.guide-section ul {
  margin: 0;
  padding-left: 20px;
}

.guide-section li {
  color: var(--muted);
  line-height: 1.5;
}

.template-box {
  min-height: 320px;
  padding: 13px;
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  line-height: 1.55;
}

.term-form {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  align-items: end;
}

.term-form .toggle {
  min-height: 42px;
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-weight: 750;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  transform: translateY(20px);
  opacity: 0;
  max-width: 360px;
  border-radius: 8px;
  padding: 12px 14px;
  color: #fff;
  background: var(--ink);
  box-shadow: var(--shadow);
  transition: 180ms ease;
  pointer-events: none;
}

.toast button {
  margin-left: 10px;
  border: 1px solid rgba(255, 255, 255, 0.36);
  border-radius: 6px;
  padding: 5px 9px;
  color: #fff;
  background: transparent;
  font-weight: 750;
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
  pointer-events: auto;
}

@media (max-width: 1180px) {
  .split-workspace,
  .split-workspace.split-open {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 900px) {
  .app-shell,
  .manuscript-grid,
  .canon-grid,
  .guide-grid,
  .term-form {
    grid-template-columns: 1fr;
  }

  .app-shell {
    height: 100vh;
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr);
  }

  .library-panel {
    max-height: 160px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .mini-list {
    max-height: 220px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .topbar,
  .pane-header {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar {
    max-height: none;
  }

  .topbar .search-row,
  .topbar .topbar-actions {
    flex-wrap: wrap;
  }
}

@media (max-width: 620px) {
  .workspace,
  .library-panel {
    padding: 16px;
  }

  .topbar-actions > *,
  .pane-actions > *,
  .search-row > * {
    flex: 1 1 100%;
  }

  .work-pane {
    min-height: 0;
  }
}
