:root {
  color-scheme: light;
  --bg: #f4f1ea;
  --surface: #fffdf8;
  --surface-2: #ebe5d8;
  --line: #d8d0c2;
  --ink: #24211d;
  --muted: #736b5f;
  --accent: #286b66;
  --accent-soft: rgba(40, 107, 102, 0.15);
  --warm: #b45b42;
  --warm-soft: rgba(180, 91, 66, 0.18);
  --shadow: 0 18px 44px rgba(36, 33, 29, 0.12);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  margin: 0;
  overflow: hidden;
}

button,
input,
textarea {
  font: inherit;
}

button {
  background: var(--accent);
  border: 0;
  border-radius: 8px;
  color: #fff;
  cursor: pointer;
  font-weight: 800;
  min-height: 40px;
  padding: 0 14px;
}

button:disabled {
  cursor: wait;
  opacity: 0.65;
}

button.secondary {
  background: var(--surface-2);
  color: var(--ink);
}

button.danger {
  background: #ead8d2;
  color: #9b341e;
}

button.ghost {
  background: transparent;
  color: var(--accent);
  min-height: 32px;
  padding: 0 4px;
}

button.full {
  width: 100%;
}

a {
  color: var(--accent);
  font-weight: 800;
  text-decoration: none;
}

h1,
h2,
h3,
p {
  margin: 0;
}

.hidden {
  display: none !important;
}

.login-view {
  align-items: center;
  display: flex;
  height: 100vh;
  justify-content: center;
  padding: 24px;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 28px;
  width: min(420px, 100%);
}

.brand {
  align-items: center;
  display: flex;
  gap: 12px;
  margin-bottom: 22px;
}

.brand h1 {
  font-size: 28px;
  line-height: 1;
}

.brand p,
.hint,
.pane-header p,
.profile-strip small,
.book-main small,
.reader-topbar p,
.notes-pane header p,
.soft-empty,
.note-head span {
  color: var(--muted);
}

.mark {
  align-items: center;
  background: var(--ink);
  border-radius: 8px;
  color: #fff;
  display: flex;
  flex: 0 0 48px;
  font-weight: 900;
  height: 48px;
  justify-content: center;
  letter-spacing: 0;
}

.field {
  display: grid;
  gap: 7px;
  margin-top: 12px;
}

.field label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

input,
textarea {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  min-width: 0;
  padding: 10px 11px;
  width: 100%;
}

textarea {
  line-height: 1.45;
  resize: vertical;
}

.actions {
  display: flex;
  gap: 10px;
  margin-top: 16px;
}

.workspace {
  display: grid;
  grid-template-columns: 330px minmax(420px, 1fr) 380px;
  height: 100vh;
  overflow: hidden;
}

.mobile-topbar,
.mobile-backdrop {
  display: none;
}

.workspace.library-collapsed {
  grid-template-columns: minmax(420px, 1fr) 380px;
}

.workspace.notes-collapsed {
  grid-template-columns: 330px minmax(420px, 1fr);
}

.workspace.library-collapsed.notes-collapsed {
  grid-template-columns: minmax(420px, 1fr);
}

.pane,
.reader-pane {
  height: 100vh;
  min-height: 0;
}

.pane {
  background: var(--surface);
  border-color: var(--line);
  overflow-y: auto;
  padding: 18px;
}

.library-pane {
  border-right: 1px solid var(--line);
}

.notes-pane {
  border-left: 1px solid var(--line);
}

.reader-pane {
  display: grid;
  grid-template-rows: auto 1fr;
  overflow-y: auto;
  padding: 18px 22px;
  position: relative;
}

.pane-header,
.reader-topbar,
.profile-strip,
.note-head {
  align-items: flex-start;
  display: flex;
  gap: 12px;
  justify-content: space-between;
}

.pane-header,
.reader-topbar {
  margin-bottom: 14px;
}

.pane-header h2,
.reader-topbar h2 {
  font-size: 20px;
  line-height: 1.2;
}

.icon-button {
  align-items: center;
  background: var(--surface-2);
  color: var(--ink);
  display: flex;
  font-size: 24px;
  height: 36px;
  justify-content: center;
  min-height: 36px;
  padding: 0;
  width: 36px;
}

.rail-button {
  background: var(--ink);
  border-radius: 0 8px 8px 0;
  box-shadow: var(--shadow);
  height: 72px;
  left: 0;
  min-height: 0;
  padding: 0 10px;
  position: fixed;
  top: 50%;
  transform: translateY(-50%);
  writing-mode: vertical-rl;
  z-index: 5;
}

.rail-button.right {
  border-radius: 8px 0 0 8px;
  left: auto;
  right: 0;
}

.profile-strip {
  background: var(--surface-2);
  border-radius: 8px;
  margin-bottom: 14px;
  padding: 12px;
}

.profile-strip span {
  display: block;
  font-size: 20px;
  font-weight: 900;
}

.profile-strip small {
  display: block;
  margin-top: 2px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-bottom: 14px;
  padding: 14px;
}

.panel.compact h3 {
  font-size: 16px;
  margin-bottom: 10px;
}

.book-list,
.note-list {
  display: grid;
  gap: 12px;
}

.book-card,
.note-card,
.soft-empty,
.empty-state,
.epub-notice {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.book-card.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.book-main {
  align-items: flex-start;
  background: transparent;
  color: var(--ink);
  display: grid;
  gap: 7px;
  height: auto;
  justify-items: start;
  padding: 14px;
  text-align: left;
  width: 100%;
}

.book-main strong {
  font-size: 17px;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.book-kind,
.shared-label,
.note-anchor,
.eyebrow {
  color: var(--warm);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

.book-actions {
  align-items: center;
  border-top: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 14px 14px;
}

.reader-actions {
  align-items: center;
  display: flex;
  gap: 10px;
}

.icon-control {
  font-size: 16px;
  min-width: 42px;
  padding: 0 10px;
}

.jump-form,
.reader-jump-form {
  align-items: center;
  display: flex;
  gap: 8px;
}

.jump-form input,
.reader-jump-form input {
  height: 40px;
  max-width: 80px;
  text-align: center;
}

.file-link {
  align-items: center;
  background: var(--surface-2);
  border-radius: 8px;
  color: var(--ink);
  display: flex;
  min-height: 40px;
  padding: 0 14px;
}

.empty-state {
  align-items: center;
  align-self: stretch;
  display: flex;
  flex-direction: column;
  gap: 10px;
  justify-content: center;
  min-height: 520px;
  padding: 24px;
  text-align: center;
}

.epub-notice {
  align-self: stretch;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  min-height: calc(100vh - 110px);
  overflow: hidden;
}

.epub-toolbar {
  align-items: center;
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  padding: 10px;
}

.epub-reader {
  height: calc(100vh - 160px);
  overflow-y: auto;
  padding: 28px;
  width: min(920px, 100%);
  margin: 0 auto;
}

.epub-chapter {
  color: #24211d;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 18px;
  line-height: 1.75;
  margin: 0 auto;
  max-width: 760px;
}

.epub-chapter img,
.epub-chapter svg,
.epub-chapter video,
.epub-chapter audio {
  display: none;
}

.epub-chapter h1,
.epub-chapter h2,
.epub-chapter h3 {
  line-height: 1.25;
  margin: 1.2em 0 0.6em;
}

.epub-chapter p {
  margin: 0 0 1em;
}

.epub-count {
  color: var(--muted);
  font-family: Inter, ui-sans-serif, system-ui, sans-serif;
  font-size: 13px;
  margin-bottom: 18px;
}

.epub-highlight {
  border-radius: 3px;
  box-shadow: 0 0 0 1px rgba(36, 33, 29, 0.1) inset;
  cursor: pointer;
}

.epub-highlight.user-a {
  background: rgba(70, 240, 220, 0.34);
}

.epub-highlight.user-b {
  background: rgba(255, 179, 92, 0.36);
}

.epub-highlight.draft {
  background: rgba(255, 241, 95, 0.52);
  outline: 2px solid rgba(36, 33, 29, 0.2);
}

.epub-highlight.active {
  outline: 2px solid rgba(36, 33, 29, 0.34);
}

.pdf-wrap {
  align-self: stretch;
  min-height: calc(100vh - 110px);
}

.pdf-toolbar {
  align-items: center;
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-bottom: 12px;
}

.pdf-reader {
  display: grid;
  justify-items: center;
  min-height: calc(100vh - 170px);
  overflow: auto;
  padding: 8px 0 28px;
}

.pdf-loading {
  color: var(--muted);
  padding: 48px;
}

.pdf-page {
  background: #fff;
  box-shadow: var(--shadow);
  position: relative;
}

.pdf-page canvas {
  display: block;
  position: relative;
  z-index: 1;
}

.text-layer,
.highlight-layer {
  inset: 0;
  position: absolute;
}

.text-layer {
  color: transparent;
  overflow: hidden;
  user-select: text;
  z-index: 2;
}

.text-layer span {
  cursor: text;
  position: absolute;
  transform-origin: 0 0;
  white-space: pre;
}

.highlight-layer {
  pointer-events: none;
  z-index: 3;
}

.highlight {
  appearance: none;
  border: 0;
  border-radius: 3px;
  box-shadow: 0 0 0 1px rgba(36, 33, 29, 0.12) inset;
  cursor: pointer;
  opacity: 0.34;
  pointer-events: auto;
  position: absolute;
  z-index: 1;
}

.highlight.active {
  opacity: 0.48;
  outline: 2px solid rgba(36, 33, 29, 0.34);
}

.highlight.draft {
  background: #fff15f;
  opacity: 0.42;
  outline: 2px solid rgba(36, 33, 29, 0.2);
}

.highlight.user-a {
  background: #46f0dc;
}

.highlight.user-b {
  background: #ffb35c;
}

.inline-note-box {
  background: var(--ink);
  border-radius: 8px;
  box-shadow: var(--shadow);
  color: #fff;
  display: grid;
  gap: 8px;
  padding: 10px;
  position: fixed;
  width: 288px;
  z-index: 20;
}

.inline-note-box.user-a {
  border-top: 4px solid #5fc7ba;
}

.inline-note-box.user-b {
  border-top: 4px solid #f39a6b;
}

.inline-note-author {
  font-weight: 900;
}

.inline-note-box textarea {
  border: 0;
  min-height: 76px;
}

.inline-note-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.inline-note-actions button {
  min-height: 34px;
}

.note-card {
  cursor: pointer;
  padding: 14px;
  position: relative;
}

.note-card.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.note-card.user-b.active {
  border-color: var(--warm);
  box-shadow: 0 0 0 3px var(--warm-soft);
}

.note-author-dot {
  border-radius: 999px;
  display: inline-block;
  height: 10px;
  margin-right: 7px;
  width: 10px;
}

.note-author-dot.user-a {
  background: #28998e;
}

.note-author-dot.user-b {
  background: #d86c42;
}

blockquote {
  border-left: 3px solid var(--accent);
  color: var(--muted);
  margin: 10px 0;
  padding-left: 10px;
}

.note-card p {
  line-height: 1.55;
  margin-top: 12px;
  overflow-wrap: anywhere;
}

.note-delete {
  background: transparent;
  color: #9b341e;
  font-size: 12px;
  min-height: 26px;
  padding: 0;
  position: absolute;
  right: 14px;
  top: 38px;
}

.comment-button {
  background: var(--surface-2);
  color: var(--ink);
  font-size: 12px;
  margin-top: 12px;
  min-height: 30px;
  padding: 0 10px;
}

.comment-list {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.comment-item {
  background: #f7f2e8;
  border-radius: 8px;
  padding: 9px;
}

.comment-item div {
  align-items: center;
  display: flex;
  gap: 8px;
  justify-content: space-between;
}

.comment-item span {
  color: var(--muted);
  font-size: 11px;
}

.comment-item p {
  font-size: 13px;
  margin-top: 6px;
}

.comment-delete {
  background: transparent;
  color: #9b341e;
  font-size: 12px;
  margin-top: 4px;
  min-height: 22px;
  padding: 0;
}

.comment-form {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.comment-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.comment-actions button {
  min-height: 32px;
}

.soft-empty {
  color: var(--muted);
  padding: 18px;
}

.toast {
  background: var(--ink);
  border-radius: 8px;
  bottom: 22px;
  box-shadow: var(--shadow);
  color: #fff;
  left: 50%;
  max-width: min(560px, calc(100vw - 32px));
  padding: 12px 16px;
  position: fixed;
  transform: translateX(-50%);
  z-index: 30;
}

.note-popover {
  background: rgba(255, 253, 248, 0.96);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  color: var(--ink);
  max-width: min(320px, calc(100vw - 24px));
  padding: 10px 12px;
  pointer-events: auto;
  position: fixed;
  z-index: 40;
}

.note-popover::before {
  border-radius: 999px;
  content: "";
  display: inline-block;
  height: 9px;
  margin-right: 7px;
  width: 9px;
}

.note-popover.user-a::before {
  background: #28998e;
}

.note-popover.user-b::before {
  background: #d86c42;
}

.note-popover-head {
  align-items: center;
  display: flex;
  gap: 8px;
  justify-content: space-between;
}

.note-popover strong {
  font-size: 14px;
}

.note-popover-close {
  background: transparent;
  color: var(--muted);
  font-size: 18px;
  min-height: 24px;
  padding: 0;
}

.note-popover p {
  font-size: 14px;
  line-height: 1.45;
  margin-top: 6px;
}

.note-popover-comment {
  background: var(--surface-2);
  color: var(--ink);
  font-size: 13px;
  margin-top: 10px;
  min-height: 30px;
  padding: 0 10px;
}

.note-popover-form {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.note-popover-form textarea {
  min-height: 64px;
}

.note-popover-form div {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.note-popover-form button {
  min-height: 32px;
}

@media (max-width: 980px) {
  body {
    overflow: hidden;
  }

  .workspace,
  .workspace.library-collapsed,
  .workspace.notes-collapsed,
  .workspace.library-collapsed.notes-collapsed {
    display: grid;
    grid-template-columns: 1fr;
    grid-template-rows: 52px 1fr;
    height: 100vh;
    overflow: hidden;
  }

  .mobile-topbar {
    align-items: center;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    display: flex;
    grid-row: 1;
    justify-content: space-between;
    padding: 8px 10px;
    position: sticky;
    top: 0;
    z-index: 18;
  }

  .mobile-tab {
    background: var(--surface-2);
    color: var(--ink);
    min-height: 36px;
    padding: 0 12px;
  }

  .mobile-backdrop {
    background: rgba(36, 33, 29, 0.32);
    inset: 0;
    position: fixed;
    z-index: 19;
  }

  .workspace.drawer-open .mobile-backdrop {
    display: block;
  }

  .reader-pane {
    grid-row: 2;
    height: calc(100vh - 52px);
    min-height: 0;
    overflow-y: auto;
    padding: 8px 12px 12px;
  }

  .reader-topbar {
    align-items: center;
    display: flex;
    gap: 8px;
    justify-content: center;
    margin-bottom: 8px;
  }

  .reader-topbar > div:first-child {
    display: none;
  }

  .reader-actions {
    flex-wrap: nowrap;
    gap: 8px;
    justify-content: center;
    width: 100%;
  }

  #refreshButton,
  #openFileLink {
    display: none;
  }

  .jump-form {
    flex: 1;
    justify-content: center;
  }

  .jump-form input {
    max-width: 72px;
  }

  .jump-form button {
    padding: 0 10px;
  }

  .pdf-toolbar,
  .epub-toolbar {
    justify-content: center;
  }

  .pdf-toolbar > button,
  .epub-toolbar > button {
    display: none;
  }

  .reader-jump-form {
    display: none;
  }

  .pane {
    box-shadow: var(--shadow);
    height: 100vh;
    max-width: min(88vw, 360px);
    min-height: 0;
    overflow-y: auto;
    padding: 16px;
    position: fixed;
    top: 0;
    width: min(88vw, 360px);
    z-index: 20;
  }

  .library-pane {
    border-right: 1px solid var(--line);
    left: 0;
    transform: translateX(-105%);
    transition: transform 180ms ease;
  }

  .notes-pane {
    border-left: 1px solid var(--line);
    right: 0;
    transform: translateX(105%);
    transition: transform 180ms ease;
  }

  .workspace.mobile-library-open .library-pane {
    transform: translateX(0);
  }

  .workspace.mobile-notes-open .notes-pane {
    transform: translateX(0);
  }

  .workspace.mobile-library-open .library-pane.hidden,
  .workspace.mobile-notes-open .notes-pane.hidden {
    display: block !important;
  }

  .pane-header .icon-button {
    display: flex;
    font-size: 0;
  }

  .pane-header .icon-button::before {
    content: "×";
    font-size: 24px;
  }

  .rail-button {
    display: none;
  }

  .pdf-wrap,
  .epub-notice {
    min-height: calc(100vh - 170px);
  }

  .pdf-reader,
  .epub-reader {
    height: calc(100vh - 170px);
    min-height: 0;
  }

  .pdf-page {
    max-width: 100%;
    overflow: hidden;
  }

  .pdf-page canvas {
    max-width: 100%;
    height: auto !important;
  }

  .epub-reader {
    padding: 18px;
  }

  .inline-note-box {
    left: 12px !important;
    right: 12px;
    top: auto !important;
    bottom: 12px;
    width: auto;
  }
}
