*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg:        #36322e;
  --bg-deep:   #272422;
  --paper:     #f4f0e4;
  --paper-dim: #ede9dc;
  --paper-shadow: #d8d2c0;
  --ink:       #2a2520;
  --ink-light: #5a5248;
  --accent:    #7a6e5a;
  --btn-bg:    #ede9dc;
  --btn-shadow: rgba(0,0,0,0.25);
}

html { height: 100%; }
body {
  font-family: "Courier New", "Liberation Mono", "IBM Plex Mono", monospace;
  background: var(--bg);
  height: 100dvh;
  overflow: hidden;
  color: var(--ink);
  position: relative;
}
body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: 0.04;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 64 64' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

.nav-btn {
  background: var(--btn-bg);
  color: var(--ink-light);
  border: none;
  cursor: pointer;
  font-family: inherit;
  font-size: 12px;
  font-weight: bold;
  letter-spacing: 0.04em;
  padding: 7px 13px;
  border-radius: 2px;
  box-shadow: 1px 2px 6px var(--btn-shadow), 0 1px 2px rgba(0,0,0,0.15);
  transition: background 0.15s, transform 0.15s, box-shadow 0.15s;
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 6px;
  line-height: 1;
}
.nav-btn:hover { background: var(--paper); transform: translateY(-1px); box-shadow: 1px 4px 10px var(--btn-shadow); }
.nav-btn:active { transform: translateY(0); }

@keyframes spin { to { transform: rotate(360deg); } }

#shelf {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  padding: 40px 24px 48px;
  display: flex;
  flex-direction: column;
  align-items: center;
  opacity: 1;
  transition: opacity 0.3s, transform 0.3s;
}
#shelf.hidden { opacity: 0; pointer-events: none; transform: scale(0.97); }

.thumb-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, 208px);
  gap: 24px;
  justify-content: center;
  width: 100%;
}

.shelf-header {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: row;
  align-items: baseline;
  justify-content: space-between;
  padding-bottom: 18px;
  border-bottom: 1px solid rgba(244,240,228,0.12);
  margin-bottom: 8px;
}

.shelf-title {
  font-size: 36px;
  font-weight: bold;
  letter-spacing: -0.01em;
  font-style: italic;
  color: var(--paper);
  line-height: 1;
  text-shadow: 0 2px 12px rgba(0,0,0,0.4);
}

.shelf-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}
#btn-install { display: none; }

.thumb {
  width: 208px;
  aspect-ratio: 1 / 1.4142;
  background: var(--paper);
  border-radius: 2px;
  padding: 18px 16px 13px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  box-shadow:
    0 2px 8px rgba(0,0,0,0.3),
    3px 4px 0 -1px var(--paper-dim),
    3px 4px 6px rgba(0,0,0,0.18),
    -3px 5px 0 -1px var(--paper-shadow),
    -3px 5px 5px rgba(0,0,0,0.12);
  transition: transform 0.2s cubic-bezier(0.34,1.56,0.64,1), box-shadow 0.2s;
  position: relative;
}
.thumb:hover {
  transform: translateY(-5px) rotate(-0.5deg);
  box-shadow:
    0 10px 24px rgba(0,0,0,0.4),
    4px 6px 0 -1px var(--paper-dim),
    4px 6px 8px rgba(0,0,0,0.2),
    -4px 7px 0 -1px var(--paper-shadow),
    -4px 7px 6px rgba(0,0,0,0.14);
}

.thumb-body {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}
.thumb-header {
  font-size: 7.8px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
  opacity: 0.7;
  border-bottom: 1px solid var(--paper-shadow);
  padding-bottom: 6px;
  margin-bottom: 8px;
}
.thumb-title {
  font-size: 15.2px;
  font-weight: bold;
  line-height: 1.4;
  color: var(--ink);
  flex: 0 0 auto;
}
.thumb-date {
  font-size: 13.7px;
  color: var(--ink-light);
  opacity: 0.75;
  margin-top: 4px;
  flex: 0 0 auto;
}
.thumb-desc {
  font-size: 9.1px;
  color: var(--ink-light);
  line-height: 1.45;
  margin-top: 10px;
  display: -webkit-box;
  -webkit-line-clamp: 12;
  -webkit-box-orient: vertical;
  overflow: hidden;
  flex: 1;
  min-height: 0;
}
.thumb-lines {
  margin-top: 8px;
  padding-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  opacity: 0.18;
}
.thumb-lines span {
  height: 1px;
  background: var(--ink);
  border-radius: 1px;
}
.thumb-lines span:nth-child(2) { width: 80%; }
.thumb-lines span:nth-child(3) { width: 65%; }
.thumb-lines span:nth-child(4) { width: 90%; }
.thumb-lines span:nth-child(5) { width: 50%; }

#reader {
  position: absolute;
  inset: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 40px 24px 48px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.35s;
}
#reader.visible {
  overflow-y: auto;
  opacity: 1;
  pointer-events: auto;
}

.article-header {
  margin-bottom: 28px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--paper-shadow);
}

.article-meta {
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-light);
  margin-top: 10px;
  margin-bottom: 6px;
}

.article-desc {
  font-size: 12px;
  color: var(--ink-light);
  line-height: 1.5;
}

.article-title-row {
  display: flex;
  align-items: center;
  gap: 16px;
}

.article-title {
  flex: 1;
  font-size: 22px;
  font-weight: bold;
  letter-spacing: 0.02em;
  margin: 0;
  padding-bottom: 0;
  border: none;
  color: var(--ink);
}

.article-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.icon-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 26px;
  padding: 6px 8px;
  line-height: 1;
  opacity: 0.7;
  transition: opacity 0.15s, transform 0.12s;
}
.icon-btn:hover { opacity: 1; transform: scale(1.12); }
.icon-btn:active { transform: scale(0.98); }

#btn-refresh.spinning { animation: spin 0.7s linear infinite; }

.paper-stack {
  position: relative;
  width: 100%;
  max-width: 680px;
  min-height: 80vh;
}

.paper-stack::before,
.paper-stack::after {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--paper-dim);
  border-radius: 2px;
  z-index: 0;
}
.paper-stack::before {
  transform: rotate(0.8deg) translateY(4px) translateX(5px);
  background: var(--paper-shadow);
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
.paper-stack::after {
  transform: rotate(-1.2deg) translateY(7px) translateX(-4px);
  background: color-mix(in srgb, var(--paper-shadow) 80%, var(--bg) 20%);
  box-shadow: 0 2px 8px rgba(0,0,0,0.12);
}

.paper-page {
  position: relative;
  z-index: 1;
  background: var(--paper);
  border-radius: 2px;
  padding: 48px 52px 64px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.28), 0 1px 4px rgba(0,0,0,0.1);
}

.paper-page figure.md-fig {
  margin: 28px -8px;
  text-align: center;
}
.paper-page figure.md-fig img {
  max-width: 100%;
  border-radius: 2px;
  box-shadow: 0 2px 14px rgba(0,0,0,0.22);
  display: block;
  margin: 0 auto;
}
.paper-page figure.md-fig + p em:only-child {
  display: block;
  text-align: center;
  font-size: 10px;
  color: var(--ink-light);
  margin-top: -18px;
  margin-bottom: 20px;
  opacity: 0.7;
}

.paper-page h1 {
  font-size: 22px;
  font-weight: bold;
  letter-spacing: 0.02em;
  margin-bottom: 28px;
  padding-bottom: 10px;
  border-bottom: 2px solid var(--paper-shadow);
  color: var(--ink);
}
.paper-page h2 {
  font-size: 15px;
  font-weight: bold;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-top: 36px;
  margin-bottom: 14px;
  color: var(--ink);
}
.paper-page h3 {
  font-size: 13px;
  font-weight: bold;
  margin-top: 24px;
  margin-bottom: 10px;
  color: var(--ink);
}
.paper-page p {
  font-size: 13px;
  line-height: 1.85;
  margin-bottom: 16px;
  color: var(--ink);
}
.paper-page ul, .paper-page ol {
  font-size: 13px;
  line-height: 1.8;
  margin: 0 0 16px 22px;
  color: var(--ink);
}
.paper-page li { margin-bottom: 4px; }
.paper-page blockquote {
  border-left: 3px solid var(--accent);
  padding: 4px 0 4px 16px;
  margin: 16px 0;
  color: var(--ink-light);
  font-style: italic;
  font-size: 13px;
}
.paper-page code {
  font-family: "Courier New", monospace;
  background: var(--paper-dim);
  padding: 1px 5px;
  border-radius: 2px;
  font-size: 11.5px;
}
.paper-page pre {
  background: var(--paper-dim);
  border: 1px solid var(--paper-shadow);
  border-radius: 2px;
  padding: 14px 16px;
  margin: 16px 0;
  overflow-x: auto;
  font-size: 11.5px;
  line-height: 1.6;
}
.paper-page pre code { background: none; padding: 0; }
.paper-page a { color: var(--ink-light); text-decoration: underline; }
.paper-page a:hover { color: var(--ink); }
.paper-page hr {
  border: none;
  border-top: 1px solid var(--paper-shadow);
  margin: 28px 0;
}
.paper-page strong { font-weight: bold; }
.paper-page em { font-style: italic; }
.paper-page h2[id], .paper-page h3[id] { scroll-margin-top: 70px; }

#toast {
  position: fixed;
  top: 18px;
  left: 50%;
  transform: translateX(-50%) translateY(-60px);
  background: var(--paper);
  color: var(--ink-light);
  font-size: 11px;
  letter-spacing: 0.05em;
  padding: 8px 18px;
  border-radius: 2px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.35);
  transition: transform 0.3s cubic-bezier(0.34,1.56,0.64,1);
  pointer-events: none;
  z-index: 200;
  white-space: nowrap;
}
#toast.show { transform: translateX(-50%) translateY(0); }

@media (max-width: 540px) {
  .thumb-grid { grid-template-columns: repeat(auto-fill, 169px); }
  .thumb { width: 169px; }
  .paper-page { padding: 32px 22px 48px; }
}
