/* FiFi — app.css (ported from mockups/v2, plus gate + media styles) */

:root {
  --ink: #f6efdf;
  --muted: #adb6cb;
  --caption: #dfe5f0;
  --gold: #ffd98a;
  --gold-dim: #d9ae66;
  --card: #24304e;
  --card-2: #1c2643;
  --paper: #f4ecdb;
  --paper-ink: #3a2f24;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
  --dusk: linear-gradient(180deg,
      #14203e 0%,
      #1e3a63 26%,
      #2f5b83 46%,
      #5c86a0 62%,
      #a97f92 66%,
      #c98d78 73%,
      #eeb07f 79%,
      #f7d197 86%,
      #fbe3ad 94%,
      #fbe3ad 100%);
}

html, body { height: 100%; }
body {
  margin: 0;
  color: var(--ink);
  font-family: var(--serif);
  line-height: 1.6;
  overflow-x: hidden;
  background: var(--dusk);
  background-attachment: fixed;
}

button { touch-action: manipulation; }
.word-btn, .quiet-link, .btn, .envelope, .ember {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

/* ---------- the gate ---------- */
.gate {
  position: fixed; inset: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  text-align: center;
  box-sizing: border-box;
  padding:
    max(2rem, env(safe-area-inset-top))
    max(2rem, env(safe-area-inset-right))
    max(2rem, env(safe-area-inset-bottom))
    max(2rem, env(safe-area-inset-left));
  background: var(--dusk);
  transition: opacity 1.1s ease;
}
.gate[hidden] { display: none; }
.gate.leaving { opacity: 0; pointer-events: none; }
.gate .eyebrow { margin-bottom: 1.4rem; }
.gate-intro {
  font-size: 1.05rem;
  font-style: italic;
  color: var(--muted);
  margin: 0;
  text-wrap: balance;
}
.gate-hint {
  font-size: 1.15rem;
  font-style: italic;
  color: var(--gold);
  margin: 0 0 1.8rem;
  text-shadow: 0 0 24px rgba(255, 217, 138, 0.35);
}
.gate-form {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.3rem;
}
.gate-form input {
  font-family: var(--serif);
  font-size: 1.5rem;
  text-align: center;
  letter-spacing: 0.35em;
  width: min(60vw, 12rem);
  background: none;
  border: none;
  border-bottom: 1px solid rgba(255, 217, 138, 0.45);
  border-radius: 0;
  color: var(--ink);
  padding: 0.4rem 0.2rem;
  transition: color 0.6s ease;
}
.gate-form input:focus-visible { outline: none; border-bottom-color: var(--gold); }
/* a wrong guess just fades away — no shakes, no red, no scolding */
.gate-form input.fading { color: transparent; }

/* ---------- painted sky ---------- */
#sky-canvas, #fly-canvas {
  position: fixed; inset: 0;
  width: 100%; height: 100%;
  pointer-events: none;
}
#sky-canvas { z-index: 1; }
#fly-canvas { z-index: 4; }

.moon {
  position: fixed;
  top: 9svh; right: 13vw;
  width: 46px; height: 46px;
  border-radius: 50%;
  box-shadow: 14px -7px 0 0 #f4e8c8;
  z-index: 1;
  pointer-events: none;
}
.moon::after {
  content: "";
  position: absolute;
  inset: -46px;
  border-radius: 50%;
  background: radial-gradient(circle at 78% 38%, rgba(244, 232, 200, 0.22), transparent 62%);
}

/* ---------- painted land (silhouette layers) ---------- */
.landscape, .grass {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  width: 100%;
  pointer-events: none;
  display: block;
}
.landscape { height: 32svh; z-index: 2; }
.grass {
  height: 12svh;
  z-index: 3;
  transform-origin: 50% 100%;
}
.grass.front { animation: sway 6s ease-in-out infinite alternate; }
.grass.back { animation: sway 7.5s ease-in-out infinite alternate-reverse; animation-delay: -3s; }
@keyframes sway {
  from { transform: skewX(-3.5deg); }
  to { transform: skewX(4deg); }
}

.tree {
  position: fixed;
  bottom: 21svh; left: 5vw;
  width: 104px; height: 110px;
  z-index: 2;
  pointer-events: none;
}
.house {
  position: fixed;
  bottom: 19.5svh; left: 73vw;
  width: 34px; height: 26px;
  z-index: 3;
  pointer-events: none;
}
.home-light {
  position: fixed;
  bottom: 20.2svh; left: calc(73vw + 19px);
  width: 5px; height: 6px;
  background: #ffd98a;
  border-radius: 1px;
  box-shadow: 0 0 14px 4px rgba(255, 217, 138, 0.5);
  z-index: 3;
  pointer-events: none;
}

/* ---------- scene / scattered words ---------- */
.scene {
  position: relative;
  z-index: 4;
  min-height: 100svh;
}

.heading {
  position: absolute;
  top: 4.5svh; left: 50%;
  transform: translateX(-50%);
  width: min(88vw, 30rem);
  text-align: center;
}
.eyebrow {
  font-size: 0.72rem;
  letter-spacing: 0.32em;
  text-transform: uppercase;
  color: var(--gold-dim);
  margin: 0 0 0.8rem;
}
.intro {
  font-size: 1.04rem;
  font-style: italic;
  color: var(--muted);
  margin: 0;
  text-wrap: balance;
}

.word-btn {
  appearance: none;
  border: none;
  cursor: pointer;
  font-family: var(--serif);
  color: var(--ink);
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.1rem;
  padding: 0.5rem 1.2rem;
  background: radial-gradient(ellipse at center, rgba(12, 20, 42, 0.55), transparent 72%);
}
.word-btn .bob {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.1rem;
  animation: bob 7s ease-in-out infinite;
}
.word-btn .w {
  line-height: 1.05;
  letter-spacing: 0.01em;
  text-shadow: 0 1px 3px rgba(12, 20, 42, 0.75), 0 2px 18px rgba(12, 20, 42, 0.6);
  transition: color 0.35s ease, text-shadow 0.35s ease;
}
.word-btn .c {
  font-size: 0.66rem;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--caption);
  text-shadow: 0 1px 2px rgba(12, 20, 42, 0.8), 0 1px 10px rgba(12, 20, 42, 0.7);
  transition: color 0.35s ease;
}
.word-btn:focus-visible .w {
  color: var(--gold);
  text-shadow: 0 0 30px rgba(255, 217, 138, 0.55);
}
.word-btn:focus-visible .c { color: var(--gold-dim); }
.word-btn:focus-visible { outline: 1px solid var(--gold-dim); outline-offset: 6px; border-radius: 3px; }

/* scattered like lanterns let loose */
.word-who   { top: 20svh; left: 7vw;  transform: rotate(-3deg); }
.word-who .w   { font-size: clamp(2.8rem, 11vw, 4.2rem); }
.word-what  { top: 29svh; right: 7vw; transform: rotate(2deg); }
.word-what .w  { font-size: clamp(2rem, 8vw, 3.1rem); }
.word-what .bob { animation-duration: 8.5s; animation-delay: -2s; }
.word-when  { top: 43svh; left: 12vw; transform: rotate(1.5deg); }
.word-when .w  { font-size: clamp(2.2rem, 8.5vw, 3.3rem); }
.word-when .bob { animation-duration: 6.2s; animation-delay: -4s; }
.word-where { top: 54svh; right: 10vw; transform: rotate(-2deg); }
.word-where .w { font-size: clamp(1.9rem, 7.5vw, 2.9rem); }
.word-where .bob { animation-duration: 9s; animation-delay: -1s; }
.word-why   { top: 63svh; left: 34vw; transform: rotate(1deg); }
.word-why .w   { font-size: clamp(2rem, 8vw, 3rem); }
.word-why .bob { animation-duration: 7.6s; animation-delay: -3s; }

@keyframes bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-7px); }
}

/* ---------- quiet links resting on the hills ---------- */
.quiet-row {
  position: absolute;
  bottom: max(5.5svh, env(safe-area-inset-bottom) + 1rem);
  /* a full-width row, not left:50% + translateX(-50%). an absolutely
     positioned box anchored only at the midpoint is shrink-to-fit and can
     never exceed half the viewport, so a third link squeezed the row and
     broke "the jar" onto two lines. right padding keeps it clear of the
     breathe firefly in the corner. */
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.7rem 2.2rem;
  align-items: center;
  padding: 0 3.6rem;
  box-sizing: border-box;
  z-index: 5;
}
.quiet-link {
  appearance: none; background: none; border: none; cursor: pointer;
  font-family: var(--serif);
  font-style: italic;
  font-size: 1.02rem;
  color: #cdd2b8;
  white-space: nowrap;   /* "the jar" is one label, never two lines */
  text-decoration: underline;
  text-underline-offset: 4px;
  text-decoration-color: rgba(205, 210, 184, 0.35);
  padding: 0.8rem 0.6rem;
  margin: -0.8rem -0.6rem;
  transition: color 0.3s ease, text-decoration-color 0.3s ease;
  text-shadow: 0 1px 8px rgba(8, 14, 12, 0.7);
}
.quiet-link:focus-visible { color: var(--gold); text-decoration-color: var(--gold-dim); outline: none; }

/* ---------- breathe firefly ---------- */
.ember {
  position: fixed;
  right: max(1.5rem, env(safe-area-inset-right) + 0.75rem);
  bottom: max(2.4rem, env(safe-area-inset-bottom) + 1.2rem);
  width: 46px; height: 46px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  background: radial-gradient(circle at 50% 45%, rgba(255, 230, 150, 0.95), rgba(217, 174, 102, 0.25) 60%, transparent 75%);
  box-shadow: 0 0 26px rgba(255, 217, 138, 0.35);
  animation: ember-pulse 5s ease-in-out infinite;
  z-index: 40;
}
.ember-label {
  position: absolute;
  top: calc(100% + 4px);
  left: 50%;
  transform: translateX(-50%);
  font-family: var(--serif);
  font-size: 0.6rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: #cdd2b8;
  text-shadow: 0 1px 8px rgba(8, 14, 12, 0.7);
  pointer-events: none;
}
.ember:focus-visible { outline: 1px solid var(--gold); outline-offset: 4px; }
@keyframes ember-pulse {
  0%, 100% { transform: scale(1); opacity: 0.8; }
  50% { transform: scale(1.14); opacity: 1; }
}

/* hover states only where hover exists — avoids sticky states on touch */
@media (hover: hover) {
  .word-btn:hover .w { color: var(--gold); text-shadow: 0 0 30px rgba(255, 217, 138, 0.55); }
  .word-btn:hover .c { color: var(--gold-dim); }
  .quiet-link:hover { color: var(--gold); text-decoration-color: var(--gold-dim); }
  .btn-gold:hover { background: rgba(255, 217, 138, 0.24); }
  .btn-ghost:hover { color: var(--ink); }
  .paper-card .btn-ghost:hover { color: var(--paper-ink); }
  .envelope:hover { background: rgba(255, 217, 138, 0.1); border-color: rgba(255, 217, 138, 0.4); }
}

/* ---------- overlays ---------- */
.overlay {
  position: fixed; inset: 0;
  background: rgba(12, 16, 32, 0.78);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  display: none;
  align-items: center;
  justify-content: center;
  padding:
    max(1.4rem, env(safe-area-inset-top))
    max(1.4rem, env(safe-area-inset-right))
    max(1.4rem, env(safe-area-inset-bottom))
    max(1.4rem, env(safe-area-inset-left));
  z-index: 50;
  box-sizing: border-box;
}
.overlay.open { display: flex; }

/* freeze the world behind an open overlay */
.overlay-open .grass,
.overlay-open .word-btn .bob,
.overlay-open .ember { animation-play-state: paused; }

.card {
  background: linear-gradient(180deg, var(--card), var(--card-2));
  border: 1px solid rgba(255, 217, 138, 0.2);
  border-radius: 8px;
  max-width: 34rem;
  width: 100%;
  max-height: 86svh;
  overflow-y: auto;
  padding: 2.4rem 2.2rem 2rem;
  box-sizing: border-box;
  box-shadow: 0 30px 80px rgba(4, 8, 20, 0.6);
}
.card:focus, .breathe-scene:focus { outline: none; }
.card .kicker {
  font-size: 0.7rem;
  font-weight: 400;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: var(--gold-dim);
  margin: 0 0 1.3rem;
}
.card .body {
  font-size: 1.16rem;
  line-height: 1.75;
  margin: 0 0 1.4rem;
  white-space: pre-line;
}
.card .source {
  font-style: italic;
  font-size: 0.9rem;
  color: var(--muted);
  margin: 0 0 1.8rem;
}
.card-actions { display: flex; gap: 1rem; justify-content: space-between; align-items: center; }

.btn {
  appearance: none;
  font-family: var(--serif);
  font-size: 0.95rem;
  cursor: pointer;
  border-radius: 5px;
  min-height: 44px;
  padding: 0.6rem 1.3rem;
  transition: background 0.25s ease, color 0.25s ease, border-color 0.25s ease;
}
.btn-gold {
  background: rgba(255, 217, 138, 0.14);
  border: 1px solid rgba(255, 217, 138, 0.45);
  color: var(--gold);
}
.btn-ghost {
  background: none;
  border: 1px solid transparent;
  color: var(--muted);
}
.btn:focus-visible { outline: 1px solid var(--gold); outline-offset: 2px; }

/* ---------- entry & letter media ---------- */
.entry-media:empty, .letter-media:empty { display: none; }
.entry-media, .letter-media { margin: 0 0 1.4rem; }
.entry-media img, .letter-media img {
  display: block;
  max-width: 100%;
  border-radius: 4px;
  box-shadow: 0 8px 30px rgba(4, 8, 20, 0.5);
}
.entry-media video {
  display: block;
  width: 100%;
  border-radius: 4px;
  background: #0c1020;
}
.entry-media audio, .letter-media audio {
  display: block;
  width: 100%;
  margin-top: 0.6rem;
}
.letter-media img { box-shadow: 0 4px 18px rgba(58, 47, 36, 0.25); }

/* ---------- letters shelf ---------- */
.shelf { display: flex; flex-direction: column; gap: 0.7rem; margin: 0 0 1.6rem; }
.shelf-empty {
  font-style: italic;
  color: var(--muted);
  font-size: 0.98rem;
  margin: 0;
}
.envelope {
  appearance: none; cursor: pointer; text-align: left;
  font-family: var(--serif);
  background: rgba(244, 236, 219, 0.05);
  border: 1px solid rgba(244, 236, 219, 0.16);
  border-radius: 5px;
  color: var(--ink);
  font-size: 1.02rem;
  padding: 0.85rem 1.1rem;
  transition: background 0.25s ease, border-color 0.25s ease;
}
.envelope:focus-visible { background: rgba(255, 217, 138, 0.1); border-color: rgba(255, 217, 138, 0.4); outline: none; }
.envelope .seal { color: var(--gold-dim); font-style: italic; font-size: 0.85rem; display: block; }

/* an opened letter reads on paper */
.paper-card {
  background: var(--paper);
  color: var(--paper-ink);
  border: none;
  border-radius: 4px;
  box-shadow: 0 30px 80px rgba(4, 8, 20, 0.65);
}
.paper-card .kicker { color: #8a6f4b; }
.paper-card .source { color: #7d6c55; }
.paper-card .btn-ghost { color: #7d6c55; }

/* ---------- jar ---------- */
.slips { display: flex; flex-direction: column; gap: 0.6rem; margin: 0 0 1.5rem; }
.slips:empty { margin: 0 0 0.4rem; }
.jar-empty {
  font-style: italic;
  color: var(--muted);
  font-size: 0.95rem;
  margin: 0 0 1.5rem;
}
.slip {
  background: var(--paper);
  color: var(--paper-ink);
  font-size: 0.98rem;
  padding: 0.7rem 1rem;
  border-radius: 2px;
  transform: rotate(-0.6deg);
  box-shadow: 0 3px 10px rgba(4, 8, 20, 0.4);
}
.slip:nth-child(2n) { transform: rotate(0.8deg); }
.jar-form { display: flex; gap: 0.7rem; }
.jar-form input {
  flex: 1;
  min-width: 0;
  font-family: var(--serif);
  font-size: 1rem;
  background: rgba(244, 236, 219, 0.07);
  border: 1px solid rgba(244, 236, 219, 0.22);
  border-radius: 5px;
  color: var(--ink);
  padding: 0.55rem 0.9rem;
}
.jar-form input::placeholder { color: var(--muted); font-style: italic; }
.jar-form input:focus-visible { outline: 1px solid var(--gold-dim); }

/* ---------- breathe overlay ---------- */
.breathe-scene {
  display: flex; flex-direction: column; align-items: center; gap: 2.6rem;
  text-align: center;
  padding: 1rem;
}
.breathe-circle {
  width: 150px; height: 150px;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 42%, rgba(255, 230, 150, 0.55), rgba(217, 174, 102, 0.14) 65%, transparent 78%);
  box-shadow: 0 0 60px rgba(255, 217, 138, 0.3);
  animation: breathe 11s ease-in-out infinite;
}
/* 11s cycle = 4s in, 1s hold, 6s out — matches the words exactly */
@keyframes breathe {
  0%, 100% { transform: scale(0.72); }
  36.4% { transform: scale(1.18); }
  45.5% { transform: scale(1.18); }
}
.breathe-line { font-size: 1.15rem; font-style: italic; color: var(--ink); margin: 0; }
.breathe-sub { font-size: 0.92rem; color: var(--muted); margin: 0.4rem 0 0; }

@media (prefers-reduced-motion: reduce) {
  .ember, .word-btn .bob, .grass { animation: none; }
  .word-btn .w, .word-btn .c { transition: none; }
  .gate { transition: none; }
  /* the pacer survives Reduce Motion as a scale-free glow on the same cadence */
  .breathe-circle { animation: breathe-dim 11s ease-in-out infinite; }
}
@keyframes breathe-dim {
  0%, 100% { opacity: 0.35; }
  36.4%, 45.5% { opacity: 1; }
}
