:root {
  --bg: #05030a;
  --fg: #f0eaf8;
  --accent: #c8a8ff;
}

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

html {
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
}

body {
  background: var(--bg);
  color: var(--fg);
  font-family: 'Pretendard', -apple-system, BlinkMacSystemFont, 'Apple SD Gothic Neo',
    'Noto Sans KR', 'Malgun Gothic', sans-serif;
  overflow-x: hidden;
  cursor: crosshair;
  line-height: 1.6;
}

canvas#gl,
canvas#stars {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}
canvas#gl { z-index: 0; }
#nebula-fallback { position: fixed; inset: -10%; z-index: 0; pointer-events: none; opacity: 0;
  background: radial-gradient(ellipse at 25% 32%, rgba(99,48,158,.58), transparent 44%),
  radial-gradient(ellipse at 70% 58%, rgba(37,91,144,.53), transparent 48%),
  radial-gradient(ellipse at 45% 86%, rgba(128,41,90,.28), transparent 45%), #05030a;
  animation: nebulaDrift 19s ease-in-out infinite alternate; }
body.webgl-fallback #nebula-fallback { opacity: 1; }
body.webgl-fallback #gl { display: none; }
@keyframes nebulaDrift { to { transform: translate3d(2%, -2%, 0) scale(1.06); filter: hue-rotate(13deg); } }
canvas#stars { z-index: 2; pointer-events: none; }

#grain {
  position: fixed;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  opacity: 0.08;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

#vignette {
  position: fixed;
  inset: 0;
  z-index: 4;
  pointer-events: none;
  background: radial-gradient(ellipse at center, transparent 40%, rgba(0,0,0,0.55) 100%);
}

/* ===== Loader ===== */
#loader {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #000;
  transition: opacity .85s ease, visibility .85s ease;
  animation: loaderSafety 1s ease 4s forwards;
}
@keyframes loaderSafety { to { opacity: 0; visibility: hidden; pointer-events: none; } }
#loader.hidden { opacity: 0; visibility: hidden; }
.loader-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 20px 4px rgba(200,168,255,0.6),
              0 0 40px 8px rgba(200,168,255,0.3);
  animation: breathe 2s ease-in-out infinite;
}
#loader p {
  margin-top: 2rem;
  font-size: 0.75rem;
  letter-spacing: 0.4em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.5);
  animation: fadePulse 3s ease-in-out infinite;
}
@keyframes breathe {
  0%, 100% { transform: scale(1); opacity: 0.6; }
  50% { transform: scale(1.8); opacity: 1; }
}
@keyframes fadePulse {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 0.8; }
}

/* ===== UI / Panels ===== */
#ui {
  position: relative;
  z-index: 5;
  pointer-events: none;
}
.panel {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8vh 6vw;
  text-align: center;
}
.inner { max-width: 720px; }
.inner.center { margin: 0 auto; }

.eyebrow {
  font-size: 0.7rem;
  letter-spacing: 0.6em;
  text-transform: uppercase;
  opacity: 0.5;
  margin-bottom: 2rem;
}

h1 {
  font-size: clamp(3.5rem, 12vw, 8rem);
  font-weight: 200;
  line-height: 0.95;
  letter-spacing: -0.04em;
  margin-bottom: 2rem;
  text-shadow: 0 0 80px rgba(200,168,255,0.4);
}
h1 em, .big em {
  font-style: italic;
  font-weight: 300;
  background: linear-gradient(135deg, #fff, #c8a8ff, #ffa8d8);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
h2 {
  font-size: clamp(2rem, 6vw, 3.5rem);
  font-weight: 200;
  letter-spacing: -0.02em;
  margin-bottom: 2rem;
}
.big {
  font-size: clamp(2.2rem, 7vw, 4.5rem);
  font-weight: 200;
  line-height: 1.15;
  letter-spacing: -0.02em;
  margin-bottom: 2rem;
  text-shadow: 0 0 60px rgba(200,168,255,0.3);
}
.sub {
  font-size: clamp(0.95rem, 2vw, 1.1rem);
  font-weight: 300;
  opacity: 0.65;
  line-height: 1.8;
}
.sub.small { font-size: 0.95rem; }
.sub em {
  font-style: normal;
  color: #fff;
  text-shadow: 0 0 20px rgba(200,168,255,0.8);
  font-weight: 400;
}

.hint-scroll {
  margin-top: 6rem;
  font-size: 0.75rem;
  letter-spacing: 0.4em;
  opacity: 0.4;
  animation: floatDown 2.5s ease-in-out infinite;
}
@keyframes floatDown {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(8px); }
}

/* Fade-in animation on panels */
.panel .inner {
  opacity: 1;
  transform: translateY(0);
  transition: opacity 1.4s ease, transform 1.4s cubic-bezier(0.2, 0.8, 0.2, 1);
}
body.motion-ready .panel .inner { opacity: .18; transform: translateY(25px); }
body.motion-ready .panel.visible .inner {
  opacity: 1;
  transform: translateY(0);
}

/* ===== Audio toggle ===== */
#audio-toggle {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 20;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,0.2);
  background: rgba(0,0,0,0.3);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  color: var(--fg);
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.4s ease;
  pointer-events: auto;
  font-family: inherit;
}
#audio-toggle:hover {
  border-color: rgba(200,168,255,0.6);
  background: rgba(200,168,255,0.1);
  transform: scale(1.1);
}
#audio-toggle.on {
  border-color: rgba(200,168,255,0.8);
  color: #fff;
  box-shadow: 0 0 20px rgba(200,168,255,0.4);
}

/* ===== Forget button ===== */
#forget {
  margin-top: 3rem;
  padding: 0.85rem 2rem;
  border-radius: 99px;
  border: 1px solid rgba(255,255,255,0.15);
  background: rgba(255,255,255,0.02);
  color: rgba(255,255,255,0.6);
  font-size: 0.85rem;
  letter-spacing: 0.1em;
  cursor: pointer;
  transition: all 0.4s ease;
  pointer-events: auto;
  font-family: inherit;
}
#forget:hover {
  border-color: rgba(255,100,140,0.6);
  color: #ff8aa8;
  background: rgba(255,100,140,0.08);
}

/* Body ready state */
body.ready #ui { animation: uiFade .85s ease both; }
@keyframes uiFade {
  from { opacity: 0; }
  to { opacity: 1; }
}

@media (max-width: 640px) {
  .panel { padding: 6vh 6vw; }
  #audio-toggle { bottom: 16px; right: 16px; width: 40px; height: 40px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* Accessibility, saved constellations, and controls */
:root { --focus: #ffe5b5; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 4px; }
#ui .panel { pointer-events: none; }
#ui button { pointer-events: auto; }
.panel:last-child { min-height: 95svh; }
.memory-actions { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: .8rem; margin-top: 2rem; }
.memory-actions button { margin: 0; min-height: 44px; padding: .78rem 1.25rem; border-radius: 999px;
  background: rgba(40,23,66,.46); color: #f2e8ff; border: 1px solid rgba(208,177,252,.3);
  cursor: pointer; font: inherit; font-size: .85rem; transition: background .25s, border-color .25s; }
.memory-actions button:hover { background: rgba(93,64,136,.44); border-color: rgba(234,209,255,.75); }
.memory-actions #forget { margin: 0; color: #ffbacc; border-color: rgba(246,150,184,.35); }
.privacy-note { max-width: 38rem; color: #c5b7d8; opacity: .8; font-size: .78rem; margin: 1.6rem auto 0; }
.visit-counter { position: fixed; z-index: 12; top: max(18px, env(safe-area-inset-top));
  right: max(22px, env(safe-area-inset-right)); color: #e8d9ff; font-size: .76rem;
  letter-spacing: .18em; text-shadow: 0 0 12px rgba(196,155,254,.55); }
#audio-toggle { width: auto; min-width: 62px; height: 44px; border-radius: 24px; padding: 0 12px; gap: 3px;
  bottom: max(16px, env(safe-area-inset-bottom)); right: max(16px, env(safe-area-inset-right));
  background: rgba(10,6,20,.68); }
#audio-toggle .sound-state { font: 600 .60rem/1 system-ui, sans-serif; letter-spacing: .06em; }
.toast { position: fixed; z-index: 110; top: max(64px, env(safe-area-inset-top)); left: 50%;
  transform: translateX(-50%) translateY(-10px); max-width: min(92vw, 500px);
  padding: 11px 19px; border-radius: 18px; border: 1px solid rgba(216,183,250,.4);
  background: rgba(10,9,28,.91); color: #f6eeff; font-size: .84rem; line-height: 1.55;
  opacity: 0; pointer-events: none; text-align: center; transition: opacity .25s, transform .25s; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
@media (max-width:640px) { .memory-actions {gap: .55rem} .memory-actions button {font-size: .79rem; padding: .72rem 1rem}
  .visit-counter {right: 18px} .panel {min-height: 100svh} .privacy-note {font-size: .72rem}
  #audio-toggle {min-width: 65px} }
@media (prefers-reduced-motion: reduce) { #nebula-fallback {animation: none}
  body.motion-ready .panel .inner {opacity:1; transform:none}
  body.motion-ready .panel.visible .inner {opacity:1; transform:none} }
