:root {
  --cream: #faf6f0;
  --ink: #141412;
  --teal: #005655;
  --mid: #008d81;
  --bright: #25a596;
  --sand: #e8d2ad;
  --paper: #fffdf8;
  --muted: #6b6860;
  --line: rgba(20, 20, 18, 0.1);
  --reader: #161513;
  --chrome: rgba(255, 255, 255, 0.08);
  --chrome-border: rgba(255, 255, 255, 0.12);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body {
  height: 100%;
  height: 100dvh;
  max-height: 100dvh;
}
[hidden] { display: none !important; }
body {
  margin: 0;
  font-family: Inter, system-ui, sans-serif;
  color: var(--ink);
  background: var(--cream);
  overflow: hidden;
  overscroll-behavior: none;
}
.btn, .icon-btn, .open-card, .nav-hit, .search-hit, .thumbs button {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.only-phone { display: none; }

h1, h2 { font-family: Syne, Inter, sans-serif; font-weight: 600; margin: 0; }
p { margin: 0; }
button, input { font: inherit; }
code {
  font-size: 0.9em;
  background: rgba(20, 20, 18, 0.06);
  padding: 0.05em 0.35em;
  border-radius: 4px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  height: 42px;
  padding: 0 16px;
  border-radius: 999px;
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  font-weight: 500;
  letter-spacing: 0.01em;
}
.btn.solid {
  background: var(--teal);
  color: #fff;
}
.btn.ghost {
  background: transparent;
  border-color: var(--line);
  color: var(--ink);
}
.btn:hover { filter: brightness(1.06); }

.icon-btn {
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: inherit;
  cursor: pointer;
  display: grid;
  place-items: center;
  position: relative;
  z-index: 21;
}
.icon-btn:hover { background: transparent; opacity: 0.7; }
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn[aria-pressed="true"] { color: var(--bright); }

/* Library */
.library {
  height: 100%;
  overflow: auto;
  padding: calc(28px + var(--safe-top)) 32px 64px;
}
.lib-top {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  max-width: 1120px;
  margin: 0 auto 32px;
}
.brand { display: flex; gap: 16px; align-items: center; }
.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background:
    linear-gradient(135deg, var(--teal), var(--bright));
  box-shadow: 0 8px 20px rgba(0, 86, 85, 0.25);
}
.brand h1 { font-size: 1.8rem; letter-spacing: -0.03em; }
.brand p { color: var(--muted); margin-top: 2px; font-size: 0.95rem; }
.lib-actions { display: flex; gap: 10px; flex-wrap: wrap; }

.phone-hint {
  max-width: 1120px;
  margin: 0 auto 28px;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 14px 18px;
  border-radius: 18px;
  background: var(--ink);
  color: var(--cream);
}
.phone-hint img {
  width: 128px;
  height: 128px;
  border-radius: 8px;
  background: #fff;
  flex: none;
}
.phone-hint strong { display: block; font-family: Syne, sans-serif; margin-bottom: 4px; }
.phone-hint p { color: rgba(250, 246, 240, 0.72); line-height: 1.45; }
.phone-hint a { color: var(--bright); }

.drop-hero {
  max-width: 1120px;
  margin: 0 auto 40px;
  border: 1.5px dashed rgba(20, 20, 18, 0.22);
  border-radius: 24px;
  padding: 48px 24px;
  text-align: center;
  background: rgba(255, 255, 255, 0.45);
  transition: border-color 0.2s, background 0.2s, transform 0.2s;
  cursor: pointer;
}
.drop-hero.is-over {
  border-color: var(--teal);
  background: rgba(37, 165, 150, 0.08);
  transform: scale(1.01);
}
.drop-stack {
  width: 72px;
  height: 84px;
  margin: 0 auto 16px;
  position: relative;
}
.drop-stack span {
  position: absolute;
  inset: 0;
  background: var(--paper);
  border-radius: 4px 10px 4px 4px;
  box-shadow: 0 8px 18px rgba(20, 20, 18, 0.12);
}
.drop-stack span:nth-child(1) { transform: rotate(-8deg) translate(-8px, 6px); }
.drop-stack span:nth-child(2) { transform: rotate(6deg) translate(8px, 4px); }
.drop-stack span:nth-child(3) { background: linear-gradient(#fff, var(--sand)); }
.drop-title { font-family: Syne, sans-serif; font-size: 1.35rem; }
.drop-sub { color: var(--muted); max-width: 520px; margin: 8px auto 0; line-height: 1.5; }

.shelf-section { max-width: 1120px; margin: 0 auto 36px; }
.shelf-section h2 {
  font-size: 0.82rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 16px;
}
.shelf-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 22px;
}

.book-card {
  display: grid;
  gap: 10px;
}
.book-card .open-card {
  appearance: none;
  -webkit-appearance: none;
  border: 0;
  background: transparent;
  padding: 0;
  text-align: left;
  cursor: pointer;
  color: inherit;
  display: grid;
  gap: 10px;
  width: 100%;
  font: inherit;
}
.book-card .cover {
  aspect-ratio: 3 / 4;
  border-radius: 2px 10px 10px 2px;
  background: #d9d2c5 center/cover no-repeat;
  box-shadow:
    inset -10px 0 16px rgba(0, 0, 0, 0.12),
    8px 14px 28px rgba(20, 20, 18, 0.18);
  transform: perspective(900px) rotateY(-8deg);
  transform-origin: left center;
  transition: transform 0.25s ease;
  position: relative;
  overflow: hidden;
}
.book-card .cover::after {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 10px;
  background: linear-gradient(90deg, rgba(0,0,0,.18), transparent);
}
.book-card:hover .cover { transform: perspective(900px) rotateY(-2deg) translateY(-4px); }
.book-card .meta strong { display: block; font-size: 0.98rem; }
.book-card .meta span { color: var(--muted); font-size: 0.85rem; }
.book-card .card-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}
.book-card .remove {
  border: 0;
  background: none;
  color: var(--muted);
  cursor: pointer;
  padding: 0;
  font-size: 0.8rem;
}
.book-card .remove:hover { color: #8c5b5e; }

/* Reader */
.reader {
  position: fixed;
  inset: 0;
  height: 100dvh;
  max-height: 100dvh;
  background:
    radial-gradient(ellipse at 50% 42%, #2a2722 0%, var(--reader) 72%);
  color: #f4f0e8;
  display: grid;
  grid-template-rows: auto 1fr auto;
  overscroll-behavior: none;
}
.reader-top, .reader-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  padding-top: calc(10px + var(--safe-top));
  position: relative;
  z-index: 20;
  background: transparent;
  color: #fff;
  mix-blend-mode: difference;
  pointer-events: none;
}
.reader-top > *,
.reader-bar > * {
  pointer-events: auto;
}
.reader-title {
  flex: 1;
  min-width: 0;
  display: grid;
}
.reader-title strong {
  font-family: Syne, sans-serif;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.reader-title span { color: inherit; opacity: 0.7; font-size: 0.8rem; }
.reader-tools { display: flex; gap: 2px; }
.reader-bar {
  justify-content: center;
  padding-bottom: calc(14px + var(--safe-bottom));
}
.chrome-show-icon { display: none; }
.reader.is-immersive .chrome-hide-icon { display: none; }
.reader.is-immersive .chrome-show-icon { display: block; }
.reader.is-immersive {
  grid-template-rows: 1fr;
}
.reader.is-immersive .reader-top,
.reader.is-immersive .reader-bar {
  position: absolute;
  left: 0;
  right: 0;
  background: transparent;
}
.reader.is-immersive .reader-top { top: 0; }
.reader.is-immersive .reader-bar { bottom: 0; }
.reader.is-immersive .stage {
  grid-row: 1;
  min-height: 100%;
  padding: 4px;
}
.pager {
  display: flex;
  align-items: center;
  gap: 6px;
  background: transparent;
  border: 1px solid currentColor;
  border-radius: 999px;
  padding: 4px 12px;
  min-width: 110px;
  justify-content: center;
}
.pager input {
  width: 3.2ch;
  background: transparent;
  border: 0;
  color: inherit;
  text-align: right;
  outline: none;
}
.pager span { color: inherit; opacity: 0.7; }

.stage {
  position: relative;
  min-height: 0;
  display: grid;
  place-items: center;
  padding: 8px 56px 12px;
  touch-action: none;
  overflow: hidden;
}
.book-wrap {
  width: min(1100px, 100%);
  height: 100%;
  display: grid;
  place-items: center;
}
#book {
  width: 100%;
  height: 100%;
  filter: drop-shadow(0 22px 40px rgba(0, 0, 0, 0.45));
  transform-origin: center center;
}
.reader.is-pinched .nav-hit { pointer-events: none; }
.reader.is-pinched .stage { cursor: grab; }
.reader.is-pinched .stage.is-panning { cursor: grabbing; }
.stf__wrapper,
.stf__block {
  height: 100%;
}
.flip-page,
.stf__item {
  background: var(--paper);
  overflow: hidden;
}
.flip-page img.is-shifted {
  position: relative;
}
.flip-page img,
.stf__item img {
  width: 100%;
  height: 100%;
  object-fit: fill;
  display: block;
  pointer-events: none;
  user-select: none;
  background: var(--paper);
}

.nav-hit {
  position: absolute;
  top: 8%;
  bottom: 8%;
  width: 56px;
  border: 0;
  background: transparent;
  cursor: pointer;
  z-index: 3;
}
.nav-hit.left { left: 0; }
.nav-hit.right { right: 0; }
.nav-hit:hover { background: linear-gradient(90deg, transparent, rgba(255,255,255,0.04)); }
.nav-hit.left:hover { background: linear-gradient(270deg, transparent, rgba(255,255,255,0.04)); }

.load-panel {
  position: absolute;
  inset: 70px 0 80px;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 16px;
  z-index: 5;
  pointer-events: none;
}
.load-cover {
  width: 160px;
  height: 214px;
  border-radius: 2px 8px 8px 2px;
  background: #2c2a26 center/cover no-repeat;
  box-shadow: 8px 16px 40px rgba(0,0,0,.4);
}
.load-panel p { color: rgba(244,240,232,.8); }
.meter {
  width: min(280px, 70vw);
  height: 4px;
  border-radius: 99px;
  background: rgba(255,255,255,.12);
  overflow: hidden;
}
.meter span {
  display: block;
  height: 100%;
  width: 0%;
  background: var(--bright);
  transition: width 0.2s ease;
}

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(360px, 100%);
  background: #1d1b18;
  color: #f4f0e8;
  z-index: 20;
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--chrome-border);
  box-shadow: -20px 0 50px rgba(0,0,0,.35);
}
.drawer header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(12px + var(--safe-top)) 12px 12px 18px;
}
.drawer h2 { font-size: 1.05rem; }
.thumbs {
  overflow: auto;
  padding: 8px 16px 24px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.thumbs button {
  border: 1px solid transparent;
  background: #111;
  padding: 0;
  border-radius: 6px;
  overflow: hidden;
  cursor: pointer;
  color: #f4f0e8;
}
.thumbs button.is-current { border-color: var(--bright); }
.thumbs img { width: 100%; display: block; aspect-ratio: 3/4; object-fit: cover; }
.thumbs span {
  display: block;
  font-size: 0.75rem;
  padding: 6px;
  color: rgba(244,240,232,.65);
}

.search-drawer { gap: 8px; }
.search-drawer input[type="search"] {
  margin: 0 16px;
  height: 44px;
  border-radius: 10px;
  border: 1px solid var(--chrome-border);
  background: var(--chrome);
  color: inherit;
  padding: 0 12px;
  outline: none;
}
.search-results { overflow: auto; padding: 8px 16px 24px; display: grid; gap: 8px; }
.search-hit {
  text-align: left;
  background: var(--chrome);
  border: 1px solid var(--chrome-border);
  color: inherit;
  border-radius: 10px;
  padding: 10px 12px;
  cursor: pointer;
}
.search-hit b { color: var(--bright); }
.search-hit small { display: block; color: rgba(244,240,232,.5); margin-bottom: 4px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--cream);
  padding: 10px 16px;
  border-radius: 999px;
  z-index: 40;
  font-size: 0.9rem;
}

.reader.no-touch-turn .nav-hit { pointer-events: none; }
.sound-off .sound-waves { display: none; }
.touch-off,
.sound-off { position: relative; }
.touch-off::after,
.sound-off::after {
  content: "";
  position: absolute;
  width: 18px;
  height: 1.8px;
  background: currentColor;
  border-radius: 2px;
  transform: rotate(-36deg);
  pointer-events: none;
}

@media (max-width: 720px) {
  .only-desk { display: none; }
  .only-phone { display: block; }
  .drop-title .only-phone { display: inline; }
  .phone-hint { display: none !important; }
  .library { padding: calc(16px + var(--safe-top)) 18px calc(32px + var(--safe-bottom)); }
  .lib-top { flex-direction: column; align-items: flex-start; gap: 14px; }
  .lib-actions { width: 100%; }
  .lib-actions .btn { width: 100%; height: 48px; }
  .stage { padding: 4px 10px 8px; }
  .nav-hit { display: none; }
  .icon-btn { width: 44px; height: 44px; }
  .reader-top {
    gap: 2px;
    padding: 4px 6px;
    padding-top: calc(4px + var(--safe-top));
  }
  .reader-bar { padding-bottom: calc(10px + var(--safe-bottom)); }
  .reader-tools .tool-extra { display: none; }
  .reader-title { display: none; }
  .shelf-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
  .drop-hero { padding: 32px 18px; }
  .pager input { font-size: 16px; width: 4ch; }
  .search-drawer input[type="search"] { font-size: 16px; }
}

body.is-dragging .drop-hero { border-color: var(--teal); }

.book-card .card-action {
  border: 0;
  background: none;
  color: var(--muted);
  cursor: pointer;
  padding: 0;
  font-size: 0.8rem;
}
.book-card .card-action:hover { color: var(--teal); }
.book-card .card-action.is-danger:hover { color: #8c5b5e; }
.book-card .share-url {
  font-size: 0.75rem;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.gate-page {
  display: grid;
  place-items: center;
  padding: 32px 20px;
  overflow: auto;
}
.gate {
  width: min(420px, 100%);
  display: grid;
  gap: 28px;
}
.gate-form,
.publish-dialog form {
  display: grid;
  gap: 14px;
}
.gate-form label,
.publish-dialog label {
  display: grid;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--muted);
}
.gate-form input,
.publish-dialog input {
  height: 44px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  padding: 0 12px;
}
.gate-error {
  color: #8c5b5e;
  font-size: 0.9rem;
}
.slug-row {
  display: flex;
  align-items: center;
  gap: 2px;
}
.slug-host {
  font-size: 0.85rem;
  color: var(--muted);
  white-space: nowrap;
}
.publish-dialog {
  border: 0;
  border-radius: 18px;
  padding: 28px;
  width: min(440px, calc(100vw - 32px));
  background: var(--cream);
  color: var(--ink);
  box-shadow: 0 24px 60px rgba(20, 20, 18, 0.28);
}
.publish-dialog::backdrop { background: rgba(20, 20, 18, 0.45); }
.publish-dialog h2 { font-size: 1.3rem; }
.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 8px;
}
