/* ─────────────────────────────────────────────────────────────────────────────
   Mythologica — presentation tier styles
   Responsive, distraction-free, tuned for long-form reading (PRD §7.1).
   ───────────────────────────────────────────────────────────────────────────── */

:root {
  --ink: #1b2330;
  --ink-soft: #4a5568;
  --ink-faint: #7b8794;
  --paper: #fbf8f3;
  --surface: #ffffff;
  --line: #e6e0d6;
  --navy: #223a5e;
  --navy-dark: #182a45;
  --gold: #b8894b;
  --gold-soft: #f3e9d8;
  --danger: #b3261e;
  --success: #2f7d54;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(24, 42, 69, 0.06), 0 8px 24px rgba(24, 42, 69, 0.06);
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--sans);
  color: var(--ink);
  background: var(--paper);
  line-height: 1.6;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

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

.container { width: 100%; max-width: 1080px; margin: 0 auto; padding: 0 1.25rem; }

/* ── Header ─────────────────────────────────────────────────────────────────── */
.site-header {
  background: var(--navy);
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 10;
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.15);
}
.nav {
  max-width: 1080px;
  margin: 0 auto;
  padding: 0.8rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  color: #fff;
  font-family: var(--serif);
  font-size: 1.35rem;
  font-weight: 600;
  letter-spacing: 0.01em;
}
.brand:hover { text-decoration: none; }
.brand__mark { color: var(--gold); }
.nav__links { display: flex; align-items: center; gap: 0.4rem; }
.nav__link {
  color: rgba(255, 255, 255, 0.85);
  padding: 0.4rem 0.7rem;
  border-radius: 8px;
  font-size: 0.95rem;
}
.nav__link:hover { color: #fff; background: rgba(255, 255, 255, 0.1); text-decoration: none; }

/* ── Buttons ───────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  font: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  padding: 0.5rem 1rem;
  border-radius: 999px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.btn:hover { text-decoration: none; }
.btn--primary { background: var(--gold); color: #fff; }
.btn--primary:hover { background: #a2763b; }
.btn--ghost { background: transparent; border-color: currentColor; color: var(--navy); }
.nav .btn--ghost { color: #fff; }
.btn--ghost:hover { background: rgba(184, 137, 75, 0.12); }
.btn--block { width: 100%; }

/* ── Main / footer ─────────────────────────────────────────────────────────── */
.view { flex: 1; padding-top: 2rem; padding-bottom: 3rem; }
.page-title { font-family: var(--serif); font-size: 1.8rem; margin: 0 0 1.25rem; }
.site-footer {
  border-top: 1px solid var(--line);
  color: var(--ink-faint);
  font-size: 0.85rem;
  padding: 1.5rem 0;
}
.back-link { display: inline-block; margin-bottom: 1rem; color: var(--ink-soft); font-size: 0.9rem; }

/* ── Search + filters ──────────────────────────────────────────────────────── */
.catalog-head { margin-bottom: 1rem; }
.search { display: flex; gap: 0.5rem; }
.search__input {
  flex: 1;
  padding: 0.7rem 1rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  font: inherit;
}
.search__input:focus { outline: 2px solid var(--gold); border-color: transparent; }
.filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
  margin: 0.5rem 0 0.25rem;
}
.filters__note { font-style: italic; color: var(--ink-soft); margin: 0; flex: 1; }
.filter__select {
  padding: 0.45rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  font: inherit;
  color: var(--ink);
}
.result-count { color: var(--ink-faint); font-size: 0.85rem; margin: 0.75rem 0; }

/* ── Card grid ─────────────────────────────────────────────────────────────── */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 1rem;
}
.card {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.1rem;
  color: var(--ink);
  box-shadow: var(--shadow);
  transition: transform 0.15s, box-shadow 0.15s;
}
.card:hover {
  text-decoration: none;
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(24, 42, 69, 0.08), 0 16px 32px rgba(24, 42, 69, 0.1);
}
.card__culture,
.detail__culture,
.reader__culture {
  align-self: flex-start;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--gold);
  background: var(--gold-soft);
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
}
.card__title { font-family: var(--serif); font-size: 1.2rem; margin: 0.15rem 0 0; }
.card__author { color: var(--ink-faint); font-size: 0.85rem; font-style: italic; margin: 0; }
.card__summary {
  color: var(--ink-soft);
  font-size: 0.92rem;
  margin: 0.2rem 0 0;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ── Tags ──────────────────────────────────────────────────────────────────── */
.tag-row { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: auto; padding-top: 0.5rem; }
.tag {
  font-size: 0.78rem;
  color: var(--navy);
  background: #eef2f7;
  border-radius: 999px;
  padding: 0.15rem 0.6rem;
}
a.tag:hover { background: #e0e7f0; text-decoration: none; }

/* ── States ────────────────────────────────────────────────────────────────── */
.state { text-align: center; padding: 3rem 1rem; color: var(--ink-faint); }
.state--error { color: var(--danger); }
.state--empty { display: flex; flex-direction: column; align-items: center; gap: 1rem; }

/* ── Detail ────────────────────────────────────────────────────────────────── */
.detail { max-width: 720px; }
.detail__title { font-family: var(--serif); font-size: 2.2rem; line-height: 1.15; margin: 0.6rem 0 0.25rem; }
.detail__author { color: var(--ink-faint); font-style: italic; margin: 0; }
.meta { display: flex; gap: 2rem; margin: 1.25rem 0; padding: 0; }
.meta dt { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-faint); }
.meta dd { margin: 0.15rem 0 0; font-weight: 600; }
.detail__summary { font-size: 1.05rem; color: var(--ink-soft); }
.detail__actions { display: flex; flex-wrap: wrap; gap: 0.75rem; margin-top: 1.75rem; }

/* ── Reader (F4) + notes (F7) ──────────────────────────────────────────────── */
.reader-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 2rem;
}
@media (min-width: 900px) {
  .reader-layout { grid-template-columns: minmax(0, 1fr) 300px; align-items: start; }
}
.reader { max-width: 680px; margin: 0 auto; }
.reader__title { font-family: var(--serif); font-size: 2.1rem; line-height: 1.15; margin: 0.6rem 0 0.25rem; }
.reader__author { color: var(--ink-faint); font-style: italic; margin: 0 0 1.5rem; }
.reader__body { font-family: var(--serif); font-size: 1.18rem; line-height: 1.8; }
.reader__body p { margin: 0 0 1.3rem; }
.reader__body p:first-letter { }

.notes {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.1rem;
  position: sticky;
  top: 5rem;
}
.notes--guest { text-align: center; color: var(--ink-soft); }
.notes__title { font-size: 1.05rem; margin: 0 0 0.75rem; }
.notes__form { display: flex; flex-direction: column; gap: 0.5rem; margin-bottom: 1rem; }
.notes__ref-input,
.notes__input {
  width: 100%;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
  font-size: 0.9rem;
  resize: vertical;
}
.notes__input:focus,
.notes__ref-input:focus { outline: 2px solid var(--gold); border-color: transparent; }
.notes__list { display: flex; flex-direction: column; gap: 0.6rem; }
.notes__empty { color: var(--ink-faint); font-size: 0.9rem; font-style: italic; }
.note {
  position: relative;
  background: var(--gold-soft);
  border-radius: 8px;
  padding: 0.6rem 2rem 0.6rem 0.75rem;
}
.note__ref { display: block; font-size: 0.72rem; font-weight: 700; color: var(--gold); text-transform: uppercase; letter-spacing: 0.04em; }
.note__text { margin: 0.15rem 0 0; font-size: 0.9rem; white-space: pre-wrap; }
.note__delete {
  position: absolute;
  top: 0.35rem;
  right: 0.45rem;
  border: none;
  background: none;
  color: var(--ink-faint);
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
}
.note__delete:hover { color: var(--danger); }

/* ── Auth forms ────────────────────────────────────────────────────────────── */
.auth-wrap { max-width: 380px; margin: 1rem auto; }
.auth-form { display: flex; flex-direction: column; gap: 1rem; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.5rem; box-shadow: var(--shadow); }
.field { display: flex; flex-direction: column; gap: 0.35rem; }
.field__label { font-size: 0.85rem; font-weight: 600; color: var(--ink-soft); }
.field__input { padding: 0.6rem 0.8rem; border: 1px solid var(--line); border-radius: 8px; font: inherit; }
.field__input:focus { outline: 2px solid var(--gold); border-color: transparent; }
.field__hint { font-size: 0.78rem; color: var(--ink-faint); }
.form-error { color: var(--danger); font-size: 0.9rem; margin: 0; min-height: 1.2em; }
.auth-switch { text-align: center; color: var(--ink-soft); font-size: 0.9rem; margin-top: 1.25rem; }

/* ── Toasts ────────────────────────────────────────────────────────────────── */
#toast-host { position: fixed; bottom: 1.25rem; left: 50%; transform: translateX(-50%); z-index: 50; display: flex; flex-direction: column; gap: 0.5rem; align-items: center; }
.toast {
  background: var(--ink);
  color: #fff;
  padding: 0.6rem 1.1rem;
  border-radius: 999px;
  font-size: 0.9rem;
  box-shadow: var(--shadow);
  opacity: 1;
  transition: opacity 0.3s, transform 0.3s;
}
.toast--success { background: var(--success); }
.toast--error { background: var(--danger); }
.toast--out { opacity: 0; transform: translateY(8px); }

/* ── Small screens ─────────────────────────────────────────────────────────── */
@media (max-width: 560px) {
  .detail__title { font-size: 1.7rem; }
  .reader__body { font-size: 1.08rem; }
  .meta { gap: 1.25rem; }
  .nav { flex-wrap: wrap; }
}

/* ── In-site PDF reader ─────────────────────────────────────────────────────── */
.pdf-reader { display: flex; flex-direction: column; gap: 1rem; }
.pdf-reader__toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem 1rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 0.6rem 1rem;
  position: sticky;
  top: 0.5rem;
  z-index: 5;
}
.pdf-reader__toolbar .back-link { margin: 0; }
.pdf-reader__title {
  font-weight: 600;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1 1 12rem;
  min-width: 0;
}
.pdf-reader__controls { display: flex; align-items: center; gap: 0.4rem; margin-left: auto; }
.pdf-reader__controls .btn { padding: 0.35rem 0.7rem; }
.pdf-reader__pagelabel { color: var(--ink-soft); min-width: 4.5rem; text-align: center; font-variant-numeric: tabular-nums; }
.pdf-reader__sep { width: 1px; height: 1.4rem; background: var(--line); margin: 0 0.35rem; }
.pdf-reader__scroll { overflow: auto; display: flex; justify-content: safe center; padding-bottom: 1rem; }
.pdf-reader__canvas {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 4px;
  box-shadow: var(--shadow);
  max-width: none;
}
@media (max-width: 640px) {
  .pdf-reader__title { flex-basis: 100%; order: 2; }
  .pdf-reader__controls { margin-left: 0; }
}
