/*
 * site.css — presentation for the Book Promotion Site
 * (Requirements 9.1, 9.2, 9.3, 9.4, 9.5, 9.6, plus quote animation for 2.4).
 *
 * This is a presentation asset only. It styles the class hooks emitted by the
 * templates in templates/ (layout.php, public/gallery.php, public/detail.php,
 * public/not-found.php, admin/{login,list,edit}.php).
 *
 * =====================================================================
 * PALETTE + CONTRAST DOCUMENTATION (Requirement 9.4)
 * =====================================================================
 * Requirement 9.4: light color scheme with a contrast ratio between the page
 * background and the PRIMARY TEXT of at least 4.5:1 (WCAG AA for normal text).
 *
 * Chosen tokens (see :root below):
 *   --bg   = #ffffff  (page background)  -> relative luminance L_bg   = 1.0000
 *   --text = #1a1a1a  (primary text)     -> relative luminance L_text = 0.0103
 *
 * Contrast ratio (WCAG formula: (L_lighter + 0.05) / (L_darker + 0.05)):
 *   Relative luminance uses the sRGB linearization:
 *     c_srgb = channel/255; c_lin = c_srgb <= 0.03928
 *              ? c_srgb/12.92
 *              : ((c_srgb + 0.055)/1.055) ^ 2.4
 *     L = 0.2126*R_lin + 0.7152*G_lin + 0.0722*B_lin
 *
 *   For #1a1a1a: each channel = 26/255 = 0.10196 -> c_lin = 0.010330
 *                L_text = 0.010330  (all channels equal, weights sum to 1)
 *   For #ffffff: L_bg = 1.0
 *
 *   contrast = (1.0 + 0.05) / (0.010330 + 0.05)
 *            = 1.05 / 0.060330
 *            = 17.40 : 1
 *
 * 17.40:1 comfortably exceeds the required 4.5:1. The unit test (task 15.4)
 * recomputes this from the --bg / --text tokens below.
 * =====================================================================
 */

:root {
    /* Core palette — light, fresh, inviting (Requirement 9.4). */
    --bg: #ffffff;            /* page background  — L = 1.0000 */
    --text: #1a1a1a;          /* PRIMARY TEXT     — L = 0.0103; contrast 17.40:1 */
    --primary: #2563eb;       /* interactive/brand accent (buttons, links) */
    --primary-contrast: #ffffff; /* text on top of --primary fills */
    --primary-hover: #1d4ed8;

    /* Supporting light-scheme tokens (surfaces, borders, muted text). */
    --surface: #f7f9fc;       /* card / panel background, a soft light tint */
    --surface-alt: #eef2f7;   /* alternate surface (table headers, quotes) */
    --border: #d9e0ea;        /* hairline borders */
    --text-muted: #4a5568;    /* secondary text; on --bg contrast ~8.6:1 (>4.5) */
    --danger: #c02626;
    --success: #1f7a3d;

    /* Layout tokens. */
    --maxw: 1280px;           /* content max width */
    --gap: 1.5rem;            /* grid/gutter spacing */
    --radius: 10px;
    --shadow: 0 1px 3px rgba(26, 26, 26, 0.08), 0 4px 12px rgba(26, 26, 26, 0.06);

    /* Quote entrance animation timing (Requirement 2.4: complete < 2000ms). */
    --quote-duration: 600ms;  /* well under the 2000ms ceiling */
    --quote-easing: ease;
}

/* -------------------------------------------------------------------
 * Reset / base
 * box-sizing: border-box + max-width:100% on media prevents horizontal
 * overflow at every viewport (Requirements 9.1, 9.5, 9.6, 9.7).
 * ------------------------------------------------------------------- */
*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    /* Fluid base type; scales gently but stays readable 320px–1920px. */
    font-size: 100%;
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    line-height: 1.6;
    /* Guard against any accidental horizontal scrolling. */
    overflow-x: hidden;
}

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

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

a:hover,
a:focus {
    color: var(--primary-hover);
    text-decoration: underline;
}

h1, h2, h3 {
    line-height: 1.25;
    color: var(--text);
}

/* -------------------------------------------------------------------
 * Site chrome (layout.php)
 * ------------------------------------------------------------------- */
.site-header {
    /* Opaque, colorful header. z-index:2 keeps it ABOVE the animated
       background shapes so they never show through it (per the brief). */
    position: relative;
    z-index: 2;
    background: linear-gradient(120deg, #6d5efc 0%, #4aa3ff 45%, #37d6c3 100%);
    box-shadow: 0 2px 12px rgba(26, 26, 26, 0.15);
}

.site-header__inner,
.site-footer__inner,
.site-main {
    width: 100%;
    max-width: var(--maxw);
    margin: 0 auto;
    padding: 1rem var(--gap);
}

.site-header__brand {
    display: inline-flex;
    flex-direction: column;
    gap: 0.15rem;
    text-decoration: none;
}

.site-header__title {
    color: #ffffff;
    font-size: 1.6rem;
    font-weight: 800;
    letter-spacing: 0.01em;
    line-height: 1.1;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.18);
}

.site-header__tagline {
    color: rgba(255, 255, 255, 0.9);
    font-size: 0.85rem;
    font-weight: 500;
}

.site-header__brand:hover,
.site-header__brand:focus {
    text-decoration: none;
}

.site-header__brand:hover .site-header__title,
.site-header__brand:focus .site-header__title {
    text-decoration: underline;
}

/* Main + footer sit ABOVE the background shapes (z-index:1) but their own
   backgrounds stay transparent so the shapes show through the page body. */
.site-main {
    position: relative;
    z-index: 1;
    padding-top: 2rem;
    padding-bottom: 3rem;
    min-height: 60vh;
}

.site-footer {
    position: relative;
    z-index: 1;
    background: var(--surface);
    border-top: 1px solid var(--border);
}

.site-footer__note {
    margin: 0;
    color: var(--text-muted);
    font-size: 0.9rem;
}

/* ===================================================================
 * GALLERY GRID — RESPONSIVE COLUMN RULES (Requirements 9.1, 9.2, 9.3)
 * ===================================================================
 * Breakpoint contract (verified by integration test 17.2):
 *   - viewport width <= 768px            -> 1 column  (no horizontal scroll)  [9.1]
 *   - 768px < width <= 1200px            -> EXACTLY 3 columns                  [9.2]
 *   - width > 1200px                     -> EXACTLY 4 columns                  [9.3]
 *
 * Base (mobile-first) is a single column. The two min-width media queries at
 * 768px+1px and 1200px+1px switch to 3 then 4 columns, so the "> 768" and
 * "> 1200" boundaries are exclusive exactly as the requirements state.
 * grid-template-columns with 1fr tracks + box-sizing:border-box guarantees no
 * horizontal overflow at any width.
 * ------------------------------------------------------------------- */

.gallery__heading {
    margin: 0 0 1.5rem;
    font-size: clamp(1.5rem, 4vw, 2.25rem);
}

.gallery__empty {
    padding: 2rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-muted);
    text-align: center;
}

.gallery__grid {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    gap: var(--gap);
    /* 9.1: single column at <= 768px (mobile-first default). */
    grid-template-columns: 1fr;
}

/* 9.2: > 768px and <= 1200px -> exactly 3 columns. */
@media (min-width: 769px) {
    .gallery__grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* 9.3: > 1200px -> exactly 4 columns. */
@media (min-width: 1201px) {
    .gallery__grid {
        grid-template-columns: repeat(4, 1fr);
    }
}

.gallery__item {
    display: flex;
}

/* -------------------------------------------------------------------
 * Book cards (gallery.php)
 * ------------------------------------------------------------------- */
.book-card {
    display: flex;
    flex-direction: column;
    width: 100%;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    color: var(--text);
    text-decoration: none;
    box-shadow: var(--shadow);
    transition: transform 150ms ease, box-shadow 150ms ease;
}

.book-card:hover,
.book-card:focus {
    transform: translateY(-3px);
    box-shadow: 0 6px 18px rgba(26, 26, 26, 0.12);
    text-decoration: none;
}

.book-card__cover {
    /* Consistent cover area; images scale inside without overflowing. */
    aspect-ratio: 2 / 3;
    background: var(--surface-alt);
    overflow: hidden;
}

.book-card__cover-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Placeholder swap target (cover-img--placeholder set by onerror handler). */
.cover-img--placeholder {
    object-fit: contain;
    padding: 1rem;
    background: var(--surface-alt);
}

.book-card__body {
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.book-card__title {
    margin: 0;
    font-size: 1.1rem;
}

.book-card__desc {
    margin: 0;
    color: var(--text-muted);
    font-size: 0.95rem;
}

/* ===================================================================
 * BOOK DETAIL PAGE — FLUID REFLOW (Requirements 9.5, 9.6)
 * ===================================================================
 * All containers are fluid (width:100%, max-width caps) and images use
 * max-width:100%, so the page reflows without horizontal scrolling from
 * 320px to 1920px. The header is a single column on small screens and
 * becomes a two-column [cover | intro] layout at wider widths. Because the
 * reflow is pure CSS layout (no JS), it completes on the same frame, well
 * within the 500ms budget of Requirement 9.6.
 * ------------------------------------------------------------------- */
.book-detail {
    max-width: 860px;
    margin: 0 auto;
}

.book-detail__header {
    display: flex;
    flex-direction: column;
    gap: var(--gap);
    margin-bottom: 2rem;
}

.book-detail__cover {
    flex: 0 0 auto;
    max-width: 260px;
}

.book-detail__cover-img {
    width: 100%;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.book-detail__title {
    margin: 0 0 1rem;
    font-size: clamp(1.6rem, 5vw, 2.5rem);
}

/* Two-column header once there is room; single column below (fluid reflow). */
@media (min-width: 641px) {
    .book-detail__header {
        flex-direction: row;
        align-items: flex-start;
    }
    .book-detail__intro {
        flex: 1 1 auto;
    }
}

.book-detail__sections {
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

.section-block__title {
    margin: 0 0 0.5rem;
    font-size: 1.35rem;
}

.section-block__body {
    margin: 0;
    color: var(--text);
    white-space: pre-line; /* preserve author paragraph breaks */
}

/* -------------------------------------------------------------------
 * Buy actions (detail.php) — top and bottom blocks
 * ------------------------------------------------------------------- */
.buy-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.buy-actions--top {
    margin-top: 1rem;
}

.buy-actions--bottom {
    margin-top: 2.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border);
}

.buy-action {
    display: inline-block;
    padding: 0.65rem 1.25rem;
    background: var(--primary);
    color: var(--primary-contrast);
    border-radius: var(--radius);
    font-weight: 600;
    text-decoration: none;
    transition: background 150ms ease;
}

.buy-action:hover,
.buy-action:focus {
    background: var(--primary-hover);
    color: var(--primary-contrast);
    text-decoration: none;
}

/* ===================================================================
 * ANIMATED QUOTES (Requirement 2.4)
 * ===================================================================
 * animate.js (task 15.2) adds the class "quote-visible" to a .animated-quote
 * when >= 50% of it enters the viewport, exactly once. The entrance transition
 * animates opacity + translateY. Its DURATION (--quote-duration = 600ms) is far
 * below the 2000ms completion ceiling of Requirement 2.4.
 *
 * Initial state: hidden + offset. Final state (.quote-visible): fully visible.
 * prefers-reduced-motion disables the motion (shows the quote immediately).
 * ------------------------------------------------------------------- */
.animated-quote {
    margin: 0;
    padding: 1.5rem 1.75rem;
    background: var(--surface-alt);
    border-left: 4px solid var(--primary);
    border-radius: var(--radius);

    /* Initial (pre-animation) state. */
    opacity: 0;
    transform: translateY(20px);
    transition:
        opacity var(--quote-duration) var(--quote-easing),
        transform var(--quote-duration) var(--quote-easing);
    will-change: opacity, transform;
}

.animated-quote.quote-visible {
    opacity: 1;
    transform: translateY(0);
}

.animated-quote__text {
    margin: 0;
    font-size: 1.25rem;
    font-style: italic;
    color: var(--text);
    quotes: "\201C" "\201D";
}

.animated-quote__text::before { content: open-quote; }
.animated-quote__text::after  { content: close-quote; }

/* Respect reduced-motion: no transform/opacity animation, show immediately. */
@media (prefers-reduced-motion: reduce) {
    .animated-quote {
        opacity: 1;
        transform: none;
        transition: none;
        will-change: auto;
    }
    .book-card {
        transition: none;
    }
}

/* ===================================================================
 * NOT-FOUND (not-found.php)
 * =================================================================== */
.not-found {
    max-width: 520px;
    margin: 3rem auto;
    text-align: center;
}

.not-found__title {
    font-size: clamp(1.5rem, 5vw, 2.25rem);
    margin: 0 0 1rem;
}

.not-found__message {
    color: var(--text-muted);
    margin: 0 0 1.5rem;
}

/* ===================================================================
 * SHARED CONTROLS — buttons, badges, forms (admin + public)
 * =================================================================== */
.btn {
    display: inline-block;
    padding: 0.55rem 1.1rem;
    border: 1px solid transparent;
    border-radius: var(--radius);
    font: inherit;
    font-weight: 600;
    line-height: 1.2;
    cursor: pointer;
    text-decoration: none;
    transition: background 150ms ease, border-color 150ms ease, color 150ms ease;
}

.btn--primary {
    background: var(--primary);
    color: var(--primary-contrast);
}
.btn--primary:hover,
.btn--primary:focus {
    background: var(--primary-hover);
    color: var(--primary-contrast);
    text-decoration: none;
}

.btn--secondary {
    background: var(--surface-alt);
    color: var(--text);
    border-color: var(--border);
}
.btn--secondary:hover,
.btn--secondary:focus {
    background: var(--border);
    color: var(--text);
    text-decoration: none;
}

.btn--danger {
    background: var(--danger);
    color: #ffffff;
}
.btn--danger:hover,
.btn--danger:focus {
    background: #a11f1f;
    color: #ffffff;
    text-decoration: none;
}

.btn--link {
    background: transparent;
    color: var(--primary);
    padding-left: 0.5rem;
    padding-right: 0.5rem;
}

.badge {
    display: inline-block;
    padding: 0.2rem 0.6rem;
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 600;
}
.badge--published {
    background: #e3f4e9;
    color: var(--success);
}
.badge--draft {
    background: var(--surface-alt);
    color: var(--text-muted);
}

/* Form fields (login + edit) */
.form-field {
    margin-bottom: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.form-field__label {
    font-weight: 600;
    color: var(--text);
}

.form-field__input {
    width: 100%;
    max-width: 100%;
    padding: 0.6rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font: inherit;
    color: var(--text);
    background: var(--bg);
}

.form-field__input:focus {
    outline: 2px solid var(--primary);
    outline-offset: 1px;
    border-color: var(--primary);
}

.form-field--checkbox {
    flex-direction: row;
    align-items: center;
    gap: 0.5rem;
}

.form-field__input--order {
    max-width: 6rem;
}

.form-field__error {
    margin: 0;
    color: var(--danger);
    font-size: 0.9rem;
}

.form-actions {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    margin-top: 1.5rem;
}

/* ===================================================================
 * ADMIN LOGIN (admin/login.php)
 * =================================================================== */
.admin-login {
    max-width: 380px;
    margin: 3rem auto;
    padding: 2rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.admin-login__title {
    margin: 0 0 1.5rem;
    font-size: 1.5rem;
}

.admin-login__error {
    margin: 0 0 1rem;
    padding: 0.75rem 1rem;
    background: #fdecec;
    color: var(--danger);
    border: 1px solid #f5c2c2;
    border-radius: var(--radius);
}

/* ===================================================================
 * ADMIN LIST (admin/list.php)
 * =================================================================== */
.admin-list__head {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
}

.admin-list__title {
    margin: 0;
}

.admin-list__message {
    margin: 0 0 1rem;
    padding: 0.75rem 1rem;
    background: #e3f4e9;
    color: var(--success);
    border: 1px solid #bfe6cd;
    border-radius: var(--radius);
}

.admin-list__empty {
    color: var(--text-muted);
}

.admin-table {
    width: 100%;
    border-collapse: collapse;
    /* Wrapping content keeps the table fluid without horizontal scroll. */
}

.admin-table th,
.admin-table__cell {
    text-align: left;
    padding: 0.75rem;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

.admin-table thead th {
    background: var(--surface-alt);
    font-size: 0.9rem;
}

.admin-table__cell--actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
}

.inline-form {
    display: inline;
    margin: 0;
}

/* ===================================================================
 * ADMIN EDIT (admin/edit.php)
 * =================================================================== */
.admin-edit {
    max-width: 760px;
    margin: 0 auto;
}

.admin-edit__title {
    margin: 0 0 1.5rem;
}

.admin-edit__errors {
    margin: 0 0 1.5rem;
    padding: 1rem 1.25rem;
    background: #fdecec;
    color: var(--danger);
    border: 1px solid #f5c2c2;
    border-radius: var(--radius);
}

.admin-edit__errors-lead {
    margin: 0 0 0.5rem;
    font-weight: 600;
}

.admin-edit__errors-list {
    margin: 0;
    padding-left: 1.25rem;
}

.form-group {
    margin: 0 0 2rem;
    padding: 1.25rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
}

.form-group__legend {
    padding: 0 0.5rem;
    font-weight: 700;
    color: var(--text);
}

.repeat-row {
    display: grid;
    gap: 0.75rem;
    padding: 1rem;
    margin-bottom: 1rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

/* Multi-column repeat rows once there is room; single column on small screens. */
@media (min-width: 641px) {
    .repeat-row--section,
    .repeat-row--link {
        grid-template-columns: 1fr 1fr 6rem;
        align-items: start;
    }
    .repeat-row--quote {
        grid-template-columns: 1fr 6rem;
        align-items: start;
    }
}

.repeat-row--new {
    border-style: dashed;
    background: var(--surface-alt);
}

/* ===================================================================
 * ANIMATED BACKGROUND SHAPES (decorative, all pages)
 * ===================================================================
 * A fixed, full-viewport layer of large, softly-coloured, blurred shapes that
 * drift VERY slowly. It sits behind the page content (z-index:0) while the
 * header is opaque and drawn above it (z-index:2), so the shapes never show
 * through the header. Page content (z-index:1) has a transparent background so
 * the shapes are visible behind it.
 *
 * Which shapes are shown is driven by the <body> page class:
 *   - .page--gallery / .page--not-found / .admin  -> circles only
 *   - .page--detail                               -> circles + squares + triangles
 *
 * The layer is aria-hidden and pointer-events:none, and all motion is disabled
 * under prefers-reduced-motion.
 * ------------------------------------------------------------------- */
.bg-shapes {
    position: fixed;
    inset: 0;
    overflow: hidden;
    z-index: 0;
    pointer-events: none;
}

.shape {
    position: absolute;
    opacity: 0.4;
    filter: blur(8px);
    will-change: transform;
    animation-duration: 140s;
    animation-timing-function: ease-in-out;
    animation-iteration-count: infinite;
    animation-direction: alternate;
}

.shape--circle   { border-radius: 50%; }
.shape--square   { border-radius: 18%; }
.shape--triangle { clip-path: polygon(50% 0%, 0% 100%, 100% 100%); }

/* By default (gallery, admin, not-found) only circles are shown. The detail
   page re-enables squares and triangles below. */
.shape--square,
.shape--triangle { display: none; }

.page--detail .shape--square,
.page--detail .shape--triangle { display: block; }

/* --- Circles (present on every page) --- */
.shape--c1 { width: 420px; height: 420px; top: -80px;  left: -60px; background: #e0d7ff; animation-name: drift-a; animation-duration: 130s; }
.shape--c2 { width: 320px; height: 320px; top: 42%;    left: 72%;   background: #d3f5e7; animation-name: drift-b; animation-duration: 160s; animation-delay: -30s; }
.shape--c3 { width: 260px; height: 260px; top: 66%;    left: 6%;    background: #d6ecff; animation-name: drift-c; animation-duration: 120s; animation-delay: -60s; }
.shape--c4 { width: 380px; height: 380px; top: 8%;     left: 56%;   background: #ffe6cf; animation-name: drift-d; animation-duration: 175s; animation-delay: -15s; }
.shape--c5 { width: 200px; height: 200px; top: 80%;    left: 44%;   background: #ffd6e7; animation-name: drift-b; animation-duration: 145s; animation-delay: -90s; }

/* --- Squares (detail page only) --- */
.shape--sq1 { width: 240px; height: 240px; top: 20%; left: 12%; background: #fff4c2; animation-name: drift-c; animation-duration: 165s; }
.shape--sq2 { width: 180px; height: 180px; top: 55%; left: 82%; background: #e0d7ff; animation-name: drift-a; animation-duration: 135s; animation-delay: -40s; }
.shape--sq3 { width: 300px; height: 300px; top: 78%; left: 28%; background: #d3f5e7; animation-name: drift-d; animation-duration: 190s; animation-delay: -70s; }

/* --- Triangles (detail page only) --- */
.shape--tr1 { width: 260px; height: 260px; top: 14%; left: 78%; background: #d6ecff; animation-name: drift-b; animation-duration: 155s; }
.shape--tr2 { width: 220px; height: 220px; top: 60%; left: 4%;  background: #ffe6cf; animation-name: drift-c; animation-duration: 180s; animation-delay: -50s; }
.shape--tr3 { width: 300px; height: 300px; top: 84%; left: 64%; background: #ffd6e7; animation-name: drift-a; animation-duration: 200s; animation-delay: -20s; }

/* Very slow, gentle drift vectors (in different directions). Combined with
   animation-direction:alternate they ease slowly back and forth. */
@keyframes drift-a { from { transform: translate(0, 0) rotate(0deg); }      to { transform: translate(6vw, 4vh) rotate(12deg); } }
@keyframes drift-b { from { transform: translate(0, 0) rotate(0deg); }      to { transform: translate(-5vw, 6vh) rotate(-10deg); } }
@keyframes drift-c { from { transform: translate(0, 0) rotate(0deg); }      to { transform: translate(4vw, -6vh) rotate(8deg); } }
@keyframes drift-d { from { transform: translate(0, 0) rotate(0deg); }      to { transform: translate(-6vw, -4vh) rotate(-14deg); } }

@media (prefers-reduced-motion: reduce) {
    .shape { animation: none; }
}
