/* ─── Saint-Imier Night ─── */
:root {
  --bg: #0C0C0C;
  --bg-light: #141414;
  --german-silver: #B8B0A8;
  --ray: #D4CFC8;
  --text: #E8E4DC;
  --text-dim: #8A8580;
  --font-sans: 'Sora', sans-serif;
  --font-serif: 'Literata', serif;
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-serif);
  overflow: hidden;
  width: 100vw;
  height: 100vh;
  cursor: none;
  user-select: none;
  -webkit-user-select: none;
}

/* ─── Grain Texture ─── */
body::before {
  content: '';
  position: fixed;
  inset: -10%;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)' opacity='0.035'/%3E%3C/svg%3E");
  background-repeat: repeat;
  background-size: 256px 256px;
  pointer-events: none;
  z-index: 0;
}

/* ─── The Sky ─── */
#sky {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
}

/* ─── Stars ─── */
.star {
  position: absolute;
  z-index: 2;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: auto;
  cursor: none;
  transition: opacity 0.5s var(--ease-out);
}

.star-label {
  display: block;
  text-align: center;
  white-space: nowrap;
  transition: opacity 0.4s var(--ease-out), color 0.4s var(--ease-out), text-shadow 0.4s var(--ease-out);
}

.star-glow {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(212,207,200,0.08) 0%, transparent 70%);
  opacity: 0;
  transition: opacity 0.5s var(--ease-out);
  pointer-events: none;
}

/* Core star: Zeitwinkel */
.star.core {
  z-index: 3;
}

.star.core .star-label {
  font-family: var(--font-serif);
  font-size: clamp(2rem, 4.5vw, 4rem);
  font-weight: 400;
  font-style: italic;
  color: var(--text);
  letter-spacing: -0.02em;
  opacity: 0.5;
}

.star.core .star-glow {
  width: 120px;
  height: 120px;
}

/* Watch stars */
.star.watch .star-label {
  font-family: var(--font-sans);
  font-size: clamp(1rem, 2vw, 1.6rem);
  font-weight: 300;
  color: var(--german-silver);
  letter-spacing: 0.05em;
  opacity: 0.35;
}

/* Story stars */
.star.story .star-label {
  font-family: var(--font-sans);
  font-size: clamp(0.6rem, 1.1vw, 0.85rem);
  font-weight: 300;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--text-dim);
  opacity: 0.2;
}

/* Dim stars */
.star.dim .star-label {
  font-family: var(--font-sans);
  font-size: clamp(0.55rem, 0.9vw, 0.7rem);
  font-weight: 300;
  letter-spacing: 0.12em;
  color: var(--text-dim);
  opacity: 0.1;
}

/* Illuminated state */
.star.illuminated .star-label {
  opacity: 1;
  color: var(--text);
  text-shadow: 0 0 20px rgba(212, 207, 200, 0.3);
}

.star.illuminated .star-glow {
  opacity: 1;
}

.star.illuminated.watch .star-label {
  color: var(--ray);
}

/* Pinned state */
.star.pinned .star-label {
  opacity: 1;
  color: var(--text);
  text-shadow: 0 0 20px rgba(212, 207, 200, 0.3);
}

.star.pinned .star-glow {
  opacity: 1;
}

/* ─── Twinkle ─── */
@keyframes twinkle {
  0%, 100% { opacity: var(--base-opacity); }
  50% { opacity: calc(var(--base-opacity) * 0.6); }
}

.star.twinkle .star-label {
  animation: twinkle var(--twinkle-duration, 3s) ease-in-out infinite;
  animation-delay: var(--twinkle-delay, 0s);
}

/* ─── Constellation Lines ─── */
#constellation {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
}

.constellation-line {
  transition: opacity 1.2s var(--ease-out);
}

/* ─── Stardust ─── */
#stardust {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
}

.stardust-dot {
  position: absolute;
  width: 2px;
  height: 2px;
  background: var(--german-silver);
  border-radius: 50%;
  opacity: var(--sd-opacity, 0.05);
  animation: twinkle var(--sd-duration, 4s) ease-in-out infinite;
  animation-delay: var(--sd-delay, 0s);
}

/* ─── Detail Panel ─── */
#detail-panel {
  position: fixed;
  z-index: 20;
  pointer-events: none;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.5s var(--ease-out), transform 0.5s var(--ease-out);
}

#detail-panel.open {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.detail-inner {
  background: rgba(12, 12, 12, 0.92);
  border: 1px solid rgba(184, 176, 168, 0.15);
  padding: 1.6rem 2rem;
  max-width: 320px;
  position: relative;
}

.detail-title {
  font-family: var(--font-serif);
  font-size: 1.1rem;
  font-weight: 400;
  font-style: italic;
  color: var(--text);
  margin-bottom: 0.6rem;
  line-height: 1.3;
}

.detail-body {
  font-family: var(--font-serif);
  font-size: 0.82rem;
  font-weight: 300;
  line-height: 1.7;
  color: var(--text-dim);
}

.detail-close {
  position: absolute;
  top: 0.6rem;
  right: 0.8rem;
  background: none;
  border: none;
  color: var(--text-dim);
  font-family: var(--font-sans);
  font-size: 1.2rem;
  font-weight: 300;
  cursor: none;
  padding: 0;
  line-height: 1;
  transition: color 0.3s ease;
}

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

/* ─── Telescope Cursor ─── */
#cursor {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 9999;
  pointer-events: none;
  transform: translate(-50%, -50%);
  opacity: 0;
  transition: opacity 0.3s ease;
}

#cursor.active {
  opacity: 1;
}

.cursor-glow {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 180px;
  height: 180px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(212,207,200,0.04) 0%, transparent 70%);
  pointer-events: none;
}

.cursor-ring {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 32px;
  height: 32px;
  border: 1px solid rgba(184, 176, 168, 0.35);
  border-radius: 50%;
  pointer-events: none;
  transition: width 0.3s ease, height 0.3s ease, border-color 0.3s ease;
}

.cursor-dot {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 4px;
  height: 4px;
  background: var(--ray);
  border-radius: 50%;
  pointer-events: none;
  box-shadow: 0 0 8px rgba(212, 207, 200, 0.4);
}

#cursor.near-star .cursor-ring {
  width: 48px;
  height: 48px;
  border-color: rgba(184, 176, 168, 0.6);
}

/* ─── Corner Marks ─── */
.mark {
  position: fixed;
  z-index: 10;
  font-family: var(--font-sans);
  font-size: 0.52rem;
  font-weight: 300;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--text-dim);
  opacity: 0;
  transition: opacity 1.5s var(--ease-out) 0.8s;
  pointer-events: none;
}

.mark.visible {
  opacity: 0.35;
}

#mark-tl { top: 2.4rem; left: 2.4rem; }
#mark-tr { top: 2.4rem; right: 2.4rem; }
#mark-bl { bottom: 2.4rem; left: 2.4rem; }
#mark-br { bottom: 2.4rem; right: 2.4rem; text-align: right; }

/* ─── Hint ─── */
#hint {
  position: fixed;
  bottom: 2.4rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  font-family: var(--font-sans);
  font-size: 0.52rem;
  font-weight: 300;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--text-dim);
  opacity: 0;
  transition: opacity 1s var(--ease-out) 2.5s;
  pointer-events: none;
}

#hint.visible {
  opacity: 0.3;
}

/* ─── Loader ─── */
#loader {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2rem;
  transition: opacity 1s var(--ease-out), visibility 1s;
}

#loader.done {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.loader-dot {
  width: 6px;
  height: 6px;
  background: var(--ray);
  border-radius: 50%;
  animation: loaderBeat 2s ease-in-out infinite;
}

.loader-ring {
  width: 20px;
  height: 20px;
  border: 1px solid var(--german-silver);
  border-radius: 50%;
  opacity: 0.3;
  animation: loaderRing 2s ease-in-out infinite;
}

@keyframes loaderBeat {
  0%, 100% { transform: scale(1); opacity: 0.9; }
  50% { transform: scale(1.5); opacity: 1; }
}

@keyframes loaderRing {
  0%, 100% { transform: scale(1); opacity: 0.3; }
  50% { transform: scale(1.6); opacity: 0.1; }
}

.loader-label {
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.loader-line {
  font-family: var(--font-serif);
  font-size: 0.9rem;
  font-style: italic;
  color: var(--german-silver);
  opacity: 0;
  animation: loaderTextIn 1s var(--ease-out) 0.3s forwards;
}

.loader-sub {
  font-family: var(--font-sans);
  font-size: 0.55rem;
  font-weight: 300;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--text-dim);
  opacity: 0;
  animation: loaderTextIn 1s var(--ease-out) 0.8s forwards;
}

@keyframes loaderTextIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ─── Mobile ─── */
@media (max-width: 640px) {
  body { cursor: auto; }
  #cursor { display: none; }
  .star.core .star-label { font-size: 1.6rem; }
  .star.watch .star-label { font-size: 0.85rem; }
  .star.story .star-label { font-size: 0.55rem; letter-spacing: 0.1em; }
  .star.dim .star-label { font-size: 0.5rem; }
  .detail-inner { max-width: 260px; padding: 1.2rem 1.4rem; }
  .detail-title { font-size: 0.95rem; }
  .detail-body { font-size: 0.78rem; }
  .mark { font-size: 0.45rem; letter-spacing: 0.1em; }
  #mark-tl { top: 1.2rem; left: 1.2rem; }
  #mark-tr { top: 1.2rem; right: 1.2rem; }
  #mark-bl { bottom: 1.2rem; left: 1.2rem; }
  #mark-br { bottom: 1.2rem; right: 1.2rem; }
  #hint { bottom: 1.2rem; font-size: 0.48rem; }
}

/* ─── Reduced motion ─── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
