:root {
  --ink: #eef0ff;
  --ink-soft: rgba(226, 230, 255, 0.68);
  --gold: #ffe29a;
  --line: rgba(255, 255, 255, 0.14);
  --glass: rgba(10, 14, 32, 0.58);
  --serif: "Cormorant Garamond", Georgia, "Times New Roman", serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #04060f;
  color: var(--ink);
  font-family: var(--sans);
}

body {
  background:
    radial-gradient(ellipse at 20% 15%, rgba(70, 60, 140, 0.35), transparent 55%),
    radial-gradient(ellipse at 85% 70%, rgba(20, 70, 120, 0.3), transparent 50%),
    radial-gradient(ellipse at 50% 120%, rgba(110, 50, 110, 0.22), transparent 55%),
    #04060f;
}

.fog {
  position: fixed;
  inset: -12%;
  pointer-events: none;
  translate: calc(var(--mx, 0) * var(--depth) * 1px) calc(var(--my, 0) * var(--depth) * 1px);
  will-change: translate, transform;
}
.fog-a {
  --depth: -36;
  background:
    radial-gradient(ellipse 38% 28% at 24% 28%, rgba(128, 96, 210, 0.2), transparent 70%),
    radial-gradient(ellipse 34% 24% at 72% 18%, rgba(60, 110, 205, 0.15), transparent 70%);
  animation: drift-a 48s ease-in-out infinite alternate;
}
.fog-b {
  --depth: -70;
  background:
    radial-gradient(ellipse 42% 26% at 78% 74%, rgba(70, 150, 190, 0.14), transparent 70%),
    radial-gradient(ellipse 36% 24% at 18% 82%, rgba(180, 90, 170, 0.13), transparent 70%);
  animation: drift-b 64s ease-in-out infinite alternate;
}
@keyframes drift-a { from { transform: translate3d(-1.5%, 0, 0) scale(1); } to { transform: translate3d(1.5%, 1%, 0) scale(1.06); } }
@keyframes drift-b { from { transform: translate3d(1.5%, 1%, 0) scale(1.04); } to { transform: translate3d(-1.5%, -1%, 0) scale(1); } }

#sky {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: grab;
}
#sky.dragging { cursor: grabbing; }
#sky.over-star { cursor: pointer; }

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

.title {
  position: fixed;
  top: max(3.5vh, env(safe-area-inset-top));
  left: 0; right: 0;
  margin: 0;
  text-align: center;
  font-family: var(--serif);
  font-style: italic;
  font-weight: 300;
  font-size: clamp(2.6rem, 8vw, 5rem);
  letter-spacing: 0.04em;
  color: #fff8e4;
  text-shadow: 0 0 18px rgba(255, 226, 154, 0.55), 0 0 60px rgba(255, 226, 154, 0.25);
  pointer-events: none;
  user-select: none;
  animation: title-in 2.4s ease-out both;
}
@keyframes title-in {
  from { opacity: 0; letter-spacing: 0.18em; filter: blur(6px); }
  to   { opacity: 1; letter-spacing: 0.04em; filter: blur(0); }
}

button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

.ghost {
  background: var(--glass);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.45rem 0.95rem;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  transition: border-color 0.2s, background 0.2s;
}
.ghost:hover { border-color: rgba(255, 226, 154, 0.55); }
.ghost.icon { width: 2.2rem; height: 2.2rem; padding: 0; font-size: 1.4rem; line-height: 1; }

.topbar {
  position: fixed;
  z-index: 3;
  top: max(1rem, env(safe-area-inset-top));
  right: 1rem;
  display: flex;
  gap: 0.5rem;
  align-items: center;
  font-size: 0.9rem;
}
.topbar .ghost.icon { font-size: 1.05rem; }
.ghost[aria-pressed="true"] { border-color: rgba(255, 226, 154, 0.7); color: var(--gold); }
#sound-toggle.muted { opacity: 0.5; text-decoration: line-through; }

.light-count {
  position: fixed;
  top: max(1.15rem, env(safe-area-inset-top));
  left: 1rem;
  margin: 0;
  max-width: 40vw;
  font-family: var(--serif);
  font-style: italic;
  font-size: 1rem;
  color: var(--ink-soft);
  pointer-events: none;
}
@media (max-width: 760px) {
  .title { top: calc(env(safe-area-inset-top) + 3.6rem); }
  .light-count {
    left: 0;
    right: 0;
    max-width: none;
    text-align: center;
    top: calc(env(safe-area-inset-top) + 3.6rem + 4.4rem);
    font-size: 0.95rem;
  }
}

.count { color: var(--gold); margin-left: 0.25rem; font-variant-numeric: tabular-nums; }

.hint {
  position: fixed;
  left: 0; right: 0;
  bottom: calc(max(0.6rem, env(safe-area-inset-bottom)) + 14.6rem);
  margin: 0;
  text-align: center;
  font-size: 0.78rem;
  letter-spacing: 0.05em;
  color: var(--ink-soft);
  pointer-events: none;
  transition: opacity 1.2s;
}
.hint.gone { opacity: 0; }

.notice {
  position: fixed;
  left: 50%;
  bottom: calc(max(0.6rem, env(safe-area-inset-bottom)) + 16.4rem);
  transform: translateX(-50%);
  margin: 0;
  max-width: calc(100% - 2rem);
  text-align: center;
  font-family: var(--serif);
  font-style: italic;
  font-size: 1.35rem;
  color: var(--gold);
  text-shadow: 0 0 14px rgba(255, 226, 154, 0.5);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.6s;
}
.notice.show { opacity: 1; }
.notice.error { color: #ffb4b4; text-shadow: none; }

.composer {
  position: fixed;
  left: 50%;
  bottom: calc(max(0.6rem, env(safe-area-inset-bottom)) + 2.1rem);
  transform: translateX(-50%);
  width: min(640px, calc(100% - 2rem));
  padding: 0.85rem 1rem 0.75rem;
  background: var(--glass);
  border: 1px solid var(--line);
  border-radius: 1.2rem;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 0 40px rgba(120, 130, 255, 0.12);
}
.composer textarea {
  display: block;
  width: 100%;
  resize: none;
  background: transparent;
  border: 0;
  color: var(--ink);
  font-family: var(--serif);
  font-size: 1.2rem;
  line-height: 1.35;
  outline: none;
}
.composer textarea::placeholder { color: rgba(226, 230, 255, 0.45); font-style: italic; }
.composer.sending textarea { color: transparent; }
.moods { display: flex; flex-wrap: wrap; gap: 0.35rem; margin-top: 0.5rem; }
.mood-chip {
  width: 2.1rem;
  height: 2.1rem;
  padding: 0;
  font-size: 1.05rem;
  line-height: 1;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid transparent;
  border-radius: 50%;
  opacity: 0.6;
  transition: opacity 0.2s, border-color 0.2s, transform 0.15s;
}
.mood-chip:hover { opacity: 1; }
.mood-chip { --hue: 48; }
.mood-chip:hover { box-shadow: 0 0 12px hsla(var(--hue), 100%, 70%, 0.35); }
.mood-chip[aria-pressed="true"] {
  opacity: 1;
  border-color: hsl(var(--hue), 100%, 76%);
  background: hsla(var(--hue), 100%, 70%, 0.14);
  box-shadow: 0 0 16px hsla(var(--hue), 100%, 70%, 0.55);
  transform: scale(1.1);
}
.composer-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-top: 0.4rem; }
.counter { font-size: 0.75rem; color: var(--ink-soft); font-variant-numeric: tabular-nums; }

.primary {
  border: 1px solid rgba(255, 226, 154, 0.5);
  border-radius: 999px;
  padding: 0.55rem 1.5rem;
  font-weight: 500;
  letter-spacing: 0.08em;
  color: var(--gold);
  background: rgba(255, 226, 154, 0.07);
  box-shadow: 0 0 16px rgba(255, 226, 154, 0.1);
  transition: background 0.25s, box-shadow 0.25s, transform 0.15s, opacity 0.2s;
}
.primary:hover { background: rgba(255, 226, 154, 0.15); box-shadow: 0 0 28px rgba(255, 226, 154, 0.28); }
.primary:active { transform: scale(0.97); }
.primary:disabled { opacity: 0.5; cursor: progress; }

.tooltip {
  position: fixed;
  z-index: 5;
  max-width: min(280px, calc(100vw - 2rem));
  padding: 0.65rem 0.85rem;
  background: rgba(8, 11, 26, 0.88);
  border: 1px solid rgba(255, 226, 154, 0.35);
  border-radius: 0.8rem;
  box-shadow: 0 0 24px rgba(255, 226, 154, 0.18);
  pointer-events: none;
}
.tooltip[hidden], .modal[hidden], .archive[hidden] { display: none; }
.tooltip-text {
  margin: 0 0 0.35rem;
  font-family: var(--serif);
  font-size: 1.05rem;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}
.tooltip-date { font-size: 0.72rem; color: var(--ink-soft); }

.archive {
  position: fixed;
  z-index: 6;
  top: 0; right: 0; bottom: 0;
  width: min(380px, 100%);
  padding: max(1rem, env(safe-area-inset-top)) 1rem 1rem;
  display: flex;
  flex-direction: column;
  background: rgba(6, 9, 22, 0.88);
  border-left: 1px solid var(--line);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  animation: slide-in 0.3s ease-out;
}
@keyframes slide-in { from { transform: translateX(30px); opacity: 0; } to { transform: none; opacity: 1; } }
.archive-head { display: flex; align-items: center; justify-content: space-between; }
.archive-head h2 { margin: 0; font-family: var(--serif); font-style: italic; font-weight: 400; font-size: 1.8rem; color: #fff8e4; }
.archive-list { list-style: none; margin: 1rem 0 0; padding: 0; overflow-y: auto; flex: 1; }
.archive-list li + li { margin-top: 0.5rem; }
.archive-item {
  width: 100%;
  text-align: left;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--line);
  border-radius: 0.8rem;
  padding: 0.7rem 0.85rem;
  transition: border-color 0.2s, background 0.2s;
}
.archive-item:hover { border-color: rgba(255, 226, 154, 0.5); background: rgba(255, 226, 154, 0.06); }
.archive-item time { display: block; font-size: 0.72rem; color: var(--gold); margin-bottom: 0.2rem; }
.archive-item span {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  overflow-wrap: anywhere;
  font-family: var(--serif);
  font-size: 1.05rem;
  line-height: 1.3;
}
.archive-empty { color: var(--ink-soft); font-family: var(--serif); font-style: italic; font-size: 1.15rem; margin-top: 1.5rem; }

.modal {
  position: fixed;
  z-index: 8;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgba(2, 3, 10, 0.6);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  animation: fade-in 0.25s ease-out;
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
/* Свиток: плотный «пергамент» ночного неба с двумя свёрнутыми краями и планетой-орбой. */
.modal-card {
  --hue: 48;
  position: relative;
  width: min(560px, 100%);
  padding: 2.6rem 2rem 2.3rem;
  background:
    radial-gradient(ellipse at 50% 0%, hsla(var(--hue), 90%, 70%, 0.1), transparent 60%),
    linear-gradient(180deg, rgba(22, 26, 54, 0.97), rgba(10, 13, 30, 0.98));
  border: 1px solid hsla(var(--hue), 100%, 80%, 0.22);
  border-radius: 4px;
  box-shadow: 0 0 70px hsla(var(--hue), 100%, 70%, 0.22), 0 20px 60px rgba(0, 0, 0, 0.5);
  animation: unroll 0.7s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}
.modal-card::before,
.modal-card::after {
  content: "";
  position: absolute;
  left: -14px;
  right: -14px;
  height: 22px;
  border-radius: 11px;
  background: linear-gradient(
    180deg,
    hsl(var(--hue), 55%, 88%) 0%,
    hsl(var(--hue), 45%, 62%) 40%,
    hsl(var(--hue), 40%, 28%) 100%
  );
  box-shadow: 0 0 22px hsla(var(--hue), 100%, 70%, 0.35), inset 0 -2px 3px rgba(0, 0, 0, 0.35);
}
.modal-card::before { top: -11px; }
.modal-card::after { bottom: -11px; }
.modal-body { max-height: 46vh; overflow-y: auto; padding-right: 0.2rem; }
@keyframes unroll {
  from { opacity: 0; transform: scaleY(0.25) translateY(-10px); }
  60% { opacity: 1; }
  to { opacity: 1; transform: none; }
}

.orb {
  position: relative;
  flex: none;
  width: 1.7rem;
  height: 1.7rem;
  border-radius: 50%;
  background: radial-gradient(circle at 32% 30%, hsl(var(--hue), 100%, 94%), hsl(var(--hue), 90%, 66%) 42%, hsl(var(--hue), 70%, 26%) 100%);
  box-shadow: 0 0 18px hsla(var(--hue), 100%, 70%, 0.65);
  margin-right: 0.45rem;
}
.orb::after {
  content: "";
  position: absolute;
  left: -45%;
  right: -45%;
  top: 38%;
  height: 24%;
  border: 1.5px solid hsla(var(--hue), 100%, 85%, 0.6);
  border-radius: 50%;
  transform: rotate(-18deg);
}
.modal-close { position: absolute; top: 0.9rem; right: 0.9rem; }
.modal-date { display: block; font-size: 0.8rem; letter-spacing: 0.04em; color: var(--gold); }
.modal-text {
  margin: 0;
  font-family: var(--serif);
  font-size: 1.6rem;
  line-height: 1.4;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

@media (max-width: 520px) {
  .topbar { right: 0.6rem; gap: 0.35rem; font-size: 0.82rem; }
  .topbar .ghost { padding: 0.4rem 0.7rem; }
  .topbar .ghost.icon { padding: 0; }
  .quote { font-size: 0.9rem; }
  .composer textarea { font-size: 1.1rem; }
  .modal-text { font-size: 1.4rem; }
}

@media (prefers-reduced-motion: reduce) {
  .title, .archive, .modal, .modal-card, .fog, .topbar, .light-count, .composer, .quote, .hint { animation: none; }
  .hint, .notice { transition: none; }
}

.quote {
  position: fixed;
  left: 0; right: 0;
  bottom: max(0.6rem, env(safe-area-inset-bottom));
  margin: 0;
  padding: 0 1rem;
  text-align: center;
  font-family: var(--serif);
  font-style: italic;
  font-size: 1rem;
  color: rgba(226, 230, 255, 0.55);
  pointer-events: none;
}

.connect-banner {
  position: fixed;
  z-index: 4;
  left: 50%;
  top: max(5.2rem, calc(env(safe-area-inset-top) + 4.4rem));
  transform: translateX(-50%);
  width: min(520px, calc(100% - 2rem));
  display: flex;
  align-items: center;
  gap: 0.9rem;
  padding: 0.7rem 0.9rem;
  background: var(--glass);
  border: 1px solid rgba(255, 226, 154, 0.35);
  border-radius: 1rem;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  font-size: 0.85rem;
  line-height: 1.35;
  color: var(--ink-soft);
}
.connect-banner[hidden] { display: none; }
.connect-banner p { margin: 0; }
#sky.connecting { cursor: crosshair; }
#sky.connecting.over-star { cursor: pointer; }

.modal-meta { display: flex; align-items: center; gap: 0.7rem; margin: 0 0 1rem; }
.modal-meta .modal-date { margin: 0; }
.modal-mood { font-size: 1.3rem; line-height: 1; }
.modal-mood:empty { display: none; }
.ritual-title { margin: 0 2rem 0.2rem 0; font-family: var(--serif); font-style: italic; font-weight: 400; font-size: 2rem; color: #fff8e4; }
.ritual-question { margin: 0 0 1.1rem; color: var(--ink-soft); font-size: 0.95rem; }
.ritual .modal-body { margin-bottom: 1.1rem; }
.ritual-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 0.8rem; margin-top: 1.2rem; }

.flyer {
  position: fixed;
  z-index: 7;
  margin: 0;
  pointer-events: none;
  font-family: var(--serif);
  font-size: 1.2rem;
  line-height: 1.35;
  color: var(--ink);
  overflow: hidden;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  text-shadow: 0 0 14px rgba(255, 226, 154, 0.6);
}
.flyer-dot {
  position: fixed;
  z-index: 7;
  width: 46px;
  height: 46px;
  margin: -23px 0 0 -23px;
  pointer-events: none;
  border-radius: 50%;
  background: radial-gradient(circle, #fffbe9 0%, rgba(255, 226, 154, 0.75) 22%, rgba(255, 211, 107, 0.18) 55%, transparent 72%);
}

.topbar, .light-count, .composer, .quote, .hint {
  animation: fade-late 2.6s ease-out 1.4s backwards;
}
@keyframes fade-late { from { opacity: 0; } to { opacity: 1; } }
