/* =========================================================
   MUJI Minimalist Editorial Style — Mobile-First Reader
   ========================================================= */

:root,
[data-theme="paper"] {
  --bg: #F7F5F0;
  --surface: #FDFCFA;
  --surface-alt: #EFECE4;
  --border: #E4E0D6;
  --border-strong: #CEC9BC;
  --ink: #2B2A28;
  --ink-secondary: #68655E;
  --ink-muted: #98948A;
  --accent: #7F0019;
  --accent-soft: rgba(127, 0, 25, 0.08);
  --backdrop: rgba(28, 27, 25, 0.36);
  --chrome-bg: rgba(247, 245, 240, 0.94);
}

[data-theme="warm"] {
  --bg: #EFE7D8;
  --surface: #F6F0E4;
  --surface-alt: #E5DBCA;
  --border: #DCD0BC;
  --border-strong: #C5B7A0;
  --ink: #362E25;
  --ink-secondary: #6E6152;
  --ink-muted: #9A8D7B;
  --accent: #7F0019;
  --accent-soft: rgba(127, 0, 25, 0.08);
  --backdrop: rgba(34, 28, 21, 0.4);
  --chrome-bg: rgba(239, 231, 216, 0.94);
}

[data-theme="dark"] {
  --bg: #181715;
  --surface: #201F1C;
  --surface-alt: #282623;
  --border: #302E2A;
  --border-strong: #45423C;
  --ink: #D8D4CB;
  --ink-secondary: #9C988F;
  --ink-muted: #706D66;
  --accent: #B84253;
  --accent-soft: rgba(184, 66, 83, 0.14);
  --backdrop: rgba(0, 0, 0, 0.6);
  --chrome-bg: rgba(24, 23, 21, 0.94);
}

:root {
  --font-sans: "Noto Sans SC", -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --font-serif: "Noto Serif SC", "Songti SC", "STSong", "SimSun", Georgia, serif;
  --reader-font: var(--font-serif);
  --reader-size: 18px;
  --reader-lh: 1.95;
  --reader-indent: 2em;
  --max-catalog: 680px;
  --max-reader: 660px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

*,
*::before,
*::after {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html {
  font-size: 16px;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--ink);
  line-height: 1.6;
  min-height: 100dvh;
  transition: background-color 0.2s ease, color 0.2s ease;
}

button,
input {
  font-family: inherit;
  color: inherit;
}

button {
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
}

.hidden {
  display: none !important;
}

/* ================= READING PROGRESS BAR ================= */
.progress-track {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  z-index: 90;
  background: transparent;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.progress-track.active {
  opacity: 1;
}

.progress-bar {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width 0.1s linear;
}

/* ================= CATALOG HEADER ================= */
.site-header {
  position: sticky;
  top: 0;
  z-index: 30;
  background: var(--chrome-bg);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  padding-top: var(--safe-top);
}

.header-inner {
  max-width: var(--max-catalog);
  margin: 0 auto;
  padding: 16px 20px 0;
}

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

.brand-mark {
  width: 10px;
  height: 28px;
  background: var(--accent);
  flex-shrink: 0;
}

.brand-text {
  flex: 1;
  min-width: 0;
}

.brand-title {
  margin: 0;
  font-size: 18px;
  font-weight: 500;
  letter-spacing: 0.12em;
  line-height: 1.2;
}

.brand-sub {
  margin: 3px 0 0;
  font-size: 11px;
  color: var(--ink-muted);
  letter-spacing: 0.06em;
}

.icon-btn {
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--ink-secondary);
  border: 1px solid transparent;
  font-size: 20px;
  line-height: 1;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.icon-btn:active {
  color: var(--ink);
  border-color: var(--border);
}

/* Search Input */
.search-wrap {
  position: relative;
  display: flex;
  align-items: center;
  margin-bottom: 12px;
}

.search-icon {
  position: absolute;
  left: 12px;
  color: var(--ink-muted);
  pointer-events: none;
}

.search-input {
  width: 100%;
  height: 38px;
  padding: 0 34px 0 36px;
  font-size: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 2px;
  outline: none;
  transition: border-color 0.15s ease;
  -webkit-appearance: none;
}

.search-input::-webkit-search-cancel-button,
.search-input::-webkit-search-decoration {
  -webkit-appearance: none;
  appearance: none;
}

.search-input::placeholder {
  color: var(--ink-muted);
}

.search-input:focus {
  border-color: var(--ink-secondary);
}

.search-clear {
  position: absolute;
  right: 4px;
  width: 30px;
  height: 30px;
  font-size: 18px;
  color: var(--ink-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* Tabs */
.tab-bar {
  display: flex;
  gap: 24px;
  overflow-x: auto;
  scrollbar-width: none;
}

.tab-bar::-webkit-scrollbar {
  display: none;
}

.tab-btn {
  position: relative;
  padding: 10px 0 11px;
  font-size: 13px;
  letter-spacing: 0.06em;
  color: var(--ink-secondary);
  white-space: nowrap;
  transition: color 0.15s ease;
}

.tab-btn.active {
  color: var(--ink);
  font-weight: 500;
}

.tab-btn.active::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 2px;
  background: var(--accent);
}

/* ================= CATALOG MAIN ================= */
.catalog-main {
  max-width: var(--max-catalog);
  margin: 0 auto;
  padding: 16px 20px 48px;
}

/* Continue Reading Banner */
.continue-banner {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  padding: 14px 16px;
  margin-bottom: 18px;
  cursor: pointer;
  transition: background-color 0.15s ease;
}

.continue-banner:active {
  background: var(--surface-alt);
}

.continue-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

.continue-label {
  font-size: 11px;
  letter-spacing: 0.1em;
  color: var(--accent);
  font-weight: 500;
}

.continue-progress {
  font-size: 11px;
  color: var(--ink-muted);
  font-variant-numeric: tabular-nums;
}

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

.continue-title {
  font-size: 15px;
  font-weight: 500;
  color: var(--ink);
  line-height: 1.4;
}

.continue-author {
  font-size: 12px;
  color: var(--ink-secondary);
  margin-top: 2px;
}

.continue-arrow {
  font-size: 16px;
  color: var(--ink-muted);
}

/* Filter & Toolbar */
.filter-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  margin-bottom: 14px;
  font-size: 13px;
}

.text-btn {
  font-size: 12px;
  color: var(--accent);
  letter-spacing: 0.04em;
  padding: 4px 2px;
}

.list-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  color: var(--ink-muted);
}

.sort-btn {
  font-size: 12px;
  color: var(--ink-secondary);
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 2px;
  background: var(--surface);
}

/* Catalog List */
.catalog-list {
  display: flex;
  flex-direction: column;
}

.article-row {
  display: grid;
  grid-template-columns: 38px 1fr;
  gap: 12px;
  padding: 16px 2px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  width: 100%;
  transition: background-color 0.15s ease;
}

.article-row:active {
  background: var(--surface-alt);
}

.row-num {
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  color: var(--ink-muted);
  padding-top: 4px;
  letter-spacing: 0.04em;
}

.row-content {
  min-width: 0;
}

.row-title-line {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.row-title {
  font-size: 16px;
  font-weight: 500;
  color: var(--ink);
  line-height: 1.45;
  word-break: break-word;
}

.row-badge {
  font-size: 10px;
  color: var(--accent);
  border: 1px solid var(--accent);
  padding: 0 4px;
  line-height: 1.5;
  flex-shrink: 0;
}

.row-excerpt {
  margin: 5px 0 8px;
  font-size: 13px;
  color: var(--ink-secondary);
  line-height: 1.6;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.row-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 12px;
  color: var(--ink-muted);
}

.row-author {
  color: var(--ink-secondary);
}

.row-read-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--border-strong);
  display: inline-block;
}

/* Authors Grid */
.authors-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(145px, 1fr));
  gap: 10px;
  padding-top: 14px;
}

.author-card {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  text-align: left;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.author-card:active {
  background: var(--surface-alt);
  border-color: var(--border-strong);
}

.author-card-name {
  font-size: 14px;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.author-card-count {
  font-size: 11px;
  color: var(--ink-muted);
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}

/* Load More & Empty State */
.load-more-wrap {
  padding: 28px 0 8px;
  text-align: center;
}

.muji-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 40px;
  padding: 0 28px;
  font-size: 13px;
  letter-spacing: 0.08em;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 2px;
}

.muji-btn:active {
  background: var(--surface-alt);
}

.empty-state {
  text-align: center;
  padding: 64px 20px;
  color: var(--ink-muted);
}

.empty-title {
  margin: 0 0 6px;
  font-size: 15px;
  color: var(--ink-secondary);
}

.empty-desc {
  margin: 0;
  font-size: 13px;
}

.site-footer {
  max-width: var(--max-catalog);
  margin: 0 auto;
  padding: 0 20px calc(36px + var(--safe-bottom));
  text-align: center;
}

.footer-rule {
  height: 1px;
  background: var(--border);
  margin-bottom: 18px;
}

.footer-note {
  margin: 0;
  font-size: 11px;
  letter-spacing: 0.12em;
  color: var(--ink-muted);
}

/* ================= READER VIEW ================= */
.reader-topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 40;
  height: calc(50px + var(--safe-top));
  padding: var(--safe-top) 12px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: var(--chrome-bg);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  transform: translateY(0);
  transition: transform 0.22s ease;
}

.reader-topbar.chrome-hidden {
  transform: translateY(-100%);
}

.reader-nav-btn {
  height: 36px;
  padding: 0 8px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  color: var(--ink-secondary);
  flex-shrink: 0;
}

.reader-nav-btn.icon-only {
  width: 36px;
  justify-content: center;
  padding: 0;
}

.reader-nav-btn.is-fav {
  color: var(--accent);
}

.reader-nav-btn.is-fav svg {
  fill: var(--accent);
}

.reader-top-title {
  flex: 1;
  min-width: 0;
  text-align: center;
  font-size: 13px;
  color: var(--ink-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Article Content */
.reader-article {
  max-width: var(--max-reader);
  margin: 0 auto;
  padding: calc(74px + var(--safe-top)) 22px calc(108px + var(--safe-bottom));
  min-height: 100dvh;
}

.article-header {
  margin-bottom: 32px;
}

.article-index {
  font-size: 11px;
  letter-spacing: 0.14em;
  color: var(--ink-muted);
  font-variant-numeric: tabular-nums;
  margin-bottom: 10px;
}

.article-title {
  margin: 0 0 14px;
  font-family: var(--reader-font);
  font-size: 24px;
  font-weight: 500;
  line-height: 1.42;
  letter-spacing: 0.03em;
  color: var(--ink);
}

.article-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 13px;
  color: var(--ink-muted);
}

.author-link {
  color: var(--ink-secondary);
  border-bottom: 1px solid var(--border-strong);
  padding-bottom: 1px;
}

.article-note {
  margin: 10px 0 0;
  font-size: 12px;
  color: var(--ink-muted);
}

.article-rule {
  margin-top: 24px;
  height: 1px;
  background: var(--border);
}

.article-body {
  font-family: var(--reader-font);
  font-size: var(--reader-size);
  line-height: var(--reader-lh);
  color: var(--ink);
  letter-spacing: 0.02em;
  word-break: break-word;
  overflow-wrap: break-word;
}

.article-body p {
  margin: 0 0 1.08em;
  text-indent: var(--reader-indent);
  text-align: justify;
}

.article-body p.no-indent {
  text-indent: 0;
}

.loading-state {
  padding: 60px 0;
  text-align: center;
  font-family: var(--font-sans);
  font-size: 13px;
  color: var(--ink-muted);
}

/* Article Footer */
.article-footer {
  margin-top: 56px;
}

.end-mark {
  display: flex;
  align-items: center;
  gap: 16px;
  color: var(--ink-muted);
  font-size: 12px;
  letter-spacing: 0.2em;
  margin-bottom: 28px;
}

.end-mark::before,
.end-mark::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

.article-actions {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-bottom: 32px;
}

.muji-btn-outline {
  height: 36px;
  padding: 0 20px;
  font-size: 13px;
  letter-spacing: 0.06em;
  color: var(--ink-secondary);
  border: 1px solid var(--border-strong);
  border-radius: 2px;
  background: var(--surface);
}

.muji-btn-outline.active {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-soft);
}

.article-pager {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.pager-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  text-align: left;
  min-width: 0;
}

.pager-card.pager-next {
  text-align: right;
}

.pager-card:disabled {
  opacity: 0.4;
  cursor: default;
}

.pager-dir {
  font-size: 11px;
  color: var(--ink-muted);
  letter-spacing: 0.08em;
}

.pager-title {
  font-size: 13px;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Bottom Floating Reader Toolbar */
.reader-bottombar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  height: calc(56px + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: var(--chrome-bg);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-top: 1px solid var(--border);
  transform: translateY(0);
  transition: transform 0.22s ease;
}

.reader-bottombar.chrome-hidden {
  transform: translateY(100%);
}

.tool-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  font-size: 10px;
  letter-spacing: 0.06em;
  color: var(--ink-secondary);
}

.tool-btn:disabled {
  opacity: 0.35;
}

.tool-btn:active {
  color: var(--ink);
}

/* ================= SHEETS & DRAWER ================= */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: var(--backdrop);
}

.bottom-sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 70;
  max-width: var(--max-reader);
  margin: 0 auto;
  background: var(--surface);
  border-top: 1px solid var(--border-strong);
  padding-bottom: calc(18px + var(--safe-bottom));
}

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

.sheet-title {
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.1em;
  color: var(--ink);
}

.sheet-body {
  padding: 16px 20px 8px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

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

.setting-label {
  font-size: 13px;
  color: var(--ink-secondary);
  letter-spacing: 0.06em;
  flex-shrink: 0;
}

.theme-pills,
.seg-control,
.stepper {
  display: flex;
  gap: 8px;
}

.theme-pill,
.seg-btn,
.step-btn {
  height: 34px;
  padding: 0 14px;
  font-size: 12px;
  border: 1px solid var(--border-strong);
  border-radius: 2px;
  color: var(--ink-secondary);
  background: var(--bg);
}

.theme-pill.active,
.seg-btn.active {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-soft);
  font-weight: 500;
}

.step-val {
  min-width: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

/* Side Drawer */
.side-drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 70;
  width: min(84vw, 340px);
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
}

.drawer-list {
  flex: 1;
  overflow-y: auto;
  padding: 6px 20px 24px;
}

.drawer-item {
  display: flex;
  align-items: baseline;
  gap: 10px;
  width: 100%;
  padding: 13px 0;
  border-bottom: 1px solid var(--border);
  text-align: left;
  font-size: 14px;
  color: var(--ink);
}

.drawer-item.current {
  color: var(--accent);
  font-weight: 500;
}

.drawer-item-num {
  font-size: 11px;
  color: var(--ink-muted);
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(76px + var(--safe-bottom));
  transform: translateX(-50%);
  z-index: 100;
  padding: 9px 18px;
  font-size: 12px;
  letter-spacing: 0.06em;
  background: var(--ink);
  color: var(--bg);
  border-radius: 2px;
  white-space: nowrap;
}

/* Desktop breathing room */
@media (min-width: 720px) {
  .header-inner {
    padding: 22px 24px 0;
  }
  .catalog-main {
    padding: 24px 24px 64px;
  }
  .reader-article {
    padding: 96px 32px 128px;
  }
  .article-title {
    font-size: 28px;
  }
}
