/* ===========================================================
   Pathfinder Tales — design tokens
   Concept: a hand-carried adventure journal. Parchment pages,
   deep pine cover, a wax-seal used as the recurring signature
   for every "go" action (begin story / play narration).
=========================================================== */

:root {
  --pine-900: #16281f;
  --pine-800: #1f3a2e;
  --pine-700: #2c4d3d;
  --parchment-shelf: #e4d3a4;
  --parchment: #ede0be;
  --page: #f8f1de;
  --page-edge: #e6d6a8;
  --ink: #22283b;
  --ink-soft: #4a4f63;
  --marigold: #e8a33d;
  --marigold-dark: #c6822a;
  --berry: #b23a48;
  --berry-dark: #8f2836;
  --teal: #3e8e8e;
  --teal-dark: #2d6b6b;
  --cream-card: #fbf6e9;

  --font-display: "Fredoka", ui-rounded, system-ui, sans-serif;
  --font-body: "Atkinson Hyperlegible", -apple-system, sans-serif;

  --radius-lg: 22px;
  --radius-md: 14px;
  --shadow-soft: 0 10px 30px rgba(22, 40, 31, 0.18);
  --shadow-card: 0 6px 18px rgba(22, 40, 31, 0.14);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--parchment-shelf);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 18px;
  line-height: 1.55;
  transition: background .25s ease;
}

body.is-reading {
  background: var(--page);
}

@media (prefers-reduced-motion: no-preference) {
  .story-card, .choice-btn, .icon-btn, .seal-btn { transition: transform .18s ease, box-shadow .18s ease; }
}

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

button { font-family: inherit; cursor: pointer; }
button:focus-visible, select:focus-visible, input:focus-visible, a:focus-visible {
  outline: 3px solid var(--teal);
  outline-offset: 2px;
}

/* ---------------- topbar ---------------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 24px;
  background: var(--pine-800);
  color: var(--parchment);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  background: none;
  border: none;
  color: inherit;
  padding: 6px 4px;
  border-radius: var(--radius-md);
}
.brand-seal { color: var(--marigold); display: flex; }
.brand-text {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 22px;
  letter-spacing: 0.2px;
}

.topbar-right { display: flex; gap: 8px; }

.icon-btn {
  background: rgba(237, 224, 190, 0.12);
  border: 1px solid rgba(237, 224, 190, 0.3);
  color: var(--parchment);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}
.icon-btn:hover { background: rgba(237, 224, 190, 0.22); }

/* ---------------- auth bar + modal ---------------- */

#auth-bar { display: flex; align-items: center; }

.auth-pill {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(237, 224, 190, 0.12);
  border: 1px solid rgba(237, 224, 190, 0.3);
  color: var(--parchment);
  padding: 6px 8px 6px 14px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 700;
}
.auth-pill .email { max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.auth-pill button {
  background: rgba(237, 224, 190, 0.18);
  border: none;
  color: var(--parchment);
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 700;
}
.auth-pill button:hover { background: rgba(237, 224, 190, 0.3); }

.sign-in-btn {
  background: var(--marigold);
  color: var(--pine-900);
  border: none;
  padding: 8px 16px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 14px;
}
.sign-in-btn:hover { background: var(--marigold-dark); color: white; }

.auth-modal {
  position: fixed;
  inset: 0;
  background: rgba(22, 40, 31, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 40;
  padding: 20px;
}
.auth-modal-inner {
  background: var(--cream-card);
  border-radius: var(--radius-lg);
  padding: 26px 26px 22px;
  max-width: 380px;
  width: 100%;
  box-shadow: var(--shadow-soft);
}
.auth-modal-inner h2 { font-family: var(--font-display); font-size: 21px; margin: 0 0 6px; color: var(--pine-900); }
.auth-modal-inner p { color: var(--ink-soft); font-size: 14.5px; margin: 0 0 16px; }
.auth-modal-inner input[type="email"] {
  padding: 10px 12px; border-radius: 8px; border: 1px solid var(--page-edge);
  font-size: 15px; font-family: inherit;
}
.auth-status { font-size: 13.5px; font-weight: 700; color: var(--teal-dark); min-height: 18px; }

/* ---------------- paywall + badges ---------------- */

.badge.owned-badge { background: var(--teal); }
.badge.price-badge { background: var(--marigold); color: var(--pine-900); }

.paywall-panel { text-align: center; }
.paywall-lock {
  width: 56px; height: 56px;
  border-radius: 50%;
  background: var(--marigold);
  color: var(--pine-900);
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 16px;
}
.paywall-panel h3 { font-family: var(--font-display); font-size: 22px; margin: 0 0 10px; color: var(--pine-900); }
.paywall-panel p { color: var(--ink-soft); font-size: 16px; max-width: 440px; margin: 0 auto 20px; }
.paywall-price { font-family: var(--font-display); font-size: 28px; color: var(--pine-800); margin-bottom: 18px; }

/* ---------------- voice settings panel ---------------- */

.voice-panel {
  position: fixed;
  top: 68px;
  right: 16px;
  z-index: 30;
  background: var(--cream-card);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-soft);
  border: 1px solid var(--page-edge);
}
.voice-panel-inner { padding: 18px 20px; width: min(300px, 82vw); }
.voice-panel h2 { font-family: var(--font-display); font-size: 18px; margin: 0 0 12px; color: var(--pine-800); }
.voice-row { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; font-size: 15px; font-weight: 700; color: var(--ink-soft); }
.voice-row select, .voice-row input[type="range"] { font-family: inherit; font-size: 15px; }
.voice-row select { padding: 8px; border-radius: 8px; border: 1px solid var(--page-edge); background: white; }

.btn-small {
  background: var(--pine-800);
  color: var(--parchment);
  border: none;
  padding: 8px 16px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 14px;
}

/* ---------------- library / shelf view ---------------- */

.shelf-wrap {
  max-width: 980px;
  margin: 0 auto;
  padding: 40px 24px 80px;
}

.shelf-intro { text-align: center; margin-bottom: 34px; }
.shelf-intro h1 {
  font-family: var(--font-display);
  font-size: clamp(30px, 5vw, 44px);
  color: var(--pine-900);
  margin: 0 0 10px;
}
.shelf-intro p { color: var(--ink-soft); font-size: 18px; max-width: 560px; margin: 0 auto; }

.shelf-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 26px;
}

.story-card {
  position: relative;
  background: var(--cream-card);
  border-radius: var(--radius-md);
  box-shadow: 0 2px 8px rgba(22, 40, 31, 0.1);
  padding: 24px 20px 20px;
  padding-left: 30px;
  text-align: left;
  border: none;
  color: var(--ink);
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 250px;
}
.story-card::before {
  /* book spine */
  content: "";
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 10px;
  border-radius: var(--radius-md) 0 0 var(--radius-md);
  background: var(--spine-color, var(--pine-700));
}
.story-card:not([disabled]):hover { transform: translateY(-4px); box-shadow: var(--shadow-soft); }
.story-card:not([disabled]) { cursor: pointer; }
.story-card[disabled] { opacity: 0.68; cursor: default; }

.story-card-icon {
  width: 52px; height: 52px;
  border-radius: 14px;
  display: flex; align-items: center; justify-content: center;
  background: var(--spine-color, var(--pine-700));
  color: var(--cream-card);
}
.story-card h2 { font-family: var(--font-display); font-size: 22px; margin: 0; color: var(--pine-900); }
.story-card .tagline { color: var(--ink-soft); font-size: 15.5px; margin: 0; flex-grow: 1; }
.story-card .meta-row { display: flex; align-items: center; justify-content: space-between; font-size: 13.5px; color: var(--ink-soft); font-weight: 700; }
.story-card .badge {
  display: inline-block;
  background: var(--spine-color, var(--pine-700));
  color: var(--cream-card);
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12.5px;
  letter-spacing: 0.3px;
}
.story-card .soon-badge { background: var(--ink-soft); }

/* ---------------- reader view (ebook style) ---------------- */

.reader-wrap {
  max-width: 640px;
  margin: 0 auto;
  padding: 0 0 48px;
}

.reader-sticky-top {
  position: sticky;
  top: 0;
  z-index: 8;
  background: var(--page);
  padding: 14px clamp(16px, 4vw, 24px) 0;
  margin: 0 calc(-1 * clamp(16px, 4vw, 24px));
}

.reader-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 10px;
}

.back-link {
  background: none;
  border: none;
  color: var(--pine-800);
  font-weight: 700;
  font-size: 14.5px;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 2px;
  flex-shrink: 0;
}
.back-link:hover { text-decoration: underline; }

.reader-top .page-story-title {
  font-family: var(--font-display);
  font-size: 12.5px;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  color: var(--ink-soft);
  font-weight: 600;
  text-align: right;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.progress-track {
  height: 4px;
  border-radius: 999px;
  background: var(--page-edge);
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  border-radius: 999px;
  transition: width .3s ease;
}

.page-card {
  padding: 22px clamp(16px, 4vw, 24px) 8px;
  position: relative;
}

.page-illustration {
  display: block;
  width: 100%;
  max-height: 320px;
  object-fit: cover;
  border-radius: var(--radius-md);
  margin-bottom: 24px;
}

.page-text {
  font-size: clamp(17px, 2.1vw + 1px, 20px);
  line-height: 1.75;
  color: var(--ink);
  margin: 0 0 26px;
  white-space: pre-line;
  max-width: 66ch;
}

.narration-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 28px;
  flex-wrap: wrap;
  position: sticky;
  bottom: 0;
  background: linear-gradient(to top, var(--page) 60%, transparent);
  padding: 10px 0 14px;
  padding-bottom: calc(14px + env(safe-area-inset-bottom, 0px));
  z-index: 4;
}

.seal-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--teal);
  color: white;
  border: none;
  padding: 10px 18px 10px 14px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 15px;
  box-shadow: 0 4px 10px rgba(46, 107, 107, 0.35);
}
.seal-btn:hover { background: var(--teal-dark); }
.seal-btn.is-playing { background: var(--berry); box-shadow: 0 4px 10px rgba(143, 40, 54, 0.35); }
.seal-btn.is-playing:hover { background: var(--berry-dark); }
.seal-btn svg { flex-shrink: 0; }

.narration-status { font-size: 13.5px; color: var(--ink-soft); font-weight: 700; }

.choices { display: flex; flex-direction: column; }

.choice-btn {
  display: flex;
  align-items: center;
  gap: 14px;
  text-align: left;
  background: none;
  border: none;
  border-bottom: 1px solid var(--page-edge);
  padding: 17px 4px;
  font-size: 17px;
  font-weight: 700;
  color: var(--ink);
  min-height: 52px;
}
.choice-btn:first-child { border-top: 1px solid var(--page-edge); }
.choice-btn:hover { background: rgba(232, 163, 61, 0.1); color: var(--pine-900); }
.choice-btn:active { background: rgba(232, 163, 61, 0.2); }
.choice-btn .choice-num {
  flex-shrink: 0;
  width: 26px; height: 26px;
  border-radius: 50%;
  background: var(--marigold);
  color: var(--pine-900);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display);
  font-size: 13px;
}

.ending-panel { text-align: center; }
.ending-panel .page-text { text-align: left; }
.ending-tag {
  display: inline-block;
  font-family: var(--font-display);
  font-size: 13px;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  padding: 4px 14px;
  border-radius: 999px;
  margin-bottom: 14px;
  background: var(--marigold);
  color: var(--pine-900);
}
.ending-tag.dark { background: var(--berry); color: white; }
.ending-tag.chapter-tag { background: var(--teal); color: white; display: block; width: fit-content; margin-bottom: 16px; }
.ending-actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; margin-top: 22px; }

.primary-btn, .ghost-btn {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 16px;
  padding: 12px 24px;
  border-radius: 999px;
  border: none;
  min-height: 46px;
}
.primary-btn { background: var(--pine-800); color: var(--parchment); }
.primary-btn:hover { background: var(--pine-900); }
.ghost-btn { background: transparent; color: var(--pine-800); border: 2px solid var(--pine-800); }
.ghost-btn:hover { background: var(--pine-800); color: var(--parchment); }

.foot-note {
  text-align: center;
  color: var(--ink-soft);
  font-size: 13.5px;
  padding: 10px 20px 30px;
}

body.is-reading .foot-note { display: none; }

@media (max-width: 520px) {
  .page-text { font-size: 17px; }
  .choice-btn { font-size: 16px; }
  .ending-actions { flex-direction: column; }
  .ending-actions .primary-btn, .ending-actions .ghost-btn { width: 100%; }
}
