@import "tailwindcss";

@theme {
  --color-gold: #d2b15f;
  --color-gold-light: #eed68f;
  --color-gold-dark: #9a7f3c;
  --color-mystic-purple: #6d526e;
  --color-mystic-purple-light: #a883a5;
  --color-mystic-purple-dark: #453547;
  --color-dark-bg: #0d1113;
  --color-dark-card: #151b1e;
  --color-dark-border: rgba(133, 165, 164, 0.24);
  --color-teal: #64aaa5;
  --font-heading: 'IM Fell English', serif;
  --font-body: 'EB Garamond', serif;
}

@layer base {
  body {
    font-family: var(--font-body);
    background-color: var(--color-dark-bg);
    color: #e7ece9;
    min-height: 100vh;
  }

  h1, h2, h3, h4, h5, h6 {
    font-family: var(--font-heading);
    letter-spacing: 0;
  }

  input, select, textarea {
    color: #f1e7cf;
  }

  ::selection {
    background: rgba(201, 160, 70, 0.35);
    color: #f5ecd6;
  }
}

@layer components {
  .reader-shell {
    min-height: calc(100vh - 10rem);
    background: #0a0e0f;
  }

  .reader-toolbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    min-height: 4.75rem;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    border-bottom: 1px solid rgba(133, 165, 164, 0.24);
    background: rgba(13, 17, 19, 0.96);
    padding: 0.75rem clamp(1rem, 3vw, 2.5rem);
    backdrop-filter: blur(14px);
  }

  .reader-toolbar__title,
  .reader-toolbar__actions {
    display: flex;
    min-width: 0;
    align-items: center;
    gap: 0.75rem;
  }

  .reader-toolbar__actions {
    flex-shrink: 0;
  }

  .reader-toolbar__eyebrow {
    color: var(--color-gold);
    font-size: 0.7rem;
    font-weight: 600;
    line-height: 1.1;
    text-transform: uppercase;
    letter-spacing: 0.08em;
  }

  .reader-toolbar__heading {
    overflow: hidden;
    color: #f1f5f4;
    font-size: 1.15rem;
    line-height: 1.25;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .reader-icon-button {
    display: inline-grid;
    width: 2.5rem;
    height: 2.5rem;
    flex: 0 0 2.5rem;
    place-items: center;
    border: 1px solid rgba(133, 165, 164, 0.32);
    border-radius: 0.25rem;
    color: #dfe8e4;
    transition: border-color 0.2s ease, background-color 0.2s ease, color 0.2s ease;
  }

  .reader-icon-button svg {
    width: 1.25rem;
    height: 1.25rem;
  }

  .reader-icon-button:hover,
  .reader-icon-button:focus-visible {
    border-color: var(--color-gold);
    background: rgba(210, 177, 95, 0.12);
    color: var(--color-gold-light);
    outline: none;
  }

  .reader-text-button {
    color: #bac6c1;
    font-size: 0.875rem;
    font-weight: 600;
    transition: color 0.2s ease;
  }

  .reader-text-button:hover,
  .reader-text-button:focus-visible {
    color: var(--color-gold-light);
    outline: none;
  }

  .reader-canvas {
    height: calc(100vh - 14.75rem);
    min-height: 42rem;
    padding: clamp(0.75rem, 2vw, 1.5rem);
  }

  .reader-document {
    display: block;
    width: 100%;
    height: 100%;
    border: 1px solid rgba(133, 165, 164, 0.3);
    border-radius: 0.25rem;
    background: #151b1e;
    box-shadow: 0 20px 48px rgba(0, 0, 0, 0.34);
  }

  @media (max-width: 640px) {
    .reader-toolbar {
      align-items: flex-start;
    }

    .reader-toolbar__actions {
      gap: 0.4rem;
    }

    .reader-text-button {
      display: none;
    }

    .reader-canvas {
      height: calc(100vh - 13.75rem);
      min-height: 34rem;
      padding: 0.5rem;
    }
  }

  .btn-gold {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.625rem 1.5rem;
    background-color: var(--color-gold);
    color: #1b140b;
    font-weight: 700;
    border-radius: 0.375rem;
    transition: all 0.2s ease;
    cursor: pointer;
  }
  .btn-gold:hover {
    background-color: var(--color-gold-light);
    box-shadow: 0 0 20px rgba(212, 168, 67, 0.3);
    transform: translateY(-1px);
  }

  .btn-outline-gold {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.625rem 1.5rem;
    border: 1px solid var(--color-gold);
    color: var(--color-gold);
    font-weight: 700;
    border-radius: 0.375rem;
    transition: all 0.2s ease;
    cursor: pointer;
    background: transparent;
  }
  .btn-outline-gold:hover {
    background-color: rgba(212, 168, 67, 0.1);
    box-shadow: 0 0 20px rgba(212, 168, 67, 0.2);
    transform: translateY(-1px);
  }

  .btn-purple {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.625rem 1.5rem;
    background-color: var(--color-mystic-purple);
    color: #f3e7d0;
    font-weight: 700;
    border-radius: 0.375rem;
    transition: all 0.2s ease;
    cursor: pointer;
  }
  .btn-purple:hover {
    background-color: var(--color-mystic-purple-light);
    box-shadow: 0 0 20px rgba(139, 92, 246, 0.3);
    transform: translateY(-1px);
  }

  .btn-danger {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.625rem 1.5rem;
    background-color: #dc2626;
    color: white;
    font-weight: 700;
    border-radius: 0.375rem;
    transition: all 0.2s ease;
    cursor: pointer;
  }
  .btn-danger:hover {
    background-color: #ef4444;
    transform: translateY(-1px);
  }

  .card-dark {
    background: var(--color-dark-card);
    border: 1px solid var(--color-dark-border);
    border-radius: 0.5rem;
    transition: all 0.3s ease;
  }
  .card-dark:hover {
    border-color: rgba(212, 168, 67, 0.3);
    box-shadow: 0 0 30px rgba(212, 168, 67, 0.08);
    transform: translateY(-2px);
  }

  .gradient-gold-text {
    color: var(--color-gold-light);
  }

  .input-dark {
    width: 100%;
    padding: 0.625rem 1rem;
    background-color: rgba(20, 15, 10, 0.85);
    border: 1px solid rgba(110, 90, 55, 0.5);
    border-radius: 0.375rem;
    color: #f1e7cf;
    transition: border-color 0.2s ease;
  }
  .input-dark:focus {
    outline: none;
    border-color: var(--color-gold);
    box-shadow: 0 0 0 2px rgba(212, 168, 67, 0.2);
  }

  .badge-purple {
    display: inline-flex;
    align-items: center;
    padding: 0.25rem 0.75rem;
    background-color: rgba(109, 82, 110, 0.24);
    color: var(--color-mystic-purple-light);
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 500;
  }

  .badge-gold {
    display: inline-flex;
    align-items: center;
    padding: 0.25rem 0.75rem;
    background-color: rgba(212, 168, 67, 0.2);
    color: var(--color-gold-light);
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 500;
  }

  .table-dark {
    width: 100%;
    border-collapse: collapse;
  }
  .table-dark th {
    padding: 0.75rem 1rem;
    text-align: left;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #9ca3af;
    border-bottom: 1px solid rgba(75, 85, 99, 0.5);
  }
  .table-dark td {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid rgba(55, 65, 81, 0.3);
  }
  .table-dark tbody tr:hover {
    background-color: rgba(255, 255, 255, 0.02);
  }
}

@layer utilities {
  .animate-fade-in {
    animation: fadeIn 0.5s ease-out forwards;
    opacity: 0;
  }

  .animate-slide-up {
    animation: slideUp 0.5s ease-out forwards;
    opacity: 0;
  }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

@layer components {
  .library-hero {
    position: relative;
    min-height: 520px;
    height: min(72vh, 640px);
    overflow: hidden;
    border-bottom: 1px solid var(--color-dark-border);
    background: #111719;
  }

  .library-cover-wall {
    position: absolute;
    inset: -3rem;
    display: grid;
    grid-template-columns: repeat(4, minmax(11rem, 1fr));
    gap: 1rem;
    align-items: center;
    transform: rotate(-2deg) scale(1.06);
  }

  .library-cover-tile {
    aspect-ratio: 3 / 4;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 4px;
    background: #20292c;
    box-shadow: 0 18px 38px rgba(0, 0, 0, 0.35);
  }

  .library-cover-tile:nth-child(even) {
    transform: translateY(2.5rem);
  }

  .library-cover-tile img {
    width: 100%;
    height: 100%;
    object-fit: cover;
  }

  .library-cover-tile span {
    display: grid;
    width: 100%;
    height: 100%;
    place-items: center;
    color: var(--color-gold);
    font-family: var(--font-heading);
    font-size: 2rem;
  }

  .library-hero-scrim {
    position: absolute;
    inset: 0;
    background: rgba(7, 10, 12, 0.62);
  }

  .library-hero-content {
    position: relative;
    z-index: 1;
    display: flex;
    width: min(100% - 2rem, 80rem);
    height: 100%;
    margin: 0 auto;
    flex-direction: column;
    align-items: flex-start;
    justify-content: center;
    padding: 4rem 0;
  }

  .library-kicker {
    color: var(--color-teal);
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
  }

  .library-hero h1 {
    margin-top: 0.5rem;
    color: #fffaf0;
    font-size: 4.25rem;
    font-weight: 700;
    line-height: 1;
  }

  .library-hero-copy {
    max-width: 42rem;
    margin-top: 1.25rem;
    color: #d5ddda;
    font-size: 1.2rem;
    line-height: 1.65;
  }

  .library-search {
    display: flex;
    width: min(100%, 38rem);
    height: 3.25rem;
    margin-top: 1.75rem;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 6px;
    background: rgba(13, 17, 19, 0.9);
  }

  .library-search input {
    min-width: 0;
    flex: 1;
    border: 0;
    background: transparent;
    padding: 0 1rem;
    color: #fff;
    outline: 0;
  }

  .library-search button {
    display: grid;
    width: 3.25rem;
    place-items: center;
    border-left: 1px solid rgba(255, 255, 255, 0.18);
    color: var(--color-gold-light);
  }

  .library-search input:focus-visible,
  .library-search button:focus-visible {
    outline: 2px solid var(--color-teal);
    outline-offset: -3px;
  }

  .library-search svg,
  .library-text-link svg,
  .library-category-link > svg,
  .book-card-meta svg {
    width: 1.1rem;
    height: 1.1rem;
  }

  .library-hero-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-top: 1rem;
  }

  .library-band,
  .catalog-shell {
    width: min(100% - 2rem, 80rem);
    margin: 0 auto;
  }

  .library-band {
    padding: 4.5rem 0;
  }

  .library-section-heading,
  .catalog-heading {
    display: flex;
    align-items: end;
    justify-content: space-between;
    gap: 2rem;
    margin-bottom: 1.75rem;
  }

  .library-section-heading h2,
  .catalog-heading h1 {
    margin-top: 0.3rem;
    color: #f0f3f1;
    font-size: 2.25rem;
    font-weight: 700;
  }

  .library-text-link {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    color: var(--color-gold-light);
    font-weight: 700;
  }

  .library-featured-grid,
  .catalog-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 1.25rem;
  }

  .book-card {
    display: flex;
    min-width: 0;
    overflow: hidden;
    flex-direction: column;
    border: 1px solid var(--color-dark-border);
    border-radius: 6px;
    background: var(--color-dark-card);
    transition: border-color 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
  }

  .book-card:hover {
    border-color: rgba(210, 177, 95, 0.55);
    box-shadow: 0 16px 32px rgba(0, 0, 0, 0.24);
    transform: translateY(-2px);
  }

  .book-card-cover {
    display: block;
    aspect-ratio: 3 / 4;
    overflow: hidden;
    border-bottom: 1px solid var(--color-dark-border);
    background: #20292c;
  }

  .book-card-cover img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s ease;
  }

  .book-card:hover .book-card-cover img {
    transform: scale(1.02);
  }

  .book-card-placeholder {
    display: flex;
    width: 100%;
    height: 100%;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    padding: 1.5rem;
    color: #879693;
    text-align: center;
  }

  .book-card-placeholder svg {
    width: 2.75rem;
    height: 2.75rem;
  }

  .book-card-placeholder strong {
    color: #cbd5d1;
    font-family: var(--font-heading);
    line-height: 1.2;
  }

  .book-card-copy {
    display: flex;
    flex: 1;
    flex-direction: column;
    padding: 1rem;
  }

  .book-card-category {
    color: var(--color-teal);
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
  }

  .book-card h2 {
    margin-top: 0.45rem;
    color: #f1f3f2;
    font-size: 1.05rem;
    font-weight: 700;
    line-height: 1.25;
  }

  .book-card h2 a:hover {
    color: var(--color-gold-light);
  }

  .book-card-author {
    margin-top: 0.35rem;
    color: #98a5a2;
    font-size: 0.88rem;
  }

  .book-card-description {
    display: -webkit-box;
    margin-top: 0.7rem;
    overflow: hidden;
    color: #b4bfbc;
    font-size: 0.82rem;
    line-height: 1.5;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
  }

  .book-card-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-top: auto;
    padding-top: 1rem;
    color: #7f908c;
    font-size: 0.75rem;
  }

  .book-card-open-icon {
    display: grid;
    width: 2rem;
    height: 2rem;
    flex: 0 0 auto;
    place-items: center;
    border: 1px solid rgba(210, 177, 95, 0.35);
    border-radius: 4px;
    color: var(--color-gold-light);
  }

  .library-category-band {
    border-block: 1px solid var(--color-dark-border);
    background: #111719;
  }

  .library-section-note,
  .catalog-heading > span,
  .catalog-heading p {
    color: #899794;
  }

  .catalog-heading__actions {
    display: flex;
    align-items: center;
    gap: 1rem;
    color: #899794;
  }

  .catalog-pdf-link {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    min-height: 2.5rem;
    border: 1px solid rgba(210, 177, 95, 0.52);
    border-radius: 4px;
    padding: 0.5rem 0.75rem;
    color: var(--color-gold-light);
    font-size: 0.8rem;
    font-weight: 700;
    transition: border-color 0.2s ease, background-color 0.2s ease, color 0.2s ease;
  }

  .catalog-pdf-link svg {
    width: 1rem;
    height: 1rem;
  }

  .catalog-pdf-link:hover,
  .catalog-pdf-link:focus-visible {
    border-color: var(--color-gold-light);
    background: rgba(210, 177, 95, 0.12);
    color: #fff2c9;
    outline: none;
  }

  .library-category-list {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    border-top: 1px solid var(--color-dark-border);
  }

  .library-category-link {
    display: grid;
    grid-template-columns: 2.5rem minmax(0, 1fr) 1.25rem;
    gap: 1rem;
    align-items: center;
    min-width: 0;
    padding: 1.1rem 0;
    border-bottom: 1px solid var(--color-dark-border);
    color: #dce3e0;
  }

  .library-category-link:nth-child(odd) {
    padding-right: 1.5rem;
  }

  .library-category-link:nth-child(even) {
    padding-left: 1.5rem;
    border-left: 1px solid var(--color-dark-border);
  }

  .library-category-icon {
    display: grid;
    width: 2.5rem;
    height: 2.5rem;
    place-items: center;
    color: var(--color-teal);
  }

  .library-category-icon svg {
    width: 1.5rem;
    height: 1.5rem;
  }

  .library-category-link strong,
  .library-category-link small {
    display: block;
  }

  .library-category-link small {
    margin-top: 0.2rem;
    color: #788985;
    font-size: 0.75rem;
  }

  .library-category-link:hover strong,
  .library-category-link:hover > svg {
    color: var(--color-gold-light);
  }

  .catalog-shell {
    padding: 3.5rem 0 5rem;
  }

  .catalog-heading > div > p:last-child {
    margin-top: 0.4rem;
  }

  .catalog-filter-band {
    margin-bottom: 2rem;
    padding-block: 1.25rem;
    border-block: 1px solid var(--color-dark-border);
  }

  .catalog-filter-band form {
    display: grid;
    grid-template-columns: minmax(14rem, 1.8fr) minmax(11rem, 1fr) minmax(10rem, 0.8fr) auto;
    gap: 1rem;
    align-items: end;
  }

  .catalog-filter-band label {
    display: block;
    margin-bottom: 0.4rem;
    color: #8e9d99;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
  }

  .catalog-filter-band input,
  .catalog-filter-band select {
    width: 100%;
    height: 2.75rem;
    border: 1px solid var(--color-dark-border);
    border-radius: 4px;
    background: #111719;
    padding: 0 0.8rem;
    color: #e8eeeb;
    outline: 0;
  }

  .catalog-filter-band input:focus,
  .catalog-filter-band select:focus {
    border-color: var(--color-teal);
    box-shadow: 0 0 0 2px rgba(100, 170, 165, 0.16);
  }

  .catalog-filter-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
  }

  .catalog-filter-actions .btn-gold {
    height: 2.75rem;
  }

  .catalog-clear-link {
    color: #9aaaa6;
    font-size: 0.85rem;
  }

  .catalog-clear-link:hover {
    color: var(--color-gold-light);
  }

  .catalog-empty-state {
    display: flex;
    min-height: 22rem;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    text-align: center;
  }

  .catalog-empty-state > svg {
    width: 3.5rem;
    height: 3.5rem;
    color: #5f706c;
  }

  .catalog-empty-state h2 {
    color: #e7ece9;
    font-size: 1.6rem;
  }

  .catalog-empty-state p {
    color: #899794;
  }
}

@media (max-width: 1023px) {
  .library-featured-grid,
  .catalog-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .catalog-filter-band form {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 767px) {
  .library-hero {
    min-height: 540px;
    height: 76vh;
  }

  .library-cover-wall {
    grid-template-columns: repeat(3, minmax(8rem, 1fr));
  }

  .library-hero h1 {
    font-size: 3rem;
  }

  .library-hero-copy {
    font-size: 1rem;
  }

  .library-band {
    padding: 3.25rem 0;
  }

  .library-section-heading,
  .catalog-heading {
    align-items: flex-start;
    flex-direction: column;
    gap: 0.75rem;
  }

  .catalog-heading__actions {
    width: 100%;
    justify-content: space-between;
  }

  .library-featured-grid,
  .catalog-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.85rem;
  }

  .library-category-list {
    grid-template-columns: 1fr;
  }

  .library-category-link:nth-child(odd),
  .library-category-link:nth-child(even) {
    padding-inline: 0;
    border-left: 0;
  }

  .catalog-filter-band form {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 479px) {
  .library-featured-grid,
  .catalog-grid {
    grid-template-columns: 1fr;
  }
}
