:root {
  --bg: #e8dfc9;
  --bg-2: #ddd0b2;
  --ink: #2a2016;
  --ink-soft: #5a4d3c;
  --wood: #4a3626;
  --wood-dark: #2f2115;
  --wood-light: #6b4f38;
  --accent: #2f5d50;
  --accent-warm: #c98a3d;
  --card: #f6efe0;
  --card-edge: #e2d3b3;
  --shadow: rgba(30, 20, 10, 0.35);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15110c;
    --bg-2: #1d170f;
    --ink: #ece1cd;
    --ink-soft: #bfae94;
    --wood: #3a2c20;
    --wood-dark: #1c140d;
    --wood-light: #4f3b2a;
    --accent: #6cc0a4;
    --accent-warm: #e3ac57;
    --card: #241c14;
    --card-edge: #3a2c1e;
    --shadow: rgba(0, 0, 0, 0.6);
  }
}

:root[data-theme="dark"] {
  --bg: #15110c;
  --bg-2: #1d170f;
  --ink: #ece1cd;
  --ink-soft: #bfae94;
  --wood: #3a2c20;
  --wood-dark: #1c140d;
  --wood-light: #4f3b2a;
  --accent: #6cc0a4;
  --accent-warm: #e3ac57;
  --card: #241c14;
  --card-edge: #3a2c1e;
  --shadow: rgba(0, 0, 0, 0.6);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(ellipse 900px 500px at 50% 0%, color-mix(in srgb, var(--accent-warm) 14%, transparent), transparent 65%),
    linear-gradient(180deg, var(--bg) 0%, var(--bg-2) 100%);
  color: var(--ink);
  font-family: "Zen Kaku Gothic New", "Hiragino Sans", "Yu Gothic", sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

.page {
  max-width: 1000px;
  margin: 0 auto;
  padding: clamp(1.25rem, 3vw, 2rem) 1.5rem clamp(4rem, 10vw, 7rem);
}

/* ---------- Hero banner ---------- */

.hero-banner {
  display: block;
  width: 100%;
  height: auto;
  max-height: 640px;
  object-fit: cover;
  object-position: center center;
  margin: 0 0 clamp(1rem, 2.5vw, 1.75rem);
  box-shadow: 0 24px 40px -24px rgba(0, 0, 0, 0.55);
}

/* ---------- Bookcase ---------- */

.category-filter {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.5rem;
  margin: 0 0 clamp(2rem, 5vw, 3rem);
}

.category-filter button {
  font-family: "Zen Kaku Gothic New", sans-serif;
  font-size: 0.85rem;
  padding: 0.45rem 1.05rem;
  border-radius: 999px;
  border: 1px solid var(--card-edge);
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
  transition: background 150ms ease, color 150ms ease, border-color 150ms ease;
}

.category-filter button:hover,
.category-filter button:focus-visible {
  border-color: var(--accent-warm);
  color: var(--ink);
}

.category-filter button.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #f4ead6;
}

.bookcase {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(2.2rem, 5vw, 3.2rem);
}

.shelf-frame {
  display: flex;
  justify-content: center;
  width: 100%;
}

.shelf {
  position: relative;
  display: inline-flex;
  align-items: flex-end;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.55rem;
  padding: 0 2rem 1.6rem;
  max-width: min(94vw, 780px);
}

.shelf::after {
  content: "";
  position: absolute;
  left: -22px;
  right: -22px;
  bottom: 0;
  height: 16px;
  background: linear-gradient(180deg, var(--wood-light) 0%, var(--wood) 55%, var(--wood-dark) 100%);
  border-radius: 3px;
  box-shadow: 0 10px 18px -6px var(--shadow), inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.shelf::before {
  content: "";
  position: absolute;
  left: -22px;
  right: -22px;
  bottom: -16px;
  height: 26px;
  background: var(--wood-dark);
  filter: blur(2px);
  opacity: 0.35;
  border-radius: 50%;
  transform: scaleX(0.96);
}

/* ---------- Book spines ---------- */

.book {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  cursor: pointer;
  transition: transform 220ms ease, box-shadow 220ms ease;
}

.book:hover,
.book:focus-visible {
  transform: translateY(-10px);
}

.book:focus-visible {
  outline: 2px solid var(--accent-warm);
  outline-offset: 3px;
}

.book.book--spine {
  padding: 0.7rem 0.35rem;
  border-radius: 4px 4px 2px 2px;
  color: #f4ead6;
  background: linear-gradient(90deg, rgba(0,0,0,0.22) 0%, transparent 12%, transparent 88%, rgba(255,255,255,0.12) 100%), var(--spine-color, var(--accent));
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.18), 0 6px 10px -4px var(--shadow);
}

.book.book--spine:hover,
.book.book--spine:focus-visible {
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.18), 0 16px 20px -8px var(--shadow);
}

/* 表紙あり本: 実写真(cover)またはCSSで描いた見本(mockCover)を、少し後ろに
   傾けて棚に立てかけたように見せる。幅は画面サイズに応じて3段階の固定値 */
.book.book--cover {
  aspect-ratio: 2 / 3;
  padding: 0;
  width: 130px;
  --lean: -3deg;
  transform: rotate(var(--lean));
  transform-origin: bottom center;
}

@media (max-width: 839px) {
  .book.book--cover { width: 112px; }
}

@media (max-width: 599px) {
  .shelf {
    display: flex;
    width: 100%;
    max-width: none;
    padding: 0 0.4rem 1.3rem;
    gap: 0.35rem;
  }
  .book.book--cover { width: calc((100% - 0.7rem) / 3); }
  .shelf::after, .shelf::before { left: -8px; right: -8px; }
  .page { padding: 1rem 1.5rem 3rem; }
  .hero-banner { margin-bottom: 0.85rem; }
}

.book.book--cover:hover,
.book.book--cover:focus-visible {
  transform: translateY(-10px) rotate(var(--lean));
}

.cover-visual {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: 4px;
  overflow: hidden;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.15), 0 10px 16px -6px var(--shadow);
  background: var(--spine-color, var(--accent));
}

.cover-visual img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.cover-visual::after {
  content: "";
  position: absolute;
  top: 3px;
  bottom: 3px;
  right: -3px;
  width: 4px;
  background: repeating-linear-gradient(180deg, #efe6d2 0 2px, #d8cba9 2px 3px);
  border-radius: 0 2px 2px 0;
  box-shadow: 1px 0 2px rgba(0,0,0,0.25);
}

.cover-visual--mini {
  width: 52px;
  height: auto;
  aspect-ratio: 2 / 3;
  flex-shrink: 0;
  margin: 0;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.15), 0 4px 8px -3px rgba(0,0,0,0.35);
}

.mock-cover-inner {
  height: 100%;
  box-sizing: border-box;
  padding: 0.9rem 0.8rem 0.8rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  background: linear-gradient(160deg, color-mix(in srgb, var(--spine-color) 85%, white 15%) 0%, var(--spine-color) 55%, color-mix(in srgb, var(--spine-color) 80%, black 25%) 100%);
  color: #f4ead6;
}

.mock-title {
  font-family: "Shippori Mincho", serif;
  font-weight: 700;
  font-size: 1.05rem;
  line-height: 1.35;
  text-wrap: balance;
}

.mock-author {
  font-family: "Zen Kaku Gothic New", sans-serif;
  font-size: 0.7rem;
  opacity: 0.8;
}

.book .spine-title {
  writing-mode: vertical-rl;
  text-orientation: mixed;
  font-family: "Shippori Mincho", serif;
  font-weight: 600;
  font-size: 0.98rem;
  letter-spacing: 0.06em;
  line-height: 1.5;
  max-height: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}

.book .spine-author {
  writing-mode: vertical-rl;
  text-orientation: mixed;
  font-family: "Zen Kaku Gothic New", sans-serif;
  font-size: 0.68rem;
  opacity: 0.75;
  margin-top: 0.5rem;
}

@media (prefers-reduced-motion: reduce) {
  .book { transition: none; }
  .book:hover, .book:focus-visible,
  .book.book--cover:hover, .book.book--cover:focus-visible,
  .book.book--spine:hover, .book.book--spine:focus-visible {
    transform: none;
  }
}

/* ---------- Detail overlay ---------- */

.backdrop {
  position: fixed;
  inset: 0;
  background: color-mix(in srgb, var(--wood-dark) 85%, transparent);
  backdrop-filter: blur(4px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 200ms ease;
  z-index: 10;
}

.backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

.detail-card {
  position: relative;
  width: min(92vw, 520px);
  max-height: 85vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--card);
  border: 2px solid var(--accent-warm);
  border-radius: 10px;
  padding: 2rem 1.8rem 1.8rem;
  box-shadow: 0 30px 60px -16px rgba(0,0,0,0.7);
  transform: translateY(16px) scale(0.98);
  opacity: 0;
  transition: transform 260ms cubic-bezier(.2,.8,.2,1), opacity 220ms ease;
}

.backdrop.open .detail-card {
  transform: translateY(0) scale(1);
  opacity: 1;
}

@media (prefers-reduced-motion: reduce) {
  .backdrop, .detail-card { transition: none; }
}

.detail-card .close-btn {
  position: absolute;
  top: 1.2rem;
  right: 1.2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--card-edge);
  border: none;
  border-radius: 50%;
  color: var(--ink);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  width: 2.2rem;
  height: 2.2rem;
  padding: 0;
}

.detail-card .close-btn:hover,
.detail-card .close-btn:focus-visible {
  background: var(--accent-warm);
  color: var(--wood-dark);
}

.close-btn-bottom {
  display: block;
  width: 100%;
  margin-top: 1.6rem;
  background: none;
  border: 1px solid var(--card-edge);
  border-radius: 999px;
  color: var(--ink-soft);
  font-family: "Zen Kaku Gothic New", sans-serif;
  font-size: 0.85rem;
  padding: 0.65rem 1rem;
  cursor: pointer;
  transition: border-color 150ms ease, color 150ms ease;
}

.close-btn-bottom:hover,
.close-btn-bottom:focus-visible {
  border-color: var(--ink-soft);
  color: var(--ink);
}

/* ---------- Kindle floating action buttons ---------- */

.fab-stack {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 8;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.6rem;
}

.fab-btn {
  display: block;
  width: 260px;
  height: auto;
  filter: drop-shadow(0 6px 14px rgba(0, 0, 0, 0.35));
  transition: transform 150ms ease;
}

.fab-btn img {
  display: block;
  width: 100%;
  height: auto;
}

.fab-btn:hover,
.fab-btn:focus-visible {
  transform: translateY(-2px) scale(1.03);
}

@media (max-width: 599px) {
  .fab-stack {
    right: 0.6rem;
    bottom: 1.4rem;
    width: 53vw;
    max-width: 304px;
    gap: 0.2rem;
  }
  .fab-btn {
    width: 100%;
    height: auto;
  }
  .fab-btn img {
    width: 100%;
    height: auto;
  }
}

.detail-card .category-badge {
  display: inline-block;
  font-size: 0.7rem;
  font-family: "Zen Kaku Gothic New", sans-serif;
  letter-spacing: 0.05em;
  color: var(--accent-warm);
  border: 1px solid var(--accent-warm);
  border-radius: 999px;
  padding: 0.15rem 0.6rem;
  margin-bottom: 0.8rem;
}

.detail-head {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  margin-bottom: 1.4rem;
}

.detail-head-text {
  min-width: 0;
}

.detail-card h2 {
  font-family: "Shippori Mincho", serif;
  font-size: 1.2rem;
  margin: 0;
  text-wrap: balance;
}

.detail-card .author {
  font-size: 0.8rem;
  color: var(--ink-soft);
  margin: 0.25rem 0 0;
}

.note-block {
  margin-top: 1.6rem;
}

.note-label {
  font-family: "Zen Kaku Gothic New", sans-serif;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--accent-warm);
  letter-spacing: 0.03em;
  margin: 0 0 0.5rem;
}

.detail-card .note {
  font-family: "Klee One", "Zen Kaku Gothic New", cursive;
  font-size: 1.15rem;
  line-height: 1.9;
  color: var(--ink);
  margin: 0;
  white-space: pre-line;
}

.detail-card .amazon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  width: 100%;
  background: var(--wood-dark);
  color: var(--accent-warm);
  border: 1.5px solid var(--accent-warm);
  text-decoration: none;
  font-family: "Zen Kaku Gothic New", sans-serif;
  font-size: 0.9rem;
  font-weight: 700;
  padding: 0.7rem 1.3rem;
  border-radius: 999px;
  transition: background 150ms ease, color 150ms ease;
}

.detail-card .amazon-btn:hover,
.detail-card .amazon-btn:focus-visible {
  background: var(--accent-warm);
  color: var(--wood-dark);
}

/* スマホ: 中央カードではなく、画面下から7割の高さでせり上がるシートに */
@media (max-width: 599px) {
  .backdrop {
    justify-content: flex-end;
    padding: 0 0.9rem 0.9rem;
  }

  .detail-card {
    width: 100%;
    max-width: none;
    height: 89vh;
    max-height: 89vh;
    border-radius: 20px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 2rem 1.6rem 2.6rem;
    transform: translateY(calc(100% + 0.9rem));
  }

  .backdrop.open .detail-card {
    transform: translateY(0);
  }

  .cover-visual--mini {
    width: 88px;
  }

  .detail-card h2 {
    font-size: 1.85rem;
  }

  .detail-card .author {
    font-size: 1.05rem;
  }

  .note-label {
    font-size: 1rem;
  }

  .detail-card .note {
    font-size: 1.1rem;
    line-height: 1.8;
  }

  .detail-card .amazon-btn {
    font-size: 1.1rem;
    padding: 0.95rem 1.3rem;
  }
}

@media (max-width: 599px) and (prefers-reduced-motion: reduce) {
  .detail-card,
  .backdrop.open .detail-card {
    transform: none;
  }
}
