:root {
  --bg: #efe9dc;
  --paper: #f6f1e7;
  --ink: #2b2620;
  --ink-soft: #6b6356;
  --ink-faint: #9a9183;
  --accent: #9e3b2e;
  --accent-soft: #b9614f;
  --line: rgba(43, 38, 32, 0.12);
  --serif: "EB Garamond", Georgia, "Times New Roman", serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--serif);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.stage {
  max-width: 720px;
  margin: 0 auto;
  padding: 64px 24px 96px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* ---- Masthead ---- */
.masthead { text-align: center; margin-bottom: 44px; }
.eyebrow {
  font-family: var(--sans);
  font-size: 11px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 0 0 18px;
}
.wordmark {
  font-size: clamp(48px, 11vw, 84px);
  font-weight: 500;
  letter-spacing: -0.01em;
  margin: 0;
  line-height: 1;
}
.tagline {
  font-style: italic;
  font-size: clamp(16px, 2.4vw, 19px);
  color: var(--ink-soft);
  margin: 14px 0 0;
}

/* ---- Cards ---- */
.cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  width: 100%;
  margin-bottom: 26px;
}
.card {
  position: relative;
  background: var(--paper);
  border: 0.5px solid var(--line);
  border-radius: 10px;
  padding: 22px 18px 28px;
  min-height: 116px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  transition: opacity 0.45s ease, transform 0.25s ease;
}
.card .caption {
  font-family: var(--sans);
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-faint);
  position: absolute;
  top: 16px;
  left: 18px;
}
.card .word {
  font-size: clamp(24px, 4.6vw, 32px);
  font-weight: 500;
  margin-top: 14px;
  transition: opacity 0.4s ease;
}
.card.swapping .word { opacity: 0; }
.reroll {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 24px;
  height: 24px;
  border: none;
  background: transparent;
  color: var(--ink-faint);
  font-size: 15px;
  cursor: pointer;
  border-radius: 50%;
  opacity: 0;
  transition: opacity 0.2s ease, color 0.2s ease, transform 0.4s ease;
}
.card:hover .reroll, .reroll:focus-visible { opacity: 1; }
.reroll:hover { color: var(--accent); }
.reroll:active { transform: rotate(-180deg); }

/* ---- Shuffle ---- */
.shuffle {
  font-family: var(--sans);
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-soft);
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px 12px;
  margin-bottom: 34px;
  transition: color 0.2s ease;
}
.shuffle:hover { color: var(--accent); }

/* ---- Generate ---- */
.generate-wrap { margin-bottom: 8px; }
.generate {
  font-family: var(--sans);
  font-size: 13px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #fff;
  background: var(--accent);
  border: none;
  border-radius: 8px;
  padding: 14px 34px;
  cursor: pointer;
  transition: background 0.2s ease, transform 0.12s ease, opacity 0.2s ease;
}
.generate:hover { background: #8a3024; }
.generate:active { transform: scale(0.98); }
.generate:disabled { cursor: default; }

/* ---- Paper / story ---- */
.paper {
  position: relative;
  width: 100%;
  max-width: 600px;
  background: var(--paper);
  border-radius: 14px;
  border: 0.5px solid rgba(43, 38, 32, 0.08);
  padding: 40px clamp(28px, 6vw, 56px) 34px;
  margin-top: 40px;
  transition: transform 0.26s ease;
}
.paper.landed { animation: landPulse 0.3s ease; }
@keyframes landPulse {
  0% { transform: scale(1); }
  45% { transform: scale(1.012); }
  100% { transform: scale(1); }
}
.story-title {
  text-align: center;
  font-style: italic;
  font-weight: 500;
  font-size: clamp(22px, 3.4vw, 28px);
  margin: 0;
}
.rule {
  width: 44px;
  border: none;
  border-top: 1.5px solid var(--accent);
  margin: 16px auto 28px;
}
.story-body {
  font-size: 18px;
  line-height: 1.75;
  text-align: justify;
  hyphens: auto;
}
.story-body p { margin: 0 0 1em; text-indent: 1.4em; }
.story-body p:first-of-type { text-indent: 0; }
.story-body p:first-of-type::first-letter {
  font-size: 3.1em;
  float: left;
  line-height: 0.8;
  padding: 6px 8px 0 0;
  font-weight: 500;
}
.story-body .w { opacity: 0; transition: opacity 0.5s ease; }
.story-body.shown .w { opacity: 1; }

.keep {
  position: absolute;
  top: 18px;
  right: 20px;
  border: none;
  background: none;
  font-size: 19px;
  color: var(--ink-faint);
  cursor: pointer;
  transition: color 0.2s ease, transform 0.2s ease;
}
.keep:hover { color: var(--accent-soft); transform: scale(1.1); }
.keep.kept { color: var(--accent); }

.actions {
  margin-top: 30px;
  text-align: center;
  font-family: var(--sans);
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
.act {
  background: none;
  border: none;
  color: var(--ink-soft);
  font: inherit;
  letter-spacing: inherit;
  text-transform: inherit;
  cursor: pointer;
  padding: 4px 6px;
  transition: color 0.2s ease;
}
.act:hover { color: var(--accent); }
.actions .dot, .site-foot .dot { color: var(--ink-faint); margin: 0 6px; }

/* ---- Byline ---- */
.byline-zone { margin-top: 16px; text-align: center; min-height: 22px; }
.add-name {
  background: none;
  border: none;
  font-family: var(--sans);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-faint);
  cursor: pointer;
  padding: 4px 6px;
  transition: color 0.2s ease;
}
.add-name:hover { color: var(--accent); }
.name-input {
  font-family: var(--serif);
  font-style: italic;
  font-size: 16px;
  text-align: center;
  color: var(--accent);
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--line);
  padding: 3px 6px;
  width: 180px;
  outline: none;
}
.name-input:focus { border-bottom-color: var(--accent-soft); }
.byline {
  font-style: italic;
  font-size: 15px;
  color: var(--accent);
  margin: 0;
  cursor: pointer;
  opacity: 0.9;
  transition: opacity 0.2s ease;
}
.byline:hover { opacity: 1; }

/* ---- Shelf ---- */
.shelf-wrap { width: 100%; max-width: 600px; margin-top: 30px; padding-top: 18px; border-top: 0.5px solid var(--line); }
.shelf {
  display: flex;
  gap: 5px;
  align-items: flex-end;
  justify-content: center;
  min-height: 44px;
  flex-wrap: wrap;
}
.spine {
  width: 9px;
  border-radius: 2px 2px 0 0;
  background: var(--ink-faint);
  cursor: pointer;
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 0.4s ease, transform 0.4s ease, background 0.2s ease, height 0.2s ease;
}
.spine.in { opacity: 0.55; transform: translateY(0); }
.spine:hover { opacity: 1; background: var(--ink-soft); }
.spine.kept { background: var(--accent); opacity: 0.9; }
.spine.current { opacity: 1; box-shadow: 0 -3px 0 0 var(--accent); }
.shelf-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 12px;
  font-family: var(--sans);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-faint);
}
.sound-toggle { display: flex; align-items: center; gap: 7px; cursor: pointer; }
.sound-toggle input { accent-color: var(--accent); }

/* ---- Footer ---- */
.site-foot {
  margin-top: 70px;
  text-align: center;
  font-family: var(--sans);
}
.site-foot nav { font-size: 12px; letter-spacing: 0.06em; }
.site-foot a { color: var(--ink-soft); text-decoration: none; transition: color 0.2s ease; }
.site-foot a:hover { color: var(--accent); }
.copyright { font-size: 11px; color: var(--ink-faint); margin-top: 14px; letter-spacing: 0.04em; }

/* ---- Toast ---- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%) translateY(20px);
  background: var(--ink);
  color: var(--paper);
  font-family: var(--sans);
  font-size: 13px;
  padding: 10px 18px;
  border-radius: 8px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
  z-index: 50;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.ad-slot { width: 100%; max-width: 600px; margin-top: 24px; min-height: 0; }

/* ---- Content pages ---- */
.prose {
  max-width: 680px;
  margin: 0 auto;
  padding: 72px 24px 96px;
  font-size: 18px;
  line-height: 1.75;
}
.prose h1 { font-size: clamp(32px, 6vw, 46px); font-weight: 500; margin: 0 0 8px; }
.prose h2 { font-size: 24px; font-weight: 500; margin: 38px 0 10px; }
.prose .lead { font-style: italic; color: var(--ink-soft); font-size: 20px; margin-bottom: 32px; }
.prose a { color: var(--accent); }
.prose .back { font-family: var(--sans); font-size: 12px; letter-spacing: 0.08em; text-transform: uppercase; display: inline-block; margin-bottom: 40px; text-decoration: none; color: var(--ink-soft); }
.gallery-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 20px; margin-top: 32px; }
.gallery-card { background: var(--paper); border: 0.5px solid var(--line); border-radius: 12px; padding: 24px 26px; }
.gallery-card .gc-cards { font-family: var(--sans); font-size: 11px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink-faint); margin-bottom: 10px; }
.gallery-card .gc-title { font-style: italic; font-size: 21px; margin: 0 0 12px; }
.gallery-card .gc-body { font-size: 16px; line-height: 1.7; }

@media (max-width: 560px) {
  .stage { padding: 44px 18px 72px; }
  .cards { grid-template-columns: 1fr; gap: 12px; }
  .card { min-height: 92px; padding: 18px; }
  .card .word { margin-top: 8px; }
  .card .reroll { opacity: 0.7; }
  .story-body { font-size: 17px; text-align: left; }
}
