/* ==========================================================================
   Avezz Immersive Reader / Article Scroll (css/pages/reader.css)
   1:1 Fidelity with UI/articles.html
   ========================================================================== */

:root {
  --reader-bg-outer: #eceef2;
  --reader-surface: #fcfbf8;
  --reader-surface-float: rgba(252, 251, 248, 0.88);
  --reader-surface-alt: #f1efe9;
  --reader-surface-hover: #e6e3db;
  --reader-border: #e3e0d8;
  --reader-text: #2c3542;
  --reader-text-strong: #0f172a;
  --reader-text-muted: #6e7785;
  --reader-accent: #1877f2;
  --reader-accent-soft: rgba(24, 119, 242, 0.12);
  --reader-like: #10b981;
  --reader-dislike: #ef4444;
  --reader-star: #eab308;
  --reader-shadow-sm: 0 2px 10px rgba(15, 23, 42, 0.08);
  --reader-shadow-lg: 0 14px 36px rgba(15, 23, 42, 0.16);
}

[data-theme="dark"] {
  --reader-bg-outer: #0b0b0d;
  --reader-surface: #161619;
  --reader-surface-float: rgba(28, 28, 32, 0.88);
  --reader-surface-alt: #232329;
  --reader-surface-hover: #2f2f37;
  --reader-border: #2c2c34;
  --reader-text: #d4d7de;
  --reader-text-strong: #f8fafc;
  --reader-text-muted: #8b92a0;
  --reader-accent: #3b82f6;
  --reader-accent-soft: rgba(59, 130, 246, 0.18);
  --reader-shadow-sm: 0 2px 12px rgba(0, 0, 0, 0.4);
  --reader-shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.55);
}

body.scroll-body {
  height: 100dvh;
  min-height: 0;
  width: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  display: flex;
  flex-direction: row;
  align-items: stretch;
  justify-content: center;
  background: var(--reader-bg-outer);
  color: var(--reader-text);
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

.reader-shell {
  position: relative;
  width: 100%;
  max-width: 780px;
  height: 100%;
  background: var(--reader-surface);
  box-shadow: 0 0 0 1px var(--reader-border), var(--reader-shadow-lg);
  overflow: hidden;
  overflow: clip;
}

/* Thin right-edge single-article progress line */
.progress-rail {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 3px;
  background: var(--reader-border);
  z-index: 30;
  pointer-events: none;
}

.progress-fill {
  width: 100%;
  height: 0%;
  background: var(--reader-accent);
  border-radius: 0 0 2px 2px;
  transition: height 0.18s ease;
}

/* Scrollable Reading Canvas */
.reader-scroll {
  position: relative;
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
  scrollbar-width: none;
  padding-bottom: calc(6.5rem + env(safe-area-inset-bottom, 0px));
}

.reader-scroll::-webkit-scrollbar {
  display: none;
}

.article-section {
  padding: calc(4rem + env(safe-area-inset-top, 0px)) 1.15rem 1.75rem;
  min-width: 0;
}

@media (min-width: 640px) {
  .article-section {
    padding: 3.5rem 2.5rem 2rem;
  }
}

.article-section + .article-section::before {
  content: "•••";
  display: block;
  text-align: center;
  padding: 0.75rem 0 2.5rem;
  color: var(--reader-text-muted);
  font-size: 18px;
  letter-spacing: 0.25em;
}

/* Author Row (left of static socials inside .article-meta-bar) */
.reader-author-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
}

.reader-author-link {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  color: inherit;
  text-decoration: none;
}

.reader-author-link:hover {
  text-decoration: none;
  opacity: 0.88;
}

.reader-author-av {
  position: relative;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, #2563eb, #0ea5e9);
  color: #ffffff;
  font-size: 13px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
}

.reader-author-av img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.reader-author-meta {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.reader-author-name {
  font-size: 14px;
  font-weight: 700;
  color: var(--reader-text-strong);
  line-height: 1.2;
}

.reader-author-date {
  font-size: 12px;
  color: var(--reader-text-muted);
  line-height: 1.3;
}

.article-title {
  font-size: clamp(1.7rem, 4vw, 2.35rem);
  line-height: 1.18;
  font-weight: 700;
  color: var(--reader-text-strong);
  margin: 0 0 12px;
  overflow-wrap: anywhere;
}

/* Author + Right Media Actions Bar */
.article-meta-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 24px;
}

/* Scrollable Categories Row (own row on top) */
.article-cats {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  padding: 2px 0;
  margin-bottom: 12px;
}

.article-cats::-webkit-scrollbar {
  display: none;
}

.cat-tag {
  display: inline-flex;
  align-items: center;
  height: 24px;
  padding: 0 10px;
  border-radius: 999px;
  background: var(--reader-surface-alt);
  color: var(--reader-text-muted);
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
  flex-shrink: 0;
  text-decoration: none;
  transition: background 0.15s ease, color 0.15s ease;
}

.cat-tag:hover {
  background: var(--reader-surface-hover);
  color: var(--reader-text-strong);
  text-decoration: none;
}

.meta-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: auto;
  flex-shrink: 0;
}

.meta-actions form {
  display: contents;
}

.meta-btn {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 0;
  background: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--reader-text-muted);
  transition: background 0.15s ease, color 0.15s ease;
}

.meta-btn:hover {
  background: var(--reader-surface-alt);
  color: var(--reader-text-strong);
}

.meta-btn.share.active {
  color: var(--reader-star);
}

.meta-btn .icon {
  width: 17px;
  height: 17px;
}

.reader-menu-wrap {
  position: relative;
}

.inline-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 168px;
  max-height: 260px;
  overflow-y: auto;
  padding: 6px;
  border-radius: 10px;
  background: var(--reader-surface);
  border: 1px solid var(--reader-border);
  box-shadow: var(--reader-shadow-lg);
  z-index: 32;
  display: none;
  flex-direction: column;
  gap: 2px;
}

.inline-menu.open {
  display: flex;
}

.inline-menu-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  padding: 7px 10px;
  border-radius: 7px;
  border: 0;
  background: none;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--reader-text);
  text-align: left;
  cursor: pointer;
  text-decoration: none;
}

.inline-menu-item-left {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.inline-menu-item .icon {
  width: 15px;
  height: 15px;
}

.inline-menu-item:hover {
  background: var(--reader-surface-alt);
  text-decoration: none;
}

.inline-menu-item.is-saved {
  color: var(--reader-accent);
}

.inline-menu-item--danger {
  color: var(--reader-dislike);
}

.article-cover {
  margin-bottom: 22px;
  border-radius: 12px;
  overflow: hidden;
  background: var(--reader-surface-alt);
}

.article-cover img {
  display: block;
  width: 100%;
  max-height: 420px;
  object-fit: cover;
}

/* Article Readable Body */
.article-body {
  min-width: 0;
  overflow-wrap: anywhere;
}

.article-body table {
  display: block;
  max-width: 100%;
  overflow-x: auto;
  margin-bottom: 1.25rem;
}

.article-body iframe,
.article-body video {
  max-width: 100%;
}

.article-body .readable {
  font-family: Georgia, "Iowan Old Style", "Palatino Linotype", serif;
  font-size: 1.08rem;
  line-height: 1.82;
  margin: 0 0 1.25rem;
  padding: 6px 10px;
  margin-left: -10px;
  margin-right: -10px;
  border-radius: 8px;
  color: var(--reader-text);
  transition: background 0.2s ease;
}

.article-body h2.readable,
.article-body h3.readable,
.article-body h4.readable {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  color: var(--reader-text-strong);
  font-weight: 700;
  line-height: 1.3;
  margin-top: 1.6rem;
}

.article-body blockquote.readable {
  border-left: 3px solid var(--reader-accent);
  padding-left: 16px;
  color: var(--reader-text-muted);
  font-style: italic;
}

.article-body pre.readable {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.9rem;
  line-height: 1.55;
  background: var(--reader-surface-alt);
  border: 1px solid var(--reader-border);
  padding: 12px 14px;
  margin-left: 0;
  margin-right: 0;
  overflow-x: auto;
}

.article-body ul {
  padding-left: 1.5rem;
  margin-bottom: 1.25rem;
}

.article-body li.readable {
  margin-bottom: 0.45rem;
}

.reader-shell[data-click-to-read="1"] .article-body .readable {
  cursor: pointer;
}

.article-body .readable:hover {
  background: rgba(128, 128, 128, 0.06);
}

.article-body .readable.speaking {
  background: var(--reader-accent-soft);
}

/* Floating Horizontal Icon Rows (Top Right: 3 | Bottom Right: 4) */
.fab-stack {
  position: absolute;
  right: 14px;
  z-index: 25;
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
}

.fab-stack--top { top: calc(12px + env(safe-area-inset-top, 0px)); }
.fab-stack--bottom { bottom: calc(16px + env(safe-area-inset-bottom, 0px)); }

.fab-btn {
  position: relative;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--reader-surface-float);
  color: var(--reader-text);
  border: 1px solid var(--reader-border);
  box-shadow: var(--reader-shadow-sm);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  cursor: pointer;
  text-decoration: none;
  transition: transform 0.12s ease, background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.fab-btn .icon {
  width: 18px;
  height: 18px;
}

.fab-btn[hidden] { display: none; }
.fab-btn:hover { background: var(--reader-surface-alt); color: var(--reader-text-strong); text-decoration: none; }
.fab-btn:active { transform: scale(0.93); }
.fab-btn.is-active { background: var(--reader-accent); color: #ffffff; border-color: var(--reader-accent); }
.fab-btn.is-like { color: var(--reader-like); border-color: var(--reader-like); }
.fab-btn.is-dislike { color: var(--reader-dislike); border-color: var(--reader-dislike); }

.fab-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 17px;
  height: 17px;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--reader-accent);
  color: #ffffff;
  font-size: 10px;
  font-weight: 700;
  line-height: 17px;
  text-align: center;
  box-shadow: 0 0 0 2px var(--reader-surface);
}

/* Dropdown Popovers (TTS Config & Stack Jump) */
.reader-popover {
  position: absolute;
  top: calc(58px + env(safe-area-inset-top, 0px));
  right: 14px;
  width: 268px;
  max-width: calc(100% - 28px);
  max-height: 75dvh;
  overflow-y: auto;
  background: var(--reader-surface);
  border: 1px solid var(--reader-border);
  border-radius: 12px;
  box-shadow: var(--reader-shadow-lg);
  padding: 12px;
  z-index: 35;
  display: none;
  flex-direction: column;
  gap: 10px;
}

.reader-popover.open {
  display: flex;
}

.pop-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  font-weight: 700;
  color: var(--reader-text-strong);
  padding-bottom: 6px;
  border-bottom: 1px solid var(--reader-border);
}

.pop-head button {
  background: none;
  border: 0;
  color: var(--reader-text-muted);
  cursor: pointer;
  padding: 2px;
  display: inline-flex;
}

.pop-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--reader-text-muted);
}

.pop-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  background: none;
  border: 0;
  padding: 2px 0;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--reader-text);
  cursor: pointer;
}

.pop-select {
  width: 100%;
  height: 32px;
  padding: 0 8px;
  border-radius: 8px;
  border: 1px solid var(--reader-border);
  background: var(--reader-surface-alt);
  color: var(--reader-text-strong);
  font-size: 12.5px;
  outline: 0;
}

.pop-range {
  width: 100%;
  accent-color: var(--reader-accent);
  cursor: pointer;
}

.reader-switch {
  position: relative;
  width: 36px;
  height: 20px;
  border-radius: 999px;
  background: var(--reader-border);
  flex-shrink: 0;
  transition: background 0.15s ease;
  display: inline-block;
}

.reader-switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #ffffff;
  transition: transform 0.15s ease;
}

.reader-switch[aria-checked="true"] {
  background: var(--reader-accent);
}

.reader-switch[aria-checked="true"]::after {
  transform: translateX(16px);
}

.stack-item {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  width: 100%;
  border: 0;
  background: none;
  padding: 8px 10px;
  border-radius: 8px;
  text-align: left;
  color: var(--reader-text);
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s ease;
}

.stack-item:hover { background: var(--reader-surface-alt); text-decoration: none; }
.stack-item[aria-current="true"] { background: var(--reader-accent-soft); color: var(--reader-accent); }
.stack-item-kicker { font-size: 10.5px; font-weight: 700; text-transform: uppercase; opacity: 0.7; }
.stack-item-title { font-size: 13px; font-weight: 600; }

/* Comments Bottom Sheet */
.reader-sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  z-index: 40;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.reader-sheet-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

.comments-sheet {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 72%;
  background: var(--reader-surface);
  color: var(--reader-text);
  border-radius: 18px 18px 0 0;
  box-shadow: var(--reader-shadow-lg);
  z-index: 45;
  display: flex;
  flex-direction: column;
  transform: translateY(100%);
  visibility: hidden;
  pointer-events: none;
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1), visibility 0s linear 0.3s;
}

.comments-sheet.open {
  transform: translateY(0);
  visibility: visible;
  pointer-events: auto;
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1), visibility 0s linear 0s;
}

.sheet-handle-wrap {
  display: flex;
  justify-content: center;
  padding: 10px 0 4px;
  cursor: pointer;
}

.sheet-handle {
  width: 38px;
  height: 4px;
  border-radius: 999px;
  background: var(--reader-border);
}

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 16px 12px;
  border-bottom: 1px solid var(--reader-border);
}

.sheet-head button {
  background: none;
  border: 0;
  color: var(--reader-text-muted);
  cursor: pointer;
  padding: 4px;
  display: inline-flex;
}

.sheet-title { font-size: 15px; font-weight: 700; color: var(--reader-text-strong); }
.sheet-sub { font-size: 12px; color: var(--reader-text-muted); }

.sheet-list {
  flex: 1;
  overflow-y: auto;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.sheet-list .disc-tree {
  width: 100%;
}

.sheet-input-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--reader-border);
  background: var(--reader-surface-alt);
}

.sheet-input {
  flex: 1;
  height: 38px;
  padding: 0 14px;
  border-radius: 999px;
  border: 1px solid var(--reader-border);
  background: var(--reader-surface);
  color: var(--reader-text-strong);
  font-size: 13.5px;
  outline: 0;
}

.sheet-input:focus { border-color: var(--reader-accent); }

.sheet-send {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 0;
  background: var(--reader-accent);
  color: #ffffff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  cursor: pointer;
}

.reader-empty {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 24px;
  text-align: center;
}
