:root {
  --ink: #eaf0ff;
  --ink-soft: rgba(234, 240, 255, 0.66);
  --warm: #ffcf8a;
  --warm-deep: #ff9d5c;
  --cool: #8fb6ff;
  --panel-bg: rgba(12, 16, 34, 0.72);
  --panel-border: rgba(255, 255, 255, 0.12);
  --radius-md: 15px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  color: var(--ink);
  font-family: "Nunito", "PingFang SC", "Hiragino Sans GB", "Noto Sans", "Segoe UI", system-ui, sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
}
body { position: fixed; inset: 0; }

.hidden { display: none !important; }

/* ---- Background: plain dark fallback shown behind/without a video ---- */
#sky-bg {
  position: fixed;
  inset: 0;
  z-index: 0;
  background:
    radial-gradient(120% 90% at 50% 18%, #131a38 0%, #0a0e22 45%, #05060f 100%);
}
#scene {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
}
#mountains {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 40vh; /* sit on the waterline (100% - 60%) */
  width: 100%;
  height: 26vh;
  z-index: 2;
  pointer-events: none;
}
#mountains .mtn-far { fill: #0b1633; opacity: 0.85; }
#mountains .mtn-near { fill: #060d22; }
#mist {
  position: fixed;
  left: -10%;
  right: -10%;
  width: 120%;
  bottom: calc(40vh - 40px);
  height: 120px;
  z-index: 3;
  pointer-events: none;
  background: radial-gradient(60% 100% at 50% 50%, rgba(180, 200, 240, 0.14), rgba(180, 200, 240, 0) 70%);
  filter: blur(8px);
  animation: mist-drift 26s ease-in-out infinite alternate;
}
@keyframes mist-drift {
  from { transform: translateX(-4%); opacity: 0.7; }
  to { transform: translateX(4%); opacity: 1; }
}

/* ---- Video background + fallback layers ---- */
/* Two stacked layers crossfade between playlist clips. Both sit at z-index 0
   and 1; the active one fades to opacity 1 (.bg-show), the other to 0. */
.bg-video {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  z-index: 0;
  pointer-events: none;
  opacity: 0;
  transition: opacity 1.6s ease-in-out;
  will-change: opacity;
}
.bg-video.bg-show {
  opacity: 1;
  z-index: 1;
}
#bg-scrim {
  position: fixed;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(4, 6, 16, 0.32) 0%, rgba(4, 6, 16, 0.42) 55%, rgba(3, 5, 12, 0.6) 100%);
}
/* When a video background is active, hide the procedural lake layers. */
body.has-video #sky-bg,
body.has-video #scene,
body.has-video #mountains,
body.has-video #mist { display: none; }

/* ---- Whispers (pannable world of lanterns) ---- */
#lanterns {
  position: fixed;
  inset: 0;
  z-index: 5;
  overflow: hidden;
  touch-action: none;
}
#world {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  will-change: transform;
}
.lantern {
  position: absolute;
  top: 0;
  left: 0;
  border: none;
  padding: 12px;
  cursor: pointer;
  pointer-events: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  border-radius: 50%;
  /* Spherical shading: bright specular near top-left, darkening to the
     bottom edge, so each reads as a rounded 3D balloon rather than a flat disc. */
  background:
    radial-gradient(circle at 34% 26%, #ffffff 0%, var(--l-core) 30%, var(--l-edge) 74%, var(--l-deep) 100%);
  box-shadow:
    0 0 calc(22px * var(--glow, 1)) calc(6px * var(--glow, 1)) var(--l-halo),
    0 10px 22px rgba(0, 0, 0, 0.34),
    inset 0 -12px 20px rgba(0, 0, 0, 0.28),
    inset 0 9px 16px rgba(255, 255, 255, 0.3);
  animation: sway-bob 5s ease-in-out infinite;
  will-change: transform;
  -webkit-tap-highlight-color: transparent;
  overflow: visible;
}
.lantern::before { /* glossy specular highlight */
  content: "";
  position: absolute;
  top: 12%;
  left: 18%;
  width: 34%;
  height: 26%;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.9), rgba(255, 255, 255, 0));
  filter: blur(1px);
  pointer-events: none;
}
.lantern::after { /* tiny knot at the bottom, like a balloon */
  content: "";
  position: absolute;
  bottom: -5px;
  left: 50%;
  width: 8px;
  height: 8px;
  transform: translateX(-50%) rotate(45deg);
  background: var(--l-deep);
  border-radius: 2px;
  pointer-events: none;
}
.lantern-text {
  position: relative;
  font-weight: 700;
  line-height: 1.22;
  color: rgba(28, 18, 32, 0.92);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-word;
  text-shadow: 0 1px 1px rgba(255, 255, 255, 0.35);
}
.lantern.type-wish {
  --l-core: #ffdd97;
  --l-edge: #ff9d4e;
  --l-deep: #d97a2e;
  --l-halo: rgba(255, 168, 92, 0.5);
}
.lantern.type-pain {
  --l-core: #d3e8ff;
  --l-edge: #8fb6ff;
  --l-deep: #5b7fc7;
  --l-halo: rgba(120, 165, 240, 0.45);
}
.lantern.type-pain .lantern-text { color: rgba(16, 22, 44, 0.92); }
.lantern:active { filter: brightness(1.1); }
@keyframes sway-bob {
  0%, 100% { filter: brightness(1); }
  50% { filter: brightness(1.08); }
}

/* ---- Top bar ---- */
.top-bar {
  position: fixed;
  top: calc(12px + var(--safe-top));
  left: 14px;
  right: 14px;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  pointer-events: none;
}
.brand {
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  color: rgba(234, 240, 255, 0.5);
  text-transform: uppercase;
}
.top-icons { display: flex; gap: 9px; }
.icon-btn {
  pointer-events: auto;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid var(--panel-border);
  background: rgba(255, 255, 255, 0.06);
  color: var(--ink);
  font-size: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(8px);
  cursor: pointer;
  position: relative;
}
.icon-btn::before { content: ""; position: absolute; inset: -9px; }
.icon-btn[aria-pressed="true"] {
  box-shadow: 0 0 12px rgba(255, 207, 138, 0.6);
  border-color: rgba(255, 207, 138, 0.55);
}

/* ---- Invitation ---- */
.tagline {
  position: fixed;
  top: 24vh;
  left: 0;
  right: 0;
  z-index: 6;
  margin: 0;
  padding: 0 30px;
  text-align: center;
  white-space: pre-line;
  font-size: 1.12rem;
  line-height: 1.7;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: rgba(238, 242, 255, 0.9);
  text-shadow: 0 2px 24px rgba(0, 0, 0, 0.5);
  pointer-events: none;
  animation: fade-in 1.6s ease-out both;
}
.tap-hint {
  position: fixed;
  bottom: calc(84px + var(--safe-bottom));
  left: 0;
  right: 0;
  z-index: 6;
  margin: 0;
  text-align: center;
  font-size: 0.76rem;
  color: var(--ink-soft);
  pointer-events: none;
  animation: fade-in 2.2s ease-out both;
}

/* ---- Now-playing strip (sits just above the bottom bar) ---- */
.now-playing {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(70px + var(--safe-bottom));
  z-index: 19;
  max-width: 82vw;
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 0.74rem;
  letter-spacing: 0.02em;
  color: rgba(233, 238, 255, 0.82);
  background: rgba(8, 11, 26, 0.42);
  backdrop-filter: blur(6px);
  border: 1px solid rgba(255, 255, 255, 0.08);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
  opacity: 1;
  transition: opacity 0.6s ease;
}
.now-playing.hidden {
  display: block;
  opacity: 0;
  pointer-events: none;
}

/* ---- Bottom invitation bar ---- */
.bottom-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  display: flex;
  gap: 12px;
  padding: 12px 16px calc(14px + var(--safe-bottom));
  background: linear-gradient(180deg, rgba(6, 9, 22, 0) 0%, rgba(6, 9, 22, 0.7) 60%, rgba(4, 6, 16, 0.92) 100%);
}
.bottom-btn {
  flex: 1;
  border-radius: 999px;
  padding: 13px 10px;
  font-size: 0.94rem;
  font-weight: 700;
  color: var(--ink);
  cursor: pointer;
  border: 1px solid var(--panel-border);
  backdrop-filter: blur(8px);
  transition: transform 0.14s ease, box-shadow 0.2s ease;
}
.bottom-btn:active { transform: scale(0.97); }
#entry-pain {
  background: linear-gradient(135deg, rgba(120, 160, 240, 0.24), rgba(120, 160, 240, 0.08));
  box-shadow: 0 0 22px rgba(120, 160, 240, 0.28);
}
#entry-wish {
  background: linear-gradient(135deg, rgba(255, 175, 110, 0.26), rgba(255, 175, 110, 0.08));
  box-shadow: 0 0 22px rgba(255, 168, 92, 0.28);
}

/* ---- Mini panels ---- */
.mini-panel {
  position: fixed;
  top: calc(56px + var(--safe-top));
  right: 14px;
  z-index: 31;
  width: min(290px, calc(100vw - 28px));
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-md);
  padding: 14px;
  backdrop-filter: blur(14px);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.4);
  animation: fade-in 0.18s ease-out;
}
.mini-panel-row { display: flex; gap: 8px; margin-top: 8px; }
.mini-panel input[type="text"] { flex: 1; min-width: 0; }
.mini-close {
  position: absolute;
  top: 6px;
  right: 8px;
  background: none;
  border: none;
  color: var(--ink-soft);
  font-size: 18px;
  cursor: pointer;
  line-height: 1;
  padding: 6px;
}
.find-result { margin-top: 10px; font-size: 0.86rem; color: var(--ink-soft); max-height: 46vh; overflow-y: auto; }
.find-results-title { margin: 2px 0 8px; font-size: 0.78rem; color: var(--ink-soft); opacity: 0.8; }
.find-result-row {
  display: block;
  width: 100%;
  text-align: left;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  color: var(--ink);
  padding: 9px 11px;
  margin-bottom: 7px;
  font-size: 0.86rem;
  line-height: 1.35;
  cursor: pointer;
  transition: background 0.14s ease;
}
.find-result-row:active { background: rgba(255, 255, 255, 0.12); }
.share-qr {
  display: block;
  width: 180px;
  height: 180px;
  max-width: 100%;
  margin: 6px auto 10px;
  border-radius: 10px;
  background: #fff;
  padding: 8px;
}
#coffee-text, .music-now { margin: 4px 0 10px; font-size: 0.86rem; color: var(--ink-soft); }
.music-now { font-weight: 600; color: var(--ink); margin-bottom: 2px; }
.music-credit { display: block; color: var(--ink-soft); text-decoration: underline; margin: 0 2px 8px; }

/* ---- Sheets ---- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(3, 5, 14, 0.6);
  backdrop-filter: blur(3px);
  z-index: 40;
  animation: fade-in 0.18s ease-out;
}
.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 41;
  background: linear-gradient(180deg, rgba(18, 24, 52, 0.96) 0%, rgba(8, 11, 28, 0.98) 100%);
  border-top: 1px solid var(--panel-border);
  border-radius: 24px 24px 0 0;
  padding: 10px 20px calc(22px + var(--safe-bottom));
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 -16px 48px rgba(0, 0, 0, 0.5);
  animation: slide-up 0.24s cubic-bezier(0.22, 1, 0.36, 1);
}
.sheet-handle { width: 42px; height: 4px; border-radius: 2px; background: rgba(255, 255, 255, 0.22); margin: 6px auto 14px; }
.sheet-close { position: absolute; top: 10px; right: 14px; }
.sheet h2 { margin: 0 0 12px; font-size: 1.12rem; }
.sheet h3 { font-size: 0.92rem; color: var(--ink-soft); margin: 18px 0 8px; }

textarea, input[type="text"] {
  width: 100%;
  border-radius: var(--radius-md);
  border: 1px solid var(--panel-border);
  background: rgba(255, 255, 255, 0.05);
  color: var(--ink);
  padding: 12px 14px;
  font-size: 0.95rem;
  font-family: inherit;
  resize: vertical;
  outline: none;
}
textarea:focus, input[type="text"]:focus { border-color: rgba(255, 207, 138, 0.5); }
.char-count { text-align: right; font-size: 0.74rem; color: var(--ink-soft); margin: 4px 2px 12px; }
label { display: block; font-size: 0.84rem; color: var(--ink-soft); margin: 4px 2px 6px; }
.hint { font-size: 0.77rem; color: var(--ink-soft); margin: 4px 2px; line-height: 1.5; }
.honeypot { position: absolute !important; left: -9999px !important; width: 1px; height: 1px; opacity: 0; }

.crisis-banner {
  background: rgba(255, 179, 102, 0.12);
  border: 1px solid rgba(255, 179, 102, 0.32);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  margin-bottom: 12px;
}
.crisis-banner p { margin: 0; font-size: 0.79rem; line-height: 1.5; color: #ffd9ad; }
.form-error { color: #ff9a9a; font-size: 0.82rem; margin: 6px 2px; }

.sheet-actions { display: flex; gap: 10px; margin-top: 16px; }
button { font-family: inherit; }
.btn-primary, .btn-secondary {
  flex: 1;
  border-radius: 999px;
  padding: 12px 18px;
  font-size: 0.92rem;
  font-weight: 700;
  border: 1px solid transparent;
  cursor: pointer;
}
.btn-primary { background: linear-gradient(135deg, var(--warm), var(--warm-deep)); color: #241132; }
.btn-secondary { background: rgba(255, 255, 255, 0.07); border-color: var(--panel-border); color: var(--ink); }
.btn-small { flex: none; padding: 9px 14px; font-size: 0.82rem; }
.link-btn { background: none; border: none; color: var(--ink-soft); font-size: 0.77rem; text-decoration: underline; cursor: pointer; padding: 6px 0; }

.code-display {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px dashed var(--panel-border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  margin: 10px 0;
}
#confirm-code { flex: 1; font-size: 1.05rem; font-weight: 800; letter-spacing: 0.03em; word-break: break-all; }

.detail-content {
  background: rgba(255, 255, 255, 0.05);
  border-radius: var(--radius-md);
  padding: 14px;
  font-size: 0.97rem;
  line-height: 1.65;
  white-space: pre-wrap;
  margin-top: 6px;
}
.detail-replies { display: flex; flex-direction: column; gap: 10px; margin-bottom: 14px; }
.reply-item {
  background: rgba(255, 255, 255, 0.045);
  border-left: 2px solid rgba(255, 207, 138, 0.4);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 0.88rem;
  line-height: 1.5;
  white-space: pre-wrap;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(92px + var(--safe-bottom));
  transform: translateX(-50%);
  background: rgba(16, 20, 44, 0.94);
  border: 1px solid var(--panel-border);
  color: var(--ink);
  padding: 12px 20px;
  border-radius: 999px;
  font-size: 0.88rem;
  z-index: 60;
  animation: fade-in 0.2s ease-out;
  max-width: 90vw;
  text-align: center;
  backdrop-filter: blur(8px);
}

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes slide-up { from { translate: 0 26px; opacity: 0.5; } to { translate: 0 0; opacity: 1; } }

[dir="rtl"] .top-bar { flex-direction: row-reverse; }
[dir="rtl"] .code-display, [dir="rtl"] .mini-panel-row { direction: rtl; }

@media (prefers-reduced-motion: reduce) {
  .lantern, #mist { animation: none; }
}

@media (min-width: 640px) {
  .sheet { left: 50%; right: auto; width: 480px; translate: -50% 0; border-radius: 24px; bottom: 40px; }
  @keyframes slide-up { from { translate: -50% 26px; opacity: 0.5; } to { translate: -50% 0; opacity: 1; } }
  .tagline { font-size: 1.35rem; }
}
