/* ===== palette & tokens ===== */
:root {
  --bg:          #FDF6EC;
  --bg-light:    #FFF9F2;
  --cream:       #F5E6D3;
  --dusty-rose:  #C9A0A0;
  --rose-dark:   #A87C7C;
  --brown:       #8B7355;
  --brown-dark:  #4A3728;
  --brown-light: #B8956A;
  --wood-1:      #A0714F;
  --wood-2:      #8B5E3C;
  --wood-3:      #6B4226;
  --gold:        #D4A574;
  --heart:       #D48B8B;
  --shadow:      rgba(74, 55, 40, .12);

  --font-display: 'Cormorant Garamond', Georgia, serif;
  --font-body:    'Nunito', 'Segoe UI', sans-serif;

  --ease-out-back: cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* ===== reset & base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--brown-dark);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow-y: auto;
  position: relative;
}

/* ===== floating particles ===== */
.particles {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}

.particle {
  position: absolute;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--gold);
  opacity: 0;
  animation: float-up linear infinite;
}

@keyframes float-up {
  0% {
    opacity: 0;
    transform: translateY(0) scale(0);
  }
  10% {
    opacity: 0.4;
    transform: translateY(-10vh) scale(1);
  }
  90% {
    opacity: 0.15;
  }
  100% {
    opacity: 0;
    transform: translateY(-100vh) scale(0.5);
  }
}

/* ===== header ===== */
header {
  text-align: center;
  padding: 1.2rem 1rem 0.5rem;
  z-index: 1;
  flex-shrink: 0;
}

header h1 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: clamp(1.8rem, 4vw, 2.6rem);
  color: var(--brown-dark);
  letter-spacing: 0.02em;
}

.subtitle {
  font-family: var(--font-display);
  font-style: italic;
  font-size: 0.95rem;
  color: var(--dusty-rose);
  margin-top: 0.15rem;
}

.book-counter {
  color: var(--brown-light);
}

/* ===== search bar ===== */
.search-bar {
  margin-top: 0.5rem;
  display: flex;
  justify-content: center;
}

.search-bar input {
  width: 280px;
  padding: 0.45rem 0.8rem;
  border: 2px solid var(--cream);
  border-radius: 20px;
  background: var(--bg-light);
  color: var(--brown-dark);
  font-family: var(--font-body);
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

.search-bar input::placeholder {
  color: var(--dusty-rose);
  opacity: 0.6;
}

.search-bar input:focus {
  border-color: var(--dusty-rose);
  box-shadow: 0 0 0 3px rgba(201, 160, 160, 0.2);
}

/* ===== main / shelves ===== */
main {
  width: 100%;
  max-width: 1100px;
  padding: 0 1.5rem;
  z-index: 1;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  min-height: 0;
}

.shelf-section {
  margin-bottom: 0;
}

.shelf-label {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: clamp(0.9rem, 2vw, 1.15rem);
  color: var(--dusty-rose);
  text-align: center;
  margin-bottom: 0.2rem;
  letter-spacing: 0.02em;
}

.shelf-container {
  position: relative;
}

.books-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  justify-content: center;
  padding: 0.4rem 1rem 0;
  align-items: flex-end;
}

/* wooden shelf plank */
.shelf-plank {
  height: 14px;
  border-radius: 0 0 6px 6px;
  background: linear-gradient(
    180deg,
    var(--wood-1) 0%,
    var(--wood-2) 40%,
    var(--wood-3) 100%
  );
  box-shadow:
    0 4px 8px rgba(74, 55, 40, 0.25),
    inset 0 2px 3px rgba(255, 255, 255, 0.1);
  position: relative;
}

.shelf-plank::before {
  content: '';
  position: absolute;
  top: -4px;
  left: 0;
  right: 0;
  height: 4px;
  background: linear-gradient(
    180deg,
    var(--brown-light),
    var(--wood-1)
  );
  border-radius: 4px 4px 0 0;
}

/* ===== book card ===== */
.book {
  position: relative;
  width: 100px;
  flex-shrink: 0;
  cursor: pointer;
  animation: book-appear 0.6s var(--ease-out-back) both;
  animation-delay: var(--delay, 0ms);
}

@keyframes book-appear {
  from {
    opacity: 0;
    transform: translateY(30px) scale(0.85);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.book-cover-wrapper {
  width: 100px;
  height: 150px;
  border-radius: 4px 8px 8px 4px;
  overflow: hidden;
  box-shadow:
    3px 3px 8px var(--shadow),
    -1px 0 3px rgba(0,0,0,0.05);
  transition: transform 0.35s var(--ease-out-back), box-shadow 0.35s ease;
  position: relative;
}

/* book spine edge */
.book-cover-wrapper::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 6px;
  background: linear-gradient(
    90deg,
    rgba(0,0,0,0.15),
    rgba(0,0,0,0.02)
  );
  z-index: 2;
}

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

.book:hover .book-cover-wrapper {
  transform: rotate(-3deg) scale(1.08) translateY(-8px);
  box-shadow:
    6px 10px 20px rgba(74, 55, 40, 0.2),
    -2px 0 6px rgba(0,0,0,0.08);
}

/* ===== spine view ===== */
.book.spine-view {
  width: 38px;
}

.book-spine {
  width: 38px;
  height: 150px;
  border-radius: 3px 5px 5px 3px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
  box-shadow:
    2px 2px 6px var(--shadow),
    -1px 0 2px rgba(0,0,0,0.05);
  transition: transform 0.35s var(--ease-out-back), box-shadow 0.35s ease;
}

/* subtle lighting on spine edge */
.book-spine::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  background: linear-gradient(90deg, rgba(0,0,0,0.12), transparent);
  z-index: 1;
}

.book-spine::after {
  content: '';
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: linear-gradient(270deg, rgba(0,0,0,0.08), transparent);
}

.spine-title {
  writing-mode: vertical-rl;
  text-orientation: mixed;
  transform: rotate(180deg);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.7rem;
  line-height: 1.2;
  padding: 8px 2px;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  max-height: 140px;
  letter-spacing: 0.01em;
}

.book.spine-view:hover .book-spine {
  transform: rotate(-2deg) scale(1.06) translateY(-8px);
  box-shadow:
    4px 8px 16px rgba(74, 55, 40, 0.2),
    -1px 0 4px rgba(0,0,0,0.08);
}

/* ===== hover popover ===== */
.book-info {
  position: absolute;
  bottom: calc(100% + 12px);
  left: 50%;
  transform: translateX(-50%) translateY(8px);
  width: 200px;
  background: var(--bg-light);
  border: 2px solid var(--cream);
  border-radius: 12px;
  padding: 0.8rem;
  box-shadow: 0 8px 24px rgba(74, 55, 40, 0.15);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease, transform 0.3s var(--ease-out-back);
  z-index: 10;
}

.book-info::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 8px solid transparent;
  border-top-color: var(--cream);
}

.book:hover .book-info {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
  pointer-events: auto;
}

.book-info .title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.05rem;
  color: var(--brown-dark);
  line-height: 1.3;
}

.book-info .author {
  font-size: 0.85rem;
  color: var(--brown);
  margin-top: 0.15rem;
}

.book-info .rating {
  margin-top: 0.5rem;
  font-size: 1rem;
  letter-spacing: 2px;
  color: var(--heart);
}

.book-info .comment {
  margin-top: 0.5rem;
  font-size: 0.82rem;
  font-style: italic;
  color: var(--rose-dark);
  line-height: 1.4;
}

.star-badge {
  font-size: 1.1rem;
  color: var(--gold);
  margin-bottom: 0.25rem;
}

.book.starred {
  filter: drop-shadow(0 0 6px var(--gold));
}

/* ===== empty state ===== */
.empty-msg {
  text-align: center;
  font-style: italic;
  color: var(--brown);
  opacity: 0.7;
  margin-top: 1rem;
  font-size: 0.95rem;
}

/* ===== footer ===== */
footer {
  text-align: center;
  padding: 0.5rem 1rem;
  font-size: 0.8rem;
  color: var(--dusty-rose);
  font-style: italic;
  z-index: 1;
  flex-shrink: 0;
}

/* ===== theme toggle button ===== */
.theme-toggle {
  position: absolute;
  top: 1.2rem;
  right: 1.5rem;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 2px solid var(--cream);
  background: var(--bg-light);
  cursor: pointer;
  font-size: 1.3rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
  z-index: 20;
  box-shadow: 0 2px 8px var(--shadow);
}

.theme-toggle:hover {
  transform: scale(1.1) rotate(10deg);
  border-color: var(--dusty-rose);
}

/* show the correct icon per theme */
.theme-toggle-icon::after {
  content: attr(data-cozy);
}

/* ============================================================
   RETRO ARCADE GIRLY THEME
   ============================================================ */
[data-theme="retro"] {
  --bg:          #1A0A2E;
  --bg-light:    #2A1448;
  --cream:       #3D1F5C;
  --dusty-rose:  #FF69B4;
  --rose-dark:   #FF1493;
  --brown:       #C8A2E6;
  --brown-dark:  #F0D0FF;
  --brown-light: #9B59B6;
  --wood-1:      #FF69B4;
  --wood-2:      #CC00FF;
  --wood-3:      #8B00CC;
  --gold:        #FFE100;
  --heart:       #FF69B4;
  --shadow:      rgba(255, 105, 180, 0.2);

  --font-display: 'Press Start 2P', monospace;
  --font-body:    'VT323', monospace;
}

/* ── base overrides ── */
[data-theme="retro"] body {
  background:
    repeating-linear-gradient(
      0deg,
      transparent,
      transparent 2px,
      rgba(255, 255, 255, 0.015) 2px,
      rgba(255, 255, 255, 0.015) 4px
    ),
    var(--bg);
}

/* ── header ── */
[data-theme="retro"] header h1 {
  font-size: clamp(1.4rem, 4vw, 2rem);
  text-shadow:
    0 0 10px #FF69B4,
    0 0 30px #FF69B4,
    0 0 60px #CC00FF;
  color: #fff;
  letter-spacing: 0.05em;
}

[data-theme="retro"] .subtitle {
  font-family: 'VT323', monospace;
  font-style: normal;
  font-size: 1.4rem;
  color: #00FFFF;
  text-shadow: 0 0 8px #00FFFF;
}

[data-theme="retro"] .book-counter {
  color: #FF69B4;
}

/* ── theme toggle ── */
[data-theme="retro"] .theme-toggle {
  border-color: #CC00FF;
  background: var(--bg-light);
  box-shadow:
    0 0 8px rgba(204, 0, 255, 0.4),
    inset 0 0 4px rgba(204, 0, 255, 0.2);
}

[data-theme="retro"] .theme-toggle:hover {
  box-shadow:
    0 0 16px rgba(255, 105, 180, 0.6),
    inset 0 0 8px rgba(255, 105, 180, 0.3);
}

[data-theme="retro"] .theme-toggle-icon::after {
  content: attr(data-retro);
}

/* ── search bar ── */
[data-theme="retro"] .search-bar input {
  font-family: 'VT323', monospace;
  font-size: 1.2rem;
  border: 2px solid #CC00FF;
  background: #2A1448;
  color: #F0D0FF;
  border-radius: 4px;
  box-shadow: 0 0 8px rgba(204, 0, 255, 0.3);
}

[data-theme="retro"] .search-bar input::placeholder {
  color: #FF69B4;
  opacity: 0.5;
}

[data-theme="retro"] .search-bar input:focus {
  border-color: #FF69B4;
  box-shadow: 0 0 12px rgba(255, 105, 180, 0.5);
}

/* ── shelf label ── */
[data-theme="retro"] .shelf-label {
  font-family: 'Press Start 2P', monospace;
  font-size: clamp(0.6rem, 2vw, 0.8rem);
  color: #00FFFF;
  text-shadow: 0 0 10px #00FFFF, 0 0 20px rgba(0, 255, 255, 0.3);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

/* ── shelf plank → neon platform ── */
[data-theme="retro"] .shelf-plank {
  height: 6px;
  border-radius: 0;
  background: linear-gradient(90deg, #FF69B4, #CC00FF, #00FFFF, #CC00FF, #FF69B4);
  box-shadow:
    0 0 12px rgba(255, 105, 180, 0.6),
    0 0 24px rgba(204, 0, 255, 0.3),
    0 2px 4px rgba(0, 0, 0, 0.3);
}

[data-theme="retro"] .shelf-plank::before {
  display: none;
}

/* ── spine view ── */
[data-theme="retro"] .book-spine {
  border: 2px solid #CC00FF;
  border-radius: 2px;
  box-shadow:
    3px 3px 0 #3D1F5C,
    0 0 6px rgba(204, 0, 255, 0.25);
}

[data-theme="retro"] .book-spine::before {
  background: linear-gradient(90deg, rgba(204, 0, 255, 0.15), transparent);
}

[data-theme="retro"] .book-spine::after {
  background: linear-gradient(270deg, rgba(204, 0, 255, 0.1), transparent);
}

[data-theme="retro"] .spine-title {
  font-family: 'VT323', monospace;
  font-size: 0.85rem;
}

[data-theme="retro"] .book.spine-view:hover .book-spine {
  border-color: #FF69B4;
  box-shadow:
    4px 4px 0 #3D1F5C,
    0 0 14px rgba(255, 105, 180, 0.4);
}

/* ── book cards ── */
[data-theme="retro"] .book-cover-wrapper {
  border-radius: 4px;
  border: 3px solid #CC00FF;
  box-shadow:
    4px 4px 0 #3D1F5C,
    0 0 8px rgba(204, 0, 255, 0.3);
}

[data-theme="retro"] .book-cover-wrapper::before {
  background: linear-gradient(
    90deg,
    rgba(204, 0, 255, 0.2),
    transparent
  );
}

[data-theme="retro"] .book:hover .book-cover-wrapper {
  transform: translateY(-12px) scale(1.05);
  border-color: #FF69B4;
  box-shadow:
    6px 6px 0 #3D1F5C,
    0 0 20px rgba(255, 105, 180, 0.5),
    0 0 40px rgba(204, 0, 255, 0.3);
  animation: retro-bounce 0.4s var(--ease-out-back);
}

@keyframes retro-bounce {
  0%   { transform: translateY(0) scale(1); }
  40%  { transform: translateY(-16px) scale(1.08); }
  70%  { transform: translateY(-10px) scale(1.04); }
  100% { transform: translateY(-12px) scale(1.05); }
}

/* ── popover ── */
[data-theme="retro"] .book-info {
  border-radius: 4px;
  border: 3px solid #CC00FF;
  background: #1A0A2E;
  box-shadow:
    6px 6px 0 #3D1F5C,
    0 0 16px rgba(204, 0, 255, 0.3);
}

[data-theme="retro"] .book-info::after {
  border-top-color: #CC00FF;
}

[data-theme="retro"] .book-info .title {
  font-family: 'Press Start 2P', monospace;
  font-size: 0.6rem;
  color: #FFE100;
  text-shadow: 0 0 6px rgba(255, 225, 0, 0.4);
  line-height: 1.6;
}

[data-theme="retro"] .book-info .author {
  font-family: 'VT323', monospace;
  font-size: 1.1rem;
  color: #00FFFF;
}

[data-theme="retro"] .book-info .rating {
  color: #FF69B4;
  text-shadow: 0 0 6px rgba(255, 105, 180, 0.5);
}

[data-theme="retro"] .book-info .comment {
  font-family: 'VT323', monospace;
  font-style: normal;
  font-size: 1rem;
  color: #C8A2E6;
}

[data-theme="retro"] .star-badge {
  color: #FFD700;
  text-shadow: 0 0 8px rgba(255, 215, 0, 0.6);
}

[data-theme="retro"] .book.starred {
  filter: drop-shadow(0 0 8px #FFD700);
}

/* ── particles become stars ── */
[data-theme="retro"] .particle {
  border-radius: 1px;
  transform: rotate(45deg);
}

/* ── empty state ── */
[data-theme="retro"] .empty-msg {
  font-family: 'VT323', monospace;
  color: #C8A2E6;
  font-style: normal;
  font-size: 1.3rem;
}

/* ── footer ── */
[data-theme="retro"] footer {
  font-family: 'VT323', monospace;
  font-style: normal;
  font-size: 1.1rem;
  color: #CC00FF;
}

/* ===== responsive ===== */
@media (max-width: 600px) {
  .books-grid {
    gap: 0.4rem;
  }

  .book {
    width: 70px;
  }

  .book.spine-view {
    width: 28px;
  }

  .book-spine {
    width: 28px;
    height: 105px;
  }

  .spine-title {
    font-size: 0.55rem;
    max-height: 95px;
  }

  .book-cover-wrapper {
    width: 70px;
    height: 105px;
  }

  .book-info {
    width: 160px;
    padding: 0.6rem;
    font-size: 0.85rem;
  }

  .theme-toggle {
    width: 36px;
    height: 36px;
    font-size: 1rem;
    top: 0.6rem;
    right: 0.6rem;
  }

  .shelf-label {
    font-size: 0.8rem;
  }

  header {
    padding: 0.8rem 1rem 0.3rem;
  }

  header h1 {
    font-size: 1.4rem;
  }
}
