/* ---------- Actions ---------- */
.actions {
  position: fixed;
  bottom: max(16px, env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  z-index: 6;
  width: min(94vw, 640px);
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 0.5rem 0.6rem;
}

.btn {
  font-family: inherit;
  font-size: 0.92rem;
  letter-spacing: 0.04em;
  padding: 0.65rem 1.2rem;
  border-radius: 999px;
  cursor: pointer;
  /* keep the fill inside the border so it can't bleed past the curve */
  background-clip: padding-box;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.btn.primary {
  background: linear-gradient(to bottom, #e8e9eb, #c6c8cc);
  border: 2px solid #85888d;
  color: #1b1c1e;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
}

.btn.primary:hover { transform: translateY(-1px); box-shadow: 0 6px 22px rgba(0, 0, 0, 0.6); }

.btn.secondary {
  background: rgba(255, 255, 255, 0.07);
  border: 2px solid var(--line-strong);
  color: var(--ink);
  backdrop-filter: blur(3px);
}

.btn.secondary:hover { background: rgba(255, 255, 255, 0.12); transform: translateY(-1px); }

.btn.ghost {
  background: rgba(255, 255, 255, 0.03);
  border: 2px solid var(--line);
  color: var(--ink-dim);
  backdrop-filter: blur(3px);
}

.btn.ghost:hover { background: rgba(255, 255, 255, 0.08); color: var(--ink); }

.count {
  width: 100%;
  text-align: center;
  font-size: 0.78rem;
  font-style: italic;
  color: var(--ink-faint);
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.95), 0 0 3px rgba(0, 0, 0, 0.85);
}

/* ---------- Modals ---------- */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(6, 7, 9, 0.74);
  backdrop-filter: blur(4px);
  padding: 1rem;
}

.overlay[hidden] { display: none; }

.modal {
  position: relative;
  width: min(480px, 94vw);
  max-height: 88vh;
  overflow-y: auto;
  overflow-x: clip;    /* nothing in a modal scrolls sideways — a dragged card's
                          transform must never grow a horizontal scroll range */
  background: linear-gradient(to bottom, #202226, #17181c);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 1.6rem 1.7rem 1.7rem;
  box-shadow: 0 12px 60px rgba(0, 0, 0, 0.8);
  animation: modal-in 0.3s ease;
}

/* Full-focus pages — the album and simple-mode Read share this one shell:
   an opaque night overlay (nothing beneath gets composited), a chromeless
   modal whose content floats on the dark, a close pinned to the viewport,
   and the vigil de-rendered while the page is up (see focusDim). */
.overlay.night {
  background: #08090c;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}
.modal.bare {
  background: none;
  border: none;
  box-shadow: none;
  padding: 0;
  max-height: none;
  overflow: visible;
}
.modal.bare .close {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 0.8rem);
  right: calc(env(safe-area-inset-right, 0px) + 1rem);
  font-size: 1.7rem;
  z-index: 30;
}
body.page-focus #candle-field,
body.page-focus .center-stack,
body.page-focus .actions { visibility: hidden; }

/* A night page's scroll box gets the stairwell's slim warm thread of a
   scrollbar — a white slab would cut the dark in two. */
.reading-list, .simple-wall {
  scrollbar-width: thin;                                   /* Firefox */
  scrollbar-color: rgba(255, 224, 165, 0.28) transparent;
}
.reading-list::-webkit-scrollbar, .simple-wall::-webkit-scrollbar { width: 9px; }
.reading-list::-webkit-scrollbar-track, .simple-wall::-webkit-scrollbar-track { background: transparent; }
.reading-list::-webkit-scrollbar-thumb, .simple-wall::-webkit-scrollbar-thumb {
  background: rgba(255, 224, 165, 0.24);
  border-radius: 9px;
  border: 3px solid transparent;      /* insets the thumb, leaving a thin rail */
  background-clip: content-box;
}
.reading-list::-webkit-scrollbar-thumb:hover, .simple-wall::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 231, 183, 0.45);
}

@keyframes modal-in {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: translateY(0); }
}

.modal h2 {
  font-weight: normal;
  color: #e6e8ea;
  letter-spacing: 0.04em;
  margin-bottom: 0.3rem;
}

.modal-sub { font-size: 0.88rem; color: var(--ink-dim); margin-bottom: 1rem; }

/* compose header + subtitle centered */
.compose h2, .compose .modal-sub { text-align: center; }

.close {
  position: absolute;
  top: 0.7rem; right: 0.9rem;
  background: none;
  border: none;
  font-size: 1.5rem;
  color: var(--ink-dim);
  cursor: pointer;
  line-height: 1;
}

.close:hover { color: var(--ink); }

/* Circular back button — mirrors the close ×, top-left, only in the Light act */
.compose-back {
  position: absolute;
  top: 0.7rem; left: 0.9rem;
  width: 2rem; height: 2rem;
  display: flex; align-items: center; justify-content: center;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--line);
  border-radius: 50%;
  font-size: 1.15rem; line-height: 1;
  color: var(--ink-dim);
  cursor: pointer;
  opacity: 0; pointer-events: none;
  transition: opacity 0.35s ease, background 0.2s ease, color 0.2s ease;
}
.compose-back:hover { background: rgba(255, 255, 255, 0.12); color: var(--ink); }
.compose.lighting .compose-back { opacity: 1; pointer-events: auto; }

/* Two-act compose: Write collapses, Light expands. grid-rows 1fr↔0fr animates
   height cleanly without capping content. */
.phase {
  display: grid;
  transition: grid-template-rows 0.5s ease, opacity 0.4s ease;
}
.phase > .phase-inner { overflow: hidden; min-height: 0; }
.compose-write { grid-template-rows: 1fr; opacity: 1; }
.compose-light { grid-template-rows: 0fr; opacity: 0; }
.compose.lighting .compose-write { grid-template-rows: 0fr; opacity: 0; pointer-events: none; }
.compose.lighting .compose-light  { grid-template-rows: 1fr; opacity: 1; }

/* once lit, the WHOLE box dissolves and shrinks toward the candle in one
   continuous ~1s motion: chrome, title, buttons, and backdrop fade; the box
   collapses to candle size so the overlay recenters it to the middle; and the
   glow blooms unclipped. Then it lingers before placement. */
.overlay.dissolving { background: transparent; backdrop-filter: none; transition: background 1s ease; }

.compose.lit {
  background: transparent; border-color: transparent; box-shadow: none;
  overflow: visible;                 /* let the glow bloom past the vanishing box */
  padding: 0.5rem;                   /* shrink the box toward the candle */
  transition: background 1s ease, border-color 1s ease, box-shadow 1s ease, padding 1s ease;
}

/* collapse everything but the candle so the box hugs it and recenters */
.compose h2, .compose .modal-sub {
  max-height: 5rem;
  overflow: hidden;
  transition: max-height 1s ease, margin 1s ease, opacity 0.6s ease;
}
.compose.lit h2, .compose.lit .modal-sub { max-height: 0; margin: 0; opacity: 0; }
.compose.lit .close, .compose.lit .compose-back { opacity: 0; pointer-events: none; transition: opacity 0.6s ease; }
.compose.lit #compose-candle { margin-bottom: 0; }
.compose.lit .compose-light {
  grid-template-rows: 0fr; opacity: 0; pointer-events: none;
  transition: grid-template-rows 1s ease, opacity 0.7s ease;
}

/* handoff: the compose candle's ghost fades in place as the placement candle,
   already overlaid at the same spot and size, departs for the photo */
.overlay.handoff { opacity: 0; transition: opacity 0.35s ease; }

/* the candle steps forward to center as the form clears */
#compose-candle { transition: transform 0.55s ease, margin 1s ease; }
.compose.lighting #compose-candle { transform: scale(1.06) translateY(8px); }

/* Shared form fields */
.compose textarea, .compose input,
.memory textarea, .memory input[type="text"] {
  width: 100%;
  font-family: inherit;
  font-size: 0.95rem;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.7rem 0.85rem;
  margin-bottom: 0.7rem;
  resize: vertical;
}

.compose textarea:focus, .compose input:focus,
.memory textarea:focus, .memory input[type="text"]:focus {
  outline: none;
  border-color: #b9bcc0;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.08);
}

.btn.wide { width: 100%; }

/* Occupies the same slot as the button it replaces, so the modal's layout
   (and the candle above it) doesn't jump at the moment of lighting. */
.ignite-note {
  margin-top: 0;
  min-height: 2.8rem;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-style: italic;
  font-size: 0.9rem;
  color: var(--ink);
}

.ignite-note[hidden] { display: none; }

.field-error { border-color: #c25b4a !important; }

/* Big candle in compose modal */
.big-candle {
  position: relative;
  height: 90px;   /* tealight + just enough headroom for the lit flame; the
                     glow overflows freely — the box dissolves once it's lit */
  display: flex;
  align-items: flex-end;
  justify-content: center;
  margin-bottom: 0.75rem;
}

.big-tealight { position: relative; width: 84px; height: 58px; }

.big-cup {
  position: absolute;
  top: 16px; left: 0;
  width: 84px; height: 42px;
  z-index: 1;
  border-radius: 4px 4px 34px 34px / 4px 4px 16px 16px;
  background:
    linear-gradient(to bottom, rgba(255, 200, 120, 0.5) 0%, rgba(255, 190, 105, 0) 60%),
    linear-gradient(to bottom, rgba(40, 24, 8, 0) 65%, rgba(40, 24, 8, 0.35) 100%),
    linear-gradient(90deg, #55401f 0%, #a8874e 15%, #ecd096 50%, #a8874e 85%, #55401f 100%);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.55);
}

.big-cup::before {
  content: '';
  position: absolute;
  top: -16px; left: 0;
  width: 84px; height: 32px;
  box-sizing: border-box;
  border-radius: 50%;
  background: radial-gradient(ellipse at 50% 62%, #96682f 0%, #6b4820 55%, #462f14 100%);
  border: 1.5px solid rgba(255, 228, 170, 0.7);
  box-shadow: inset 0 2px 4px rgba(255, 230, 180, 0.3);
}

.big-wax {
  position: absolute;
  top: 4px; left: 7px;
  width: 70px; height: 24px;
  z-index: 2;
  border-radius: 50%;
  background: radial-gradient(ellipse at 50% 40%,
    #fffce9 0%, #ffeeb2 30%, #ffd97e 55%, #edb457 78%, #cf9143 94%);
  transition: box-shadow 1.3s ease;
}

/* unlit: a dark veil over the pool until the flame wakes it — opacity fade
   is GPU-cheap, unlike animating filter (which can flash on laptops) */
.big-wax::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: rgba(38, 26, 12, 0.5);
  opacity: 1;
  transition: opacity 1.3s ease;
}

.big-candle.lit .big-wax { box-shadow: 0 0 30px rgba(255, 205, 110, 0.5); }

.big-candle.lit .big-wax::after { opacity: 0; }

.wick {
  position: absolute;
  top: 9px; left: 50%;
  width: 3px; height: 10px;
  z-index: 3;
  transform: translateX(-50%) rotate(6deg);
  background: #241809;
  border-radius: 2px;
}

.big-flame {
  position: absolute;
  bottom: 42px; left: 50%;              /* base on the wick, in the pool */
  width: 26px; height: 44px;
  transform: translateX(-50%) scale(0);
  transform-origin: 50% 100%;
  border-radius: 50% 50% 50% 50% / 62% 62% 38% 38%;
  background: radial-gradient(circle at 50% 80%,
    var(--flame-1) 0%, var(--flame-2) 36%, var(--flame-3) 66%, rgba(255, 110, 20, 0) 100%);
  filter: blur(0.6px);
  opacity: 0;
  will-change: transform, opacity;
  z-index: 4;
}

/* Ignition and flicker are one chained animation (no transition→animation
   handoff, which desktop compositors can glitch into an invisible flame). */
@keyframes ignite {
  from { transform: translateX(-50%) scale(0); opacity: 0; }
  30%  { opacity: 1; }
  to   { transform: translateX(-50%) scale(1); opacity: 1; }
}

@keyframes glow-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.flame-core {
  position: absolute;
  bottom: 5px; left: 50%;
  width: 10px; height: 18px;
  transform: translateX(-50%);
  border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%;
  background: radial-gradient(circle at 50% 70%, #ffffff 0%, #fff2c0 60%, rgba(255, 240, 180, 0) 100%);
}

/* Circular glow centered on the candle body — the same shape (and center
   point, scaled 2.8×) as the small candle's .glow, so the light doesn't
   change character when the candle is carried to the photo. */
.big-glow {
  position: absolute;
  bottom: -97px; left: 50%;
  width: 250px; height: 250px;
  transform: translateX(-50%);
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 190, 90, 0.5) 0%, rgba(255, 170, 60, 0.18) 42%, rgba(255, 150, 40, 0) 70%);
  opacity: 0;
  transition: opacity 1s ease;   /* finishes before the pulse animation begins */
  pointer-events: none;
}

.big-candle.lit .big-flame {
  animation:
    ignite 1.1s cubic-bezier(0.2, 1.4, 0.4, 1) forwards,
    flicker 2s ease-in-out 1.1s infinite;
}

.big-candle.lit .big-glow {
  animation:
    glow-in 1s ease forwards,
    glowpulse 2s ease-in-out 1.1s infinite;
}

