/*
 * BookLink.fyi Stylesheet
 * Design system from DESIGN_SPEC.md
 * Target: < 10KB
 */

/* =============================================================================
   CSS Custom Properties (Design Tokens)
   ============================================================================= */

:root {
    /* Core palette */
    --bg-primary: #FAFAF8;
    --bg-surface: #FFFFFF;
    --bg-subtle: #F5F3EF;

    --text-primary: #1A1A18;
    --text-secondary: #6B6B63;
    --text-tertiary: #9C9C93;

    --border-default: #E8E6E1;
    --border-hover: #D1CFC8;

    --accent: #2563EB;
    --accent-hover: #1D4ED8;
    --accent-subtle: #EFF6FF;

    /* Typography */
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;

    --text-xs: 0.75rem;
    --text-sm: 0.875rem;
    --text-base: 1rem;
    --text-lg: 1.125rem;
    --text-xl: 1.5rem;
    --text-2xl: 2rem;
    --text-3xl: 2.5rem;

    --font-weight-normal: 400;
    --font-weight-medium: 500;
    --font-weight-semibold: 600;
    --font-weight-bold: 700;

    --line-height-tight: 1.2;
    --line-height-normal: 1.5;
    --line-height-relaxed: 1.65;

    /* Spacing (8px base grid) */
    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 0.75rem;
    --space-4: 1rem;
    --space-5: 1.5rem;
    --space-6: 2rem;
    --space-8: 3rem;
    --space-10: 4rem;
    --space-12: 6rem;

    /* Layout */
    --max-width: 640px;
    --border-radius: 8px;
    --border-radius-lg: 12px;

    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
    --shadow-book: 0 8px 24px rgba(0,0,0,0.12), 0 2px 4px rgba(0,0,0,0.08);
}

/* =============================================================================
   Base Reset & Typography
   ============================================================================= */

*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-family);
    font-size: var(--text-base);
    line-height: var(--line-height-normal);
    color: var(--text-primary);
    background: var(--bg-primary);
}

a {
    color: var(--accent);
    text-decoration: none;
}

a:hover {
    color: var(--accent-hover);
    text-decoration: underline;
}

img {
    max-width: 100%;
    height: auto;
    display: block;
}

code {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 0.9em;
    background: var(--bg-subtle);
    padding: 0.1em 0.4em;
    border-radius: 4px;
}

/* =============================================================================
   Page Layout
   ============================================================================= */

.page-container {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.main-content {
    flex: 1;
    width: 100%;
    max-width: var(--max-width);
    margin: 0 auto;
    padding: var(--space-5) var(--space-4);
}

/* =============================================================================
   Header
   ============================================================================= */

.site-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-4);
    max-width: var(--max-width);
    margin: 0 auto;
    width: 100%;
}

.logo {
    font-size: var(--text-lg);
    font-weight: var(--font-weight-bold);
    color: var(--text-primary);
    text-decoration: none;
}

.logo:hover {
    color: var(--text-primary);
    text-decoration: none;
}

.search-icon-link {
    padding: var(--space-2);
    color: var(--text-secondary);
    border-radius: var(--border-radius);
    transition: background 0.15s ease;
}

.search-icon-link:hover {
    background: var(--bg-subtle);
    color: var(--text-primary);
    text-decoration: none;
}

.search-icon {
    width: 24px;
    height: 24px;
    display: block;
}

/* =============================================================================
   Footer
   ============================================================================= */

.site-footer {
    padding: var(--space-6) var(--space-4);
    text-align: center;
    border-top: 1px solid var(--border-default);
    margin-top: auto;
}

.footer-nav {
    margin-bottom: var(--space-3);
}

.footer-nav a {
    color: var(--text-secondary);
    font-size: var(--text-sm);
}

.footer-nav a:hover {
    color: var(--text-primary);
}

.footer-divider {
    color: var(--text-tertiary);
    margin: 0 var(--space-2);
}

.affiliate-disclosure {
    font-size: var(--text-xs);
    color: var(--text-tertiary);
    line-height: var(--line-height-relaxed);
    max-width: 500px;
    margin: 0 auto;
}

.affiliate-disclosure a {
    color: var(--text-secondary);
}

/* =============================================================================
   Home Page
   ============================================================================= */

.home-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: calc(100vh - 200px);
    text-align: center;
    padding: var(--space-6) 0;
}

.home-logo {
    font-size: var(--text-3xl);
    font-weight: var(--font-weight-bold);
    color: var(--text-primary);
    margin-bottom: var(--space-2);
}

.home-tagline {
    font-size: var(--text-lg);
    color: var(--text-secondary);
    margin-bottom: var(--space-8);
}

.home-hint {
    margin-top: var(--space-5);
    font-size: var(--text-sm);
    color: var(--text-tertiary);
}

/* =============================================================================
   Search Form
   ============================================================================= */

.search-form {
    position: relative;
    width: 100%;
    max-width: 480px;
}

.search-input {
    width: 100%;
    padding: var(--space-4) var(--space-5);
    padding-right: var(--space-10);
    font-size: var(--text-lg);
    font-family: var(--font-family);
    border: 2px solid var(--border-default);
    border-radius: 999px;
    background: var(--bg-surface);
    outline: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.search-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-subtle);
}

.search-input::placeholder {
    color: var(--text-tertiary);
}

.search-submit {
    position: absolute;
    right: var(--space-3);
    top: 50%;
    transform: translateY(-50%);
    width: 40px;
    height: 40px;
    padding: var(--space-2);
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: 50%;
    transition: background 0.15s ease, color 0.15s ease;
}

.search-submit:hover {
    background: var(--bg-subtle);
    color: var(--text-primary);
}

.search-submit svg {
    width: 100%;
    height: 100%;
}

/* =============================================================================
   Book Page
   ============================================================================= */

.book-page {
    padding-bottom: var(--space-6);
}

.book-header {
    display: flex;
    gap: var(--space-5);
    margin-bottom: var(--space-6);
}

.book-cover-wrapper {
    flex-shrink: 0;
}

.book-cover {
    width: 180px;
    aspect-ratio: 2/3;
    border-radius: 4px;
    box-shadow: var(--shadow-book);
    object-fit: cover;
    background: var(--bg-subtle);
}

.book-cover-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-4);
    background: hsl(var(--cover-hue, 220), 30%, 85%);
}

.placeholder-title {
    font-size: var(--text-sm);
    font-weight: var(--font-weight-semibold);
    color: hsl(var(--cover-hue, 220), 30%, 30%);
    text-align: center;
    word-break: break-word;
}

.book-info {
    flex: 1;
    min-width: 0;
}

.book-title {
    font-size: var(--text-xl);
    font-weight: var(--font-weight-bold);
    line-height: var(--line-height-tight);
    margin-bottom: var(--space-2);
}

.book-subtitle {
    font-size: var(--text-base);
    color: var(--text-secondary);
    margin-bottom: var(--space-3);
}

.book-author {
    font-size: var(--text-lg);
    color: var(--text-secondary);
    margin-bottom: var(--space-3);
}

.book-meta {
    font-size: var(--text-sm);
    color: var(--text-tertiary);
}

.meta-divider {
    margin: 0 var(--space-2);
}

/* Mobile book layout */
@media (max-width: 480px) {
    .book-header {
        flex-direction: column;
        align-items: center;
        text-align: center;
    }

    .book-cover {
        width: 140px;
        margin-bottom: var(--space-4);
    }
}

/* =============================================================================
   Retailer Buttons
   ============================================================================= */

.retailer-section {
    margin-bottom: var(--space-6);
}

.retailer-section-free {
    padding-top: var(--space-5);
    border-top: 1px solid var(--border-default);
}

.section-heading {
    font-size: var(--text-base);
    font-weight: var(--font-weight-semibold);
    margin-bottom: var(--space-4);
}

.section-heading-subtle {
    font-size: var(--text-sm);
    color: var(--text-secondary);
    font-weight: var(--font-weight-medium);
}

.retailer-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-3);
}

.retailer-grid-free {
    grid-template-columns: 1fr 1fr;
}

.retailer-button {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    border: 1.5px solid var(--border-default);
    border-radius: var(--border-radius);
    background: var(--bg-surface);
    color: var(--text-primary);
    font-size: var(--text-sm);
    font-weight: var(--font-weight-medium);
    text-decoration: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
    cursor: pointer;
    min-height: 48px;
}

.retailer-button:hover {
    border-color: var(--border-hover);
    box-shadow: var(--shadow-sm);
    transform: translateY(-1px);
    text-decoration: none;
    color: var(--text-primary);
}

.retailer-button:active {
    transform: translateY(0);
    box-shadow: none;
}

.retailer-button-free {
    background: var(--bg-subtle);
}

.retailer-icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.retailer-icon svg {
    width: 100%;
    height: 100%;
}

.retailer-name {
    flex: 1;
    text-align: left;
}

.external-icon {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
    color: var(--text-tertiary);
}

.external-icon svg {
    width: 100%;
    height: 100%;
}

@media (max-width: 360px) {
    .retailer-grid {
        grid-template-columns: 1fr;
    }
}

/* =============================================================================
   Description Toggle
   ============================================================================= */

.description-section {
    margin-bottom: var(--space-6);
}

.description-toggle {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    width: 100%;
    padding: var(--space-3) 0;
    background: none;
    border: none;
    font-family: var(--font-family);
    font-size: var(--text-sm);
    font-weight: var(--font-weight-medium);
    color: var(--text-secondary);
    cursor: pointer;
    text-align: left;
}

.description-toggle:hover {
    color: var(--text-primary);
}

.description-toggle .chevron {
    width: 16px;
    height: 16px;
    transition: transform 0.2s ease;
}

.description-toggle[aria-expanded="true"] .chevron {
    transform: rotate(180deg);
}

.description-content {
    padding-top: var(--space-3);
    font-size: var(--text-sm);
    line-height: var(--line-height-relaxed);
    color: var(--text-secondary);
}

.description-content[hidden] {
    display: none;
}

/* =============================================================================
   Copy Link Bar
   ============================================================================= */

.copy-link-bar {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
    background: var(--bg-subtle);
    border-radius: var(--border-radius);
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: var(--text-sm);
    color: var(--text-secondary);
    margin-top: var(--space-6);
}

.copy-link-url {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    user-select: all;
}

.copy-button {
    flex-shrink: 0;
    padding: var(--space-2) var(--space-3);
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 6px;
    font-family: var(--font-family);
    font-size: var(--text-sm);
    font-weight: var(--font-weight-medium);
    cursor: pointer;
    transition: background 0.15s ease, transform 0.1s ease;
}

.copy-button:hover {
    background: var(--accent-hover);
}

.copy-button.copied {
    background: #16A34A;
}

/* =============================================================================
   Not Found Page
   ============================================================================= */

.not-found-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: calc(100vh - 200px);
    text-align: center;
    padding: var(--space-6) 0;
}

.not-found-title {
    font-size: var(--text-xl);
    font-weight: var(--font-weight-semibold);
    margin-bottom: var(--space-2);
}

.not-found-message {
    font-size: var(--text-base);
    color: var(--text-secondary);
    margin-bottom: var(--space-6);
}

/* =============================================================================
   About Page
   ============================================================================= */

.about-page {
    padding-bottom: var(--space-8);
}

.about-title {
    font-size: var(--text-2xl);
    font-weight: var(--font-weight-bold);
    margin-bottom: var(--space-6);
}

.about-section {
    margin-bottom: var(--space-6);
}

.about-lead {
    font-size: var(--text-lg);
    line-height: var(--line-height-relaxed);
    margin-bottom: var(--space-4);
}

.about-section p {
    line-height: var(--line-height-relaxed);
    color: var(--text-secondary);
    margin-bottom: var(--space-4);
}

.about-section p:last-child {
    margin-bottom: 0;
}

.about-heading {
    font-size: var(--text-lg);
    font-weight: var(--font-weight-semibold);
    margin-bottom: var(--space-4);
    color: var(--text-primary);
}

.about-list {
    padding-left: var(--space-5);
    color: var(--text-secondary);
    line-height: var(--line-height-relaxed);
}

.about-list li {
    margin-bottom: var(--space-2);
}

.affiliate-disclosure-detailed {
    padding: var(--space-3);
    background: var(--bg-subtle);
    border-radius: var(--border-radius);
    font-size: var(--text-sm);
}

.about-cta {
    text-align: center;
    padding-top: var(--space-6);
    border-top: 1px solid var(--border-default);
}

.cta-button {
    display: inline-block;
    padding: var(--space-3) var(--space-6);
    background: var(--accent);
    color: white;
    border-radius: var(--border-radius);
    font-weight: var(--font-weight-medium);
    text-decoration: none;
    transition: background 0.15s ease;
}

.cta-button:hover {
    background: var(--accent-hover);
    color: white;
    text-decoration: none;
}

/* =============================================================================
   Utilities
   ============================================================================= */

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

/* =============================================================================
   Skeleton Loading States
   ============================================================================= */

@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
}

.skeleton {
    background: var(--bg-subtle);
    animation: pulse 2s ease-in-out infinite;
}

.skeleton-text {
    height: 1em;
    border-radius: 4px;
    margin-bottom: var(--space-2);
}

.skeleton-title {
    height: 1.5em;
    width: 80%;
}

.skeleton-author {
    height: 1.2em;
    width: 50%;
}
