:root {
  --ink: #191525;
  --paper: #fffaf0;
  --cream: #fff3cf;
  --purple: #6c5ce7;
  --pink: #ff5fa2;
  --cyan: #22d3c5;
  --yellow: #ffe55c;
  --orange: #ff8a4c;
  --green: #6fd08c;
  --wood: #9b5d3a;
  --wood-dark: #6b3f2b;
  --white: #ffffff;
  --radius: 18px;
  --border: 3px solid var(--ink);
  --shadow: 6px 6px 0 var(--ink);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 10% 10%, rgba(255, 229, 92, .45) 0 90px, transparent 92px),
    radial-gradient(circle at 90% 4%, rgba(255, 95, 162, .24) 0 120px, transparent 122px),
    linear-gradient(180deg, #fffaf0 0%, #f5f0ff 100%);
  font-family: "DM Sans", system-ui, sans-serif;
}

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

.skip-link {
  position: fixed;
  left: 1rem;
  top: 1rem;
  z-index: 100;
  transform: translateY(-150%);
  padding: .75rem 1rem;
  background: var(--ink);
  color: var(--white);
  border-radius: 8px;
}
.skip-link:focus { transform: translateY(0); }

.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;
}

.site-header,
main,
.site-footer {
  width: min(1180px, calc(100% - 32px));
  margin-inline: auto;
}

.site-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 2rem;
  padding: 72px 0 34px;
}

.header-copy { max-width: 780px; }
.eyebrow {
  margin: 0 0 .45rem;
  font-size: .78rem;
  font-weight: 800;
  letter-spacing: .16em;
  text-transform: uppercase;
}

h1, h2, h3 {
  font-family: "Archivo Black", Impact, sans-serif;
  letter-spacing: -.035em;
}

h1 {
  margin: 0;
  font-size: clamp(2.65rem, 7vw, 6.8rem);
  line-height: .9;
  text-wrap: balance;
}

h1 span {
  display: inline-block;
  color: var(--purple);
  text-shadow: 3px 3px 0 var(--yellow);
}

.intro {
  max-width: 620px;
  margin: 1.3rem 0 0;
  font-size: clamp(1rem, 2vw, 1.2rem);
}

.header-actions,
.curator-actions,
.detail-actions,
.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: .75rem;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  padding: .72rem 1rem;
  border: var(--border);
  border-radius: 12px;
  color: var(--ink);
  background: var(--white);
  box-shadow: 4px 4px 0 var(--ink);
  font-weight: 800;
  line-height: 1;
  text-decoration: none;
  cursor: pointer;
  transition: transform .14s ease, box-shadow .14s ease;
}

.button:hover { transform: translate(-2px, -2px); box-shadow: 6px 6px 0 var(--ink); }
.button:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--ink); }
.button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible, .book-spine:focus-visible {
  outline: 4px solid var(--cyan);
  outline-offset: 3px;
}

.button-primary { background: var(--yellow); }
.button-secondary { background: var(--white); }
.button-danger { background: #ffd7df; }
.button-small { min-height: 42px; padding: .55rem .8rem; }

.curator-only { display: none !important; }
body.curator-mode .curator-only { display: inline-flex !important; }
body.curator-mode .curator-panel { display: flex !important; }

.stats-strip {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
  margin-bottom: 24px;
}

.stat-card {
  position: relative;
  overflow: hidden;
  min-height: 118px;
  padding: 1rem 1.1rem;
  border: var(--border);
  border-radius: var(--radius);
  background: var(--white);
  box-shadow: var(--shadow);
}

.stat-card:nth-child(1) { background: var(--cyan); }
.stat-card:nth-child(2) { background: var(--pink); }
.stat-card:nth-child(3) { background: var(--yellow); }

.stat-number {
  display: block;
  font-family: "Archivo Black", Impact, sans-serif;
  font-size: clamp(2rem, 5vw, 3.6rem);
  line-height: .95;
}

.stat-label { display: block; margin-top: .4rem; font-weight: 800; }

.toolbar {
  display: flex;
  gap: .75rem;
  align-items: center;
  margin: 36px 0 28px;
}

.search-field { flex: 1; }
.search-field input {
  width: 100%;
  min-height: 52px;
  padding: 0 1rem;
  border: var(--border);
  border-radius: 999px;
  background: rgba(255,255,255,.9);
  box-shadow: 4px 4px 0 var(--ink);
}

.library { display: grid; gap: 30px; }

.shelf-section {
  position: relative;
  padding: 22px 22px 0;
  border: var(--border);
  border-radius: 24px;
  background: rgba(255,255,255,.65);
  box-shadow: var(--shadow);
}

.shelf-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 16px;
}

.shelf-heading h2 { margin: 0; font-size: clamp(1.25rem, 3vw, 2rem); }
.shelf-count {
  padding: .35rem .65rem;
  border: 2px solid var(--ink);
  border-radius: 999px;
  background: var(--cream);
  font-weight: 800;
}

.book-row {
  display: flex;
  align-items: flex-end;
  min-height: 280px;
  gap: 10px;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 10px 6px 16px;
  scrollbar-color: var(--purple) transparent;
}

.book-row::after {
  content: "";
  min-width: 12px;
}

.book-spine {
  --book-color: var(--pink);
  position: relative;
  flex: 0 0 clamp(72px, 10vw, 112px);
  width: clamp(72px, 10vw, 112px);
  height: var(--book-height, 220px);
  padding: 12px 8px;
  border: var(--border);
  border-bottom-width: 0;
  border-radius: 8px 8px 2px 2px;
  background: var(--book-color);
  box-shadow: inset -8px 0 rgba(0,0,0,.08), 4px 0 0 var(--ink);
  color: var(--ink);
  cursor: pointer;
  transform-origin: bottom center;
  transition: transform .18s ease;
}

.book-spine:hover { transform: translateY(-12px) rotate(-1.5deg); }
.book-spine::before,
.book-spine::after {
  content: "";
  position: absolute;
  left: 10px;
  right: 10px;
  height: 3px;
  background: var(--ink);
  opacity: .8;
}
.book-spine::before { top: 20px; }
.book-spine::after { bottom: 20px; }

.book-spine-title {
  position: absolute;
  inset: 34px 12px 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  overflow: hidden;
  font-family: "Archivo Black", Impact, sans-serif;
  font-size: clamp(.82rem, 1.8vw, 1rem);
  line-height: 1.05;
  text-align: left;
}

.book-spine-rating {
  position: absolute;
  right: 7px;
  top: 7px;
  min-width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border: 2px solid var(--ink);
  border-radius: 50%;
  background: var(--yellow);
  font-size: .7rem;
  font-weight: 900;
}

.shelf-board {
  height: 28px;
  margin: 0 -22px;
  border-top: var(--border);
  border-radius: 0 0 20px 20px;
  background: repeating-linear-gradient(90deg, var(--wood), var(--wood) 45px, #a96a45 46px, #a96a45 90px);
  box-shadow: inset 0 -8px var(--wood-dark);
}

.empty-section {
  align-self: center;
  margin: auto;
  padding: 1rem;
  border: 2px dashed rgba(25,21,37,.35);
  border-radius: 14px;
  color: rgba(25,21,37,.65);
  text-align: center;
}

.empty-state {
  padding: 58px 22px;
  border: var(--border);
  border-radius: 24px;
  background: var(--white);
  box-shadow: var(--shadow);
  text-align: center;
}
.empty-state h2 { margin: 1rem auto .5rem; max-width: 600px; }
.empty-state p { margin: 0; }
.empty-sticker {
  width: 100px;
  height: 100px;
  display: grid;
  place-items: center;
  margin: auto;
  border: var(--border);
  border-radius: 50% 45% 52% 46%;
  background: var(--yellow);
  box-shadow: 5px 5px 0 var(--pink), 9px 9px 0 var(--ink);
  font-family: "Archivo Black", Impact, sans-serif;
  transform: rotate(-8deg);
}

.curator-panel {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 2rem;
  margin-top: 38px;
  padding: 24px;
  border: var(--border);
  border-radius: 20px;
  background: var(--cream);
  box-shadow: var(--shadow);
}
.curator-panel h2 { margin: 0 0 .45rem; }
.curator-panel p:last-child { margin: 0; max-width: 720px; }
.curator-panel code { padding: .1rem .3rem; background: rgba(255,255,255,.8); border-radius: 5px; }
.file-button input { display: none; }

.site-footer {
  padding: 52px 0 70px;
  text-align: center;
  font-weight: 800;
}

::backdrop { background: rgba(25, 21, 37, .72); backdrop-filter: blur(4px); }

dialog {
  width: min(980px, calc(100% - 28px));
  max-height: min(92vh, 900px);
  padding: 0;
  border: 0;
  border-radius: 24px;
  background: transparent;
  overflow: visible;
}

dialog[open] { animation: dialog-in .18s ease-out; }
@keyframes dialog-in { from { opacity: 0; transform: translateY(16px) scale(.98); } }

.dialog-close {
  position: absolute;
  z-index: 10;
  right: -10px;
  top: -10px;
  width: 46px;
  height: 46px;
  border: var(--border);
  border-radius: 50%;
  background: var(--yellow);
  box-shadow: 4px 4px 0 var(--ink);
  font-size: 1.9rem;
  font-weight: 900;
  line-height: 1;
  cursor: pointer;
}

.open-book {
  display: grid;
  grid-template-columns: minmax(280px, .85fr) minmax(360px, 1.15fr);
  min-height: 620px;
  border: var(--border);
  border-radius: 18px;
  background: var(--paper);
  box-shadow: 12px 12px 0 var(--ink);
  overflow: hidden;
}

.open-book-cover {
  min-height: 620px;
  border-right: var(--border);
  background-position: center;
  background-size: cover;
}

.generated-cover {
  display: grid;
  place-items: center;
  padding: 2rem;
  text-align: center;
}
.generated-cover span {
  max-width: 12ch;
  font-family: "Archivo Black", Impact, sans-serif;
  font-size: clamp(2rem, 6vw, 5rem);
  line-height: .95;
  text-transform: uppercase;
  text-shadow: 3px 3px 0 rgba(255,255,255,.5);
}

.open-book-page {
  position: relative;
  overflow-y: auto;
  padding: clamp(28px, 5vw, 62px);
  background:
    linear-gradient(90deg, rgba(108,92,231,.12), transparent 24px),
    repeating-linear-gradient(0deg, transparent 0 31px, rgba(25,21,37,.05) 32px);
}
.open-book-page h2 { margin: 0 0 .35rem; font-size: clamp(2rem, 5vw, 4.4rem); line-height: .95; }
.detail-category { margin: 0 0 1rem; font-weight: 900; text-transform: uppercase; letter-spacing: .12em; color: var(--purple); }
.detail-author { margin: 0; font-size: 1.15rem; font-weight: 700; }
.detail-rating { display: flex; align-items: center; gap: .75rem; margin: 1.2rem 0 .5rem; }
.detail-rating #detail-stars { letter-spacing: .08em; color: #c68600; }
.detail-score { padding: .3rem .55rem; border: 2px solid var(--ink); border-radius: 999px; background: var(--yellow); }
.detail-date { margin: 0 0 1.6rem; color: rgba(25,21,37,.72); }
.detail-review { white-space: pre-wrap; line-height: 1.75; }
.detail-actions { margin-top: 2rem; }
#detail-purchase[hidden] { display: none; }

.form-dialog { overflow: auto; background: var(--paper); border: var(--border); box-shadow: 10px 10px 0 var(--ink); }
#book-form { padding: clamp(22px, 5vw, 48px); }
.form-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; }
.form-heading h2 { margin: 0 0 1.5rem; font-size: clamp(2rem, 5vw, 3.5rem); }
.inline-close { position: static; flex: 0 0 auto; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
label > span, legend { display: block; margin-bottom: .42rem; font-weight: 900; }
input, select, textarea {
  width: 100%;
  padding: .85rem .9rem;
  border: 2px solid var(--ink);
  border-radius: 10px;
  background: var(--white);
}
textarea { resize: vertical; }
#book-form > label, .rating-fieldset, .cover-upload-row { display: block; margin-top: 1rem; }
.rating-fieldset { padding: 1rem; border: 2px solid var(--ink); border-radius: 14px; background: var(--white); }
.rating-picker { display: flex; flex-wrap: wrap; gap: .35rem; }
.rating-star {
  width: 38px;
  height: 38px;
  padding: 0;
  border: 2px solid var(--ink);
  border-radius: 50%;
  background: var(--white);
  cursor: pointer;
  font-size: 1.2rem;
}
.rating-star.is-selected, .rating-star:hover { background: var(--yellow); }
#rating-output { display: block; margin-top: .6rem; font-weight: 800; }
.cover-upload-row { display: grid !important; grid-template-columns: 1fr 130px; gap: 1rem; align-items: end; }
.cover-upload small { display: block; margin-top: .45rem; color: rgba(25,21,37,.72); }
.cover-preview {
  aspect-ratio: 2 / 3;
  display: grid;
  place-items: center;
  border: 2px dashed var(--ink);
  border-radius: 10px;
  background: var(--cream);
  background-position: center;
  background-size: cover;
  overflow: hidden;
  text-align: center;
  font-weight: 900;
}
.form-error { min-height: 1.4em; margin: .8rem 0 0; color: #a5002d; font-weight: 800; }
.form-actions { justify-content: flex-end; margin-top: 1.3rem; }

@media (max-width: 820px) {
  .site-header { align-items: flex-start; flex-direction: column; padding-top: 44px; }
  .stats-strip { grid-template-columns: 1fr; }
  .stat-card { min-height: 96px; }
  .open-book { grid-template-columns: 1fr; max-height: 88vh; overflow-y: auto; }
  .open-book-cover { min-height: 420px; border-right: 0; border-bottom: var(--border); }
  .open-book-page { overflow: visible; }
  .curator-panel { align-items: flex-start; flex-direction: column; }
}

@media (max-width: 560px) {
  :root { --shadow: 4px 4px 0 var(--ink); }
  .site-header, main, .site-footer { width: min(100% - 20px, 1180px); }
  .header-actions, .curator-actions, .detail-actions, .form-actions { width: 100%; }
  .header-actions .button, .curator-actions .button { flex: 1 1 100%; }
  .form-grid { grid-template-columns: 1fr; }
  .cover-upload-row { grid-template-columns: 1fr 96px; }
  .shelf-section { padding-inline: 12px; }
  .shelf-board { margin-inline: -12px; }
  .book-row { min-height: 240px; }
  .book-spine { flex-basis: 78px; width: 78px; }
  .dialog-close { right: 4px; top: 4px; }
}

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