:root,
html[data-theme="white"] {
  --bg: #ffffff;
  --ink: #1d2430;
  --card: #ffffff;
  --brand: #0f6b5d;
  --brand-soft: #e8f7f3;
  --muted: #687481;
  --border: #e1e8ef;
  --shadow: 0 10px 22px rgba(20, 35, 48, 0.07);
  --topbar: rgba(255, 255, 255, 0.94);
}

html[data-theme="orange"] {
  --bg: #fff8f1;
  --ink: #2f1d13;
  --card: #fffdf9;
  --brand: #d9721c;
  --brand-soft: #ffe7cf;
  --muted: #8a5f42;
  --border: #f1d5bf;
  --shadow: 0 12px 24px rgba(112, 64, 27, 0.13);
  --topbar: rgba(255, 245, 235, 0.95);
}

html[data-theme="dark"] {
  --bg: #151a1d;
  --ink: #e8f0f3;
  --card: #1f272c;
  --brand: #20a086;
  --brand-soft: #24463f;
  --muted: #9ab0ba;
  --border: #30424a;
  --shadow: 0 18px 30px rgba(0, 0, 0, 0.35);
  --topbar: rgba(24, 31, 35, 0.9);
}

html[data-theme="night"] {
  --bg: #090d18;
  --ink: #edf1ff;
  --card: #11182c;
  --brand: #5aa2ff;
  --brand-soft: #1c3157;
  --muted: #acb9df;
  --border: #26385f;
  --shadow: 0 20px 34px rgba(3, 7, 20, 0.55);
  --topbar: rgba(10, 15, 28, 0.9);
}

html[data-theme="sunset"] {
  --bg: #fff2ea;
  --ink: #2a1c18;
  --card: #fffaf6;
  --brand: #d15a39;
  --brand-soft: #ffe1d6;
  --muted: #8b5b4f;
  --border: #efc8bb;
  --shadow: 0 12px 24px rgba(143, 69, 45, 0.15);
  --topbar: rgba(255, 240, 232, 0.95);
}

html[data-theme="forest"] {
  --bg: #eef6f1;
  --ink: #173127;
  --card: #f8fdf9;
  --brand: #2a8a62;
  --brand-soft: #d8f0e5;
  --muted: #4d7663;
  --border: #c5e4d5;
  --shadow: 0 12px 24px rgba(35, 94, 72, 0.14);
  --topbar: rgba(239, 248, 243, 0.95);
}

html[data-theme="ocean"] {
  --bg: #ecf5ff;
  --ink: #122a44;
  --card: #f7fbff;
  --brand: #2f7fd6;
  --brand-soft: #d8ebff;
  --muted: #547799;
  --border: #c3def9;
  --shadow: 0 12px 24px rgba(33, 92, 162, 0.13);
  --topbar: rgba(239, 247, 255, 0.95);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "IBM Plex Sans", sans-serif;
  font-size: calc(16px * var(--ui-font-scale, 1));
  color: var(--ink);
  background: var(--bg);
  min-height: 100vh;
  overflow-x: hidden;
}

html {
  overflow-x: hidden;
}

h1, h2, h3, .brand { font-family: "Space Grotesk", sans-serif; }

body[data-ui-font="sans"] {
  font-family: "IBM Plex Sans", sans-serif;
}

body[data-ui-font="serif"] {
  font-family: "Merriweather", Georgia, serif;
}

body[data-ui-font="handwritten"] {
  font-family: "Caveat", "Segoe Print", cursive;
}

body[data-ui-font="mono"] {
  font-family: "Courier New", "IBM Plex Mono", monospace;
}

body[data-ui-font="display"] {
  font-family: "Space Grotesk", "IBM Plex Sans", sans-serif;
}

body[data-ui-font="serif"] h1,
body[data-ui-font="serif"] h2,
body[data-ui-font="serif"] h3,
body[data-ui-font="serif"] .brand {
  font-family: "Merriweather", Georgia, serif;
}

body[data-ui-font="handwritten"] h1,
body[data-ui-font="handwritten"] h2,
body[data-ui-font="handwritten"] h3,
body[data-ui-font="handwritten"] .brand {
  font-family: "Caveat", "Segoe Print", cursive;
}

body[data-ui-font="mono"] h1,
body[data-ui-font="mono"] h2,
body[data-ui-font="mono"] h3,
body[data-ui-font="mono"] .brand {
  font-family: "Courier New", "IBM Plex Mono", monospace;
}

body[data-ui-font="display"] h1,
body[data-ui-font="display"] h2,
body[data-ui-font="display"] h3,
body[data-ui-font="display"] .brand {
  font-family: "Space Grotesk", sans-serif;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  padding: 12px 0;
  background: var(--topbar);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}

.topbar-shell {
  width: min(1240px, 94vw);
  margin: 0 auto;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 14px;
}

.nav-backdrop {
  display: none;
}

.brand {
  color: var(--ink);
  text-decoration: none;
  font-weight: 700;
  letter-spacing: 0.03em;
}

.nav-toggle {
  display: none;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--ink);
  border-radius: 10px;
  padding: 8px 12px;
  font-weight: 600;
}

.navlinks {
  display: flex;
  margin-left: auto;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
}

.nav-primary,
.nav-secondary {
  display: flex;
  align-items: center;
  gap: 8px;
}

.nav-notifications {
  position: relative;
  flex-shrink: 0;
}

.notification-bell {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  border: 1px solid color-mix(in srgb, var(--border) 76%, var(--brand) 24%);
  background: color-mix(in srgb, var(--card) 92%, var(--brand-soft) 8%);
  color: var(--ink);
  cursor: pointer;
}

.notification-bell-text {
  display: none;
  margin-left: 8px;
  font-size: 0.88rem;
  font-weight: 700;
}

.notification-bell-count {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: #d64545;
  color: #fff;
  font-size: 0.68rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--card);
}

.notification-dropdown {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  width: min(380px, 92vw);
  max-height: min(70vh, 620px);
  overflow: auto;
  padding: 12px;
  border-radius: 16px;
  border: 1px solid color-mix(in srgb, var(--border) 72%, var(--brand) 28%);
  background: color-mix(in srgb, var(--card) 96%, #fff 4%);
  box-shadow: 0 20px 40px rgba(10, 18, 26, 0.18);
  z-index: 150;
}

.notification-dropdown-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.notification-link-btn {
  border: 0;
  background: transparent;
  color: var(--brand);
  font-weight: 700;
  cursor: pointer;
  padding: 0;
}

.notification-dropdown-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.notification-item {
  border: 1px solid color-mix(in srgb, var(--border) 78%, var(--brand) 22%);
  border-radius: 14px;
  padding: 10px 12px;
  background: color-mix(in srgb, var(--card) 88%, var(--brand-soft) 12%);
}

.notification-item.unread {
  border-color: color-mix(in srgb, var(--brand) 40%, var(--border) 60%);
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--brand) 16%, transparent);
}

.notification-item-head {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.notification-avatar {
  width: 34px;
  height: 34px;
  border-radius: 999px;
  object-fit: cover;
  background: var(--brand-soft);
  border: 1px solid var(--border);
  flex-shrink: 0;
}

.notification-copy {
  min-width: 0;
  flex: 1 1 auto;
}

.notification-title {
  font-weight: 700;
  font-size: 0.9rem;
  line-height: 1.45;
}

.notification-message,
.notification-meta,
.notification-empty,
.notification-suggestions-label {
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.45;
}

.notification-message {
  margin-top: 4px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.notification-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-top: 8px;
}

.notification-item-link,
.notification-item-toggle {
  border: 0;
  background: transparent;
  color: var(--brand);
  font-size: 0.78rem;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  padding: 0;
}

.notification-suggestions {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.notification-suggestion-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.notification-suggestion-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--brand-soft) 62%, #fff 38%);
  border: 1px solid color-mix(in srgb, var(--border) 78%, var(--brand) 22%);
  color: var(--ink);
  text-decoration: none;
  font-size: 0.78rem;
  font-weight: 600;
}

.sidebar-user {
  display: none;
}

.nav-primary {
  flex-wrap: nowrap;
  justify-content: flex-start;
  flex: 1;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
}

.nav-primary::-webkit-scrollbar {
  display: none;
}

.navlinks a,
.nav-logout-btn {
  color: var(--ink);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.93rem;
  padding: 7px 10px;
  border-radius: 10px;
  border: 1px solid transparent;
  transition: background 0.2s ease, border-color 0.2s ease;
  white-space: nowrap;
}

.navlinks a:hover,
.navlinks a:focus-visible,
.nav-logout-btn:hover,
.nav-logout-btn:focus-visible {
  background: var(--brand-soft);
  border-color: var(--border);
  outline: none;
}

.nav-auth-link-primary {
  font-weight: 700;
}

/* White and Orange themes: Light background, dark text */
html[data-theme="white"] .nav-auth-link-primary,
html[data-theme="orange"] .nav-auth-link-primary {
  background: var(--brand-soft) !important;
  color: var(--brand) !important;
  border: 1px solid var(--brand) !important;
}

/* Dark and Night themes: Dark background, light text */
html[data-theme="dark"] .nav-auth-link-primary,
html[data-theme="night"] .nav-auth-link-primary {
  background: #000 !important;
  color: #fff !important;
  border: 1px solid var(--brand) !important;
}

.nav-auth-link-primary:hover,
.nav-auth-link-primary:focus-visible {
  filter: brightness(1.1);
}

.nav-logout-btn {
  cursor: pointer;
}

.nav-profile-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.nav-profile-icon {
  width: 24px;
  height: 24px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
  background: var(--brand-soft);
  color: var(--brand);
  border: 1px solid var(--border);
}

.nav-more {
  position: relative;
  flex-shrink: 0;
}

.nav-more summary {
  list-style: none;
  color: var(--ink);
  font-weight: 600;
  font-size: 0.93rem;
  padding: 7px 10px;
  border-radius: 10px;
  border: 1px solid transparent;
  cursor: pointer;
  user-select: none;
}

.nav-more summary::-webkit-details-marker {
  display: none;
}

.nav-more summary:hover,
.nav-more summary:focus-visible {
  background: var(--brand-soft);
  border-color: var(--border);
  outline: none;
}

.nav-more-menu {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  min-width: 220px;
  padding: 8px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  display: none;
  z-index: 75;
}

.nav-more[open] .nav-more-menu {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-more-menu a {
  display: block;
}

.nav-menu-label {
  margin: 6px 6px 2px;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  font-weight: 700;
}

.nav-secondary .inline-form {
  display: flex;
  margin: 0;
}

.nav-secondary {
  flex-shrink: 0;
}

.page-loader {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  background: color-mix(in srgb, var(--bg) 84%, #ffffff 16%);
  backdrop-filter: blur(3px);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.24s ease, visibility 0.24s ease;
}

.page-loader.is-active {
  opacity: 1;
  visibility: visible;
}

.page-loader-card {
  display: grid;
  justify-items: center;
  gap: 10px;
  padding: 18px 24px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--card);
  box-shadow: var(--shadow);
}

.page-loader-spinner {
  width: 36px;
  height: 36px;
  border-radius: 999px;
  border: 3px solid color-mix(in srgb, var(--brand) 18%, var(--border) 82%);
  border-top-color: var(--brand);
  animation: page-loader-spin 0.9s linear infinite;
}

.page-loader-brand {
  font-family: "Space Grotesk", sans-serif;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--ink);
}

.page-loader-text {
  color: var(--muted);
  font-size: 0.9rem;
}

@keyframes page-loader-spin {
  to { transform: rotate(360deg); }
}

.nav-mobile-only {
  display: none;
}

.theme-select {
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--ink);
  border-radius: 10px;
  padding: 7px 10px;
  font-size: 0.88rem;
}

.inline-form { margin: 0; }

.link-button {
  border: 0;
  background: transparent;
  padding: 0;
  margin: 0;
  font: inherit;
  color: var(--ink);
  font-weight: 500;
  cursor: pointer;
}

.container {
  width: min(1180px, 92vw);
  margin: 26px auto 60px;
}

.hero {
  margin-bottom: 20px;
  animation: fade-up .45s ease;
}

.hero h1 { margin: 0 0 8px; font-size: clamp(1.7rem, 3vw, 2.4rem); }
.hero p { margin: 0; color: var(--muted); }

.button {
  display: inline-block;
  margin-top: 10px;
  background: var(--brand);
  color: #fff;
  padding: 10px 14px;
  border-radius: 10px;
  text-decoration: none;
  border: 0;
  cursor: pointer;
}

.button.secondary {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--border);
}

.button.saved-state {
  background: var(--brand-soft);
  border-color: var(--brand);
}

.section-switch {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
}

.panel,
.note-card,
.article-view {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px;
  box-shadow: var(--shadow);
}

.note-card {
  min-height: 290px;
  height: auto;
  display: flex;
  flex-direction: column;
  overflow: clip;
  min-width: 0;
  position: relative;
  border-radius: 18px;
  border: 1px solid color-mix(in srgb, var(--border) 80%, var(--brand) 20%);
  background:
    radial-gradient(120% 90% at 110% -10%, color-mix(in srgb, var(--brand-soft) 72%, transparent) 0%, transparent 55%),
    linear-gradient(180deg, color-mix(in srgb, var(--card) 88%, #fff 12%) 0%, var(--card) 100%);
  box-shadow:
    0 1px 0 color-mix(in srgb, var(--brand-soft) 65%, transparent),
    0 14px 28px rgba(16, 25, 34, 0.08);
  transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}

.note-card-thumb-wrap {
  width: 100%;
  height: 160px;
  border-radius: 14px;
  overflow: hidden;
  margin-bottom: 10px;
  background: var(--card);
}

.note-card-thumb {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.note-card::after {
  content: "";
  position: absolute;
  left: 16px;
  right: 16px;
  bottom: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--border) 70%, var(--brand) 30%), transparent);
  pointer-events: none;
}

.note-card:hover {
  transform: translateY(-3px);
  border-color: color-mix(in srgb, var(--brand) 34%, var(--border) 66%);
  box-shadow:
    0 1px 0 color-mix(in srgb, var(--brand-soft) 65%, transparent),
    0 20px 32px rgba(16, 25, 34, 0.12);
}

.note-card-heading {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 10px;
}

.note-card-avatar {
  width: 40px;
  height: 40px;
  border-radius: 999px;
  object-fit: cover;
  flex-shrink: 0;
  border: 1px solid color-mix(in srgb, var(--border) 72%, var(--brand) 28%);
  background: var(--brand-soft);
  box-shadow: 0 6px 14px rgba(13, 23, 33, 0.12);
}

.note-card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 12px;
  padding-top: 8px;
  border-top: 1px solid color-mix(in srgb, var(--border) 80%, var(--brand) 20%);
}

.note-card-footer-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.note-card-footer-text {
  min-width: 0;
}

.note-card-footer .actions {
  margin-top: 0;
}

/* Tighter, chip-style meta for card footers */
.note-card-footer .note-meta {
  margin: 0;
  font-size: 0.8rem;
  line-height: 1.3;
  color: var(--muted);
  white-space: nowrap;
}

.note-card-footer .actions.compact-actions {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.note-card-footer .actions .button {
  margin-top: 0;
}

.note-owner-subtitle {
  color: var(--muted);
  font-size: 0.8rem;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  margin: 0 0 4px;
  overflow-wrap: break-word;
}

.note-owner-subtitle a {
  color: color-mix(in srgb, var(--ink) 76%, var(--brand) 24%);
  text-decoration: none;
  font-weight: 700;
}

.note-owner-subtitle a:hover {
  color: var(--brand);
}

.note-card > * {
  min-width: 0;
}

.popular-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.popular-list li {
  border: 1px dashed var(--border);
  border-radius: 8px;
  padding: 8px;
}

.popular-list a {
  color: var(--ink);
  text-decoration: none;
  font-weight: 600;
  display: block;
}

.popular-list small { color: var(--muted); }

.toolbar-row {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.toolbar-row input {
  width: 100%;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--ink);
  padding: 10px;
  font: inherit;
}

.view-toggle { display: flex; gap: 8px; }
.view-toggle .button.active,
.section-switch .button.active {
  background: var(--brand);
  color: #fff;
  border-color: var(--brand);
}

.notes-wrap {
  display: grid;
  gap: 16px;
}

.section-switch {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.panel.toolbar-row {
  flex-wrap: wrap;
  gap: 12px;
}

.panel.toolbar-row > * {
  min-width: 180px;
}

.notes-notebook { grid-template-columns: repeat(auto-fit, minmax(255px, 1fr)); }
.notes-list { grid-template-columns: 1fr; }
.notes-list .note-card {
  min-height: 0;
  border-left: 6px solid color-mix(in srgb, var(--brand) 85%, var(--ink) 15%);
}

.note-title {
  margin-top: 0;
  margin-bottom: 8px;
  font-size: 1.08rem;
  line-height: 1.28;
  letter-spacing: 0.01em;
  overflow-wrap: anywhere;
  word-break: break-word;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.note-summary {
  color: var(--muted);
  line-height: 1.52;
  margin: 0;
  overflow-wrap: anywhere;
  word-break: break-word;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.note-meta {
  color: color-mix(in srgb, var(--muted) 90%, var(--ink) 10%);
  font-size: 0.82rem;
  letter-spacing: 0.02em;
  margin: 10px 0 8px;
  padding: 6px 8px;
  border-radius: 9px;
  background: color-mix(in srgb, var(--brand-soft) 58%, transparent);
  border: 1px solid color-mix(in srgb, var(--border) 75%, var(--brand) 25%);
  overflow-wrap: anywhere;
  word-break: break-word;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.note-owner {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 0.95rem;
  margin-top: 6px;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.note-owner-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid var(--border);
  background: var(--brand-soft);
}

.note-owner a {
  color: var(--brand);
  text-decoration: none;
  font-weight: 600;
}

.note-card .button,
.note-card .actions {
  margin-top: auto;
}

.note-card .actions {
  padding-top: 0;
  border-top: 0;
}

.note-card .button {
  border-radius: 999px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.article-view {
  max-width: 900px;
  margin: 0 auto;
}

.read-main {
  width: 100%;
  max-width: 100%;
  min-height: 420px;
  padding: 24px;
  margin: 0;
}

.read-main h2 {
  margin-top: 2px;
  margin-bottom: 14px;
}

.read-layout.pages-hidden {
  grid-template-columns: 1fr;
}

.book-layout.pages-hidden .book-sidebar {
  display: none;
}

.read-layout {
  align-items: start;
}

.rich-content {
  line-height: 1.75;
  font-size: 1.04rem;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.rich-content img { max-width: 100%; border-radius: 8px; margin: 8px 0; }

.reader-hero {
  background:
    radial-gradient(circle at 12% 16%, color-mix(in srgb, var(--brand-soft) 75%, transparent) 0%, transparent 32%),
    radial-gradient(circle at 88% 18%, color-mix(in srgb, var(--brand-soft) 55%, transparent) 0%, transparent 28%),
    linear-gradient(180deg, var(--card) 0%, var(--brand-soft) 100%);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px 20px;
  box-shadow: var(--shadow);
  text-align: left;
  animation: heroFloat 6.5s ease-in-out infinite;
}

.reader-hero h1 {
  margin: 0 0 12px;
  max-width: 1000px;
  line-height: 1.18;
}

@keyframes heroFloat {
  0%, 100% { background-position: 0% 0%, 100% 0%, 0 0; }
  50% { background-position: 2% 3%, 98% 2%, 0 0; }
}

.reader-meta {
  margin-bottom: 10px;
  font-size: 0.95rem;
  display: flex;
  align-items: center;
  gap: 8px;
}

.reader-owner {
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.reader-actions .button {
  margin-top: 0;
}

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

.reader-nav-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 38px;
  padding: 8px 12px;
  border-radius: 10px;
  font-size: 0.86rem;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.reader-nav-btn .action-icon {
  width: 14px;
  height: 14px;
}

.reader-nav-btn .action-icon svg {
  width: 14px;
  height: 14px;
}

.reader-nav-btn .action-label {
  font-size: 0.8rem;
}

.reader-nav-btn.icon-only {
  width: 40px;
  min-width: 40px;
  height: 40px;
  min-height: 40px;
  padding: 0;
  border-radius: 11px;
  border-color: color-mix(in srgb, var(--border) 70%, var(--brand) 30%);
  background: color-mix(in srgb, var(--card) 88%, var(--brand-soft) 12%);
  color: color-mix(in srgb, var(--ink) 75%, var(--brand) 25%);
  box-shadow: 0 6px 14px rgba(17, 28, 39, 0.08);
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease, background-color 0.18s ease;
}

.reader-nav-btn.icon-only:hover,
.reader-nav-btn.icon-only:focus-visible {
  transform: translateY(-1px);
  border-color: color-mix(in srgb, var(--brand) 45%, var(--border) 55%);
  background: color-mix(in srgb, var(--card) 80%, var(--brand-soft) 20%);
  box-shadow: 0 10px 18px rgba(17, 28, 39, 0.13);
  outline: none;
}

.reader-nav-btn.icon-only .action-label {
  display: none;
}

.reader-layout {
  grid-template-columns: minmax(190px, 230px) minmax(0, 1fr);
  gap: 16px;
  margin-top: 16px;
}

.reader-sidebar {
  position: sticky;
  top: 82px;
}

.reader-section-title {
  margin: 0 0 12px;
  font-size: 1rem;
  letter-spacing: 0.01em;
}

.reader-main {
  border-radius: 16px;
  padding: clamp(18px, 3vw, 30px);
  --reader-font-scale: 1;
  --reader-content-max: 80ch;
}

.reader-main[data-width-mode="compact"] {
  --reader-content-max: 70ch;
}

.reader-main[data-width-mode="wide"] {
  --reader-content-max: 112ch;
}

.reader-main,
.editor-shell .book-editor {
  --note-bg-color: var(--card);
  --note-text-color: var(--ink);
  --note-accent-color: var(--brand);
}

.reader-premium-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  position: sticky;
  top: 78px;
  z-index: 22;
  margin-bottom: 10px;
  padding: 10px;
  border: 1px solid color-mix(in srgb, var(--border) 75%, var(--brand) 25%);
  border-radius: 12px;
  background: color-mix(in srgb, var(--card) 92%, var(--brand-soft) 8%);
  backdrop-filter: blur(6px);
}

.reader-tools-group {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-wrap: wrap;
}

.reader-premium-toolbar .button {
  margin-top: 0;
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 0.82rem;
}

.reader-page-indicator {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 600;
}

.reader-context-menu {
  position: fixed;
  z-index: 80;
  min-width: 196px;
  max-width: min(88vw, 260px);
  padding: 8px;
  border: 1px solid color-mix(in srgb, var(--border) 72%, var(--brand) 28%);
  border-radius: 12px;
  background: color-mix(in srgb, var(--card) 92%, var(--brand-soft) 8%);
  box-shadow: 0 18px 34px rgba(8, 15, 28, 0.2);
  backdrop-filter: blur(8px);
  display: grid;
  gap: 6px;
}

.reader-context-menu .button {
  width: 100%;
  margin-top: 0;
  justify-content: flex-start;
  padding: 7px 10px;
  border-radius: 9px;
  font-size: 0.82rem;
}

.reader-menu-label {
  margin: 2px 2px 0;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.reader-menu-select {
  width: 100%;
  min-height: 34px;
  font-size: 0.84rem;
}

.reader-progress-track {
  height: 6px;
  border-radius: 999px;
  overflow: hidden;
  background: color-mix(in srgb, var(--border) 80%, transparent);
  margin-bottom: 16px;
}

.reader-progress-fill {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, var(--brand), color-mix(in srgb, var(--brand) 72%, #ffffff 28%));
  transition: width 0.15s ease-out;
}

.reader-page-nav {
  margin-top: 18px;
  padding-top: 12px;
  border-top: 1px solid color-mix(in srgb, var(--border) 75%, var(--brand) 25%);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.reader-page-nav .button {
  margin-top: 0;
  min-width: 110px;
}

.reader-page-nav .button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.reader-page-nav-label {
  color: var(--muted);
  font-size: 0.84rem;
  text-align: center;
  white-space: nowrap;
}

.reader-main .rich-content {
  max-width: var(--reader-content-max);
  margin: 0 auto;
  font-size: calc(clamp(1rem, 1.25vw, 1.1rem) * var(--reader-font-scale));
  line-height: 1.84;
  color: var(--note-text-color);
  background: var(--note-bg-color);
  border: 1px solid color-mix(in srgb, var(--note-accent-color) 20%, var(--border) 80%);
  border-radius: 14px;
  padding: clamp(16px, 2.4vw, 24px);
  box-shadow: 0 14px 28px rgba(13, 22, 36, 0.08);
  animation: noteFadeIn 0.28s ease-out;
}

.reader-main .rich-content h1,
.reader-main .rich-content h2,
.reader-main .rich-content h3 {
  line-height: 1.28;
  margin-top: 1.4em;
  margin-bottom: 0.55em;
}

.reader-main .rich-content p,
.reader-main .rich-content ul,
.reader-main .rich-content ol,
.reader-main .rich-content blockquote {
  margin-top: 0;
  margin-bottom: 1.05em;
}

.reader-main .rich-content blockquote {
  border-left: 3px solid var(--note-accent-color);
  padding-left: 12px;
  color: var(--muted);
}

.reader-main[data-note-font-family="serif"] .rich-content {
  font-family: "Merriweather", Georgia, serif;
}

.reader-main[data-note-font-family="handwritten"] .rich-content {
  font-family: "Caveat", "Segoe Print", cursive;
  letter-spacing: 0.01em;
  font-size: calc(clamp(1.12rem, 1.42vw, 1.28rem) * var(--reader-font-scale));
  line-height: 1.68;
}

.reader-main[data-note-font-family="mono"] .rich-content {
  font-family: "Courier New", "IBM Plex Mono", monospace;
}

.reader-main[data-note-font-family="display"] .rich-content {
  font-family: "Space Grotesk", "IBM Plex Sans", sans-serif;
}

.reader-main[data-note-style-preset="vibrant"] .rich-content {
  background: linear-gradient(160deg, color-mix(in srgb, var(--note-bg-color) 88%, #ffe5d1 12%) 0%, color-mix(in srgb, var(--note-bg-color) 78%, #d6f7ff 22%) 100%);
}

.reader-main[data-note-style-preset="paper"] .rich-content {
  background:
    radial-gradient(circle at 15% 16%, rgba(220, 188, 130, 0.08), transparent 36%),
    linear-gradient(180deg, color-mix(in srgb, var(--note-bg-color) 80%, #f8f0dd 20%) 0%, color-mix(in srgb, var(--note-bg-color) 74%, #f3e4c7 26%) 100%);
}

.reader-main[data-note-style-preset="midnight"] .rich-content {
  background: linear-gradient(170deg, #172133 0%, #1f2d45 100%);
  color: #eaf2ff;
  border-color: color-mix(in srgb, #5d8dd7 46%, #1f2d45 54%);
}

.reader-main[data-note-style-preset="midnight"] .rich-content blockquote {
  color: #b7c8e9;
}

@keyframes noteFadeIn {
  from {
    opacity: 0.55;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Keep pasted rich content within viewport bounds on read pages. */
.reader-main .rich-content img,
.reader-main .rich-content video,
.reader-main .rich-content iframe,
.reader-main .rich-content table,
.reader-main .rich-content pre,
.reader-main .rich-content code {
  max-width: 100%;
}

.reader-main .rich-content pre {
  overflow-x: auto;
}

.reader-main .rich-content table {
  display: block;
  overflow-x: auto;
}

body.reader-focus-mode #note-feedback-bar,
body.reader-focus-mode #comments-root,
body.reader-focus-mode .topbar {
  display: none !important;
}

/* Sidebar handling in focus mode: hide if .pages-hidden is present */
body.reader-focus-mode .pages-hidden #public-read-sidebar,
body.reader-focus-mode .pages-hidden #owner-read-sidebar {
  display: none !important;
}

body.reader-focus-mode .reader-hero {
  border: 0;
  background: transparent;
  box-shadow: none;
  text-align: left;
  padding: 20px 0 10px;
}

body.reader-focus-mode .reader-hero h1 {
  margin: 0;
  max-width: 1000px;
}

body.reader-focus-mode .reader-meta,
body.reader-focus-mode .reader-owner,
body.reader-focus-mode .reader-actions {
  display: none !important;
}

body.reader-focus-mode .container {
  max-width: 1000px !important;
  width: 94% !important;
  margin: 0 auto !important; /* Center the overall container, but left-align content inside */
  padding-top: 10px;
}

body.reader-focus-mode #public-read-layout,
body.reader-focus-mode #owner-read-layout {
  display: block;
}

/* Restore grid if pages are explicitly shown in focus mode */
body.reader-focus-mode #public-read-layout:not(.pages-hidden),
body.reader-focus-mode #owner-read-layout:not(.pages-hidden) {
  display: grid !important;
  grid-template-columns: minmax(190px, 230px) minmax(0, 1fr);
  gap: 24px;
}

@media (max-width: 980px) {
  body.reader-focus-mode #public-read-layout:not(.pages-hidden),
  body.reader-focus-mode #owner-read-layout:not(.pages-hidden) {
    display: flex !important;
    flex-direction: column;
    gap: 16px;
  }
}

body.reader-focus-mode #public-read-content,
body.reader-focus-mode #read-page-content {
  max-width: 1000px;
  margin: 0;
  padding: clamp(18px, 3vw, 30px); /* Add padding inside content area */
  border-color: color-mix(in srgb, var(--brand) 35%, var(--border) 65%);
  box-shadow: 0 20px 38px rgba(10, 18, 26, 0.14);
}

body.reader-focus-mode .reader-premium-toolbar {
  top: 10px;
}

.reader-suggested {
  margin-top: 20px;
  overflow: hidden;
}

.reader-suggested-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 14px;
  margin-bottom: 14px;
}

.reader-suggested-copy {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.reader-suggested-controls {
  display: inline-flex;
  gap: 8px;
  flex-shrink: 0;
}

.reader-suggested-controls .button {
  min-width: 42px;
  padding: 8px 10px;
}

.reader-suggested-track-wrap {
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: thin;
  scroll-behavior: smooth;
}

.reader-suggested-track {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(200px, 46vw);
  gap: 12px;
}

.reader-suggested-card {
  display: grid;
  grid-template-rows: 130px auto;
  min-width: 0;
  color: inherit;
  text-decoration: none;
  border: 1px solid var(--border);
  border-radius: 16px;
  overflow: hidden;
  background:
    linear-gradient(180deg, color-mix(in srgb, var(--brand-soft) 72%, white 28%) 0%, var(--panel) 100%);
  box-shadow: 0 14px 28px rgba(15, 25, 35, 0.08);
}

.reader-suggested-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 18px 32px rgba(15, 25, 35, 0.12);
}

.reader-suggested-media {
  background:
    radial-gradient(circle at top left, color-mix(in srgb, var(--brand) 28%, transparent) 0%, transparent 42%),
    linear-gradient(135deg, color-mix(in srgb, var(--brand-soft) 82%, white 18%) 0%, color-mix(in srgb, var(--panel) 70%, var(--brand-soft) 30%) 100%);
}

.reader-suggested-media img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.reader-suggested-body {
  padding: 12px;
  display: grid;
  gap: 8px;
}

.reader-suggested-eyebrow,
.reader-suggested-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.reader-suggested-badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 4px 9px;
  font-size: 0.72rem;
  font-weight: 700;
  background: color-mix(in srgb, var(--brand) 10%, white 90%);
  color: var(--brand);
}

.reader-suggested-views,
.reader-suggested-author {
  color: var(--muted);
  font-size: 0.8rem;
}

.reader-suggested-title {
  margin: 0;
  font-size: 1rem;
  line-height: 1.35;
}

.reader-suggested-summary {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.4;
  min-height: 40px;
}

.reader-suggested-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.reader-suggested-tag {
  display: inline-flex;
  align-items: center;
  padding: 4px 8px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--brand-soft) 65%, white 35%);
  color: var(--text);
  font-size: 0.74rem;
}

.reader-suggested-author-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.reader-suggested-author-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid rgba(255, 255, 255, 0.5);
}

.reader-suggested-author-name {
  font-weight: 600;
  font-size: 0.85rem;
  display: block;
}

.reader-suggested-author-hint {
  font-size: 0.72rem;
  color: var(--muted);
}

.reader-feedback {
  margin-top: 18px;
}

.reader-feedback-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 16px;
}

.reader-rating-display,
.reader-likes-display .like-button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.reader-rating-value {
  font-weight: 700;
  font-size: 1.05rem;
}

.reader-star {
  color: #ffc107;
}

.reader-rating-count {
  color: var(--muted);
  font-size: 0.92rem;
}

.reader-like-icon {
  font-size: 1.16rem;
}

.reader-comments {
  margin-top: 16px;
}

.comments-login-hint {
  margin: 0 0 14px;
}

.comment-compose {
  margin-bottom: 12px;
}

.comment-compose-input {
  min-height: 68px;
  margin-bottom: 8px;
  border-radius: 12px;
  font-size: 0.94rem;
  line-height: 1.45;
  padding: 10px 12px;
}

.comment-thread {
  margin-bottom: 8px;
}

.comment-item {
  padding: 10px 12px;
  border-radius: 10px;
  margin-bottom: 6px;
  box-shadow: none;
  border: 1px solid var(--border);
}

.comment-reply {
  margin-left: 18px;
  background: transparent;
}

.comment-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.comment-avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid var(--border);
  background: var(--brand-soft);
}

.comment-author {
  font-size: 0.86rem;
  font-weight: 600;
}

.comment-time {
  color: var(--muted);
  font-size: 0.74rem;
}

.comment-body {
  margin: 0;
  white-space: pre-wrap;
  line-height: 1.42;
  font-size: 0.9rem;
}

.comment-actions {
  margin-top: 6px;
}

.reply-form {
  margin-top: 8px;
}

.reply-input {
  min-height: 60px;
  margin-bottom: 6px;
  border-radius: 10px;
  font-size: 0.9rem;
  padding: 8px 10px;
}

.comments-empty {
  color: var(--muted);
  margin: 6px 0;
  font-size: 0.9rem;
}

.reader-comments .button {
  margin-top: 0;
}

.reader-comments .button.secondary {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 0;
  font-size: 0.82rem;
  font-weight: 600;
}

.reader-comments .button.secondary:hover {
  color: var(--brand);
  text-decoration: underline;
}

.reader-comments .button.primary {
  padding: 8px 12px;
  font-size: 0.84rem;
  border-radius: 9px;
}

.rating-modal {
  max-width: 460px;
}

.rating-modal-body {
  padding: 18px;
}

.rating-stars {
  font-size: 2rem;
  color: #ffc107;
  cursor: pointer;
  text-align: center;
  margin-bottom: 14px;
}

.rating-comment-input {
  min-height: 84px;
  margin-bottom: 14px;
}

.rating-submit-btn {
  width: 100%;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.stat {
  background: var(--brand-soft);
  border-radius: 12px;
  padding: 12px;
  border: 1px solid var(--border);
}

.panel-grid {
  display: grid;
  grid-template-columns: 1.6fr 1fr;
  gap: 20px;
}

.panel-grid.sidebar-right {
  grid-template-columns: 1fr 300px;
}

.panel-grid.sidebar-left {
  grid-template-columns: 300px 1fr;
}

.flex-between {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.table {
  width: 100%;
  border-collapse: collapse;
}

.table th, .table td {
  text-align: left;
  padding: 8px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
  overflow-wrap: anywhere;
  word-break: break-word;
}

#my-notes-table-wrap {
  overflow-x: auto;
}

.actions-cell {
  display: flex;
  flex-wrap: nowrap;
  gap: 8px;
  min-width: 420px;
}

.actions-cell .button { margin-top: 0; }

.action-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  border-radius: 8px;
  font-weight: 700;
  letter-spacing: 0.01em;
  line-height: 1;
  min-height: 30px;
  padding: 6px 7px;
  white-space: nowrap;
}

.action-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 12px;
  height: 12px;
}

.action-icon svg {
  width: 12px;
  height: 12px;
  display: block;
  fill: currentColor;
}

.action-label {
  font-size: 0.66rem;
}

.action-btn.action-read,
.action-btn.action-edit {
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--ink);
}

.action-btn.action-publish {
  background: color-mix(in srgb, #1d9f79 14%, var(--card) 86%);
  border: 1px solid color-mix(in srgb, #1d9f79 34%, var(--border) 66%);
  color: #0f6b5d;
}

.action-btn.action-unpublish {
  background: color-mix(in srgb, #c9870f 14%, var(--card) 86%);
  border: 1px solid color-mix(in srgb, #c9870f 34%, var(--border) 66%);
  color: #8d5d00;
}

.action-btn.action-delete {
  background: color-mix(in srgb, #d44848 14%, var(--card) 86%);
  border: 1px solid color-mix(in srgb, #d44848 34%, var(--border) 66%);
  color: #9d2323;
}

.action-btn.icon-only {
  padding: 6px;
  min-width: 30px;
}

.action-btn.icon-only .action-label {
  display: none;
}

.activity-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.activity-list li {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px;
}

.site-dashboard-grid {
  grid-template-columns: 1.4fr 1fr;
}

.site-kpi-grid .stat-content small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.78rem;
}

.site-alerts h2 {
  margin: 0 0 10px;
}

.site-alert-item.warning {
  border-left: 4px solid #d7a214;
}

.site-alert-item.critical {
  border-left: 4px solid #c73f3f;
  background: rgba(199, 63, 63, 0.08);
}

.site-good {
  margin: 0;
  color: var(--brand);
  font-weight: 600;
}

.site-chart-wrap {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--card);
  padding: 8px;
}

.site-chart {
  width: 100%;
  height: 260px;
  display: block;
}

.site-legend {
  margin-top: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  color: var(--muted);
  font-size: 0.86rem;
}

.site-legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.site-legend i {
  width: 12px;
  height: 12px;
  border-radius: 99px;
  display: inline-block;
}

.site-funnel {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.site-funnel-row {
  display: grid;
  grid-template-columns: 180px 1fr auto;
  align-items: center;
  gap: 10px;
}

.site-funnel-label {
  color: var(--ink);
  font-size: 0.9rem;
  font-weight: 600;
}

.site-funnel-bar-wrap {
  border-radius: 999px;
  height: 10px;
  background: var(--brand-soft);
  border: 1px solid var(--border);
  overflow: hidden;
}

.site-funnel-bar {
  height: 100%;
  background: var(--brand);
  border-radius: 999px;
}

.auth-panel { max-width: 520px; margin: 0 auto; }
.auth-form p { margin: 10px 0; }
.auth-form input {
  width: 100%;
  border-radius: 10px;
  border: 1px solid var(--border);
  padding: 10px;
  font: inherit;
  background: var(--card);
  color: var(--ink);
}

label {
  display: block;
  margin: 12px 0 6px;
  font-weight: 600;
}

input[type="text"], .editor, .text-mode {
  width: 100%;
  border-radius: 10px;
  border: 1px solid var(--border);
  padding: 10px;
  font: inherit;
  background: var(--card);
  color: var(--ink);
}

.book-layout {
  display: grid;
  grid-template-columns: 230px minmax(0, 1fr);
  gap: 12px;
  margin: 12px 0;
}

.book-layout.pages-hidden {
  grid-template-columns: minmax(0, 1fr);
}

.editor-topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
  margin-bottom: 12px;
  padding: 10px 12px;
}

.editor-topbar .button {
  margin-top: 0;
}

.book-sidebar {
  padding: 12px;
  max-height: 78vh;
  overflow: auto;
}

.book-editor {
  padding: 14px;
  width: 100%;
  min-width: 0;
}

.editor-shell {
  padding: 0;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  background: transparent;
}

.editor-focus-bar {
  display: flex;
  flex-wrap: nowrap;
  justify-content: flex-start;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
  position: sticky;
  top: 66px;
  z-index: 25;
  background: linear-gradient(180deg, color-mix(in srgb, var(--card) 94%, var(--brand-soft) 6%) 0%, var(--card) 100%);
  padding: 10px;
  border: 1px solid color-mix(in srgb, var(--border) 76%, var(--brand) 24%);
  border-radius: 12px;
  box-shadow: 0 10px 20px rgba(10, 18, 26, 0.08);
  backdrop-filter: blur(6px);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.editor-focus-bar .button {
  margin-top: 0;
}

.editor-tools-toggle {
  border-color: color-mix(in srgb, var(--brand) 38%, var(--border) 62%);
  background: color-mix(in srgb, var(--brand-soft) 44%, var(--card) 56%);
  font-weight: 700;
  letter-spacing: 0.01em;
}

.quick-inline-tools {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
}

.quick-inline-tools .quick-tool-btn {
  min-height: 30px;
  min-width: 30px;
  padding: 4px 7px;
  font-size: 0.82rem;
  border: 0;
  background: transparent;
  box-shadow: none;
}

.quick-inline-tools .quick-tool-color {
  min-height: 30px;
  padding: 2px 4px;
  gap: 4px;
  border: 0;
  background: transparent;
  box-shadow: none;
}

.quick-inline-tools .quick-tool-color input[type="color"] {
  width: 22px;
  height: 22px;
}

.quick-inline-tools .quick-tool-select {
  min-width: 112px;
  min-height: 30px;
  font-size: 0.8rem;
  padding: 4px 6px;
  border: 0;
  background: transparent;
  box-shadow: none;
}

.editor-bottom-bar {
  margin-top: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.icon {
  font-size: 0.95em;
  line-height: 1;
}

.derived-meta {
  display: none;
  color: var(--muted);
  font-size: 0.92rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: min(46vw, 560px);
}

.autosave-status {
  color: var(--muted);
  font-size: 0.86rem;
  white-space: nowrap;
  margin-left: auto;
  font-weight: 600;
}

.editor-insights {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 0;
}

.editor-chip {
  border: 1px solid color-mix(in srgb, var(--border) 74%, var(--brand) 26%);
  background: color-mix(in srgb, var(--brand-soft) 64%, transparent);
  color: var(--ink);
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 0.74rem;
  letter-spacing: 0.01em;
  font-weight: 600;
}

.page-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 10px;
}

.page-tab {
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--ink);
  border-radius: 8px;
  padding: 8px;
  text-align: left;
  cursor: pointer;
  width: 100%;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.page-tab.active {
  border-color: var(--brand);
  box-shadow: 0 0 0 1px var(--brand);
  background: var(--brand-soft);
}

.page-tab.bookmarked::after {
  content: "★";
  margin-left: 6px;
  color: #e0a100;
  font-size: 0.8rem;
}

.editor { min-height: 360px; outline: none; }
.text-mode {
  min-height: 360px;
  resize: vertical;
  font-family: "Courier New", monospace;
}

.editor,
.text-mode {
  overflow-wrap: anywhere;
  word-break: break-word;
}

.editor-shell .book-layout {
  display: block;
  margin: 0;
}

.editor-shell .book-editor {
  padding: 0;
  border: 1px solid color-mix(in srgb, var(--border) 74%, var(--brand) 26%);
  box-shadow: 0 14px 30px rgba(11, 20, 30, 0.08);
  border-radius: 14px;
  background: linear-gradient(180deg, color-mix(in srgb, var(--card) 92%, #fff 8%) 0%, var(--card) 100%);
}

.editor-shell .book-editor[data-note-style-preset="professional"] {
  background: linear-gradient(180deg, color-mix(in srgb, var(--note-bg-color) 90%, #ffffff 10%) 0%, var(--note-bg-color) 100%);
}

.editor-shell .book-editor[data-note-style-preset="vibrant"] {
  background: linear-gradient(160deg, color-mix(in srgb, var(--note-bg-color) 86%, #ffe3cd 14%) 0%, color-mix(in srgb, var(--note-bg-color) 76%, #d4f2ff 24%) 100%);
}

.editor-shell .book-editor[data-note-style-preset="paper"] {
  background:
    radial-gradient(circle at 18% 18%, rgba(223, 175, 103, 0.11), transparent 34%),
    linear-gradient(180deg, color-mix(in srgb, var(--note-bg-color) 74%, #f4e8cf 26%) 0%, color-mix(in srgb, var(--note-bg-color) 70%, #e9d9b3 30%) 100%);
}

.editor-shell .book-editor[data-note-style-preset="midnight"] {
  background: linear-gradient(170deg, #172133 0%, #24324c 100%);
  border-color: color-mix(in srgb, #5d8dd7 46%, var(--border) 54%);
}

.editor-shell .editor,
.editor-shell .text-mode {
  border: 0;
  border-radius: 0;
  box-shadow: none;
  background: var(--note-bg-color);
  color: var(--note-text-color);
  padding: 12px 14px;
  min-height: 72vh;
}

.editor-shell .book-editor[data-note-font-family="serif"] .editor,
.editor-shell .book-editor[data-note-font-family="serif"] .text-mode {
  font-family: "Merriweather", Georgia, serif;
}

.editor-shell .book-editor[data-note-font-family="handwritten"] .editor,
.editor-shell .book-editor[data-note-font-family="handwritten"] .text-mode {
  font-family: "Caveat", "Segoe Print", cursive;
  font-size: 1.24rem;
  line-height: 1.6;
}

.editor-shell .book-editor[data-note-font-family="mono"] .editor,
.editor-shell .book-editor[data-note-font-family="mono"] .text-mode {
  font-family: "Courier New", "IBM Plex Mono", monospace;
}

.editor-shell .book-editor[data-note-font-family="display"] .editor,
.editor-shell .book-editor[data-note-font-family="display"] .text-mode {
  font-family: "Space Grotesk", "IBM Plex Sans", sans-serif;
}

.editor-shell .book-editor[data-note-style-preset="midnight"] .editor,
.editor-shell .book-editor[data-note-style-preset="midnight"] .text-mode {
  color: #eaf2ff;
}

.nb-note-appearance {
  display: none !important;
}

.note-design-box {
  border: 1px solid color-mix(in srgb, var(--border) 70%, var(--brand) 30%);
  background: color-mix(in srgb, var(--card) 92%, var(--brand-soft) 8%);
}

.note-color-grid {
  margin-top: 10px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.note-style-color {
  justify-content: space-between;
  gap: 8px;
  padding: 6px 8px;
}

.note-style-color span {
  font-size: 0.74rem;
  font-weight: 700;
}

.editor-shell .book-sidebar {
  position: fixed;
  right: 14px;
  top: 116px;
  width: min(340px, 92vw);
  max-height: calc(100vh - 188px);
  z-index: 55;
  background: var(--card);
  overflow: auto;
}

.tools-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.tools-head .button {
  margin-top: 0;
  padding: 6px 10px;
}

.page-admin-actions .button {
  min-width: 92px;
  justify-content: center;
}

.tools-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  border: 0;
  margin: 0;
  padding: 0;
  background: rgba(8, 12, 24, 0.28);
  cursor: pointer;
}

.editor img {
  max-width: 100%;
  border-radius: 8px;
  margin: 6px 0;
}

.editor-mode-tabs,
.rich-tools,
.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.compact-actions {
  display: flex;
  flex-wrap: nowrap;
  gap: 6px;
}

.compact-actions .button {
  margin-top: 0;
  padding: 6px 7px;
  font-size: 0.66rem;
  line-height: 1;
}

.note-actions-bar {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
}

.rich-tools {
  margin: 8px 0;
  align-items: stretch;
  display: grid;
  gap: 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}

.tool-group {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.tool-btn,
.tool-select {
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--ink);
  border-radius: 8px;
  padding: 8px 10px;
  cursor: pointer;
  min-height: 36px;
}

.tool-select {
  min-width: 120px;
}

.tool-color {
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--ink);
  border-radius: 8px;
  padding: 5px 8px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  cursor: pointer;
}

.tool-color span {
  font-weight: 700;
  font-size: 0.85rem;
}

.tool-color input[type="color"] {
  width: 24px;
  height: 24px;
  border: 0;
  padding: 0;
  background: transparent;
  cursor: pointer;
}

.tab-btn.active {
  background: var(--brand);
  color: #fff;
  border-color: var(--brand);
}

body.editor-focus-mode .topbar,
body.editor-focus-mode footer,
body.editor-focus-mode .mobile-write-fab {
  display: none !important;
}

body.editor-page .mobile-write-fab {
  display: none !important;
}

body.editor-focus-mode .container {
  width: min(1400px, 98vw);
  margin-top: 8px;
}

body.editor-focus-mode .editor-shell {
  margin-top: 4px;
}

body.editor-focus-mode .editor-focus-bar {
  top: 8px;
}

.checkbox {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
}

.checkbox input { width: auto; }
.hint { color: var(--muted); font-size: 0.9rem; }
.hidden { display: none !important; }

/* Note read focus mode - hide everything except content */
body.note-focus-mode {
  margin: 0;
}

body.note-focus-mode .topbar,
body.note-focus-mode .hero,
body.note-focus-mode .note-actions-row,
body.note-focus-mode #comments-section,
body.note-focus-mode .book-sidebar {
  display: none !important;
}

body.note-focus-mode .container {
  width: 100%;
  max-width: none;
  margin: 0;
  padding: 0;
}

body.note-focus-mode #public-read-layout {
  grid-template-columns: 1fr;
  min-height: 100vh;
}

body.note-focus-mode #public-read-content {
  border: 0;
  box-shadow: none;
  border-radius: 0;
  padding: 0;
  max-width: none;
  margin: 0;
}

body.note-focus-mode #public-read-content > h2 {
  display: none;
}

body.note-focus-mode .rich-content {
  padding: 0;
  margin: 0;
}

.focus-mode-exit {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 100;
  padding: 10px 16px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--ink);
  cursor: pointer;
  font: inherit;
  box-shadow: var(--shadow);
}

.focus-mode-exit:hover {
  border-color: var(--brand);
  background: var(--brand-soft);
}

.profile-header {
  display: flex;
  gap: 16px;
  align-items: flex-start;
}

.avatar {
  width: 96px;
  height: 96px;
  border-radius: 999px;
  object-fit: cover;
  border: 1px solid var(--border);
  background: var(--brand-soft);
}

.profile-bio {
  margin-top: 8px;
  margin-bottom: 8px;
  color: var(--ink);
  overflow-wrap: anywhere;
  word-break: break-word;
}

.profile-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.stat-chip {
  border: 1px solid color-mix(in srgb, var(--profile-accent, var(--brand)) 30%, var(--border) 70%);
  background: color-mix(in srgb, var(--profile-accent, var(--brand)) 14%, var(--brand-soft) 86%);
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 0.88rem;
}

.profile-hero {
  padding: 24px 0;
}

.profile-hero-card {
  background: linear-gradient(120deg, rgba(255,255,255,0.9), rgba(255,255,255,0.65));
  border-radius: 20px;
  box-shadow: 0 18px 35px rgba(16, 24, 46, 0.18);
  border: 1px solid rgba(255,255,255,0.4);
  padding: 24px;
}

.profile-hero-card h1 {
  margin-top: 0;
  margin-bottom: 6px;
  font-size: clamp(1.8rem, 3vw, 2.4rem);
}

.profile-hero-card p {
  margin: 0;
  color: var(--muted);
}

.profile-hero-details {
  display: flex;
  flex-direction: column;
  gap: 16px;
  flex: 1;
}

.profile-hero-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.profile-hero-actions .button {
  border-color: color-mix(in srgb, var(--profile-accent, var(--brand)) 34%, var(--border) 66%);
}

.profile-edit-grid {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  gap: 24px;
}

.profile-edit-photo {
  display: grid;
  gap: 12px;
}

.profile-edit-photo img {
  width: 160px;
  height: 160px;
  border-radius: 18px;
  object-fit: cover;
  border: 1px solid color-mix(in srgb, var(--border) 70%, var(--brand) 30%);
  box-shadow: 0 8px 18px rgba(13, 21, 33, 0.08);
}

.profile-edit-photo small {
  color: var(--muted);
  font-size: 0.85rem;
}

.profile-edit-details {
  display: grid;
  gap: 12px;
}

.profile-settings-card {
  border: 1px solid color-mix(in srgb, var(--border) 72%, var(--brand) 28%);
  border-radius: 14px;
  padding: 14px;
  background: color-mix(in srgb, var(--card) 94%, var(--brand-soft) 6%);
  box-shadow: 0 8px 18px rgba(12, 21, 34, 0.06);
}

.profile-settings-card h3 {
  margin: 0 0 10px;
  font-size: 1rem;
}

.profile-photo-preview-wrap {
  display: flex;
  justify-content: center;
}

.profile-photo-help {
  margin: 0;
  color: var(--muted);
  font-size: 0.84rem;
}

.profile-upload-control {
  display: flex;
  align-items: center;
  justify-content: center;
}

.profile-file-input {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  border: 0 !important;
}

.profile-edit-field label {
  display: block;
  margin-bottom: 4px;
  font-weight: 600;
}

.profile-edit-field input,
.profile-edit-field textarea,
.profile-edit-field select {
  border-radius: 10px;
  border: 1px solid var(--border);
  padding: 10px;
  font: inherit;
  width: 100%;
  background: var(--card);
  color: var(--ink);
}

.profile-control {
  border-radius: 10px;
  border: 1px solid color-mix(in srgb, var(--border) 72%, var(--brand) 28%) !important;
  padding: 10px;
  width: 100%;
  background: var(--card);
  color: var(--ink);
  font: inherit;
}

.profile-control-select {
  padding-right: 36px;
}

.profile-control-textarea {
  min-height: 120px;
  resize: vertical;
}

.profile-edit-field textarea {
  min-height: 120px;
  resize: vertical;
}

.profile-edit-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.profile-section-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.profile-section-heading h2 {
  margin: 0;
}

.profile-edit-panel {
  padding: 26px;
  border-radius: 18px;
}

.profile-settings-hero {
  margin-bottom: 14px;
}

.profile-edit-form {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.profile-settings-group {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  background: var(--card);
}

.profile-toggle {
  margin-top: 6px;
  margin-bottom: 6px;
}

.profile-settings-actions {
  margin-top: 14px;
}

.profile-privacy-panel {
  margin-top: 24px;
}

.profile-privacy-subtitle {
  color: var(--muted);
  margin: 2px 0 14px;
}

.privacy-block {
  padding: 14px 0;
  border-top: 1px solid var(--border);
}

.privacy-block:first-of-type {
  border-top: 0;
  padding-top: 4px;
}

.privacy-block h3 {
  margin: 0 0 6px;
}

.privacy-block p {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 0.92rem;
}

.danger-block h3 {
  color: #c62828;
}

.danger-button {
  background: #e74c3c;
  border-color: #c0392b;
  color: #fff;
}

.field-error {
  display: block;
  margin-top: 4px;
  color: #c62828;
  font-size: 0.84rem;
}

.profile-edit-top h1 {
  margin: 0;
  font-size: 1.5rem;
}

@keyframes fade-up {
  from { transform: translateY(12px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

@media (max-width: 980px) {
  .panel-grid,
  .panel-grid.sidebar-right,
  .panel-grid.sidebar-left,
  .book-layout { 
    grid-template-columns: 1fr; 
    gap: 16px;
  }
  .editor-focus-bar {
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: center;
    gap: 8px;
    padding: 8px;
    margin-bottom: 6px;
    overflow-x: auto;
  }
  .editor-focus-bar .button {
    width: auto;
    margin-top: 0;
    min-height: 36px;
    padding: 7px 10px;
    font-size: 0.84rem;
    flex: 0 0 auto;
  }
  .editor-focus-bar #toggle-tools,
  .editor-focus-bar #editor-focus-toggle {
    align-self: auto;
  }
  .quick-inline-tools {
    display: none;
  }
  .editor-bottom-bar {
    flex-direction: column;
    align-items: stretch;
  }
  .derived-meta {
    display: none;
  }
  .autosave-status {
    order: 3;
    margin-left: auto;
    white-space: nowrap;
    font-size: 0.76rem;
    flex: 0 0 auto;
  }
  .editor-topbar {
    flex-direction: column;
    align-items: stretch;
  }
  .editor-topbar .actions {
    width: 100%;
  }
  .book-sidebar {
    max-height: none;
    overflow: visible;
  }
  .book-sidebar .page-list { flex-direction: row; flex-wrap: wrap; }
  .page-tab { width: auto; }
  .read-main { min-height: 320px; padding: 18px; }
  .reader-layout {
    grid-template-columns: 1fr;
    gap: 12px;
  }
  .reader-sidebar {
    position: static;
  }
  .reader-sidebar .page-list {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 8px;
  }
  .reader-sidebar .page-tab {
    width: auto;
    max-width: 100%;
  }
  .reader-main .rich-content {
    max-width: 100%;
  }
  .editor-shell .book-editor {
    padding: 12px;
    min-height: calc(100dvh - 220px);
    display: flex;
    flex-direction: column;
  }
  .editor-shell .editor,
  .editor-shell .text-mode {
    min-height: 0;
    height: 100%;
    flex: 1 1 auto;
  }
  .comment-reply {
    margin-left: 12px;
  }
  .note-card {
    min-height: 270px;
    height: auto;
  }
  .editor-shell .book-sidebar {
    width: min(460px, 95vw);
    right: 10px;
    top: 108px;
    max-height: calc(100vh - 172px);
  }
  .site-funnel-row {
    grid-template-columns: 1fr;
    gap: 6px;
  }
}

.paywall-overlay {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 75%;
  background: linear-gradient(to bottom, transparent, var(--card) 70%);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 40px;
  text-align: center;
  z-index: 10;
}

.paywall-teaser {
  margin-top: 40px;
  position: relative;
  border-top: 1px solid var(--border);
  padding-top: 40px;
}

.paywall-content {
  background: var(--card);
  padding: 32px;
  border-radius: 20px;
  border: 1px solid var(--border);
  box-shadow: 0 15px 40px rgba(0,0,0,0.12);
  max-width: 440px;
  margin: 0 20px;
  animation: fade-up 0.5s ease;
}

.paywall-content h3 {
  margin-top: 0;
  font-size: 1.5rem;
  color: var(--ink);
}

.paywall-content p {
  color: var(--muted);
  margin-bottom: 24px;
  line-height: 1.5;
}

.paid-note-preview-text {
  margin: 8px 0 14px;
  padding: 10px 12px;
  border: 1px dashed var(--border);
  border-radius: 10px;
  background: var(--brand-soft);
  color: var(--ink);
  font-size: 0.93rem;
  line-height: 1.5;
}

.locked-mode {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 400px;
  background: var(--bg);
  border-radius: 14px;
}

.locked-mode .paywall-overlay {
  position: static;
  height: auto;
  background: transparent;
  padding: 0;
}

.preview-mode {
  position: relative;
  min-height: 400px;
}

.lock-illustration {
  background: var(--brand-soft);
  color: var(--brand);
  width: 64px;
  height: 64px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 20px;
  font-size: 24px;
}

.lock-icon {
  margin-left: auto;
  opacity: 0.5;
  font-size: 0.9em;
}

.button.large {
  padding: 14px 32px;
  font-size: 1.1rem;
  font-weight: 700;
  width: 100%;
  border-radius: 12px;
}

/* Editor Title and Page Title Enhancements */
.editor-hero {
  margin-bottom: 8px;
}

.editor-hero-bar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  transition: grid-template-columns 0.24s ease, gap 0.24s ease;
}

.editor-hero-actions {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  overflow: hidden;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.editor-icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 1px solid color-mix(in srgb, var(--border) 72%, var(--brand) 28%);
  background: color-mix(in srgb, var(--card) 94%, var(--brand-soft) 6%);
  color: var(--ink);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  font-size: 1rem;
  font-weight: 700;
  transition: transform 0.16s ease, border-color 0.16s ease, background 0.16s ease;
}

.editor-icon-btn.danger-btn {
  color: #e74c3c;
  border-color: #f5b7b1;
}

.editor-icon-btn:hover {
  transform: translateY(-1px);
  border-color: var(--brand);
}

.editor-icon-btn.danger-btn:hover {
  border-color: #e74c3c;
  background: #fdf2f2;
}

body.editor-title-editing .editor-hero-bar {
  grid-template-columns: minmax(0, 1fr) 0fr;
  gap: 0;
}

body.editor-title-editing .editor-hero-actions {
  opacity: 0;
  transform: translateX(8px);
  pointer-events: none;
}

.editor-title-input {
  font-family: "Space Grotesk", sans-serif;
  font-size: clamp(1.85rem, 3.4vw, 2.55rem);
  font-weight: 760;
  border: none !important;
  background: transparent !important;
  padding: 0 !important;
  margin: 0 0 8px !important;
  width: 100%;
  color: var(--ink);
  outline: none;
  transition: letter-spacing 0.24s ease, font-size 0.24s ease;
}

body.editor-title-editing .editor-title-input {
  letter-spacing: 0.01em;
  font-size: clamp(1.9rem, 3.7vw, 2.7rem);
}

.editor-title-input::placeholder {
  color: var(--muted);
  opacity: 0.5;
}

.page-title-editor {
  margin-bottom: 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.page-title-input {
  width: 100%;
  border-radius: 8px;
  border: 1px solid var(--border);
  padding: 8px 10px;
  font: inherit;
  background: var(--card);
  color: var(--ink);
}

/* Code Block Styling */
.code-block,
pre.code-block {
  background: var(--ink);
  color: var(--bg);
  padding: 12px;
  border-radius: 8px;
  font-family: 'Courier New', Courier, monospace;
  overflow-x: auto;
  margin: 10px 0;
  display: block;
  white-space: pre-wrap;
  word-break: break-all;
}

.code-block code {
  font-family: inherit;
  color: inherit;
}

/* Modal and User Lists */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-content {
  width: min(400px, 92vw);
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  padding: 0;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 { margin: 0; }

.user-list {
  overflow-y: auto;
  padding: 12px;
}

.activity-item {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  padding: 15px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  gap: 12px;
}

.activity-item > div {
  flex: 1;
  min-width: 200px;
}

.user-item {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.user-item .user-info {
  flex: 1;
  min-width: 150px;
}

.user-item .user-actions {
  margin-left: 0;
}

.user-item:last-child { border: 0; }

.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--brand-soft);
  border: 1px solid var(--border);
}

.user-info { display: flex; flex-direction: column; gap: 2px; }

.user-link {
  font-weight: 600;
  color: var(--ink);
  text-decoration: none;
}

.user-full-name {
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.stat-chip:hover {
  background: var(--border);
  border-color: var(--brand);
}

.user-main-line {
  display: flex;
  align-items: center;
  gap: 8px;
}

.follow-badge {
  font-size: 0.75rem;
  background: var(--brand-soft);
  color: var(--brand);
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 500;
}

.mini-follow-btn {
  margin-top: 0;
  padding: 4px 10px;
  font-size: 0.85rem;
}

/* Final Badge and Performance UI additions */
.badge {
  display: inline-block;
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
}

.status-pending { background: #fff3cd; color: #856404; }
.status-approved { background: #d4edda; color: #155724; }
.status-rejected { background: #f8d7da; color: #721c24; }
.status-completed { background: #cce5ff; color: #004085; }

.earnings-stat {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 20px;
    transition: transform 0.2s ease;
}

.earnings-stat:hover {
    transform: translateY(-2px);
}

.stat-icon {
    font-size: 2rem;
    background: var(--card);
    width: 50px;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.05);
}

.stat-content strong {
    font-size: 1.4rem;
    display: block;
}

.stat-content div {
    font-size: 0.9rem;
    color: var(--muted);
}

.note-performance-item {
    padding: 16px;
    border: 1px solid var(--border);
    border-radius: 12px;
    margin-bottom: 12px;
    list-style: none;
    background: var(--card);
    transition: border-color 0.2s;
}

.note-performance-item:hover {
    border-color: var(--brand);
}

.note-perf-title {
    font-weight: 700;
    text-decoration: none;
    color: var(--ink);
    font-size: 1.1rem;
    display: block;
    margin-bottom: 4px;
}

.note-perf-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.9rem;
    color: var(--muted);
}

.note-earned-amount {
    color: var(--brand);
    font-weight: 600;
}

.separator { opacity: 0.3; }

.note-perf-chart {
    margin-top: 12px;
    height: 6px;
    background: var(--brand-soft);
    border-radius: 10px;
    overflow: hidden;
}

.mini-bar {
    height: 100%;
    background: var(--brand);
    border-radius: 10px;
    transition: width 1s ease-out;
}

.empty-state {
    padding: 40px;
    text-align: center;
    color: var(--muted);
    font-style: italic;
    list-style: none;
}

.star-rating-input span:hover {
    transform: scale(1.2);
    display: inline-block;
}

.search-hero {
  padding: 40px 0 20px;
  text-align: center;
  max-width: 800px;
  margin: 0 auto;
}

.search-container {
  position: relative;
  display: flex;
  align-items: center;
}

.search-container input {
  width: 100%;
  padding: 18px 24px 18px 54px;
  border-radius: 16px;
  border: 2px solid var(--border);
  background: var(--card);
  color: var(--ink);
  font-size: 1.1rem;
  box-shadow: var(--shadow);
  transition: all 0.3s ease;
  outline: none;
}

.search-mode-tabs {
  margin-top: 10px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--brand-soft) 60%, transparent);
}

.search-mode-tab {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 0.82rem;
  padding: 5px 10px;
  border-radius: 999px;
  cursor: pointer;
  font-weight: 500;
}

.search-mode-tab.active {
  background: #fff;
  color: var(--brand);
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--border) 70%, var(--brand) 30%);
}

.search-hint {
  margin-top: 6px;
  font-size: 0.8rem;
  color: var(--muted);
}

.user-search-results {
  margin: 8px 0 4px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.user-search-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--card) 80%, var(--brand-soft) 20%);
  border: 1px solid color-mix(in srgb, var(--border) 82%, var(--brand) 18%);
  text-decoration: none;
  color: var(--ink);
  transition: background 0.15s ease, transform 0.12s ease, box-shadow 0.12s ease;
}

.user-search-item:hover {
  background: color-mix(in srgb, var(--brand-soft) 70%, #ffffff 30%);
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(15, 27, 39, 0.12);
}

.user-search-avatar {
  width: 28px;
  height: 28px;
  border-radius: 999px;
  object-fit: cover;
  border: 1px solid color-mix(in srgb, var(--border) 78%, var(--brand) 22%);
  background: var(--brand-soft);
}

.user-search-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.user-search-name {
  font-size: 0.86rem;
  font-weight: 600;
  line-height: 1.2;
}

.user-search-username {
  font-size: 0.78rem;
  color: var(--muted);
}

.tag-search-results {
  margin: 4px 0 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tag-search-item {
  border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--border) 80%, var(--brand) 20%);
  background: color-mix(in srgb, var(--brand-soft) 50%, #ffffff 50%);
  padding: 4px 10px;
  font-size: 0.8rem;
  cursor: pointer;
  color: var(--ink);
}

.tag-search-item:hover {
  background: color-mix(in srgb, var(--brand-soft) 80%, #ffffff 20%);
}

.search-container input:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 4px var(--brand-soft);
}

.search-icon-overlay {
  position: absolute;
  left: 20px;
  font-size: 1.4rem;
  color: var(--muted);
  pointer-events: none;
}

.feed-nav {
  display: flex;
  justify-content: center;
  gap: 32px;
  margin: 20px 0 30px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 2px;
}

.nav-tab {
  background: transparent;
  border: none;
  border-bottom: 3px solid transparent;
  padding: 12px 4px;
  color: var(--muted);
  font-weight: 600;
  cursor: pointer;
  font-size: 1rem;
  transition: all 0.2s ease;
}

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

.nav-tab.active {
  color: var(--brand);
  border-bottom-color: var(--brand);
}

.filter-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 12px;
}

.view-toggle-mini {
  display: flex;
  background: var(--brand-soft);
  padding: 4px;
  border-radius: 10px;
  gap: 2px;
}

.view-toggle-mini button {
  padding: 6px 12px;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: var(--brand);
  font-weight: 600;
  cursor: pointer;
  font-size: 0.85rem;
  transition: all 0.2s ease;
}

.view-toggle-mini button.active {
  background: white;
  box-shadow: 0 2px 6px rgba(0,0,0,0.05);
}

.tag-cloud-pro {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tag-chip {
  background: var(--card);
  border: 1px solid var(--border);
  padding: 6px 14px;
  border-radius: 99px;
  font-size: 0.88rem;
  color: var(--ink);
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.tag-chip:hover, .tag-chip.active {
  background: var(--brand);
  color: white;
  border-color: var(--brand);
  transform: translateY(-1px);
}

@media (max-width: 780px) {
  .search-hero { padding: 20px 0; }
  .search-container input { padding: 14px 20px 14px 48px; font-size: 1rem; }
  .feed-nav { gap: 16px; margin-bottom: 20px; }
  .nav-tab { font-size: 0.9rem; padding: 10px 2px; }
}

@media (max-width: 780px) {
  :root {
    --mobile-editor-toolbar-height: 62px;
    --mobile-editor-toolbar-offset: calc(var(--mobile-editor-toolbar-height) + env(safe-area-inset-bottom) + 18px);
  }
  .topbar { 
    padding: 10px 0;
  }
  .topbar-shell {
    width: min(1240px, 93vw);
    display: flex;
    gap: 10px;
  }
  .nav-toggle {
    display: inline-block;
    margin-left: auto;
    position: relative;
    z-index: 70;
  }
  .navlinks {
    display: none;
    position: fixed;
    top: 0;
    right: 0;
    width: min(84vw, 340px);
    max-width: 100vw;
    height: 100dvh;
    flex-direction: column;
    align-items: stretch;
    gap: 14px;
    border-left: 1px solid var(--border);
    border-radius: 0;
    background: var(--card);
    padding: 72px 16px calc(22px + env(safe-area-inset-bottom));
    margin-left: 0;
    box-shadow: -12px 0 32px rgba(0, 0, 0, 0.22);
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    z-index: 1200;
  }
  .nav-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.38);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    z-index: 1150;
  }
  .navlinks.open {
    display: flex;
  }
  body.nav-open .nav-backdrop {
    opacity: 1;
    pointer-events: auto;
  }
  body.nav-open {
    overflow: hidden;
  }
  .nav-primary,
  .nav-secondary {
    flex-direction: column;
    align-items: stretch;
    overflow: visible;
  }
  .nav-secondary {
    order: -1;
    border-bottom: 1px solid var(--border);
    padding-bottom: 12px;
    margin-bottom: 8px;
  }
  .nav-notifications {
    width: 100%;
  }
  .notification-bell {
    width: 100%;
    justify-content: flex-start;
    padding-inline: 12px;
  }
  .notification-bell-text {
    display: inline;
  }
  .notification-dropdown {
    position: static;
    width: 100%;
    max-height: 420px;
    margin-top: 8px;
    box-shadow: none;
  }
  .sidebar-user {
    display: block;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--brand-soft);
  }
  .sidebar-user-main {
    display: flex;
    gap: 10px;
    align-items: center;
    text-decoration: none;
    color: var(--ink);
    margin-bottom: 8px;
  }
  .sidebar-user-meta {
    display: flex;
    flex-direction: column;
    gap: 2px;
  }
.sidebar-user-meta small {
  color: var(--muted);
  font-size: 0.8rem;
}
.nav-primary .nav-profile-chip {
  display: none;
}
  .nav-more .nav-menu-label {
    margin-left: 0;
  }
  .nav-more {
    width: 100%;
  }
  .nav-more summary {
    width: 100%;
    text-align: left;
  }
  .nav-more-menu {
    position: static;
    display: flex;
    flex-direction: column;
    gap: 8px;
    background: transparent;
    border: 0;
    box-shadow: none;
    min-width: 0;
    padding: 0;
    margin-top: 8px;
  }
  .nav-more:not([open]) .nav-more-menu {
    display: none;
  }
  .nav-primary a,
  .nav-more-menu a,
  .nav-secondary a,
  .nav-secondary .link-button,
  .theme-select {
    width: 100%;
    text-align: left;
  }
  .nav-primary .nav-mobile-only {
    display: block;
  }
  .nav-primary .nav-write-link {
    display: none;
  }
  .toolbar-row { flex-direction: column; align-items: stretch; }
  .table { font-size: 0.9rem; }
  .actions-cell {
    min-width: 0;
    flex-direction: column;
    align-items: stretch;
  }
  .brand {
    font-size: 1.2rem;
  }
  .container {
    width: 100%;
    max-width: 100%;
    padding-inline: 8px;
    margin-top: 10px;
  }
  .hero h1 {
    font-size: 1.8rem;
  }
  .editor-hero-bar {
    padding-left: 6px;
    gap: 8px;
  }
  .editor-hero-actions {
    gap: 6px;
  }
  .editor-icon-btn {
    width: 32px;
    height: 32px;
    border-radius: 9px;
    font-size: 0.92rem;
  }
  .actions {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }
  .actions .button {
    width: 100%;
    text-align: center;
    margin-top: 0;
  }
  .reader-actions {
    flex-direction: row;
    align-items: stretch;
    flex-wrap: wrap;
    gap: 8px;
    position: static;
    padding: 0;
    border: 0;
    background: transparent;
  }
  .reader-actions .button {
    width: auto;
    flex: 0 0 auto;
    min-width: 0;
    margin-top: 0;
  }
  .reader-nav-btn {
    min-height: 36px;
    padding: 7px 10px;
  }
  .reader-nav-btn.icon-only {
    width: 36px;
    min-width: 36px;
    height: 36px;
    min-height: 36px;
  }
  .reader-nav-btn .action-label {
    font-size: 0.75rem;
  }
  .reader-hero {
    padding: 14px;
    border-radius: 12px;
  }
  .reader-sidebar .page-list {
    flex-wrap: nowrap;
    overflow-x: auto;
    padding-bottom: 2px;
  }
  .reader-sidebar .page-tab {
    flex: 0 0 auto;
    white-space: nowrap;
  }
  .reader-main {
    padding: 10px;
  }
  .reader-premium-toolbar {
    position: static;
    padding: 8px;
  }
  .reader-tools-group {
    width: 100%;
    flex-wrap: nowrap;
    overflow-x: auto;
    padding-bottom: 2px;
    -webkit-overflow-scrolling: touch;
  }
  .reader-premium-toolbar .button {
    flex: 0 0 auto;
    font-size: 0.76rem;
    padding: 6px 9px;
    white-space: nowrap;
  }
  .reader-main .rich-content {
    border-radius: 12px;
    padding: 12px;
  }
  .reader-context-menu {
    min-width: 170px;
    max-width: min(92vw, 240px);
    padding: 7px;
  }
  .reader-context-menu .button {
    font-size: 0.76rem;
    padding: 7px 9px;
  }
  .note-color-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
  .reader-page-nav {
    gap: 8px;
  }
  .reader-page-nav .button {
    min-width: 92px;
    padding: 7px 10px;
    font-size: 0.84rem;
  }
  .reader-page-nav-label {
    font-size: 0.8rem;
  }
  .editor-focus-bar {
    position: fixed;
    left: 10px;
    right: 10px;
    bottom: calc(env(safe-area-inset-bottom) + 8px);
    top: auto;
    z-index: 80;
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    justify-content: flex-start;
    gap: 6px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 8px;
    min-height: var(--mobile-editor-toolbar-height);
    max-height: var(--mobile-editor-toolbar-height);
    margin-bottom: 0;
    box-shadow: 0 14px 30px rgba(11, 20, 30, 0.14);
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
  }
  body.editor-focus-mode .editor-focus-bar {
    top: auto;
    bottom: calc(env(safe-area-inset-bottom) + 8px);
  }
  .editor-focus-bar > * {
    flex: 0 0 auto;
  }
  .editor-focus-bar #toggle-tools {
    width: auto;
    align-self: auto;
  }
  .editor-focus-bar .button {
    width: auto;
    flex: 0 0 auto;
    min-height: 32px;
    padding: 5px 9px;
    font-size: 0.74rem;
  }
  .quick-inline-tools {
    display: none;
  }
  .autosave-status {
    order: 3;
    margin-left: auto;
    font-size: 0.72rem;
    white-space: nowrap;
    flex: 0 0 auto;
    max-width: 34vw;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  body.editor-tools-open .editor-focus-bar {
    opacity: 0;
    pointer-events: none;
  }
  .editor-shell {
    min-height: calc(100dvh - 110px);
    padding-bottom: var(--mobile-editor-toolbar-offset);
  }
  .editor-shell form {
    padding-bottom: calc(var(--mobile-editor-toolbar-offset) + 8px);
  }
  .book-layout {
    padding-bottom: calc(var(--mobile-editor-toolbar-offset) + 8px);
  }
  .rich-tools {
    gap: 10px;
  }
  .tool-group {
    gap: 8px;
  }
  .tool-btn,
  .tool-select,
  .tool-color {
    min-height: 40px;
    font-size: 0.92rem;
  }
  .tool-select {
    min-width: 0;
    width: calc(50% - 4px);
  }
  .tool-color input[type="color"] {
    width: 28px;
    height: 28px;
  }
  .derived-meta {
    display: none;
  }
  .editor-shell .book-editor {
    padding: 10px;
    min-height: calc(100dvh - 196px - var(--mobile-editor-toolbar-offset));
    display: flex;
    flex-direction: column;
    margin-bottom: 0;
  }
  body.editor-focus-mode .container {
    width: min(100%, 100vw);
    margin: 0;
    padding-bottom: calc(var(--mobile-editor-toolbar-offset) + 14px);
  }
  body.editor-focus-mode .editor-shell {
    min-height: 100dvh;
  }
  body.editor-focus-mode .editor-shell .book-editor {
    min-height: calc(100dvh - 118px - var(--mobile-editor-toolbar-offset));
  }
  .editor-shell .editor,
  .editor-shell .text-mode {
    min-height: 0;
    height: 100%;
    flex: 1 1 auto;
    padding-bottom: 18px;
  }
  .editor-shell .book-sidebar {
    left: 10px;
    right: 10px;
    bottom: calc(var(--mobile-editor-toolbar-offset) + 10px);
    top: auto;
    width: auto;
    max-height: min(62dvh, 520px);
    border-radius: 18px 18px 14px 14px;
    box-shadow: 0 -14px 36px rgba(11, 20, 30, 0.18);
    z-index: 95;
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
  }
  body.editor-focus-mode .editor-shell .book-sidebar {
    bottom: calc(var(--mobile-editor-toolbar-offset) + 10px);
    max-height: min(62dvh, 520px);
  }
  .book-layout.pages-hidden .book-sidebar {
    display: none;
  }
  .tools-backdrop {
    background: rgba(8, 12, 24, 0.18);
    z-index: 90;
  }
  .tools-head {
    position: sticky;
    top: 0;
    z-index: 2;
    /* background: var(--card); */
    padding-bottom: 8px;
    justify-content: flex-end;
  }
  .tools-head h3 {
    display: none;
  }
  .note-card .compact-actions {
    flex-direction: row;
    align-items: center;
  }
  .note-card .compact-actions .button {
    width: auto;
  }
  .note-actions-bar {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .actions-cell {
    flex-wrap: wrap;
    min-width: 0;
  }
  .action-label {
    font-size: 0.62rem;
  }
  .reader-feedback-row {
    flex-direction: column;
    align-items: flex-start;
  }
  .reader-suggested-head {
    flex-direction: column;
  }
  .reader-suggested-controls {
    width: 100%;
    justify-content: flex-end;
  }
  .reader-suggested-track {
    grid-auto-columns: minmax(190px, 84vw);
  }
  .reader-feedback-row .button {
    width: auto;
  }
  .profile-header {
    flex-direction: column;
    align-items: flex-start;
  }
  .profile-edit-grid {
    grid-template-columns: 1fr;
  }
  .panel.toolbar-row {
    flex-direction: column;
    align-items: stretch;
  }
  .section-switch {
    justify-content: center;
  }
}

.mobile-write-fab {
  display: none;
}

@media (max-width: 780px) {
  .mobile-write-fab {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    position: fixed;
    right: 22px;
    bottom: calc(24px + env(safe-area-inset-bottom));
    width: 52px;
    height: 52px;
    border-radius: 999px;
    background: var(--brand);
    color: #fff;
    text-decoration: none;
    font-size: 1.35rem;
    font-weight: 700;
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.25);
    z-index: 1080;
  }
  body.reader-page .mobile-write-fab {
    display: none;
  }
  .mobile-write-fab-icon {
    display: inline-block;
    transform: rotate(112deg);
    line-height: 1;
  }
  body.nav-open .mobile-write-fab {
    opacity: 0;
    pointer-events: none;
  }
}

@media (max-width: 780px) {
  #cookie-banner {
    position: fixed !important;
    left: 8px !important;
    right: 8px !important;
    bottom: calc(8px + env(safe-area-inset-bottom)) !important;
    top: auto !important;
    transform: none !important;
    width: auto !important;
    max-width: none !important;
    margin: 0 !important;
    border: 1px solid var(--border) !important;
    border-radius: 12px !important;
    max-height: min(42vh, 260px) !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
    box-sizing: border-box;
    padding: 0.85rem !important;
    text-align: left !important;
    z-index: 1300 !important;
  }
  #cookie-banner p {
    margin-bottom: 0.65rem !important;
    font-size: 0.88rem !important;
    line-height: 1.4;
  }
  #cookie-banner .button {
    width: 100%;
  }
}
