:root {
  --bg: #ece5db;
  --panel: rgba(250, 246, 240, 0.88);
  --panel-strong: rgba(252, 248, 243, 0.96);
  --text: #221d18;
  --muted: #6e6458;
  --border: rgba(34, 29, 24, 0.12);
  --accent: #8b5b2b;
  --accent-soft: rgba(139, 91, 43, 0.12);
  --reader: #fffdf8;
  --shadow: 0 16px 32px rgba(48, 34, 18, 0.09);
  --reader-shadow: 0 18px 36px rgba(48, 34, 18, 0.08);
}

body.theme-dark {
  --bg: #151311;
  --panel: rgba(28, 25, 22, 0.92);
  --panel-strong: rgba(23, 20, 18, 0.97);
  --text: #f2eade;
  --muted: #b5a899;
  --border: rgba(255, 255, 255, 0.08);
  --accent: #ddb27f;
  --accent-soft: rgba(221, 178, 127, 0.11);
  --reader: #191714;
  --shadow: 0 16px 32px rgba(0, 0, 0, 0.28);
  --reader-shadow: 0 18px 36px rgba(0, 0, 0, 0.34);
}

body.theme-sepia {
  --bg: #e0d0b7;
  --panel: rgba(247, 237, 220, 0.92);
  --panel-strong: rgba(245, 234, 214, 0.97);
  --text: #2b2218;
  --muted: #6d5b46;
  --border: rgba(43, 34, 24, 0.12);
  --accent: #8a4f1c;
  --accent-soft: rgba(138, 79, 28, 0.11);
  --reader: #f6edda;
  --shadow: 0 16px 32px rgba(69, 47, 18, 0.11);
  --reader-shadow: 0 18px 36px rgba(69, 47, 18, 0.1);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Manrope", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top center, rgba(255, 255, 255, 0.4), transparent 28%),
    linear-gradient(180deg, color-mix(in srgb, var(--bg) 88%, white 12%), var(--bg));
}

button,
input,
textarea {
  font: inherit;
}

h1,
h2,
h3 {
  margin: 0;
  font-family: "Fraunces", serif;
  font-weight: 600;
}

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

.login-card,
.panel-card,
.reader-toolbar {
  border: 1px solid var(--border);
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.login-card {
  width: min(420px, 100%);
  padding: 28px;
  border-radius: 16px;
  display: grid;
  gap: 14px;
}

.field {
  display: grid;
  gap: 6px;
}

.field input,
.comment-dialog textarea,
.reply-form input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 13px;
  background: rgba(255, 255, 255, 0.42);
  color: var(--text);
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 292px;
  gap: 12px;
  min-height: 100vh;
  height: 100vh;
  padding: 12px;
}

.app-hidden {
  display: none;
}

.left-panel,
.right-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
  overflow: auto;
}

.left-panel-modal {
  width: min(360px, calc(100vw - 24px));
  max-height: calc(100vh - 24px);
  border: none;
  padding: 0;
  background: transparent;
}

.left-panel-modal::backdrop {
  background: rgba(0, 0, 0, 0.28);
}

.left-panel-modal .left-panel {
  width: 100%;
  max-height: calc(100vh - 24px);
  padding: 12px;
  overflow: auto;
}

.panel-toggle-btn {
  width: 34px;
  height: 34px;
  display: inline-grid;
  align-content: center;
  gap: 4px;
  padding: 0 8px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel);
  color: var(--text);
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease;
}

.panel-toggle-btn:hover {
  transform: translateY(-1px);
}

.panel-toggle-btn span {
  display: block;
  height: 1.5px;
  border-radius: 999px;
  background: currentColor;
  transition: transform 160ms ease, opacity 160ms ease;
}

.panel-toggle-btn span:nth-child(1) {
  transform: translateY(5.5px) rotate(45deg);
}

.panel-toggle-btn span:nth-child(2) {
  opacity: 0;
}

.panel-toggle-btn span:nth-child(3) {
  transform: translateY(-5.5px) rotate(-45deg);
}

.app-shell.left-collapsed .panel-toggle-btn span:nth-child(1) {
  transform: none;
}

.app-shell.left-collapsed .panel-toggle-btn span:nth-child(2) {
  opacity: 1;
}

.app-shell.left-collapsed .panel-toggle-btn span:nth-child(3) {
  transform: none;
}

.center-stage {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 10px;
  height: 100%;
  min-height: 0;
}

.panel-card {
  border-radius: 14px;
  padding: 12px;
}

.card-header-stack {
  display: grid;
  gap: 10px;
  margin-bottom: 10px;
}

.section-title,
.timeline-header,
.annotation-head,
.timeline-head,
.reply-item,
.progress-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.meta-label,
.annotation-meta,
.timeline-meta,
.error-text {
  margin: 0;
  color: var(--muted);
  font-size: 0.77rem;
}

.account-summary,
.book-meta,
.progress-track {
  display: grid;
  gap: 6px;
}

.book-list,
.bookmark-list,
.annotation-list {
  display: grid;
  gap: 8px;
}

.book-item,
.bookmark-item,
.annotation-item,
.timeline-item {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.3);
  padding: 10px;
}

.book-item.active {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, var(--panel));
}

.bookmark-save-btn {
  width: 100%;
  justify-self: stretch;
  padding: 9px 12px;
}

.book-item button,
.reader-chip,
.theme-btn,
.ghost-btn,
.solid-btn,
.nav-btn,
.reaction-badge,
.selection-actions button {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.34);
  color: var(--text);
  cursor: pointer;
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease;
}

.theme-btn,
.ghost-btn,
.solid-btn,
.nav-btn,
.selection-actions button,
.book-item button {
  padding: 7px 10px;
}

.theme-btn.active {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 14%, var(--panel));
}

.solid-btn {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.ghost-btn:hover,
.solid-btn:hover,
.nav-btn:hover,
.theme-btn:hover,
.selection-actions button:hover,
.book-item button:hover,
.reaction-badge:hover {
  transform: translateY(-1px);
}

.theme-switcher {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.range-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
}

.range-row input[type="range"] {
  grid-column: 1 / -1;
  width: 100%;
}

.progress-bar {
  height: 7px;
  border-radius: 999px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.42);
}

.progress-fill {
  height: 100%;
  border-radius: 999px;
}

.timeline {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.sidebar-timeline {
  display: grid;
  gap: 6px;
  overflow: auto;
}

.sidebar-timeline .timeline-item {
  width: 100%;
}

.timeline-item {
  min-height: 0;
  width: calc(25% - 5px);
  padding: 7px 8px;
  font-size: 0.8rem;
}

.timeline-head {
  align-items: flex-start;
}

.timeline-item .timeline-meta {
  font-size: 0.68rem;
}

.status-pill {
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 10px;
  background: rgba(255, 255, 255, 0.32);
  color: var(--muted);
  white-space: nowrap;
  font-size: 0.8rem;
}

.reader-toolbar {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 8px;
  border-radius: 12px;
  padding: 8px;
  min-height: 0;
  position: relative;
  z-index: 30;
}

.toolbar-actions {
  display: flex;
  justify-content: center;
  gap: 8px;
  align-items: center;
  min-width: 0;
}

.nav-btn {
  min-width: 38px;
  font-size: 1.15rem;
}

.reader-frame {
  position: relative;
  min-height: 0;
  height: 100%;
  align-self: stretch;
  border-radius: 14px;
  border: 1px solid var(--border);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.22), transparent),
    var(--reader);
  box-shadow: var(--reader-shadow);
  overflow: hidden;
}

.reader,
.empty-reader {
  min-height: 0;
  height: 100%;
}

.reader {
  width: 100%;
  padding: 0;
  overflow: hidden;
  height: 100%;
}

.reader-page {
  width: 100%;
  height: 100%;
  min-height: 0;
  overflow: hidden;
  padding: 24px 28px;
  font-family: Georgia, serif;
  box-sizing: border-box;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.reader-measure {
  position: fixed;
  left: -10000px;
  top: 0;
  visibility: hidden;
  pointer-events: none;
  z-index: -1;
}

.empty-reader {
  display: grid;
  place-items: center;
  color: var(--muted);
}

.hidden {
  display: none;
}

.annotation-item blockquote {
  margin: 0 0 12px;
  padding-left: 12px;
  border-left: 3px solid var(--border);
  color: var(--muted);
}

.reaction-inline {
  margin: 0;
}

.page-block {
  margin-bottom: 0.95em;
  border-radius: 6px;
}

.page-block img {
  max-height: 38vh;
  width: auto;
  max-width: 100%;
  display: block;
  object-fit: contain;
}

.page-block figure {
  margin: 0;
  max-height: 100%;
  overflow: hidden;
}

.page-block > *:first-child {
  margin-top: 0;
}

.page-block > *:last-child {
  margin-bottom: 0;
}

.bookmark-item {
  display: grid;
  gap: 10px;
}

.bookmark-body {
  display: grid;
  gap: 6px;
}

.bookmark-actions {
  display: flex;
  gap: 8px;
}

.bookmark-actions .ghost-btn {
  flex: 1 1 0;
  padding: 8px 10px;
}

.annotation-entry + .annotation-entry {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.annotation-item-active {
  transition: background 160ms ease, border-color 160ms ease, box-shadow 160ms ease;
}

.inline-highlight-a {
  background: rgba(201, 111, 26, 0.26);
}

.inline-highlight-b {
  background: rgba(31, 111, 120, 0.26);
}

.inline-comment-a {
  background: rgba(201, 111, 26, 0.12);
  box-shadow: inset 0 -2px 0 rgba(201, 111, 26, 0.72);
}

.inline-comment-b {
  background: rgba(31, 111, 120, 0.12);
  box-shadow: inset 0 -2px 0 rgba(31, 111, 120, 0.72);
}

.inline-reaction-a {
  background: rgba(201, 111, 26, 0.08);
  box-shadow: inset 0 -1px 0 rgba(201, 111, 26, 0.72), inset 0 1px 0 rgba(201, 111, 26, 0.3);
}

.inline-reaction-b {
  background: rgba(31, 111, 120, 0.08);
  box-shadow: inset 0 -1px 0 rgba(31, 111, 120, 0.72), inset 0 1px 0 rgba(31, 111, 120, 0.3);
}

.reader mark[data-focus-paragraph] {
  cursor: pointer;
  color: inherit;
  -webkit-text-fill-color: currentColor;
  text-decoration-color: currentColor;
}

.reaction-row,
.reply-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.reply-form {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.comment-dialog {
  width: min(520px, calc(100vw - 32px));
  border: none;
  border-radius: 14px;
  padding: 0;
  background: var(--panel-strong);
  color: var(--text);
  box-shadow: var(--shadow);
}

body.theme-dark .comment-dialog,
body.theme-dark .comment-dialog form,
body.theme-dark .selection-dialog,
body.theme-dark .selection-dialog-head,
body.theme-dark .selection-panel {
  color: var(--text);
}

body.theme-dark .comment-dialog h1,
body.theme-dark .comment-dialog h2,
body.theme-dark .comment-dialog h3,
body.theme-dark .comment-dialog p,
body.theme-dark .comment-dialog span,
body.theme-dark .comment-dialog label,
body.theme-dark .comment-dialog div,
body.theme-dark .comment-dialog strong,
body.theme-dark .comment-dialog blockquote,
body.theme-dark .comment-dialog .annotation-meta,
body.theme-dark .comment-dialog .selection-excerpt,
body.theme-dark .selection-mode-btn,
body.theme-dark .emoji-grid button {
  color: var(--text);
}

body.theme-dark .panel-card h1,
body.theme-dark .panel-card h2,
body.theme-dark .panel-card h3,
body.theme-dark .login-card h1,
body.theme-dark .login-card h2,
body.theme-dark .login-card h3,
body.theme-dark .section-title,
body.theme-dark .section-title h2,
body.theme-dark .card-header-stack,
body.theme-dark .account-summary,
body.theme-dark .book-item,
body.theme-dark .bookmark-item,
body.theme-dark .annotation-item {
  color: var(--text);
}

body.theme-dark .comment-dialog textarea,
body.theme-dark .reply-form input,
body.theme-dark .field input {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  border-color: rgba(255, 255, 255, 0.14);
}

body.theme-dark .comment-dialog textarea::placeholder,
body.theme-dark .reply-form input::placeholder,
body.theme-dark .field input::placeholder {
  color: rgba(242, 234, 222, 0.58);
}

body.theme-dark .selection-mode-btn,
body.theme-dark .ghost-btn,
body.theme-dark .nav-btn,
body.theme-dark .reaction-badge,
body.theme-dark .status-pill,
body.theme-dark .panel-toggle-btn {
  color: var(--text);
  background: rgba(255, 255, 255, 0.07);
  border-color: rgba(255, 255, 255, 0.14);
}

body.theme-dark .solid-btn {
  color: #181411;
}

.comment-dialog::backdrop {
  background: rgba(0, 0, 0, 0.35);
}

.comment-dialog form {
  padding: 20px;
}

.selection-dialog {
  width: min(560px, calc(100vw - 32px));
}

.selection-dialog-head {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
}

.selection-mode-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}

.selection-mode-btn {
  padding: 10px 12px;
}

.selection-mode-btn.active {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 14%, var(--panel));
}

.selection-panel {
  margin-bottom: 14px;
}

.emoji-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
}

.emoji-grid button {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.38);
  color: var(--text);
  cursor: pointer;
  padding: 10px 8px;
  font-size: 1.15rem;
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease;
}

.emoji-grid button.active {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 14%, var(--panel));
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 14px;
}

.empty-state {
  color: var(--muted);
}

@media (max-width: 1180px) {
  .app-shell {
    grid-template-columns: minmax(0, 1fr) 292px;
  }
}

@media (max-width: 900px) {
  .reader-toolbar {
    grid-template-columns: auto 1fr auto;
  }

  .toolbar-actions {
    overflow-x: auto;
    justify-content: flex-start;
  }

  .timeline-item {
    width: calc(50% - 3px);
  }
}

@media (max-width: 640px) {
  .app-shell {
    grid-template-columns: 1fr;
    padding: 8px;
    gap: 8px;
  }

  .right-panel {
    position: fixed;
    top: 10px;
    right: 10px;
    bottom: 10px;
    width: min(360px, calc(100vw - 36px));
    transform: translateX(calc(100% + 24px));
    transition: transform 200ms ease;
    z-index: 20;
  }

  .right-panel.open {
    transform: translateX(0);
  }

  .panel-card {
    padding: 10px;
  }

  .range-row {
    grid-template-columns: 1fr;
  }

  .timeline-item {
    width: 100%;
  }
}
