:root {
  --red: #ef2b19;
  --ink: #151619;
  --muted: #686b72;
  --paper: #f6f4ef;
  --line: rgba(20, 21, 24, 0.12);
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --turn-duration: 280ms;
  --turn-ease: cubic-bezier(0.77, 0, 0.175, 1);
  --crossfade-duration: 200ms;
  --crossfade-ease: cubic-bezier(0.23, 1, 0.32, 1);
  color-scheme: light;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { color: var(--ink); background: var(--paper); }
button, input { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button:focus-visible, input:focus-visible, a:focus-visible { outline: 3px solid #4b9cff; outline-offset: 2px; }
.hidden { display: none !important; }

.brand { display: inline-flex; align-items: center; color: inherit; text-decoration: none; }
.brand img { display: block; width: 52px; height: 48px; object-fit: contain; }

.button {
  display: inline-flex;
  min-height: 42px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 11px;
  color: var(--ink);
  background: white;
  cursor: pointer;
  font-weight: 750;
  text-decoration: none;
  transition: transform 150ms var(--ease), border-color 150ms var(--ease), background 150ms var(--ease);
}
.button:hover { border-color: rgba(20, 21, 24, 0.3); transform: translateY(-1px); }
.button:disabled { opacity: 0.42; cursor: not-allowed; transform: none; }
.button.primary { color: white; border-color: var(--red); background: var(--red); }
.button.danger { color: #b51613; border-color: rgba(181, 22, 19, 0.24); background: #fff5f3; }
.button.ghost { background: transparent; }
.icon-button { width: 42px; padding: 0; font-size: 20px; }

.field { display: grid; gap: 7px; }
.field > span { color: var(--muted); font-size: 12px; font-weight: 750; }
.field input {
  width: 100%;
  min-height: 46px;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: 11px;
  color: var(--ink);
  background: white;
}
.field input[type="file"] { padding: 10px 13px; }
.error { min-height: 20px; margin: 0; color: #b51613; font-size: 13px; }
.eyebrow { margin: 0; color: var(--red); font-size: 10px; font-weight: 850; letter-spacing: 0.17em; text-transform: uppercase; }

/* Public catalog archive */
.home-body {
  min-height: 100vh;
  background:
    linear-gradient(rgba(21, 22, 25, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(21, 22, 25, 0.035) 1px, transparent 1px),
    #f1efe9;
  background-size: 38px 38px;
}
.home-nav { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 16px; padding: 14px clamp(18px, 4vw, 58px); border-bottom: 1px solid var(--ink); background: rgba(241, 239, 233, 0.92); }
.home-nav-copy { display: grid; gap: 2px; }
.home-nav-copy strong { font-size: 12px; letter-spacing: 0.06em; }
.home-nav-copy span, .home-admin-link { color: var(--muted); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 9px; letter-spacing: 0.12em; }
.home-admin-link { padding: 10px 0 10px 20px; color: var(--ink); text-decoration: none; }
.home-main { width: min(1440px, calc(100% - clamp(36px, 8vw, 116px))); margin: 0 auto; }
.home-hero { display: grid; min-height: 430px; grid-template-columns: minmax(0, 1.5fr) minmax(260px, 0.5fr); gap: clamp(40px, 8vw, 130px); align-items: end; padding: clamp(64px, 10vw, 128px) 0 54px; border-bottom: 1px solid var(--ink); }
.home-hero h1 { margin: 14px 0 0; font-family: "Avenir Next Condensed", "DIN Condensed", sans-serif; font-size: clamp(64px, 11vw, 154px); font-stretch: condensed; font-weight: 900; letter-spacing: -0.065em; line-height: 0.72; text-transform: uppercase; }
.home-hero h1 span { color: transparent; -webkit-text-stroke: 2px var(--ink); }
.home-intro { display: grid; gap: 34px; align-items: end; }
.home-intro > p:first-child { max-width: 390px; margin: 0; color: #505258; font-size: 14px; line-height: 1.75; }
.home-count { display: flex; align-items: end; gap: 12px; margin: 0; }
.home-count strong { color: var(--red); font-family: "Avenir Next Condensed", sans-serif; font-size: 62px; line-height: 0.75; }
.home-count span { color: var(--muted); font-size: 11px; letter-spacing: 0.08em; }
.home-library { padding: 32px 0 90px; }
.home-section-heading { display: flex; align-items: center; justify-content: space-between; margin-bottom: 22px; }
.home-section-heading h2 { margin: 0; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11px; letter-spacing: 0.15em; }
.home-section-heading > span { color: var(--muted); font-size: 11px; }
.home-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: clamp(18px, 2.8vw, 42px); }
.home-card { min-width: 0; color: var(--ink); text-decoration: none; }
.home-cover { position: relative; display: grid; overflow: hidden; aspect-ratio: 3 / 4; place-items: center; border: 1px solid var(--ink); background: #1a1b1e; box-shadow: 9px 9px 0 var(--ink); transition: transform 220ms var(--ease), box-shadow 220ms var(--ease); }
.home-cover img { display: block; width: 100%; height: 100%; object-fit: contain; }
.home-card-number, .home-card-open { position: absolute; z-index: 2; padding: 7px 9px; border: 1px solid rgba(255, 255, 255, 0.24); color: white; background: rgba(15, 16, 18, 0.76); backdrop-filter: blur(12px); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 9px; letter-spacing: 0.08em; }
.home-card-number { top: 12px; left: 12px; }
.home-card-open { right: 12px; bottom: 12px; }
.home-card-copy { display: grid; gap: 8px; padding: 22px 2px 0; }
.home-card-meta, .home-card-copy time { color: var(--muted); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 9px; letter-spacing: 0.08em; }
.home-card-copy strong { overflow: hidden; font-size: clamp(20px, 2.4vw, 32px); letter-spacing: -0.045em; line-height: 1.05; text-overflow: ellipsis; white-space: nowrap; }
.home-loading { grid-column: 1 / -1; margin: 0; padding: 70px 20px; border: 1px dashed var(--muted); color: var(--muted); text-align: center; }
.home-footer { display: flex; justify-content: space-between; padding: 22px clamp(18px, 4vw, 58px); border-top: 1px solid var(--ink); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 9px; letter-spacing: 0.1em; }

@media (hover: hover) and (pointer: fine) {
  .home-card:hover .home-cover { transform: translate(-4px, -4px); box-shadow: 15px 15px 0 var(--red); }
  .home-admin-link:hover { color: var(--red); }
}

/* Admin */
.admin-body { min-height: 100vh; background: #efede7; }
.admin-login { display: grid; min-height: 100vh; place-items: center; padding: 28px; }
.login-card { width: min(420px, 100%); padding: 30px; border: 1px solid var(--line); border-radius: 22px; background: white; box-shadow: 0 24px 70px rgba(17, 18, 20, 0.1); }
.login-card .brand { margin-bottom: 26px; }
.login-card h1 { margin: 0 0 8px; font-size: 29px; letter-spacing: -0.045em; }
.login-card > p { margin: 0 0 24px; color: var(--muted); line-height: 1.55; }
.login-form { display: grid; gap: 14px; }

.admin-shell { min-height: 100vh; }
.admin-topbar { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 12px 28px; border-bottom: 1px solid var(--line); background: rgba(255, 255, 255, 0.84); backdrop-filter: blur(18px); }
.admin-user { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 13px; }
.admin-main { width: min(1180px, calc(100% - 40px)); margin: 0 auto; padding: 42px 0 70px; }
.admin-heading { display: flex; align-items: end; justify-content: space-between; gap: 24px; margin-bottom: 24px; }
.admin-heading h1 { margin: 6px 0 0; font-size: clamp(30px, 5vw, 50px); letter-spacing: -0.055em; line-height: 0.95; }
.limits { color: var(--muted); font-size: 13px; }
.upload-card { display: grid; grid-template-columns: minmax(180px, 0.8fr) minmax(260px, 1.4fr) auto; gap: 14px; align-items: end; padding: 20px; border: 1px solid var(--line); border-radius: 18px; background: white; }
.upload-status { grid-column: 1 / -1; display: flex; align-items: center; gap: 12px; min-height: 18px; color: var(--muted); font-size: 12px; }
.progress { display: none; width: 180px; height: 6px; overflow: hidden; border-radius: 99px; background: #e6e3dc; }
.progress span { display: block; width: 0; height: 100%; background: var(--red); transition: width 120ms linear; }
.progress.active { display: block; }
.catalog-section { margin-top: 34px; }
.catalog-section h2 { margin: 0 0 14px; font-size: 18px; }
.catalog-list { display: grid; gap: 12px; }
.empty { padding: 48px 20px; border: 1px dashed rgba(20, 21, 24, 0.2); border-radius: 18px; color: var(--muted); text-align: center; }
.catalog-card { display: grid; grid-template-columns: minmax(240px, 1.5fr) minmax(180px, 0.8fr) minmax(240px, 1fr); gap: 18px; align-items: center; padding: 18px 20px; border: 1px solid var(--line); border-radius: 16px; background: white; }
.catalog-title { min-width: 0; }
.catalog-title h3 { margin: 0 0 7px; overflow: hidden; font-size: 17px; text-overflow: ellipsis; white-space: nowrap; }
.catalog-title p, .catalog-meta { margin: 0; color: var(--muted); font-size: 12px; }
.status { display: inline-flex; align-items: center; gap: 6px; font-weight: 800; }
.status::before { width: 8px; height: 8px; border-radius: 50%; background: #19a05a; content: ""; }
.status.unpublished::before { background: #a0a2a7; }
.stats { display: flex; gap: 24px; }
.stat strong { display: block; font-size: 21px; }
.stat span { color: var(--muted); font-size: 11px; }
.catalog-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
.catalog-actions .button { min-height: 38px; padding: 0 12px; font-size: 12px; }

/* Reader */
.reader-body { height: 100vh; overflow: hidden; color: white; background: #292a2d; }
.reader-shell { display: grid; height: 100vh; grid-template-rows: 72px 1fr 68px; }
.reader-header, .reader-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 22px; background: rgba(24, 25, 27, 0.8); backdrop-filter: blur(18px); }
.reader-header { border-bottom: 1px solid rgba(255, 255, 255, 0.08); }
.reader-header .brand img { width: 48px; height: 44px; }
.reader-title { min-width: 0; text-align: center; }
.reader-title h1 { margin: 3px 0 0; overflow: hidden; font-size: 14px; text-overflow: ellipsis; white-space: nowrap; }
.reader-search { display: flex; align-items: center; gap: 7px; }
.reader-search input { width: 190px; min-height: 40px; padding: 0 12px; border: 1px solid rgba(255, 255, 255, 0.18); border-radius: 11px; color: white; background: rgba(255, 255, 255, 0.06); }
.reader-search .button, .reader-toolbar .button { min-height: 40px; color: rgba(255, 255, 255, 0.82); border-color: rgba(255, 255, 255, 0.13); background: rgba(255, 255, 255, 0.05); }
.reader-stage { position: relative; display: flex; min-height: 0; align-items: center; justify-content: center; padding: 22px 82px; touch-action: pan-y; }
.spread { position: relative; display: flex; width: min(100%, 1040px); height: 100%; min-height: 0; align-items: center; justify-content: center; perspective: 1600px; transform-origin: center; }
.page-slot { display: flex; max-width: 50%; height: min(100%, 760px); min-height: 0; flex: 1 1 50%; align-items: center; justify-content: flex-end; }
.page-slot:last-child { justify-content: flex-start; }
.page-slot:only-child, .spread.is-single > .page-slot { justify-content: center; }
.page-slot canvas { display: block; max-width: 100%; max-height: 100%; width: auto; height: auto; background: white; box-shadow: 0 24px 65px rgba(0, 0, 0, 0.24); }
.turn-old-spread { position: absolute; inset: 0; z-index: 2; display: flex; align-items: center; justify-content: center; pointer-events: none; }
.turn-old-spread .page-slot.is-turn-source { visibility: hidden; }
.turn-sheet { position: absolute; top: 0; bottom: 0; z-index: 3; width: 50%; pointer-events: none; transform-style: preserve-3d; will-change: transform; }
.turn-sheet[data-direction="forward"] { right: 0; transform-origin: left center; }
.turn-sheet[data-direction="backward"] { left: 0; transform-origin: right center; }
.turn-face { position: absolute; inset: 0; display: flex; overflow: hidden; align-items: center; backface-visibility: hidden; -webkit-backface-visibility: hidden; }
.turn-face .page-slot { width: 100%; max-width: 100%; flex: 1 1 100%; }
.turn-sheet[data-direction="forward"] .turn-face .page-slot { justify-content: flex-start; }
.turn-sheet[data-direction="backward"] .turn-face .page-slot { justify-content: flex-end; }
.turn-back { transform: rotateY(180deg); }
.turn-shadow { position: absolute; inset: 0; z-index: 2; background: linear-gradient(90deg, rgba(0, 0, 0, 0.32), transparent 26%, transparent 74%, rgba(0, 0, 0, 0.18)); opacity: 0; pointer-events: none; }
.reader-stage .edge { position: absolute; top: 50%; width: 48px; height: 82px; border-radius: 15px; transform: translateY(-50%); }
.reader-stage .prev { left: 20px; }
.reader-stage .next { right: 20px; }
.reader-toolbar { border-top: 1px solid rgba(255, 255, 255, 0.08); }
.toolbar-group { display: flex; align-items: center; gap: 7px; }
.page-input { width: 54px; min-height: 40px; border: 1px solid rgba(255, 255, 255, 0.15); border-radius: 11px; color: white; background: rgba(255, 255, 255, 0.06); text-align: center; }
.page-status { color: rgba(255, 255, 255, 0.72); font-size: 13px; font-weight: 750; }
.loading { position: absolute; inset: 0; display: grid; place-items: center; background: #292a2d; z-index: 4; }
.loading p { color: rgba(255, 255, 255, 0.65); }
.toast { position: fixed; right: 20px; bottom: 84px; z-index: 20; max-width: min(360px, calc(100vw - 40px)); padding: 12px 15px; border: 1px solid rgba(255, 255, 255, 0.14); border-radius: 12px; color: white; background: rgba(15, 16, 18, 0.92); opacity: 0; pointer-events: none; transform: translateY(8px); transition: opacity 180ms var(--ease), transform 180ms var(--ease); }
.toast.show { opacity: 1; transform: translateY(0); }
.reader-error { display: grid; min-height: 100vh; place-items: center; padding: 30px; color: white; background: #17181a; text-align: center; }
.reader-error img { width: 86px; height: 80px; object-fit: contain; }
.reader-error h1 { margin: 20px 0 8px; }
.reader-error p { color: rgba(255, 255, 255, 0.6); }

@media (max-width: 820px) {
  .home-main { width: min(100% - 28px, 680px); }
  .home-hero { min-height: 380px; grid-template-columns: 1fr; gap: 36px; padding-top: 64px; }
  .home-hero h1 { font-size: clamp(62px, 17vw, 104px); }
  .home-intro { grid-template-columns: 1fr auto; gap: 24px; }
  .home-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .admin-topbar { padding: 10px 14px; }
  .admin-main { width: min(100% - 24px, 720px); padding-top: 28px; }
  .admin-heading { display: block; }
  .limits { margin-top: 12px; }
  .upload-card, .catalog-card { grid-template-columns: 1fr; }
  .catalog-actions { justify-content: flex-start; }
  .reader-shell { grid-template-rows: 62px 1fr 64px; }
  .reader-header { padding: 9px 12px; }
  .reader-header .brand img { width: 46px; height: 42px; }
  .reader-title { display: none; }
  .reader-search input { width: min(38vw, 170px); }
  .reader-stage { padding: 14px 50px; }
  .page-slot { max-width: 100%; flex-basis: 100%; }
  .turn-sheet { left: 0; width: 100%; }
  .turn-sheet[data-direction="forward"] { right: auto; transform-origin: left center; }
  .turn-sheet[data-direction="backward"] { transform-origin: right center; }
  .reader-stage .edge { width: 38px; height: 64px; }
  .reader-stage .prev { left: 6px; }
  .reader-stage .next { right: 6px; }
  .reader-toolbar { padding: 9px 10px; }
  .reader-toolbar .label { display: none; }
  .toolbar-group { gap: 3px; }
}

@media (max-width: 560px) {
  .home-nav { padding: 10px 14px; }
  .home-nav-copy strong { font-size: 10px; }
  .home-nav-copy span { display: none; }
  .home-admin-link { padding-left: 8px; }
  .home-hero { min-height: 0; padding: 54px 0 38px; }
  .home-hero h1 { line-height: 0.78; }
  .home-hero h1 span { -webkit-text-stroke-width: 1.4px; }
  .home-intro { grid-template-columns: 1fr; }
  .home-count { justify-content: flex-end; }
  .home-grid { grid-template-columns: 1fr; gap: 42px; }
  .home-cover { box-shadow: 7px 7px 0 var(--ink); }
  .home-card-copy strong { font-size: 26px; }
  .home-footer { gap: 20px; }
  .reader-toolbar > .toolbar-group:first-child { display: none; }
}

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