:root {
  color-scheme: light;
  --bg: #e7ddc8;
  --paper: #fff8e8;
  --paper-soft: #f7ecd2;
  --paper-deep: #ead7aa;
  --ink: #17130e;
  --ink-soft: #443a2f;
  --muted: #6e604d;
  --line: rgba(95, 68, 37, 0.24);
  --line-strong: rgba(123, 83, 38, 0.42);
  --cinnabar: #9f2f22;
  --cinnabar-dark: #6f1f18;
  --moss: #394f3c;
  --moss-soft: #e4eadb;
  --indigo: #263f5c;
  --jade: #2f665f;
  --gold: #a7661e;
  --focus: #1f5b84;
  --shadow-sm: 0 8px 24px rgba(45, 32, 18, 0.1);
  --shadow-md: 0 18px 48px rgba(45, 32, 18, 0.16);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100dvh;
  color: var(--ink);
  font-family: "Noto Serif CJK SC", "Source Han Serif SC", "Songti SC", "STSong", serif;
  background:
    linear-gradient(rgba(23, 19, 14, 0.045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(23, 19, 14, 0.038) 1px, transparent 1px),
    url("./assets/paper-grain.svg"),
    var(--bg);
  background-size: 40px 40px, 40px 40px, 360px 360px, auto;
}

body::before {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  content: "";
  background:
    linear-gradient(115deg, rgba(57, 79, 60, 0.14), transparent 38%),
    linear-gradient(245deg, rgba(38, 63, 92, 0.12), transparent 42%);
}

button,
input {
  font: inherit;
}

button {
  touch-action: manipulation;
}

button:focus-visible,
input:focus-visible,
.skip-link:focus-visible,
.reader:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

.skip-link {
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 20;
  padding: 10px 14px;
  color: #fff8ec;
  text-decoration: none;
  background: var(--indigo);
  border-radius: var(--radius);
  transform: translateY(-140%);
  transition: transform 180ms ease;
}

.skip-link:focus {
  transform: translateY(0);
}

.site-shell {
  width: min(1200px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0 40px;
}

.masthead {
  position: relative;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) minmax(240px, auto);
  gap: 24px;
  align-items: center;
  min-height: 156px;
  padding: 24px 32px;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background:
    linear-gradient(90deg, rgba(23, 19, 14, 0.92), rgba(38, 63, 92, 0.74) 42%, transparent 42%),
    linear-gradient(135deg, rgba(255, 248, 232, 0.96), rgba(247, 236, 210, 0.9)),
    var(--paper);
  box-shadow: var(--shadow-md);
}

.masthead::before,
.masthead::after {
  position: absolute;
  inset: 14px;
  pointer-events: none;
  content: "";
  border: 1px solid rgba(255, 248, 232, 0.38);
}

.masthead::after {
  inset: 20px;
  border-color: rgba(95, 68, 37, 0.18);
  border-style: dashed;
}

.seal {
  z-index: 1;
  display: grid;
  width: 72px;
  height: 72px;
  place-items: center;
  color: #fff7e8;
  font-size: 40px;
  line-height: 1;
  background: var(--cinnabar);
  border: 3px double rgba(255, 242, 220, 0.82);
  box-shadow: inset 0 0 0 4px rgba(111, 31, 24, 0.36);
}

.masthead-copy {
  z-index: 1;
  min-width: 0;
}

.kicker,
.lede,
.volume,
.meta-line,
.reader-count,
.result-count,
.eyebrow {
  margin: 0;
}

.kicker {
  color: #f0d2b0;
  font-size: 0.95rem;
}

h1,
h2,
h3 {
  margin: 0;
  font-weight: 800;
  letter-spacing: 0;
}

h1 {
  margin-top: 8px;
  color: #fff8ec;
  font-size: 4.5rem;
  line-height: 0.98;
}

.lede {
  margin-top: 12px;
  color: #f2e4ca;
  font-size: 1.1rem;
  line-height: 1.6;
}

.collection-stats {
  z-index: 1;
  display: grid;
  grid-template-columns: repeat(2, minmax(72px, 1fr));
  gap: 8px;
  margin: 0;
  color: var(--ink);
}

.collection-stats div {
  min-height: 72px;
  padding: 12px;
  border: 1px solid rgba(95, 68, 37, 0.2);
  border-radius: var(--radius);
  background: rgba(255, 248, 232, 0.78);
}

.collection-stats dt {
  color: var(--muted);
  font-size: 0.82rem;
}

.collection-stats dd {
  margin: 6px 0 0;
  color: var(--cinnabar-dark);
  font-size: 1.55rem;
  font-weight: 800;
  line-height: 1;
}

.layout {
  display: grid;
  grid-template-columns: minmax(290px, 340px) minmax(0, 1fr);
  gap: 18px;
  margin-top: 18px;
  align-items: start;
}

.library,
.reader {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 248, 232, 0.92);
  box-shadow: var(--shadow-sm);
}

.library {
  position: sticky;
  top: 16px;
  max-height: calc(100dvh - 32px);
  padding: 16px;
  overflow: auto;
}

.library-head {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  justify-content: space-between;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.eyebrow {
  color: var(--cinnabar);
  font-size: 0.82rem;
}

.library h2 {
  margin-top: 2px;
  color: var(--ink);
  font-size: 1.55rem;
  line-height: 1.2;
}

.result-count {
  flex: 0 0 auto;
  padding-top: 4px;
  color: var(--muted);
  font-size: 0.9rem;
}

.toolbar {
  margin: 14px 0 12px;
}

.search-field {
  display: grid;
  gap: 8px;
}

.field-label {
  color: var(--ink-soft);
  font-size: 0.9rem;
  font-weight: 700;
}

.search-control {
  display: grid;
  grid-template-columns: 24px 1fr;
  align-items: center;
  min-height: 48px;
  padding: 0 12px;
  border: 1px solid rgba(95, 68, 37, 0.28);
  border-radius: var(--radius);
  background: rgba(255, 252, 242, 0.76);
  transition: border-color 180ms ease, box-shadow 180ms ease, background-color 180ms ease;
}

.search-control:focus-within {
  border-color: var(--focus);
  background: #fffdf6;
  box-shadow: 0 0 0 3px rgba(31, 91, 132, 0.16);
}

.search-control svg {
  width: 18px;
  height: 18px;
  color: var(--indigo);
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.search-control input {
  width: 100%;
  min-width: 0;
  color: var(--ink);
  border: 0;
  outline: 0;
  background: transparent;
}

.search-control input::placeholder {
  color: rgba(68, 58, 47, 0.72);
}

.text-button {
  min-height: 44px;
  cursor: pointer;
  border-radius: 999px;
  transition:
    transform 160ms ease,
    border-color 160ms ease,
    background-color 160ms ease,
    color 160ms ease,
    box-shadow 160ms ease;
}

.article-list {
  display: grid;
  gap: 10px;
  padding-top: 2px;
}

.article-card {
  position: relative;
  width: 100%;
  min-height: 88px;
  padding: 14px 14px 14px 18px;
  color: inherit;
  text-align: left;
  cursor: pointer;
  border: 1px solid rgba(95, 68, 37, 0.18);
  border-radius: var(--radius);
  background: rgba(255, 252, 242, 0.64);
  transition:
    transform 160ms ease,
    border-color 160ms ease,
    background-color 160ms ease,
    box-shadow 160ms ease;
}

.article-card::before {
  position: absolute;
  top: 14px;
  bottom: 14px;
  left: 0;
  width: 3px;
  content: "";
  background: transparent;
  border-radius: 0 4px 4px 0;
}

.article-card:hover,
.article-card:focus-visible {
  border-color: rgba(159, 47, 34, 0.42);
  background: #fffaf0;
  box-shadow: 0 8px 20px rgba(45, 32, 18, 0.09);
}

.article-card.is-selected {
  border-color: rgba(159, 47, 34, 0.58);
  background: #fff6df;
}

.article-card.is-selected::before {
  background: var(--cinnabar);
}

.article-card:active,
.text-button:active {
  transform: translateY(1px);
}

.card-title {
  display: block;
  color: var(--ink);
  font-size: 1.05rem;
  font-weight: 800;
  line-height: 1.45;
}

.card-foot {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
  color: var(--indigo);
  font-size: 0.82rem;
  line-height: 1.5;
}

.reader {
  min-height: 640px;
  padding: 32px;
  scroll-margin-top: 16px;
}

.reader-inner {
  max-width: 74ch;
  margin: 0 auto;
}

.reader-top {
  display: flex;
  gap: 16px;
  align-items: flex-start;
  justify-content: space-between;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.volume {
  color: var(--cinnabar);
  font-size: 0.95rem;
  font-weight: 700;
  line-height: 1.6;
}

.reader-count {
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.86rem;
}

.reader h2 {
  margin-top: 28px;
  color: var(--ink);
  font-size: 3rem;
  line-height: 1.18;
}

.meta-line {
  margin-top: 18px;
  padding-bottom: 20px;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
  font-size: 0.9rem;
  line-height: 1.6;
}

.meta-line a {
  color: var(--indigo);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

.reader-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 16px 0 6px;
}

.text-button {
  padding: 8px 14px;
  color: var(--indigo);
  border: 1px solid rgba(38, 63, 92, 0.28);
  background: rgba(239, 244, 246, 0.66);
}

.text-button:hover,
.text-button:focus-visible {
  border-color: rgba(38, 63, 92, 0.58);
  background: #edf5f5;
}

.text-button-primary {
  color: #fff8ec;
  border-color: var(--cinnabar);
  background: var(--cinnabar);
}

.text-button-primary:hover,
.text-button-primary:focus-visible {
  border-color: var(--cinnabar-dark);
  background: var(--cinnabar-dark);
}

.text-button:disabled {
  color: rgba(68, 58, 47, 0.48);
  cursor: not-allowed;
  border-color: rgba(95, 68, 37, 0.15);
  background: rgba(235, 226, 205, 0.44);
  transform: none;
}

.article-body {
  margin-top: 24px;
  color: var(--ink-soft);
  font-size: 1.18rem;
  line-height: 2;
}

.article-body p {
  margin: 0 0 1em;
  text-indent: 2em;
}

.article-body h3 {
  margin: 1.5em 0 0.7em;
  color: var(--cinnabar);
  font-size: 1.18em;
}

.article-body blockquote {
  margin: 1.5em 0;
  padding: 16px 18px;
  color: var(--indigo);
  border-left: 4px solid var(--cinnabar);
  background: rgba(228, 234, 219, 0.62);
}

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

.article-body ul {
  margin: 1em 0;
  padding-left: 1.6em;
}

.empty-state {
  padding: 18px;
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  background: rgba(255, 252, 242, 0.62);
}

.skeleton {
  display: grid;
  gap: 12px;
  padding-top: 8px;
}

.skeleton span {
  display: block;
  height: 18px;
  overflow: hidden;
  border-radius: 999px;
  background:
    linear-gradient(90deg, rgba(234, 215, 170, 0.45), rgba(255, 252, 242, 0.92), rgba(234, 215, 170, 0.45));
  background-size: 220% 100%;
  animation: skeleton-sheen 1200ms ease-in-out infinite;
}

.skeleton span:nth-child(2) {
  width: 92%;
}

.skeleton span:nth-child(3) {
  width: 76%;
}

@keyframes skeleton-sheen {
  from {
    background-position: 120% 0;
  }

  to {
    background-position: -120% 0;
  }
}

@media (max-width: 920px) {
  .site-shell {
    width: min(100% - 24px, 720px);
    padding-top: 12px;
  }

  .masthead {
    grid-template-columns: auto 1fr;
    padding: 22px 20px;
    background:
      linear-gradient(90deg, rgba(23, 19, 14, 0.92), rgba(38, 63, 92, 0.68)),
      var(--paper);
  }

  .collection-stats {
    grid-column: 1 / -1;
  }

  h1 {
    font-size: 3.35rem;
  }

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

  .reader {
    order: 1;
  }

  .library {
    order: 2;
    position: static;
    max-height: none;
  }
}

@media (max-width: 560px) {
  .site-shell {
    width: min(100% - 20px, 560px);
  }

  .masthead {
    gap: 14px;
    min-height: 0;
    padding: 20px 16px;
  }

  .seal {
    width: 58px;
    height: 58px;
    font-size: 32px;
  }

  h1 {
    font-size: 2.8rem;
  }

  .lede {
    font-size: 1rem;
  }

  .collection-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .collection-stats div {
    min-height: 64px;
    padding: 10px;
  }

  .reader,
  .library {
    padding: 16px;
  }

  .reader-top {
    display: grid;
  }

  .reader h2 {
    font-size: 2rem;
    line-height: 1.22;
  }

  .article-body {
    font-size: 1.08rem;
    line-height: 1.9;
  }

  .reader-actions {
    display: grid;
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 1ms !important;
  }
}
