:root {
  --black: #000;
  --white: #fff;
  --hero: "DM Sans", Aptos, "Segoe UI", system-ui, sans-serif;
  --body: Aptos, "Segoe UI", system-ui, sans-serif;
  --utility: "Cascadia Code", "SFMono-Regular", Consolas, monospace;
  --page-top: clamp(22px, 4vw, 52px);
  --nav-height: 39px;
  --swipe: 680ms cubic-bezier(.76, 0, .24, 1);
}

* { box-sizing: border-box; }

html, body {
  width: 100%;
  min-height: 100%;
}

body {
  min-width: 320px;
  margin: 0;
  color: var(--black);
  background: var(--white);
  font-family: var(--body);
}

body[data-view="upload"] {
  height: 100dvh;
  overflow: hidden;
}

::selection { color: var(--white); background: var(--black); }

button, input { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }

.skip-link {
  position: fixed;
  z-index: 30;
  top: 12px;
  left: 12px;
  padding: 10px 14px;
  color: var(--white);
  background: var(--black);
  transform: translateY(-150%);
}

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

.deck {
  min-height: 100dvh;
}

.view {
  position: relative;
  width: 100%;
  min-height: 100dvh;
  background: var(--white);
  animation: view-in 360ms cubic-bezier(.22, 1, .36, 1) both;
}

.view[hidden] { display: none; }
.view:focus { outline: none; }

.view-upload {
  display: grid;
  place-items: center;
  height: 100dvh;
  min-height: 0;
  padding: clamp(72px, 9vh, 100px) 24px clamp(28px, 5vh, 52px);
}

.upload-view-inner {
  display: grid;
  width: min(100%, 690px);
  gap: clamp(22px, 3.2vh, 32px);
}

.hero-copy { text-align: center; }

.hero-copy h1 {
  margin: 0;
  font-family: var(--hero);
  font-size: clamp(54px, 7.1vw, 108px);
  font-weight: 500;
  line-height: .94;
  letter-spacing: -.055em;
}

.hero-copy h1 em { font-weight: 500; }

.hero-copy p {
  margin: 19px 0 0;
  font-size: clamp(14px, 1.4vw, 17px);
  line-height: 1.4;
  opacity: .58;
}

.upload-box {
  width: min(100%, 590px);
  justify-self: center;
  padding: clamp(20px, 3vw, 32px);
  background: var(--white);
  border: 1px solid var(--black);
  border-radius: 14px;
  box-shadow: 9px 9px 0 var(--black);
  transition: transform 260ms cubic-bezier(.22, 1, .36, 1), box-shadow 260ms cubic-bezier(.22, 1, .36, 1);
}

.upload-box:hover,
.upload-box:focus-within {
  transform: translate(-3px, -3px);
  box-shadow: 12px 12px 0 var(--black);
}

.drop-zone {
  display: grid;
  grid-template-columns: 34px 1fr;
  column-gap: 14px;
  align-items: center;
  min-height: 82px;
  padding: 14px 18px;
  border: 1px dashed var(--black);
  border-radius: 9px;
  cursor: pointer;
  transition: background .18s ease, border-color .18s ease, transform .18s ease;
}

.drop-zone:hover { background: #f4f4f2; transform: translateY(-1px); }
.drop-zone.is-dragging { color: var(--white); background: var(--black); border-style: solid; }

.drop-zone input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.drop-zone:focus-within { outline: 2px solid var(--black); outline-offset: 3px; }
.drop-zone svg { grid-row: 1 / span 2; width: 27px; fill: none; stroke: currentColor; stroke-width: 1.7; }
.drop-title { font-weight: 650; }
.drop-note { margin-top: 3px; font-size: 11px; opacity: .58; }

.field-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-top: 18px;
}

.field-pair label {
  display: grid;
  gap: 6px;
  font-family: var(--utility);
  font-size: 9px;
  letter-spacing: .1em;
  text-transform: uppercase;
}

.field-pair label > span:first-child { opacity: .58; }

.field-pair input {
  width: 100%;
  min-width: 0;
  padding: 9px 0;
  color: var(--black);
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--black);
  border-radius: 0;
  outline: none;
  font-family: var(--body);
  font-size: 13px;
  letter-spacing: 0;
  text-transform: none;
}

.field-pair input:focus { box-shadow: 0 2px 0 var(--black); }

.slug-field {
  display: flex;
  align-items: center;
  border-bottom: 1px solid var(--black);
  font-family: var(--utility);
  font-size: 11px;
  letter-spacing: 0;
  text-transform: none;
}

.slug-field input { border: 0; box-shadow: none !important; }

.publish-row {
  display: flex;
  justify-content: flex-end;
  margin-top: 16px;
}

.primary-button {
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  min-height: 43px;
  padding: 0 15px 0 18px;
  color: var(--white);
  background: var(--black);
  border: 1px solid var(--black);
  border-radius: 7px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 650;
  transition: transform .18s ease, box-shadow .18s ease, opacity .18s ease;
}

.primary-button:hover { transform: translateY(-2px); box-shadow: 0 4px 0 rgba(0, 0, 0, .2); }
.primary-button:active { transform: translateY(0); box-shadow: none; }
.primary-button:disabled { cursor: wait; opacity: .55; }
.primary-button svg { width: 18px; fill: none; stroke: currentColor; stroke-width: 1.6; }

.form-status {
  min-height: 16px;
  margin: 10px 0 -8px;
  font-size: 11px;
  line-height: 1.4;
  opacity: .62;
}

.form-status.is-error { font-weight: 700; text-decoration: underline; opacity: 1; }

.page-switch {
  position: absolute;
  z-index: 3;
  top: var(--page-top);
  right: clamp(22px, 6vw, 96px);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  color: var(--black);
  background: transparent;
  border: 0;
  cursor: pointer;
  font-family: var(--utility);
  font-size: 9px;
  letter-spacing: .12em;
  text-transform: uppercase;
}

.page-switch svg { width: 19px; fill: none; stroke: currentColor; stroke-width: 1.2; transition: transform .2s ease; }
.page-switch:hover svg { transform: translateX(4px); }

.view-library {
  padding: var(--page-top) clamp(22px, 6vw, 96px);
  font-family: var(--hero);
}

.library-shell {
  display: flex;
  flex-direction: column;
  width: min(100%, 1320px);
  margin: 0 auto;
}

.library-topline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  min-height: var(--nav-height);
  padding-bottom: 16px;
  border-bottom: 1px solid var(--black);
}

.back-button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
  color: var(--black);
  background: transparent;
  border: 0;
  cursor: pointer;
  font-family: var(--utility);
  font-size: 9px;
  letter-spacing: .12em;
  text-transform: uppercase;
}

.back-button svg { width: 17px; fill: none; stroke: currentColor; stroke-width: 1.2; }

.library-stats {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin: 0;
  font-family: var(--utility);
  font-size: 10px;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.library-stats div { display: flex; gap: 7px; }
.library-stats dt { opacity: .52; }
.library-stats dd { margin: 0; }

.library-heading {
  display: grid;
  grid-template-columns: minmax(0, 1fr) min(280px, 40vw);
  align-items: flex-end;
  gap: 24px;
  padding: clamp(25px, 4vh, 42px) 0 22px;
}

.library-heading h2 {
  display: flex;
  align-items: baseline;
  min-width: 0;
  margin: 0;
  font-family: var(--hero);
  font-weight: 500;
}

.search-tools {
  position: relative;
  width: 100%;
  height: 37px;
}

.search-toggle {
  position: absolute;
  right: 0;
  bottom: 8px;
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
  color: var(--black);
  background: transparent;
  border: 0;
  cursor: pointer;
  z-index: 2;
}

.library-heading .folio-word,
.library-heading .search-word {
  font-size: clamp(52px, 7vw, 96px);
  line-height: .9;
  letter-spacing: -.055em;
}

.library-heading .search-word {
  max-width: 0;
  overflow: hidden;
  opacity: 0;
  transform: translateX(-18px);
  transition: max-width 520ms cubic-bezier(.22, 1, .36, 1), opacity 280ms ease, transform 520ms cubic-bezier(.22, 1, .36, 1);
}

.library-heading.is-searching .search-word {
  max-width: 5em;
  margin-right: .18em;
  opacity: 1;
  transform: translateX(0);
}

.search-toggle svg {
  width: 19px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.35;
  opacity: .58;
  transition: opacity .2s ease;
}

.search-toggle:hover svg { opacity: 1; }

.search-field {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 8px 0;
  border-bottom: 1px solid var(--black);
  opacity: 0;
  visibility: hidden;
  transform: translateX(22px);
  transition: opacity 320ms ease 110ms, transform 480ms cubic-bezier(.22, 1, .36, 1) 70ms, visibility 0s linear 480ms;
}

.library-heading.is-searching .search-field {
  opacity: 1;
  visibility: visible;
  transform: translateX(0);
  transition-delay: 110ms, 70ms, 0s;
}

.search-field input { width: 100%; min-width: 0; padding-right: 44px; color: var(--black); background: transparent; border: 0; outline: 0; }

.folio-list {
  border-top: 1px solid var(--black);
}

.folio-row {
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr) 124px 84px;
  align-items: center;
  gap: 20px;
  min-height: 108px;
  padding: 17px 0;
  color: inherit;
  border-bottom: 1px solid var(--black);
  text-decoration: none;
  transition: color .2s ease, background .2s ease, padding .2s ease;
}

.folio-row:hover { padding-right: 14px; padding-left: 14px; color: var(--white); background: var(--black); }

.folio-index {
  font-family: var(--utility);
  font-size: 10px;
  opacity: .55;
}

.folio-name h3 {
  margin: 0;
  font-family: var(--hero);
  font-size: clamp(23px, 3vw, 34px);
  font-weight: 500;
  letter-spacing: -.04em;
}

.folio-name p, .folio-meta {
  margin: 5px 0 0;
  font-family: var(--utility);
  font-size: 9px;
  letter-spacing: .03em;
  opacity: .55;
}

.folio-meta { margin: 0; white-space: pre-line; }

.open-mark {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 9px;
  font-size: 12px;
  font-weight: 650;
}

.open-mark span:last-child {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 1px solid currentColor;
  border-radius: 50%;
  transition: transform .2s ease;
}

.folio-row:hover .open-mark span:last-child { transform: rotate(-35deg); }

.loading-row, .empty-state {
  display: flex;
  align-items: center;
  min-height: 120px;
  font-family: var(--utility);
  font-size: 10px;
  letter-spacing: .05em;
  opacity: .58;
}

.loading-row p::after { content: ""; animation: ellipsis 1.4s steps(4, end) infinite; }

.toast {
  position: fixed;
  z-index: 20;
  right: 24px;
  bottom: 24px;
  display: flex;
  align-items: center;
  gap: 16px;
  max-width: min(520px, calc(100vw - 32px));
  padding: 15px 16px 15px 20px;
  color: var(--white);
  background: var(--black);
  border: 1px solid var(--white);
  box-shadow: 7px 7px 0 var(--white), 8px 8px 0 var(--black);
}

.toast[hidden] { display: none; }
.toast button { padding: 7px 10px; color: var(--black); background: var(--white); border: 1px solid var(--white); cursor: pointer; font-weight: 650; }
.toast .toast-close { padding: 4px; color: var(--white); background: transparent; border: 0; font-size: 22px; font-weight: 400; }

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

@keyframes view-in { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }
@keyframes ellipsis { 0% { content: ""; } 25% { content: "."; } 50% { content: ".."; } 75%, 100% { content: "..."; } }

:focus-visible { outline: 2px solid var(--black); outline-offset: 3px; }
.primary-button:focus-visible, .toast button:focus-visible, .folio-row:hover:focus-visible { outline-color: var(--white); }

@media (max-width: 680px) {
  :root { --page-top: 18px; }
  .view-upload { padding: 70px 16px 22px; }
  .upload-view-inner { gap: 22px; }
  .hero-copy h1 { font-size: clamp(48px, 15vw, 72px); }
  .hero-copy p { margin-top: 12px; font-size: 13px; }
  .upload-box { padding: 17px; border-radius: 11px; box-shadow: 6px 6px 0 var(--black); }
  .upload-box:hover, .upload-box:focus-within { transform: translate(-2px, -2px); box-shadow: 8px 8px 0 var(--black); }
  .drop-zone { min-height: 70px; padding: 11px 13px; }
  .field-pair { gap: 14px; margin-top: 14px; }
  .publish-row { gap: 12px; margin-top: 13px; }
  .primary-button { min-height: 40px; padding: 0 11px 0 13px; }
  .primary-button span { max-width: 58px; line-height: 1.1; text-align: left; }
  .form-status { margin-top: 7px; }
  .page-switch { right: 16px; }
  .view-library { padding-right: 16px; padding-left: 16px; }
  .library-heading { grid-template-columns: minmax(0, 1fr) 42px; align-items: end; gap: 12px; padding: 26px 0 18px; }
  .library-heading .folio-word, .library-heading .search-word { font-size: clamp(42px, 14vw, 58px); }
  .search-toggle svg { width: 17px; }
  .library-heading.is-searching .search-tools { grid-column: 1 / -1; width: 100%; }
  .library-heading.is-searching { grid-template-columns: 1fr; }
  .folio-row { grid-template-columns: 34px minmax(0, 1fr) 42px; gap: 10px; min-height: 92px; }
  .folio-meta { display: none; }
  .open-mark > span:first-child { display: none; }
}

@media (max-height: 720px) {
  .view-upload { padding-top: 58px; padding-bottom: 14px; }
  .upload-view-inner { gap: 16px; }
  .hero-copy h1 { font-size: clamp(48px, 9vh, 72px); }
  .hero-copy p { margin-top: 9px; }
  .upload-box { padding-top: 16px; padding-bottom: 14px; }
  .drop-zone { min-height: 64px; padding-top: 9px; padding-bottom: 9px; }
  .field-pair { margin-top: 12px; }
  .publish-row { margin-top: 10px; }
  .form-status { min-height: 12px; margin-top: 5px; }
}

@media (prefers-reduced-motion: reduce) {
  :root { --swipe: 1ms linear; }
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
