/* ============================================================
   The Rev George Stoddard Library by Booklyn
   Vibrant patriotic palette — Old Glory red/white/blue, gold as
   a secondary metallic accent carried over from the Booklyn brand.
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Cormorant+Garamond:ital,wght@0,400;0,500;0,600;0,700;1,500&family=EB+Garamond:ital,wght@0,400;0,500;1,400&display=swap');

:root {
  --navy: #0B1B42;
  --navy-2: #14275E;
  --navy-3: #1C3474;
  --gold: #C7A248;
  --gold-bright: #E4C468;
  --cream: #F5F1E4;
  --cream-dim: #C9C4B0;
  --white: #FFFFFF;
  --red: #C8102E;
  --red-bright: #E51937;
  --line: rgba(199, 162, 72, 0.28);
  --shadow: 0 20px 50px rgba(0, 0, 0, 0.45);
  --radius: 3px;
  --max: 1180px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--navy);
  color: var(--cream);
  font-family: 'EB Garamond', Georgia, serif;
  font-size: 18px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, .display {
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--cream);
  margin: 0 0 0.4em;
}

a { color: var(--gold-bright); text-decoration: none; }
a:hover { text-decoration: underline; }

.eyebrow {
  font-family: 'EB Garamond', Georgia, serif;
  font-variant: small-caps;
  letter-spacing: 0.22em;
  font-size: 0.8rem;
  color: var(--gold);
}

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

.wrap { max-width: var(--max); margin: 0 auto; padding: 0 24px; }

:focus-visible {
  outline: 2px solid var(--gold-bright);
  outline-offset: 3px;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}

/* ---------------- Old Glory ribbon bar (signature stripe motif) ---------------- */

.old-glory-bar {
  height: 8px;
  background: repeating-linear-gradient(
    180deg,
    var(--red) 0px, var(--red) 2px,
    var(--white) 2px, var(--white) 4px
  );
}

/* ---------------- Header / nav ---------------- */

.site-header {
  position: sticky; top: 0; z-index: 40;
  background: rgba(11, 27, 66, 0.94);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.site-header .wrap {
  display: flex; align-items: center; justify-content: space-between;
  height: 68px;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 50%;
  border: 1px solid var(--gold);
  display: flex; align-items: center; justify-content: center;
  color: var(--gold); font-family: 'Cormorant Garamond', serif; font-weight: 700; font-size: 0.85rem;
  flex-shrink: 0;
}
.brand-name { font-family: 'Cormorant Garamond', serif; font-weight: 600; font-size: 1.15rem; color: var(--cream); line-height: 1.1; }
.brand-name small { display: block; font-family: 'EB Garamond', serif; font-variant: small-caps; letter-spacing: 0.18em; font-size: 0.6rem; color: var(--gold); margin-top: 2px; }

nav.main-nav { display: flex; align-items: center; gap: 22px; font-size: 0.95rem; }
nav.main-nav a { color: var(--cream-dim); }
nav.main-nav a:hover { color: var(--gold-bright); text-decoration: none; }
#nav-auth { display: flex; gap: 18px; align-items: center; }

/* ---------------- Buttons / forms ---------------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font-family: 'EB Garamond', serif; font-variant: small-caps; letter-spacing: 0.08em;
  font-size: 0.98rem;
  padding: 12px 26px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--red); color: var(--white); border-color: rgba(255,255,255,0.15); }
.btn-primary:hover { background: var(--red-bright); text-decoration: none; box-shadow: 0 6px 20px rgba(200,16,46,0.45); }
.btn-gold { background: transparent; color: var(--gold-bright); border-color: var(--gold); }
.btn-gold:hover { background: rgba(199,162,72,0.12); text-decoration: none; }
.btn-ghost { background: transparent; color: var(--cream-dim); border-color: var(--line); }
.btn-ghost:hover { color: var(--cream); border-color: var(--gold); text-decoration: none; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-block { width: 100%; }

.field { margin-bottom: 18px; }
.field label { display: block; font-variant: small-caps; letter-spacing: 0.1em; font-size: 0.85rem; color: var(--gold); margin-bottom: 6px; }
.field input, .field textarea, .field select {
  width: 100%; padding: 11px 13px;
  background: var(--navy-2); border: 1px solid var(--line); border-radius: var(--radius);
  color: var(--cream); font-family: 'EB Garamond', serif; font-size: 1rem;
}
.field input:focus, .field textarea:focus, .field select:focus { border-color: var(--gold); outline: none; }
.field textarea { resize: vertical; min-height: 90px; }
.field-hint { font-size: 0.82rem; color: var(--cream-dim); margin-top: 4px; }

.card-panel {
  background: var(--navy-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 34px;
}

.form-message { padding: 10px 14px; border-radius: var(--radius); font-size: 0.92rem; margin-bottom: 16px; }
.form-message.error { background: rgba(200,16,46,0.18); border: 1px solid var(--red); color: #ffc3cc; }
.form-message.success { background: rgba(199,162,72,0.14); border: 1px solid var(--gold); color: var(--gold-bright); }
.hidden { display: none !important; }

/* ---------------- Divider / star rule ---------------- */

.star-rule { display: flex; align-items: center; justify-content: center; gap: 14px; margin: 18px 0; color: var(--gold); }
.star-rule::before, .star-rule::after { content: ""; height: 1px; width: 64px; background: var(--line); }
.star-rule svg { width: 12px; height: 12px; }

/* ---------------- Hero (real LOC photo, explicit longhand for reliability) ---------------- */

.hero {
  position: relative;
  overflow: hidden;
  padding: 108px 24px 84px;
  text-align: center;
  isolation: isolate;
  background-color: var(--navy);
  background-image: url('/images/hero-bg.jpg');
  background-repeat: no-repeat;
  background-position: center 38%;
  background-size: cover;
}
.hero::before {
  /* navy + red scrim over the photo, for legibility and the patriotic tint */
  content: "";
  position: absolute; inset: 0; z-index: -1;
  background-image:
    linear-gradient(180deg, rgba(11,27,66,0.55) 0%, rgba(11,27,66,0.76) 42%, rgba(6,14,36,0.92) 100%),
    radial-gradient(ellipse 900px 500px at 50% -10%, rgba(228,196,104,0.16), transparent 62%),
    radial-gradient(ellipse 70% 40% at 50% 90%, rgba(200,16,46,0.22), transparent 70%);
}
.hero::after {
  /* vignette */
  content: "";
  position: absolute; inset: 0; z-index: -1;
  box-shadow: inset 0 0 160px 40px rgba(0,0,0,0.6);
}
.hero-seal { width: 128px; height: 128px; margin: 0 auto 22px; color: var(--gold); opacity: 0.95; }
.hero-eyebrow { margin-bottom: 14px; }
.hero h1 {
  font-size: clamp(2.3rem, 6vw, 4.1rem);
  line-height: 1.05;
  margin-bottom: 10px;
  text-shadow: 0 4px 30px rgba(0,0,0,0.6);
}
.hero-by { font-variant: small-caps; letter-spacing: 0.2em; color: var(--gold-bright); font-size: 1.05rem; margin-bottom: 22px; }
.hero p.lede { max-width: 620px; margin: 0 auto 30px; color: var(--cream); font-size: 1.15rem; text-shadow: 0 2px 14px rgba(0,0,0,0.5); }
.hero-ctas { display: flex; gap: 16px; justify-content: center; flex-wrap: wrap; }

/* ---------------- Catalog grid ---------------- */

.section { padding: 60px 0; }
.section-head { text-align: center; margin-bottom: 40px; }
.section-head h2 { font-size: 2rem; }

.filters { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; margin-bottom: 34px; }
.filters button {
  font-family: 'EB Garamond', serif; font-variant: small-caps; letter-spacing: 0.06em;
  background: transparent; border: 1px solid var(--line); color: var(--cream-dim);
  padding: 7px 16px; border-radius: 20px; cursor: pointer; font-size: 0.92rem;
}
.filters button.active, .filters button:hover { border-color: var(--gold); color: var(--gold-bright); }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 28px;
}

.book-card {
  background: var(--navy-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex; flex-direction: column;
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
}
.book-card:hover { transform: translateY(-4px); box-shadow: var(--shadow); border-color: var(--gold); }
.book-cover {
  position: relative;
  aspect-ratio: 2 / 3;
  background: linear-gradient(160deg, var(--navy-3), var(--navy-2));
  border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
.book-cover img { width: 100%; height: 100%; object-fit: cover; }
.book-cover .cover-fallback { font-family: 'Cormorant Garamond', serif; color: var(--gold); text-align: center; padding: 14px; font-size: 0.95rem; }
.price-tag {
  position: absolute; top: 10px; right: 10px;
  background: var(--red); color: var(--white);
  font-family: 'EB Garamond', serif; font-variant: small-caps; letter-spacing: 0.05em;
  font-size: 0.82rem; padding: 4px 10px; border-radius: 20px;
  box-shadow: 0 4px 10px rgba(0,0,0,0.35);
}
.book-info { padding: 16px 16px 18px; flex: 1; display: flex; flex-direction: column; }
.book-info h3 { font-size: 1.2rem; margin-bottom: 2px; }
.book-info .book-author { font-size: 0.85rem; color: var(--gold); font-variant: small-caps; letter-spacing: 0.05em; margin-bottom: 8px; }
.book-info .book-desc { font-size: 0.92rem; color: var(--cream-dim); flex: 1; margin-bottom: 12px; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.book-info .btn { align-self: flex-start; padding: 9px 20px; font-size: 0.88rem; }

.empty-state { text-align: center; padding: 70px 20px; color: var(--cream-dim); }
.empty-state h3 { color: var(--cream); }

/* ---------------- Book detail page ---------------- */

.book-detail { display: grid; grid-template-columns: 300px 1fr; gap: 44px; align-items: start; }
@media (max-width: 720px) { .book-detail { grid-template-columns: 1fr; } }
.book-detail .book-cover { border-radius: var(--radius); border: 1px solid var(--line); }
.book-detail-meta .eyebrow { display: block; margin-bottom: 8px; }
.book-detail-meta h1 { font-size: 2.4rem; }
.book-detail-meta .book-author { font-size: 1rem; color: var(--gold); font-variant: small-caps; letter-spacing: 0.08em; margin-bottom: 18px; }
.book-detail-meta .desc { color: var(--cream-dim); margin-bottom: 26px; }
.purchase-box { background: var(--navy-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; margin-bottom: 26px; }
.purchase-box .price { font-family: 'Cormorant Garamond', serif; font-size: 2rem; color: var(--gold-bright); margin-bottom: 4px; }
.purchase-box .price-note { font-size: 0.85rem; color: var(--cream-dim); margin-bottom: 16px; }

.chapter-list { list-style: none; margin: 0; padding: 0; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.chapter-list li { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line); font-size: 0.95rem; }
.chapter-list li:last-child { border-bottom: none; }
.chapter-list .chapter-num { color: var(--gold); font-variant: small-caps; margin-right: 10px; }
.chapter-list a.dl-link { font-variant: small-caps; letter-spacing: 0.05em; }
.chapter-list .locked { color: var(--cream-dim); opacity: 0.6; }

/* ---------------- Dashboard / My Library ---------------- */

.library-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 24px; }
.library-card { background: var(--navy-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; display: flex; gap: 14px; }
.library-card .book-cover { width: 78px; flex-shrink: 0; border-radius: 2px; }
.library-card .lib-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.library-card .lib-actions a { font-size: 0.85rem; }

/* ---------------- Admin ---------------- */

.admin-gate { max-width: 420px; margin: 90px auto; }
.upload-row { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
@media (max-width: 640px) { .upload-row { grid-template-columns: 1fr; } }
.chapter-row { display: flex; gap: 10px; align-items: center; margin-bottom: 10px; }
.chapter-row input[type=text] { flex: 1; }
.chapter-row .chapter-file-name { font-size: 0.85rem; color: var(--cream-dim); flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chapter-row button { background: transparent; border: 1px solid var(--line); color: var(--cream-dim); border-radius: var(--radius); padding: 6px 10px; cursor: pointer; }
.progress-line { display: flex; justify-content: space-between; font-size: 0.85rem; color: var(--cream-dim); padding: 6px 0; border-bottom: 1px solid var(--line); }
.progress-line.done { color: var(--gold-bright); }
.progress-line.failed { color: #ffc3cc; }
.admin-list-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.admin-list-row .meta { font-size: 0.88rem; color: var(--cream-dim); }

/* ---------------- Footer ---------------- */

.site-footer { border-top: 1px solid var(--line); padding: 34px 0; margin-top: 60px; }
.site-footer .wrap { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 12px; font-size: 0.85rem; color: var(--cream-dim); }
.site-footer .star-rule { margin: 0 0 14px; }
