/* Palette + type system inspired by akicreate.com: a near-monochrome base
   (true black/white, not tinted grays) with a single restrained blue
   accent, a clean grotesque for UI/body text, and a serif reserved for
   headings -- the contrast between the two is the whole visual identity,
   so most components deliberately don't introduce more color than that. */
:root {
  --bg: #0c0d0f;
  --bg-elevated: #17181b;
  --border: #2a2e37;
  --text: #ededee;
  --text-muted: #9aa1ab;
  --accent: #6ea8fe;
  --accent-hover: #8fbbfe;
  --danger: #ff8080;
  --success: #7ee2a8;
  --radius: 6px;
  --header-height: 60px;
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  --font-serif: 'Playfair Display', Georgia, 'Times New Roman', serif;
  /* Without this, native controls (a <select>'s own dropdown popup,
     scrollbars, checkboxes) ignore our CSS colors entirely and render
     with the OS's light-mode defaults -- pale text on a white popup,
     unreadable against a dark page. This tells the browser to draw them
     dark-appropriate instead. */
  color-scheme: dark;
}

:root[data-theme="light"] {
  --bg: #ffffff;
  --bg-elevated: #f3f3f4;
  --border: #dedfe2;
  --text: #14161a;
  --text-muted: #6b6d72;
  --accent: #2f66c9;
  --accent-hover: #1f4fa8;
  --danger: #c8392f;
  --success: #1f8a4c;
  color-scheme: light;
}

* { box-sizing: border-box; }

::selection { background: rgba(110, 168, 254, 0.3); color: inherit; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  line-height: 1.5;
  transition: background-color 0.15s ease, color 0.15s ease;
}

h1, h2, h3 { font-family: var(--font-serif); font-weight: 700; }

a { color: var(--accent); text-decoration: none; transition: color 0.12s ease; }
a:hover { color: var(--accent-hover); text-decoration: underline; }

button { transition: background-color 0.12s ease, color 0.12s ease, border-color 0.12s ease; }

a:focus-visible, button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--header-height);
  padding: 0 1.5rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 30;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-family: var(--font-serif);
  font-weight: 700;
  font-size: 1.25rem;
  color: var(--text);
}
.brand:hover { color: var(--accent); text-decoration: none; }
.brand-mark { flex-shrink: 0; }

.site-nav { display: flex; align-items: center; gap: 1rem; }
/* Username + theme toggle travel together and are pushed to the far right
   via the auto margin -- keeps them right-most even when the nav wraps
   onto its own line on narrow screens, independent of Search/Popular/
   Log out which stay left-aligned. */
.nav-account { display: flex; align-items: center; gap: 0.75rem; margin-left: auto; }
.nav-email {
  color: var(--text-muted);
  font-size: 0.9rem;
  display: inline-block;
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: middle;
}

.theme-toggle-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.1rem;
  height: 2.1rem;
  background: none;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
}
.theme-toggle-btn:hover { color: var(--text); border-color: var(--accent); }
.theme-toggle-btn .theme-icon-dark { display: none; }
:root[data-theme="light"] .theme-toggle-btn .theme-icon-dark { display: inline; }
:root[data-theme="light"] .theme-toggle-btn .theme-icon-light { display: none; }

.logout-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: none;
  border: none;
  padding: 0;
  color: var(--accent);
  font: inherit;
  cursor: pointer;
}
.logout-btn:hover { color: var(--accent-hover); text-decoration: underline; }
.logout-icon { display: none; }

.link-button {
  background: none;
  border: none;
  padding: 0;
  color: var(--accent);
  cursor: pointer;
  font: inherit;
}
.link-button:hover { color: var(--accent-hover); text-decoration: underline; }

.logout-form, .inline-form { display: inline; }

main {
  max-width: 640px;
  margin: 0 auto;
  padding: 2.5rem 1.5rem;
}

.home-page { max-width: 760px; padding-top: 3.5rem; }

.cta {
  display: inline-block;
  margin-top: 1.75rem;
  padding: 0.7rem 1.6rem;
  background: var(--text);
  color: var(--bg);
  border-radius: 999px;
  font-weight: 600;
  transition: transform 0.15s ease, opacity 0.15s ease;
}
.cta:hover { opacity: 0.82; transform: translateY(-1px); text-decoration: none; }

/* Marketing pages (logged-out: home, login, signup, forgot/reset-password,
   check-email, invalid-link screens): generous whitespace, a serif display
   headline (see the global h1 rule), and understated rise-in motion --
   inspired by akicreate.com's near-monochrome restraint rather than a
   loud multi-color treatment. Scoped to these pages only; the reader/
   search/sidebar stay fully plain since extra color/motion there would
   fight readability. */
@keyframes m-rise {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

.marketing-page h1 {
  font-size: clamp(2.5rem, 6vw, 4.25rem);
  line-height: 1.08;
  margin: 0 0 0.75rem;
  animation: m-rise 0.6s ease both;
}

.marketing-page > p {
  font-size: 1.2rem;
  color: var(--text-muted);
  max-width: 34ch;
  animation: m-rise 0.6s ease 0.08s both;
}

.marketing-page a:not(.cta):not(.link-button):not(.brand) { position: relative; }
.marketing-page a:not(.cta):not(.link-button):not(.brand)::after {
  content: '';
  position: absolute;
  left: 0;
  right: 100%;
  bottom: -2px;
  height: 1px;
  background: currentColor;
  transition: right 0.2s ease;
}
.marketing-page a:not(.cta):not(.link-button):not(.brand):hover::after { right: 0; }
.marketing-page a:not(.cta):not(.link-button):not(.brand):hover { text-decoration: none; }

.marketing-page .cta { animation: m-rise 0.6s ease 0.16s both; }
.marketing-page .auth-form { animation: m-rise 0.6s ease 0.1s both; }

/* Homepage letter grid: a small interactive flourish (see public/js/home.js)
   -- hovering a row flips its letters from a random decoy into a hidden
   word, "TEXT" then "RANT" top to bottom, spelling the product name. Purely
   decorative (aria-hidden), inspired by the reveal-grid on akicreate.com. */
.letter-grid {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  margin: 3rem 0 1rem;
  animation: m-rise 0.6s ease 0.24s both;
}
.letter-grid-row { display: flex; gap: 0.5rem; }
.letter-cell {
  width: 2.75rem;
  height: 2.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.letter-cell span {
  font-family: var(--font-sans);
  font-size: 1rem;
  color: var(--text-muted);
}
.letter-cell span.revealed {
  font-family: var(--font-serif);
  font-weight: 700;
  font-size: 1.3rem;
  color: var(--text);
}
@keyframes letter-flip {
  0% { opacity: 1; transform: translateY(0); }
  45% { opacity: 0; transform: translateY(-8px); }
  55% { opacity: 0; transform: translateY(8px); }
  100% { opacity: 1; transform: translateY(0); }
}
.letter-cell span.flipping { animation: letter-flip 0.32s ease; }

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-top: 1.25rem;
}

.auth-form label { font-size: 0.85rem; color: var(--text-muted); margin-top: 0.65rem; }

.auth-form input {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.55rem 0.7rem;
  color: var(--text);
  font-size: 1rem;
}
.auth-form input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.field-hint { margin: 0.15rem 0 0; font-size: 0.8rem; color: var(--text-muted); }

.cf-turnstile { margin-top: 0.9rem; }

.auth-form button {
  margin-top: 1.25rem;
  padding: 0.6rem 1rem;
  background: var(--accent);
  color: #0c0d0f;
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
}
.auth-form button:hover { background: var(--accent-hover); }

.auth-alt-link { margin-top: 1rem; font-size: 0.9rem; color: var(--text-muted); }

.form-errors {
  color: var(--danger);
  background: rgba(255, 128, 128, 0.08);
  border: 1px solid rgba(255, 128, 128, 0.3);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  margin: 1rem 0 0;
  font-size: 0.9rem;
}

.flash { border-radius: var(--radius); padding: 0.75rem 1rem; margin: 1rem 0 0; font-size: 0.9rem; }
.flash-success { color: var(--success); background: rgba(126, 226, 168, 0.08); border: 1px solid rgba(126, 226, 168, 0.3); }
.flash-error { color: var(--danger); background: rgba(255, 128, 128, 0.08); border: 1px solid rgba(255, 128, 128, 0.3); }

.search-page, .books-page { max-width: 820px; }

/* One seamless bar (shared background/border on the form itself, with
   overflow:hidden clipping each child to its rounded corners) instead of
   three separate pill-shaped controls -- gives the text input the rest of
   the room to stretch instead of competing for width with two more boxes
   that each carry their own border/background/radius. */
.search-form {
  display: flex;
  align-items: stretch;
  margin-top: 1rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.search-form input[type="text"] {
  flex: 1;
  min-width: 0;
  background: none;
  border: none;
  padding: 0.7rem 0.9rem;
  color: var(--text);
  font-size: 1rem;
}
.search-form select {
  background: none;
  border: none;
  border-left: 1px solid var(--border);
  border-right: 10px solid var(--bg-elevated);
  color: var(--text);
  padding: 0.7rem 0.6rem 0.7rem 0.6rem;
  font-size: 0.9rem;
  color-scheme: inherit;
}
/* color-scheme on :root is meant to make the browser render the popup
   list itself (background + text) in the right palette, but Chrome/Edge
   don't always carry that through to the option list reliably -- explicit
   colors on the options themselves are what's actually guaranteed to be
   honored, so set them directly rather than relying on inheritance alone. */
.search-form option {
  background-color: var(--bg-elevated);
  color: var(--text);
}
.search-form button {
  padding: 0.7rem 1.4rem;
  background: var(--accent);
  color: #0c0d0f;
  border: none;
  border-left: 1px solid rgba(0, 0, 0, 0.15);
  font-weight: 600;
  cursor: pointer;
}
.search-form button:hover { background: var(--accent-hover); }

.result-summary { color: var(--text-muted); font-size: 0.9rem; margin-top: 1.5rem; }
.fallback-note { color: var(--accent); }

.result-list { list-style: none; padding: 0; margin: 1rem 0; }
.result-item {
  padding: 0.9rem 0;
  border-bottom: 1px solid var(--border);
}
.result-title { font-size: 1.05rem; font-weight: 600; }
/* Author name and the badge row are stacked rather than sharing one flex
   row -- previously a long, wrapping author name (default align-items:
   stretch) forced the lang/comment/like badges to stretch to match its
   full wrapped height, making them look like tall, oddly-shaped blocks
   instead of compact pills. */
.result-meta { display: flex; flex-direction: column; gap: 0.35rem; color: var(--text-muted); font-size: 0.85rem; margin-top: 0.3rem; }
.result-authors { display: block; }
.result-stats { display: flex; align-items: center; flex-wrap: wrap; gap: 0.5rem; }
.lang-tag, .popularity-tag {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  height: 1.4rem;
  line-height: 1;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0 0.4rem;
  font-size: 0.75rem;
  color: var(--text-muted);
}
.lang-tag { text-transform: uppercase; }
.popularity-tag .tag-icon { font-size: 0.85rem; }
.result-subjects { color: var(--text-muted); font-size: 0.8rem; margin-top: 0.3rem; }

.pagination {
  display: flex;
  align-items: center;
  gap: 1rem;
  justify-content: center;
  margin: 2rem 0;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.reader-layout {
  display: flex;
  align-items: flex-start;
}

/* The sidebar is position:fixed (stays put while the reader text scrolls
   past it), so it no longer reserves flex space on its own -- this class
   is toggled from reader.js whenever the sidebar is shown on a wide-enough
   viewport, so the centered reader column shifts left instead of running
   underneath it. */
.reader-layout.sidebar-visible {
  padding-right: 340px;
}

.reader-page {
  flex: 1;
  max-width: 700px;
  margin: 0 auto;
  padding: 2.5rem 1.5rem;
}

.reader-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; }
.reader-title { margin-bottom: 0.2rem; }
.reader-author { color: var(--text-muted); margin-top: 0; }

.save-toggle-btn {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  margin-top: 0.3rem;
  padding: 0.4rem 0.9rem;
  background: none;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text-muted);
  font-size: 0.85rem;
  cursor: pointer;
}
.save-toggle-btn:hover { border-color: var(--accent); color: var(--text); }
.save-toggle-btn .save-icon { font-size: 0.9rem; }
.save-toggle-btn.saved { border-color: var(--accent); color: var(--accent); }
.save-toggle-btn.saved .save-icon { color: var(--accent); }

.reader-text {
  font-size: 1.05rem;
  line-height: 1.75;
}
.reader-text p { margin: 0 0 1.1rem; }
.reader-text p::selection { background: rgba(110, 168, 254, 0.35); }

.reader-scroll-sentinel {
  height: 2.5rem;
  margin-top: 1rem;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.reader-sidebar {
  width: 340px;
  flex-shrink: 0;
  border-left: 1px solid var(--border);
  padding: 1.75rem 1.6rem;
  background: var(--bg-elevated);
  font-size: 0.95rem;
  line-height: 1.55;
  position: fixed;
  top: var(--header-height);
  right: 0;
  bottom: 0;
  overflow-y: auto;
  z-index: 20;
}
.reader-sidebar[hidden] { display: none; }

.sidebar-toggle-btn {
  display: flex;
  position: fixed;
  top: calc(var(--header-height) + 0.9rem);
  right: 0.9rem;
  z-index: 40;
  width: 2.5rem;
  height: 2.5rem;
  align-items: center;
  justify-content: center;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text);
  font-size: 1.1rem;
  cursor: pointer;
}
.sidebar-toggle-btn:hover { border-color: var(--accent); color: var(--accent); }
/* .sidebar-visible is only ever added on desktop (see setSidebarVisible in
   reader.js -- it's deliberately excluded on mobile, where the sidebar is
   an overlay instead of a layout push). At that width the sidebar already
   has its own #sidebar-close "x", so the floating toggle would just be a
   redundant second close control sitting on top of it. */
.reader-layout.sidebar-visible .sidebar-toggle-btn { display: none; }

.sidebar-close-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  margin: 0 0 1.1rem;
  background: none;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text-muted);
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
}
.sidebar-close-btn:hover { border-color: var(--accent); color: var(--accent); }

.sidebar-tabs { display: flex; gap: 0.6rem; margin: 0 0 1.4rem; }
.sidebar-tab {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: var(--radius);
  padding: 0.5rem 1rem;
  cursor: pointer;
  font: inherit;
  font-size: 0.9rem;
}
.sidebar-tab.active { color: var(--text); border-color: var(--accent); }

.sidebar-word { margin: 0 0 0.9rem; text-transform: capitalize; font-size: 1.3rem; }
.sidebar-loading, .sidebar-empty { color: var(--text-muted); font-size: 0.92rem; line-height: 1.6; }

.definition-list { padding-left: 1.4rem; margin: 0.6rem 0; }
.definition-list li { margin-bottom: 1.1rem; font-size: 0.95rem; line-height: 1.55; }
.pos-tag {
  text-transform: uppercase;
  font-size: 0.7rem;
  color: var(--accent);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.1rem 0.35rem;
  margin-right: 0.45rem;
}
.def-example { color: var(--text-muted); font-size: 0.85rem; margin-top: 0.4rem; padding-left: 0.1rem; }

.reader-sidebar h3 { font-size: 0.8rem; letter-spacing: 0.03em; text-transform: uppercase; color: var(--text-muted); margin: 1.75rem 0 0.6rem; }
.word-tags { font-size: 0.92rem; line-height: 1.6; margin: 0; }

/* --hl-intensity (0.25-1) is set inline per <mark> from its combined
   comment + like count (see highlightIntensity() in reader.js) -- more
   activity on a passage means a slightly stronger gradient, not just a
   flat highlight color. Deliberately subtle: this is a reading surface,
   not a search-result snippet, so it should read as a faint wash, not a
   marker-pen yellow box. background-color is explicitly killed because
   the browser's default UA stylesheet gives <mark> a solid yellow
   background that would otherwise show through underneath the gradient. */
.reader-text mark.hl {
  --hl-intensity: 0.25;
  background-color: transparent;
  background-image: linear-gradient(
    180deg,
    rgba(110, 168, 254, calc(var(--hl-intensity) * 0.22)) 0%,
    rgba(110, 168, 254, calc(var(--hl-intensity) * 0.08)) 100%
  );
  color: inherit;
  border-bottom: 1px solid rgba(110, 168, 254, calc(0.12 + var(--hl-intensity) * 0.28));
  cursor: pointer;
  transition: background-image 0.2s ease, border-color 0.2s ease;
}
.reader-text mark.hl:hover {
  background-image: linear-gradient(
    180deg,
    rgba(110, 168, 254, calc(var(--hl-intensity) * 0.22 + 0.06)) 0%,
    rgba(110, 168, 254, calc(var(--hl-intensity) * 0.08 + 0.06)) 100%
  );
}

.hl-quote {
  margin: 0 0 1.25rem;
  padding: 0.7rem 0.9rem;
  border-left: 3px solid var(--accent);
  border-radius: 0 var(--radius) var(--radius) 0;
  background: var(--bg);
  color: var(--text-muted);
  font-size: 0.9rem;
  line-height: 1.55;
  font-style: italic;
}

.back-to-threads {
  display: block;
  font-size: 0.8rem;
  margin: 0 0 1.25rem;
  padding-bottom: 0.9rem;
  border-bottom: 1px solid var(--border);
}

.sidebar-hint { color: var(--text-muted); font-size: 0.8rem; margin: 0 0 1rem; }

.thread-overview-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 0.75rem; }
.thread-overview-item {
  cursor: pointer;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.9rem 1rem;
  transition: border-color 0.12s ease, background-color 0.12s ease;
}
.thread-overview-item:hover { border-color: var(--accent); background: var(--bg); }
.thread-overview-item .hl-quote { margin-bottom: 0.6rem; background: none; padding: 0.1rem 0.75rem; }
.thread-comment-count { color: var(--text-muted); font-size: 0.8rem; }

.comment-count-header { margin: 0 0 1rem; padding-bottom: 0.9rem; border-bottom: 1px solid var(--border); }
.comment-count-header h2 { font-size: 1.05rem; margin: 0; }
.comment-count-header p { color: var(--text-muted); font-size: 0.8rem; margin: 0.15rem 0 0; }

/* Composer is a single shared box: default state posts a new top-level
   comment. Clicking "Reply" on any comment just relabels it and points it
   at that comment's id (see reply-toggle handler in reader.js) instead of
   spawning a form per comment -- Cancel (or a successful submit) always
   drops it back to the default. */
.composer { margin-bottom: 1.25rem; }
.composer-context[hidden] { display: none; }
.composer-context {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  font-size: 0.78rem;
  color: var(--text-muted);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 0.5rem 0.75rem;
}
.composer-context strong { color: var(--text); }
.composer-context + .composer-form textarea { border-radius: 0 0 var(--radius) var(--radius); }

.comment-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 0.6rem; }

.comment { font-size: 0.88rem; line-height: 1.45; }

.comment-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 0.9rem;
}

.comment-head { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.4rem; }
.comment-avatar {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.68rem;
  font-weight: 700;
  color: #0c0d0f;
}
.comment-author { font-weight: 700; font-size: 0.85rem; color: var(--text); }
.comment-time { color: var(--text-muted); font-size: 0.72rem; }
.comment-body { color: var(--text); }
.comment-actions { display: flex; align-items: center; gap: 0.9rem; margin-top: 0.5rem; }
.reply-toggle { font-size: 0.75rem; display: inline-flex; align-items: center; gap: 0.3rem; }
.reply-icon { font-size: 0.85rem; }

/* Replies are indented as their own cards rather than nested inside a
   shared tinted box -- keeps each reply visually distinct like the parent
   comment while the indent + tighter gap still reads as "part of this
   thread" at a glance, even several levels deep. */
.comment-list .comment-list {
  margin: 0.6rem 0 0;
  padding-left: 1.4rem;
  gap: 0.5rem;
}
.comment-list .comment-list .comment-card { padding: 0.6rem 0.8rem; }

.like-button {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.8rem;
  cursor: pointer;
  padding: 0;
}
.like-button .like-icon { font-size: 0.9rem; transition: transform 0.15s ease; }
.like-button:hover { color: var(--text); }
.like-button.liked { color: #ff6b6b; }
.like-button.liked .like-icon { transform: scale(1.15); }

.composer-form, #new-thread-form {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}
.composer-form textarea, #new-thread-form textarea {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 0.65rem 0.75rem;
  font: inherit;
  line-height: 1.5;
  resize: vertical;
}
.composer-form button, #new-thread-form button {
  align-self: flex-start;
  padding: 0.45rem 1.1rem;
  background: var(--accent);
  color: #0c0d0f;
  border: none;
  border-radius: var(--radius);
  font-weight: 600;
  cursor: pointer;
}
.composer-form button:hover, #new-thread-form button:hover { background: var(--accent-hover); }

.profile-page { max-width: 720px; }
.profile-username { color: var(--text-muted); margin-top: -0.5rem; }
.profile-page h2 { font-size: 1.1rem; margin: 2rem 0 0.75rem; }

/* Deliberately dense/compact -- one line per book, not a card grid --
   since this is meant to be a quick "what am I reading" glance, not a
   showcase. */
.saved-list { list-style: none; padding: 0; margin: 0; }
.saved-item {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  padding: 0.55rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.92rem;
}
.saved-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.saved-author { color: var(--text-muted); font-size: 0.85rem; flex-shrink: 0; }
.saved-page { margin-left: auto; color: var(--text-muted); font-size: 0.8rem; flex-shrink: 0; }
.saved-remove { font-size: 0.8rem; flex-shrink: 0; }

.error-page { text-align: center; }

.site-footer {
  text-align: center;
  padding: 1.5rem;
  color: var(--text-muted);
  font-size: 0.85rem;
  border-top: 1px solid var(--border);
  margin-top: 3rem;
}

@media (max-width: 900px) {
  .reader-layout { flex-direction: column; }
  .reader-layout.sidebar-visible { padding-right: 0; }

  /* On mobile the sidebar is an overlay panel, only ever shown via
     #sidebar-toggle -- see reader.js, which deliberately never sets
     sidebar.hidden = false on its own below this width. */
  .reader-sidebar {
    width: 100%;
    max-width: 360px;
    border-left: 1px solid var(--border);
    border-top: none;
    box-shadow: -8px 0 24px rgba(0, 0, 0, 0.35);
  }
}

@media (max-width: 600px) {
  /* The header can wrap onto two lines here (brand + nav no longer fit on
     one row), so its real height grows past the 60px desktop value. Bump
     the shared --header-height var to match (with extra headroom) so
     everything anchored to it (.reader-sidebar, .sidebar-toggle-btn)
     lands comfortably below the header instead of hugging/overlapping it. */
  :root { --header-height: 7rem; }
  .site-header { flex-wrap: wrap; gap: 0.75rem; height: auto; min-height: 7rem; padding: 1rem; }
  /* Full-width so nav-account's margin-left:auto has room to actually
     reach the right edge of the screen, leaving Search/Popular hugging
     the left and username+theme-toggle+logout hugging the right. */
  .site-nav { flex-wrap: wrap; gap: 0.6rem; width: 100%; }
  .nav-email { max-width: 90px; font-size: 0.85rem; }
  .sidebar-toggle-btn { top: calc(var(--header-height) + 1.1rem); }

  /* Matches .theme-toggle-btn's circular treatment so the two sit side by
     side as a matched pair, icon-only, hugging the right edge. */
  .logout-btn {
    width: 2.1rem;
    height: 2.1rem;
    justify-content: center;
    border: 1px solid var(--border);
    border-radius: 999px;
    color: var(--text-muted);
    font-size: 1rem;
    line-height: 1;
    gap: 0;
  }
  .logout-btn:hover { color: var(--text); border-color: var(--accent); text-decoration: none; }
  .logout-icon { display: inline; }
  .logout-label { display: none; }
  main, .reader-page { padding: 1.75rem 1.1rem; }
  /* Input keeps the full first row; language + button share the second
     row 50/50, with a top divider replacing the (now line-broken) left
     divider so it still reads as one bar instead of a stray border.
     Forcing the input's flex-basis to 100% is what actually pushes the
     other two onto their own row -- without it, all three could still
     shrink to fit on one line (flex items shrink to min-content by
     default), which is what was squeezing the input down to a sliver
     while the select stayed at its natural, much wider size. */
  .search-form { flex-wrap: wrap; }
  .search-form input[type="text"] { flex: 1 1 100%; }
  .search-form select { flex: 1 1 50%; border-left: none; border-top: 1px solid var(--border); }
  .search-form button { flex: 1 1 50%; }
  .reader-heading { flex-wrap: wrap; }
  .saved-item { flex-wrap: wrap; }
  .saved-title { white-space: normal; flex-basis: 100%; }
  .saved-page { margin-left: 0; }
}
