@import url("https://fonts.googleapis.com/css2?family=DM+Sans:wght@300;400;500;600&display=swap");

:root {
  color-scheme: light;
  --ink: #2d2926;
  --muted: #746d66;
  --paper: #f5f0e8;
  --surface: #fffdf9;
  --surface-soft: #eee6db;
  --accent: #a64f3e;
  --accent-dark: #78382d;
  --sage: #71877a;
  --line: rgba(45, 41, 38, 0.14);
  --shadow: 0 1rem 2.5rem rgba(67, 55, 45, 0.13);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  background: var(--paper);
}

body {
  min-width: 320px;
  margin: 0;
  background:
    radial-gradient(circle at 92% 4%, rgba(211, 176, 143, 0.24), transparent 28rem),
    linear-gradient(180deg, #faf7f1 0%, var(--paper) 38%, #eee7dc 100%);
  color: var(--ink);
  font-family: "DM Sans", system-ui, sans-serif;
}

button,
dialog {
  font: inherit;
}

button {
  color: inherit;
}

.page-shell {
  width: min(100% - 2rem, 76rem);
  margin: 0 auto;
  padding: clamp(2rem, 5vw, 5rem) 0 3rem;
}

.masthead {
  position: relative;
  display: block;
  padding: 0 0 clamp(3rem, 8vw, 6.5rem);
  border-bottom: 1px solid var(--line);
  text-align: center;
}

.add-book-button,
.book-search-form button,
.book-search-result button {
  border: 1px solid var(--accent);
  border-radius: 999px;
  background: var(--accent);
  color: white;
  cursor: pointer;
  font-weight: 600;
}

.add-book-button {
  margin: clamp(1.75rem, 4vw, 3rem) auto 0;
  padding: 0.72rem 1.15rem;
}

.book-search[hidden] {
  display: none;
}

.book-search {
  margin-top: 1.5rem;
  padding: clamp(1.25rem, 4vw, 2.25rem);
  border: 1px solid var(--line);
  border-radius: 1rem;
  background: rgba(255, 253, 249, 0.82);
  box-shadow: var(--shadow);
}

.book-search-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.book-search-heading h2 {
  margin: 0;
  color: var(--accent-dark);
  font-size: clamp(1.4rem, 4vw, 2rem);
  font-weight: 400;
}

.text-button {
  padding: 0.35rem;
  border: 0;
  background: transparent;
  color: var(--accent-dark);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 0.18em;
}

.book-search-form {
  display: grid;
  gap: 0.55rem;
  margin-top: 1.5rem;
}

.book-search-form > label {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.04em;
}

.book-search-form > div {
  display: flex;
  gap: 0.65rem;
}

.book-search-form input {
  min-width: 0;
  flex: 1;
  padding: 0.75rem 0.9rem;
  border: 1px solid var(--line);
  border-radius: 0.65rem;
  background: white;
  color: var(--ink);
  font: inherit;
}

.book-search-form button,
.book-search-result button {
  padding: 0.62rem 0.95rem;
}

.book-search-results {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr));
  gap: 0.8rem;
  margin-top: 1.25rem;
  color: var(--muted);
}

.book-search-result {
  display: grid;
  grid-template-columns: 3.3rem 1fr auto;
  gap: 0.75rem;
  align-items: center;
  padding: 0.7rem;
  border: 1px solid var(--line);
  border-radius: 0.75rem;
  background: white;
}

.book-search-result img {
  width: 3.3rem;
  aspect-ratio: 2 / 3;
  border-radius: 0.25rem;
  object-fit: cover;
}

.book-search-result h3,
.book-search-result p {
  margin: 0;
}

.book-search-result h3 {
  color: var(--ink);
  font-size: 0.88rem;
  line-height: 1.25;
}

.book-search-result p {
  margin-top: 0.25rem;
  font-size: 0.72rem;
}

.save-status {
  min-height: 1.25rem;
  margin: 0.8rem 0 -2rem;
  color: var(--sage);
  font-size: 0.75rem;
  font-weight: 600;
  text-align: center;
}

.save-status.error {
  color: var(--accent-dark);
}

.monogram {
  position: absolute;
  top: 0;
  left: 0;
  display: grid;
  width: 3.5rem;
  height: 3.5rem;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: rgba(255, 253, 249, 0.72);
  color: var(--accent);
  font-family: "DM Sans", system-ui, sans-serif;
  font-size: 1.65rem;
  font-style: normal;
  font-weight: 400;
  text-decoration: none;
}

h1,
.section-heading h2,
.book-details-panel h3 {
  color: var(--accent-dark);
  font-family: "DM Sans", system-ui, sans-serif;
  font-weight: 300;
  text-align: center;
  text-transform: uppercase;
}

h1 {
  max-width: 15ch;
  margin: 0 auto;
  font-size: clamp(2.9rem, 9vw, 6.8rem);
  letter-spacing: 0.055em;
  line-height: 1;
  text-wrap: balance;
}

.shelf {
  padding: clamp(3.5rem, 8vw, 6.5rem) 0;
  border-bottom: 1px solid var(--line);
}

.shelf-current {
  padding-top: clamp(2.75rem, 6vw, 4.5rem);
}

.section-heading {
  display: flex;
  justify-content: center;
  gap: 1rem;
  align-items: end;
  margin-bottom: clamp(1.5rem, 4vw, 2.5rem);
}

.section-heading h2 {
  margin: 0;
  font-size: clamp(2rem, 5vw, 3.4rem);
  letter-spacing: 0.075em;
  line-height: 1.08;
}

.section-note {
  margin: 0 0 0.2rem;
  color: var(--muted);
  font-size: 0.8rem;
}

.book-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(9.5rem, 42vw), 1fr));
  gap: clamp(1rem, 2.6vw, 1.8rem);
  align-items: start;
}

.current-grid:has(.empty-state) {
  display: block;
}

.current-grid {
  display: block;
}

.current-book-feature {
  display: grid;
  grid-template-columns: minmax(12rem, 0.7fr) minmax(24rem, 1.3fr);
  gap: clamp(2rem, 5vw, 5rem);
  align-items: center;
}

.current-book-feature .book-card {
  width: min(100%, 20rem);
}

.current-book-feature .current-book-details {
  grid-column: 2;
  margin: 0;
}

@media (min-width: 681px) {
  .current-book-feature {
    grid-template-columns: minmax(12rem, 20rem) minmax(0, 1fr);
    gap: clamp(0.75rem, 1.5vw, 1.5rem);
  }

  .book-details-panel.current-book-details {
    grid-template-columns: minmax(0, 1fr);
    gap: 1.25rem;
  }

  .current-book-details h3,
  .current-book-details .book-author {
    display: none;
  }

  .current-book-details .book-description {
    grid-column: 1;
    grid-row: auto;
    align-self: start;
  }
}

.book-card {
  position: relative;
  min-width: 0;
}

.book-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.3rem;
  margin-top: 0.65rem;
}

.book-actions button {
  position: relative;
  min-width: 0;
  padding: 0.42rem 0.2rem;
  overflow: visible;
  border: 1px solid var(--line);
  border-radius: 0.4rem;
  background: rgba(255, 253, 249, 0.72);
  color: var(--muted);
  cursor: pointer;
  font-size: clamp(0.58rem, 1.5vw, 0.68rem);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.book-drag-surface {
  cursor: grab;
  touch-action: none;
}

.book-drag-surface:active {
  cursor: grabbing;
}

.book-actions .remove-book:hover {
  border-color: var(--accent);
  color: var(--accent-dark);
}

.cover-heart-button {
  position: absolute;
  z-index: 2;
  top: 0.62rem;
  left: 0.62rem;
  display: grid;
  width: 2rem;
  height: 2rem;
  padding: 0;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.68);
  border-radius: 50%;
  box-shadow: 0 0.28rem 0.8rem rgba(45, 41, 38, 0.16);
  background: rgba(255, 253, 249, 0.92);
  color: var(--accent);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  backdrop-filter: blur(8px);
}

.cover-heart-button[aria-pressed="true"] {
  background: rgba(166, 79, 62, 0.95);
  color: white;
}

.cover-heart-button:focus-visible {
  outline: 3px solid rgba(166, 79, 62, 0.46);
  outline-offset: 3px;
}

.book-actions .remove-book {
  font-size: 1.4rem;
  font-weight: 400;
  line-height: 1;
}

.book-actions .done-button {
  font-size: 0.95rem;
  font-weight: 600;
  line-height: 1;
}

.book-actions [data-tooltip]::after,
.cover-heart-button[data-tooltip]::after {
  position: absolute;
  z-index: 6;
  padding: 0.38rem 0.55rem;
  border: 1px solid var(--line);
  border-radius: 0.38rem;
  box-shadow: 0 0.35rem 0.85rem rgba(45, 41, 38, 0.16);
  background: var(--ink);
  color: white;
  content: attr(data-tooltip);
  font-size: 0.68rem;
  font-weight: 500;
  letter-spacing: 0;
  line-height: 1;
  opacity: 0;
  pointer-events: none;
  text-transform: none;
  transition: opacity 120ms ease, transform 120ms ease;
  white-space: nowrap;
}

.book-actions [data-tooltip]::after {
  bottom: calc(100% + 0.45rem);
  left: 50%;
  transform: translate(-50%, 0.2rem);
}

.book-actions [data-tooltip]:hover::after,
.book-actions [data-tooltip]:focus-visible::after {
  opacity: 1;
  transform: translate(-50%, 0);
}

.cover-heart-button[data-tooltip]::after {
  top: 50%;
  left: calc(100% + 0.45rem);
  transform: translate(-0.2rem, -50%);
}

.cover-heart-button[data-tooltip]:hover::after,
.cover-heart-button[data-tooltip]:focus-visible::after {
  opacity: 1;
  transform: translate(0, -50%);
}

.sortable-book {
  transition: opacity 150ms ease, transform 150ms ease;
}

.sortable-book.is-dragging {
  opacity: 0.42;
}

.sortable-book.drag-over,
.book-grid.drag-over {
  outline: 2px dashed var(--accent);
  outline-offset: 0.35rem;
}

.cover-button {
  position: relative;
  display: block;
  width: 100%;
  padding: 0;
  border: 0;
  border-radius: 0.42rem;
  background: transparent;
  cursor: pointer;
  text-align: left;
  transform-origin: center bottom;
  transition: transform 180ms ease, filter 180ms ease;
}

.cover-button::after {
  position: absolute;
  inset: 0;
  border: 1px solid rgba(255, 255, 255, 0.34);
  border-radius: inherit;
  box-shadow: inset 0 0 0 1px rgba(45, 41, 38, 0.06), var(--shadow);
  content: "";
  pointer-events: none;
}

.cover-button:hover {
  filter: saturate(1.04);
  transform: translateY(-0.45rem) rotate(-0.35deg);
}

.cover-button:active {
  transform: translateY(-0.15rem) scale(0.99);
}

.book-card.is-expanded .cover-button {
  outline: 3px solid var(--accent);
  outline-offset: 5px;
  filter: saturate(1.08);
  transform: translateY(-0.35rem);
}

.book-card.is-expanded .cover-button::after {
  box-shadow:
    inset 0 0 0 1px rgba(45, 41, 38, 0.06),
    0 1.15rem 2.8rem rgba(120, 56, 45, 0.24);
}

.cover-button:focus-visible,
.dialog-close:focus-visible,
.monogram:focus-visible {
  outline: 3px solid rgba(166, 79, 62, 0.46);
  outline-offset: 4px;
}

.book-cover {
  display: block;
  width: 100%;
  aspect-ratio: 2 / 3;
  border-radius: inherit;
  background: var(--surface-soft);
  object-fit: cover;
}

.cover-badges {
  position: absolute;
  z-index: 1;
  top: 0.62rem;
  right: 0.62rem;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.42rem;
  pointer-events: none;
}

.tag {
  display: inline-flex;
  min-height: 1.8rem;
  align-items: center;
  justify-content: center;
  padding: 0.32rem 0.62rem;
  border: 1px solid rgba(255, 255, 255, 0.68);
  border-radius: 999px;
  box-shadow: 0 0.28rem 0.8rem rgba(45, 41, 38, 0.14);
  background: rgba(255, 253, 249, 0.92);
  color: var(--ink);
  font-size: 0.72rem;
  font-weight: 600;
  line-height: 1;
  backdrop-filter: blur(8px);
}

.tag.priority {
  min-width: 1.8rem;
  padding-inline: 0.48rem;
}

.tag.hold {
  background: rgba(113, 135, 122, 0.94);
  color: white;
}

.tag.loved {
  min-width: 1.8rem;
  padding-inline: 0.48rem;
  background: rgba(166, 79, 62, 0.95);
  color: white;
  font-size: 0.86rem;
}

.book-details-panel {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: minmax(12rem, 0.65fr) minmax(18rem, 1.35fr);
  gap: clamp(1.25rem, 4vw, 4rem);
  margin: 0.2rem 0 0.8rem;
  padding: clamp(1.4rem, 4vw, 2.5rem);
  border: 1px solid var(--line);
  border-radius: 0.9rem;
  background: rgba(255, 253, 249, 0.72);
  box-shadow: 0 0.7rem 1.8rem rgba(67, 55, 45, 0.07);
}

.book-details-panel[hidden] {
  display: none;
}

.book-details-panel h3 {
  grid-column: 1;
  margin: 0.32rem 0 0;
  font-size: clamp(1.65rem, 3vw, 2.3rem);
  letter-spacing: 0.055em;
  line-height: 1.08;
}

.book-meta {
  grid-column: 1;
  margin: 0;
  color: var(--muted);
  font-size: 0.67rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.book-author {
  grid-column: 1;
  margin: 0.5rem 0 0;
  color: var(--accent);
  font-size: 0.8rem;
  font-weight: 600;
}

.book-description {
  grid-column: 2;
  grid-row: 1 / span 3;
  align-self: center;
  max-width: 60ch;
  margin: 0;
  color: var(--muted);
  font-size: clamp(0.95rem, 1.6vw, 1.08rem);
  line-height: 1.65;
  text-wrap: pretty;
}

.current-progress {
  grid-column: 1 / -1;
  display: grid;
  gap: 0.5rem;
  margin-top: 1rem;
}

.mobile-current-progress {
  display: none;
}

.current-progress-label {
  margin: 0;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.progress-slider-row {
  position: relative;
  display: flex;
  align-items: center;
}

.progress-slider {
  --progress: 0%;
  width: 100%;
  height: 1.4rem;
  margin: 0;
  appearance: none;
  background: transparent;
  cursor: ew-resize;
}

.progress-slider::-webkit-slider-runnable-track {
  height: 0.72rem;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent) var(--progress), var(--surface-soft) var(--progress));
}

.progress-slider::-webkit-slider-thumb {
  width: 1.8rem;
  height: 1.8rem;
  margin-top: -0.54rem;
  appearance: none;
  border: 3px solid var(--surface);
  border-radius: 50% 50% 50% 12%;
  box-shadow: 0 0.24rem 0.65rem rgba(67, 55, 45, 0.22);
  background: var(--accent);
  transform: rotate(-45deg);
}

.progress-slider::-moz-range-track {
  height: 0.72rem;
  border-radius: 999px;
  background: var(--surface-soft);
}

.progress-slider::-moz-range-progress {
  height: 0.72rem;
  border-radius: 999px;
  background: var(--accent);
}

.progress-slider::-moz-range-thumb {
  width: 1.45rem;
  height: 1.45rem;
  border: 3px solid var(--surface);
  border-radius: 50% 50% 50% 12%;
  box-shadow: 0 0.24rem 0.65rem rgba(67, 55, 45, 0.22);
  background: var(--accent);
  transform: rotate(-45deg);
}

.progress-slider:focus-visible {
  outline: 3px solid rgba(166, 79, 62, 0.3);
  outline-offset: 4px;
}

.progress-story-labels {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-family: Georgia, serif;
  font-size: 0.68rem;
  font-style: italic;
}

.current-progress-label output {
  display: inline-grid;
  min-width: 2.2rem;
  min-height: 2.2rem;
  margin-inline: 0.22rem;
  place-items: center;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  font-size: 0.86rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* Legacy progress styling retained for browsers rendering fallback markup. */
.current-progress progress {
  width: 100%;
  height: 0.72rem;
  overflow: hidden;
  border: 0;
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--accent);
}

.current-progress progress::-webkit-progress-bar {
  border-radius: 999px;
  background: var(--surface-soft);
}

.current-progress progress::-webkit-progress-value {
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), #c57a61);
}

.current-progress progress::-moz-progress-bar {
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), #c57a61);
}

.empty-state {
  margin: 0;
  padding: 1.4rem 1.5rem;
  border: 1px dashed rgba(45, 41, 38, 0.2);
  border-radius: 0.8rem;
  background: rgba(255, 253, 249, 0.46);
  color: var(--muted);
  line-height: 1.55;
}

.empty-state.error {
  color: var(--accent-dark);
}

.book-dialog {
  width: min(58rem, calc(100% - 2rem));
  max-height: min(48rem, calc(100dvh - 2rem));
  padding: 0;
  overflow: hidden auto;
  border: 1px solid rgba(45, 41, 38, 0.16);
  border-radius: 1.25rem;
  background: var(--surface);
  box-shadow: 0 2rem 6rem rgba(45, 41, 38, 0.28);
  color: var(--ink);
}

.book-dialog::backdrop {
  background: rgba(34, 29, 26, 0.58);
  backdrop-filter: blur(6px);
}

.dialog-layout {
  display: grid;
  grid-template-columns: minmax(14rem, 0.8fr) minmax(0, 1.2fr);
  min-height: 31rem;
}

.dialog-cover-wrap {
  display: grid;
  place-items: center;
  padding: clamp(2rem, 5vw, 4rem);
  background: var(--surface-soft);
}

.dialog-cover {
  display: block;
  width: min(100%, 17rem);
  max-height: 31rem;
  border-radius: 0.35rem;
  box-shadow: 0 1.4rem 3rem rgba(45, 41, 38, 0.2);
  object-fit: contain;
}

.dialog-copy {
  align-self: center;
  padding: clamp(2.2rem, 5vw, 4.5rem);
}

.dialog-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1.3rem;
}

.dialog-tags .tag {
  border-color: var(--line);
  box-shadow: none;
  background: var(--paper);
}

.dialog-tags .tag.loved {
  background: var(--accent);
  color: white;
}

.dialog-tags .tag.hold {
  background: var(--sage);
  color: white;
}

.dialog-year {
  margin: 0 0 0.55rem;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.12em;
}

.dialog-copy h2 {
  margin: 0;
  font-size: clamp(2.2rem, 6vw, 4.4rem);
  letter-spacing: -0.045em;
  line-height: 0.98;
  text-wrap: balance;
}

.dialog-author {
  margin: 1rem 0 0;
  color: var(--accent);
  font-weight: 600;
}

.dialog-description {
  margin: 1.7rem 0 0;
  color: var(--muted);
  font-size: clamp(1rem, 2vw, 1.12rem);
  line-height: 1.7;
  text-wrap: pretty;
}

.dialog-close {
  position: sticky;
  z-index: 2;
  top: 0.8rem;
  float: right;
  width: 2.7rem;
  height: 2.7rem;
  margin: 0.8rem 0.8rem -3.5rem 0;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: rgba(255, 253, 249, 0.94);
  color: var(--ink);
  cursor: pointer;
  font-size: 1.7rem;
  line-height: 1;
}

.dialog-open {
  overflow: hidden;
}

footer {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding-top: 2rem;
  color: rgba(45, 41, 38, 0.5);
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

footer a {
  color: inherit;
  text-underline-offset: 0.2em;
}

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

@media (max-width: 680px) {
  .page-shell {
    width: min(100% - 1.25rem, 76rem);
    padding-top: 1.3rem;
  }

  .masthead {
    padding-top: 4.25rem;
  }

  .book-search-form > div {
    align-items: stretch;
  }

  .book-search-results {
    grid-template-columns: 1fr;
  }

  .monogram {
    width: 3rem;
    height: 3rem;
  }

  .section-heading {
    align-items: end;
  }

  .book-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1rem 0.78rem;
  }

  .current-book-feature {
    grid-template-columns: 1fr;
    gap: 1.5rem;
  }

  .current-book-feature .book-card {
    width: min(100%, 13rem);
    margin-inline: auto;
  }

  .current-book-feature .current-book-details {
    grid-column: 1;
  }

  .mobile-current-progress {
    display: grid;
  }

  .current-book-details .current-progress {
    display: none;
  }

  .current-book-details h3 {
    text-align: center;
  }

  .book-details-panel {
    grid-template-columns: 1fr;
    gap: 0.25rem;
  }

  .book-description {
    grid-column: 1;
    grid-row: auto;
    margin-top: 0.9rem;
  }

  .dialog-layout {
    grid-template-columns: 1fr;
  }

  .dialog-cover-wrap {
    padding: 2.25rem 3.5rem;
  }

  .dialog-cover {
    width: min(100%, 13rem);
    max-height: 20rem;
  }

  .dialog-copy {
    padding: 2rem 1.5rem 2.5rem;
  }

  footer {
    flex-direction: column;
  }
}

@media (max-width: 380px) {
  .page-shell {
    width: min(100% - 1rem, 76rem);
  }

  .book-grid {
    gap: 0.8rem 0.6rem;
  }

  .tag {
    font-size: 0.66rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  .cover-button {
    transition: none;
  }
}
