:root {
  color-scheme: light;
  --accent: #a51c30;
  --accent-strong: #811426;
  --accent-soft: #f4e7e9;
  --paper: #f5f6f3;
  --surface: #fcfcfa;
  --surface-raised: #ffffff;
  --ink: #1c1d1a;
  --muted: #686a64;
  --faint: #92958e;
  --line: #dadcd6;
  --line-strong: #bec1b9;
  --focus: #2c6aa0;
  --shadow-mobile: 0 -18px 60px rgb(24 20 20 / 0.22);
  --ui-font: "PingFang SC", "Microsoft YaHei", sans-serif;
  --headline-font: "Songti SC", STSong, serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--ui-font);
}

body {
  min-height: 100dvh;
}

button,
select,
input,
a {
  font: inherit;
}

button,
select {
  min-height: 44px;
}

button:focus-visible,
select:focus-visible,
input:focus-visible,
a:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--focus) 60%, transparent);
  outline-offset: 2px;
}

.skip-link {
  position: fixed;
  left: 16px;
  top: -80px;
  z-index: 50;
  padding: 10px 14px;
  border-radius: 6px;
  background: var(--ink);
  color: var(--surface);
  text-decoration: none;
}

.skip-link:focus {
  top: 16px;
}

.app-header {
  min-height: 72px;
  padding: 12px clamp(16px, 3vw, 48px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.brand-block {
  display: flex;
  align-items: baseline;
  gap: 12px;
  min-width: 0;
}

.brand-name {
  color: var(--accent);
  font-family: var(--headline-font);
  font-size: clamp(25px, 3vw, 34px);
  font-weight: 800;
  letter-spacing: -0.04em;
  white-space: nowrap;
}

.brand-note,
.issue-summary {
  color: var(--muted);
  font-size: 13px;
}

.issue-summary {
  text-align: right;
  white-space: nowrap;
}

.header-actions {
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 14px;
}

.theme-switch {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: repeat(2, 54px);
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--paper);
}

.theme-switch button {
  min-height: 40px;
  padding: 0 8px;
  border: 0;
  border-right: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.theme-switch button:last-child {
  border-right: 0;
}

.theme-switch button:hover {
  color: var(--ink);
  background: var(--surface-raised);
}

.theme-switch button[aria-pressed="true"] {
  background: var(--accent);
  color: #fffaf8;
}

.page-shell {
  width: min(100%, 1600px);
  margin: 0 auto;
  padding: 18px clamp(12px, 2.6vw, 40px) 28px;
}

.filter-panel {
  display: grid;
  grid-template-columns: minmax(230px, 0.7fr) minmax(500px, 1.8fr);
  gap: 12px;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.filter-field {
  min-width: 0;
}

.section-filter-field {
  grid-column: 1 / -1;
}

.paper-options,
.section-options {
  min-width: 0;
  display: grid;
  gap: 1px;
  padding: 1px;
  overflow: hidden;
  background: var(--line-strong);
}

.paper-options {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.section-options {
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
}

.paper-option,
.section-option {
  position: relative;
  min-width: 0;
  display: block;
}

.paper-option-input,
.section-option-input {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: 0;
  opacity: 0;
}

.paper-option-text,
.paper-option-loading,
.section-option-text,
.section-option-loading {
  min-height: 44px;
  padding: 0 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-raised);
  color: var(--ink-soft);
  font-size: 13px;
  font-weight: 700;
  line-height: 1.2;
  text-align: center;
  white-space: nowrap;
}

.paper-option-text,
.section-option-text {
  cursor: pointer;
  transition: background-color 140ms ease, color 140ms ease;
}

.paper-option:hover .paper-option-input:not(:disabled) + .paper-option-text,
.section-option:hover .section-option-input:not(:disabled) + .section-option-text {
  background: color-mix(in srgb, var(--accent-soft) 58%, var(--surface-raised));
  color: var(--ink);
}

.paper-option-input:checked + .paper-option-text,
.section-option-input:checked + .section-option-text {
  background: var(--accent);
  color: #fffaf8;
}

.paper-option-input:focus-visible + .paper-option-text,
.section-option-input:focus-visible + .section-option-text {
  position: relative;
  z-index: 1;
  outline: 3px solid color-mix(in srgb, var(--focus) 70%, transparent);
  outline-offset: -3px;
}

.paper-option-input:active + .paper-option-text,
.section-option-input:active + .section-option-text {
  transform: translateY(1px);
}

.paper-option-input:disabled + .paper-option-text,
.section-option-input:disabled + .section-option-text,
.paper-option-loading,
.section-option-loading {
  color: var(--faint);
  background: var(--paper);
  cursor: wait;
}

.paper-option-loading,
.section-option-loading {
  grid-column: 1 / -1;
}

select {
  width: 100%;
  padding: 0 36px 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--surface-raised);
  color: var(--ink);
  appearance: auto;
}

select:hover:not(:disabled) {
  border-color: var(--accent);
}

select:disabled {
  color: var(--faint);
  background: var(--paper);
  cursor: wait;
}

.reader-layout {
  min-height: calc(100dvh - 182px);
  margin-top: 14px;
  display: grid;
  grid-template-columns: minmax(360px, 430px) minmax(0, 1fr);
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.site-footer {
  padding: 0 16px calc(18px + env(safe-area-inset-bottom));
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
  text-align: center;
}

.site-footer a {
  color: inherit;
  text-underline-offset: 3px;
}

.site-footer a:hover {
  color: var(--accent);
}

.article-panel {
  min-width: 0;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  border-right: 1px solid var(--line);
}

.article-panel-heading {
  min-height: 74px;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--line);
}

.panel-title,
.panel-description,
.story-section,
.story-title {
  margin: 0;
}

.panel-title {
  font-size: 16px;
  font-weight: 700;
}

.panel-description {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.read-progress {
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.catalog-toolbar {
  padding: 10px 12px;
  display: grid;
  gap: 8px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.search-field {
  position: relative;
  display: block;
}

.search-field input {
  width: 100%;
  min-height: 44px;
  padding: 0 58px 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--surface-raised);
  color: var(--ink);
}

.search-field input::placeholder {
  color: var(--faint);
}

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

.clear-search {
  position: absolute;
  top: 4px;
  right: 4px;
  min-height: 36px;
  padding: 0 10px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
}

.clear-search:hover {
  background: var(--paper);
  color: var(--ink);
}

.view-filters {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  overflow: hidden;
}

.view-filters button {
  min-height: 38px;
  border: 0;
  border-right: 1px solid var(--line);
  background: var(--surface-raised);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.view-filters button:last-child {
  border-right: 0;
}

.view-filters button:hover {
  color: var(--accent);
}

.view-filters button[aria-pressed="true"] {
  background: var(--accent);
  color: #fffaf8;
}

.article-list {
  max-height: calc(100dvh - 378px);
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-color: var(--line-strong) transparent;
}

.section-group + .section-group {
  border-top: 1px solid var(--line-strong);
}

.section-heading {
  position: sticky;
  top: 0;
  z-index: 2;
  min-height: 42px;
  padding: 9px 14px;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  background: color-mix(in srgb, var(--paper) 94%, transparent);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
}

.section-name {
  font-size: 13px;
  font-weight: 700;
}

.page-number {
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.article-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.article-row {
  width: 100%;
  min-height: 66px;
  padding: 11px 14px;
  display: grid;
  grid-template-columns: 26px minmax(0, 1fr) auto;
  align-items: start;
  gap: 10px;
  border: 0;
  background: var(--surface);
  color: var(--ink);
  text-align: left;
  cursor: pointer;
  transition: background-color 140ms ease, color 140ms ease;
}

.article-row:hover {
  background: color-mix(in srgb, var(--accent-soft) 62%, var(--surface));
}

.article-row:active {
  background: var(--accent-soft);
}

.article-item.is-current .article-row {
  background: var(--accent);
  color: #fffaf8;
}

.article-item.is-read:not(.is-current) .article-title {
  color: var(--muted);
}

.article-index {
  padding-top: 3px;
  color: var(--faint);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.article-item.is-current .article-index,
.article-item.is-current .article-kind {
  color: #f8dfe3;
}

.favorite-button {
  width: 54px;
  min-height: 66px;
  padding: 0 8px;
  border: 0;
  background: var(--surface);
  color: var(--faint);
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
}

.favorite-button:hover,
.favorite-button[aria-pressed="true"] {
  color: var(--accent);
  background: var(--accent-soft);
}

.article-item.is-current .favorite-button {
  color: #f8dfe3;
  background: var(--accent);
}

.article-item.is-current .favorite-button:hover,
.article-item.is-current .favorite-button[aria-pressed="true"] {
  color: #ffffff;
  background: var(--accent-strong);
}

.article-title {
  font-family: var(--headline-font);
  font-size: 17px;
  font-weight: 700;
  line-height: 1.55;
  text-wrap: pretty;
}

.article-kind {
  padding-top: 3px;
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
}

.story-panel {
  min-width: 0;
  min-height: 560px;
  background: var(--surface-raised);
}

.story-placeholder {
  height: 100%;
  min-height: 560px;
  padding: 32px;
  display: grid;
  place-content: center;
  justify-items: center;
  text-align: center;
}

.placeholder-page {
  width: 72px;
  height: 88px;
  display: grid;
  place-items: center;
  border: 1px solid var(--accent);
  color: var(--accent);
  font-family: var(--headline-font);
  font-size: 36px;
  font-weight: 800;
}

.story-placeholder h1 {
  margin: 24px 0 8px;
  font-family: var(--headline-font);
  font-size: clamp(24px, 3vw, 34px);
}

.story-placeholder p {
  max-width: 26em;
  margin: 0;
  color: var(--muted);
  line-height: 1.7;
  text-wrap: pretty;
}

.story-reader {
  height: 100%;
  min-height: 560px;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
}

.story-reader[hidden] {
  display: none;
}

.story-toolbar {
  grid-row: 1;
  min-height: 74px;
  padding: 10px 14px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px;
  border-bottom: 1px solid var(--line);
}

.back-button {
  display: none;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
}

.story-identity {
  min-width: 0;
}

.story-section {
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
}

.story-title {
  margin-top: 3px;
  overflow: hidden;
  font-family: var(--headline-font);
  font-size: 16px;
  line-height: 1.45;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.source-link,
.archive-link {
  min-height: 44px;
  padding: 0 12px;
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--accent);
  border-radius: 6px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
}

.source-link:hover,
.archive-link:hover {
  background: var(--accent);
  color: #fffaf8;
}

.archive-link {
  border-color: var(--line-strong);
  color: var(--ink-soft);
}

.frame-status {
  grid-row: 2;
  padding: 6px 14px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 11px;
  text-align: center;
}

.frame-shell {
  grid-row: 3;
  position: relative;
  min-width: 0;
  min-height: 500px;
  overflow: hidden;
  background: #ffffff;
}

.reader-zoom {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 3;
  display: grid;
  grid-template-columns: 44px 54px 44px;
  overflow: hidden;
  border: 1px solid rgb(255 255 255 / 0.18);
  border-radius: 6px;
  background: rgb(28 29 26 / 0.92);
  color: #ffffff;
  box-shadow: 0 6px 20px rgb(0 0 0 / 0.2);
  backdrop-filter: blur(8px);
}

.reader-zoom button {
  min-width: 0;
  min-height: 44px;
  padding: 0;
  border: 0;
  border-right: 1px solid rgb(255 255 255 / 0.15);
  background: transparent;
  color: inherit;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

.reader-zoom button:last-child {
  border-right: 0;
}

.reader-zoom button:hover,
.reader-zoom button:focus-visible {
  background: var(--accent);
}

.reader-zoom button:disabled {
  color: rgb(255 255 255 / 0.36);
  cursor: not-allowed;
}

#zoom-level {
  font-variant-numeric: tabular-nums;
}

.story-frame {
  width: 100%;
  height: 100%;
  display: block;
  min-height: 500px;
  border: 0;
  background: #ffffff;
  transform-origin: top left;
  transition: transform 160ms ease;
}

.empty-state,
.error-state {
  min-height: 320px;
  padding: 32px 20px;
  display: grid;
  place-content: center;
  text-align: center;
}

.empty-state strong,
.error-state strong {
  font-family: var(--headline-font);
  font-size: 20px;
}

.empty-state p,
.error-state p {
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.65;
}

.loading-list {
  padding: 8px 14px;
}

.loading-list span {
  height: 62px;
  display: block;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--line) 62%, transparent), transparent);
  background-size: 220% 100%;
  animation: loading-sweep 1.4s ease-in-out infinite;
}

.app-message {
  position: fixed;
  left: 50%;
  bottom: calc(18px + env(safe-area-inset-bottom));
  z-index: 60;
  max-width: calc(100% - 32px);
  padding: 10px 14px;
  transform: translateX(-50%);
  border-radius: 6px;
  background: var(--ink);
  color: var(--surface);
  font-size: 13px;
  box-shadow: 0 10px 28px rgb(0 0 0 / 0.18);
}

@keyframes loading-sweep {
  from { background-position: 100% 0; }
  to { background-position: -100% 0; }
}

@media (max-width: 1080px) {
  .page-shell {
    padding-inline: 12px;
  }

  .reader-layout {
    grid-template-columns: minmax(320px, 42%) minmax(0, 1fr);
  }

  .story-toolbar {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .story-toolbar .back-button {
    display: none;
  }
}

@media (max-width: 980px) {
  .filter-panel {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 767px) {
  .app-header {
    min-height: 64px;
    padding: 9px 16px;
  }

  .brand-note {
    display: none;
  }

  .issue-summary {
    display: none;
  }

  .header-actions {
    gap: 0;
  }

  .theme-switch {
    grid-template-columns: repeat(2, 52px);
  }

  .page-shell {
    padding: 10px 10px calc(20px + env(safe-area-inset-bottom));
  }

  .filter-panel {
    grid-template-columns: 1fr;
    gap: 8px;
    padding: 10px;
  }

  .reader-layout {
    min-height: auto;
    margin-top: 10px;
    display: block;
  }

  .article-panel {
    border-right: 0;
  }

  .article-list {
    max-height: none;
    overflow: visible;
  }

  .article-row {
    min-height: 72px;
    padding-block: 13px;
  }

  .favorite-button {
    min-height: 72px;
  }

  .article-title {
    font-size: 18px;
  }

  .story-panel {
    display: none;
  }

  .story-panel.is-open {
    position: fixed;
    inset: 0;
    z-index: 40;
    min-height: 100dvh;
    display: block;
    background: var(--surface-raised);
    box-shadow: var(--shadow-mobile);
  }

  .story-panel.is-open .story-reader {
    height: 100dvh;
    min-height: 100dvh;
    padding-bottom: env(safe-area-inset-bottom);
  }

  .story-toolbar {
    min-height: 68px;
    padding-top: calc(8px + env(safe-area-inset-top));
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 8px;
  }

  .story-toolbar .back-button {
    display: inline-flex;
    align-items: center;
  }

  .story-title {
    max-width: 100%;
    font-size: 14px;
  }

  .source-link,
  .archive-link {
    width: 44px;
    padding: 0;
    justify-content: center;
    overflow: hidden;
    color: transparent;
    white-space: nowrap;
  }

  .source-link::after {
    content: "原文";
    color: var(--accent);
    font-size: 11px;
  }

  .archive-link::after {
    content: "存档";
    color: var(--ink-soft);
    font-size: 11px;
  }

  .source-link:hover::after,
  .archive-link:hover::after {
    color: #fffaf8;
  }

  .story-frame {
    min-height: 0;
  }

  .frame-shell {
    min-height: 0;
  }

  .reader-zoom {
    top: 8px;
    right: 8px;
  }

  body.reader-open {
    overflow: hidden;
  }
}

@media (max-width: 480px) {
  .paper-options,
  .section-options {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --accent: #d35b6c;
  --accent-strong: #f18a98;
  --accent-soft: #3a2025;
  --paper: #171816;
  --surface: #1e201d;
  --surface-raised: #242623;
  --ink: #f0f1ec;
  --muted: #b0b3aa;
  --faint: #858980;
  --line: #3c3f39;
  --line-strong: #555950;
  --focus: #79b5e7;
}
