:root {
  --ink: #0f0c33;
  --ink-80: rgba(15, 12, 51, 0.8);
  --ink-55: rgba(15, 12, 51, 0.55);
  --paper: #f4f2ff;
  --paper-70: rgba(244, 242, 255, 0.7);
  --accent: #ffd36e;
  --accent-ink: #2a1f06;
  --mint: #5ad1b4;
  --line: rgba(244, 242, 255, 0.28);
  --font: 'Space Grotesk', system-ui, -apple-system, 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font);
  color: var(--paper);
  background: var(--ink);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
button { font: inherit; color: inherit; cursor: pointer; }
a { color: inherit; }
[hidden] { display: none !important; }

#scene {
  position: fixed; inset: 0;
  width: 100%; height: 100%;
  display: block;
  outline: none;
}

/* ---------------- INTRO ---------------- */
.intro {
  position: fixed; inset: 0;
  z-index: 20;
  padding: clamp(20px, 4vw, 48px);
  background: linear-gradient(180deg, rgba(15, 12, 51, 0.35) 0%, rgba(15, 12, 51, 0.05) 45%, rgba(15, 12, 51, 0.45) 100%);
  transition: opacity 0.9s ease;
}
.intro.is-leaving { opacity: 0; pointer-events: none; }

.intro__brand { max-width: 34rem; }
.intro__name {
  margin: 0 0 0.35rem;
  font-size: clamp(1.4rem, 2.6vw, 2rem);
  font-weight: 500;
  letter-spacing: 0.01em;
}
.intro__tagline {
  margin: 0;
  font-size: clamp(1.05rem, 1.9vw, 1.45rem);
  font-weight: 300;
  line-height: 1.35;
  color: var(--paper);
  opacity: 0.92;
}

.intro__center {
  position: absolute; left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  display: flex; flex-direction: column; align-items: center; gap: 14px;
  text-align: center;
  width: min(90vw, 420px);
}
.intro__status {
  margin: 0;
  font-weight: 300;
  letter-spacing: 0.04em;
  opacity: 0.9;
}
.intro__bar {
  width: 180px; height: 2px;
  background: rgba(244, 242, 255, 0.2);
  border-radius: 2px; overflow: hidden;
}
.intro__bar span {
  display: block; height: 100%; width: 0%;
  background: var(--accent);
  transition: width 0.35s ease;
}
.intro__enter {
  min-width: 190px;
  padding: 12px 34px;
  border: 1px solid var(--paper);
  background: rgba(15, 12, 51, 0.25);
  border-radius: 4px;
  font-size: 1rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  backdrop-filter: blur(6px);
  transition: background 0.25s ease, color 0.25s ease, transform 0.25s ease;
  animation: pop 0.6s cubic-bezier(.2,.9,.3,1.2);
}
.intro__enter:hover, .intro__enter:focus-visible {
  background: var(--paper);
  color: var(--ink);
  transform: translateY(-1px);
}
.intro__sound {
  margin: 0;
  font-size: 0.85rem;
  font-weight: 300;
  letter-spacing: 0.05em;
  opacity: 0.8;
}
/* letter-by-letter reveal, left to right */
.intro__name .word, .intro__tagline .word { display: inline-block; white-space: pre; }
.intro__name .ch, .intro__tagline .ch { display: inline-block; opacity: 0; animation: ch-in 0.7s cubic-bezier(.2,.7,.2,1) forwards; }
@keyframes ch-in { from { opacity: 0; transform: translateX(-8px); filter: blur(5px); } to { opacity: 1; transform: none; filter: blur(0); } }

@keyframes pop { from { opacity: 0; transform: scale(0.92); } to { opacity: 1; transform: none; } }

/* ---------------- HUD ---------------- */
.hud { position: fixed; inset: 0; z-index: 10; pointer-events: none; }
.hud > * { pointer-events: auto; }

.hud__topleft {
  position: absolute; left: 20px; top: 20px;
  display: flex; flex-direction: column; gap: 10px;
}
.hud__topright { position: absolute; right: 20px; top: 24px; }

.ui-btn {
  padding: 9px 16px;
  border: 1px solid var(--line);
  background: var(--ink-55);
  border-radius: 4px;
  font-size: 0.85rem;
  letter-spacing: 0.04em;
  backdrop-filter: blur(8px);
  transition: background 0.2s ease, border-color 0.2s ease;
}
.ui-btn:hover { background: var(--ink-80); border-color: var(--paper-70); }

.crystals { display: flex; gap: 8px; }
.crystals span {
  width: 12px; height: 12px;
  border-radius: 50%;
  border: 1.5px solid var(--paper-70);
  transition: background 0.4s ease, box-shadow 0.4s ease, transform 0.4s ease;
}
.crystals span.is-found {
  background: var(--accent);
  border-color: var(--accent);
  box-shadow: 0 0 12px var(--accent);
  transform: scale(1.1);
}

/* toasts */
.toasts {
  position: absolute; left: 50%; top: 22px;
  transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 8px; align-items: center;
  width: min(92vw, 480px);
}
.toast {
  display: flex; align-items: center; gap: 14px;
  padding: 10px 12px 10px 16px;
  border: 1px solid var(--line);
  background: var(--ink-80);
  border-radius: 6px;
  font-size: 0.92rem;
  font-weight: 300;
  backdrop-filter: blur(8px);
  animation: toast-in 0.4s ease;
}
.toast.is-leaving { opacity: 0; transform: translateY(-8px); transition: all 0.35s ease; }
.toast button {
  border: 0; background: transparent;
  font-size: 1.2rem; line-height: 1;
  opacity: 0.7; padding: 2px 6px;
}
.toast button:hover { opacity: 1; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: none; } }

/* key hint */
.keyhint {
  position: absolute; left: 50%; bottom: 10vh;
  transform: translateX(-50%);
  text-align: center;
  transition: opacity 0.6s ease;
}
.keyhint.is-hidden { opacity: 0; pointer-events: none; }
.keyhint__keys { display: grid; grid-template-columns: repeat(3, 38px); gap: 6px; justify-content: center; }
.key {
  display: grid; place-items: center;
  width: 38px; height: 34px;
  border: 1px solid var(--line);
  background: var(--ink-55);
  border-radius: 6px;
  font-size: 0.7rem;
  backdrop-filter: blur(8px);
}
.key--up { grid-column: 2; grid-row: 1; }
.key:not(.key--up) { grid-row: 2; }
.keyhint__text { margin: 12px 0 0; font-weight: 300; letter-spacing: 0.03em; }

/* joystick (touch only) */
.joystick {
  display: none;
  position: absolute; left: 26px; bottom: calc(26px + env(safe-area-inset-bottom));
  width: 120px; height: 120px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: rgba(15, 12, 51, 0.35);
  backdrop-filter: blur(6px);
  touch-action: none;
}
.joystick__knob {
  position: absolute; left: 50%; top: 50%;
  width: 52px; height: 52px; margin: -26px 0 0 -26px;
  border-radius: 50%;
  background: var(--paper-70);
  transition: transform 0.05s linear;
}
@media (pointer: coarse) {
  .joystick { display: block; }
  .keyhint { bottom: 170px; }
  .keyhint__keys { display: none; }
}
.is-touch .joystick { display: block; }
.is-touch .keyhint { bottom: 170px; }
.is-touch .keyhint__keys { display: none; }

/* project card */
.card {
  position: absolute; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: min(92vw, 440px);
  padding: 18px 20px 20px;
  border: 1px solid var(--line);
  background: var(--ink-80);
  border-radius: 10px;
  backdrop-filter: blur(12px);
  animation: card-in 0.35s cubic-bezier(.2,.9,.3,1.1);
}
@media (pointer: coarse) {
  .card { left: auto; right: 16px; transform: none; width: min(60vw, 360px); bottom: calc(26px + env(safe-area-inset-bottom)); }
}
@keyframes card-in { from { opacity: 0; transform: translate(-50%, 14px); } to { opacity: 1; transform: translate(-50%, 0); } }
@media (pointer: coarse) { @keyframes card-in { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } } }
.card__kicker {
  margin: 0 0 4px;
  font-size: 0.7rem; letter-spacing: 0.16em; text-transform: uppercase;
  color: var(--accent);
}
.card__title { margin: 0; font-size: 1.35rem; font-weight: 700; }
.card__sub { margin: 2px 0 10px; font-weight: 300; opacity: 0.75; }
.card__desc { margin: 0 0 14px; font-weight: 300; line-height: 1.45; font-size: 0.95rem; }
.card__actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.card__btn {
  display: inline-block;
  padding: 9px 16px;
  border-radius: 4px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--accent-ink);
  text-decoration: none;
  font-weight: 500;
  font-size: 0.9rem;
}
.card__btn--ghost { background: transparent; color: var(--paper); border-color: var(--line); }
.card__hint { font-size: 0.78rem; opacity: 0.6; margin-left: auto; }
@media (pointer: coarse) { .card__hint { display: none; } }

/* about */
.about { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; padding: 20px; }
.about__backdrop { position: absolute; inset: 0; background: rgba(8, 6, 30, 0.6); backdrop-filter: blur(10px); }
.about__panel {
  position: relative;
  width: min(92vw, 560px);
  max-height: 86vh; overflow: auto;
  padding: 32px 32px 28px;
  border: 1px solid var(--line);
  background: var(--ink-80);
  border-radius: 14px;
  animation: pop 0.4s ease;
}
.about__close {
  position: absolute; right: 14px; top: 10px;
  border: 0; background: transparent;
  font-size: 1.8rem; line-height: 1; opacity: 0.7;
}
.about__close:hover { opacity: 1; }
.about__title { margin: 0 0 14px; font-size: 1.6rem; }
.about__body p { margin: 0 0 12px; font-weight: 300; line-height: 1.5; }
.about__links { display: flex; flex-wrap: wrap; gap: 10px 18px; margin: 18px 0 10px; }
.about__links a { color: var(--accent); text-decoration: none; border-bottom: 1px solid transparent; }
.about__links a:hover { border-bottom-color: var(--accent); }
.about__credits { margin: 14px 0 0; font-size: 0.8rem; opacity: 0.6; font-weight: 300; }
.about__credits a { color: inherit; }

@media (max-width: 640px) {
  .toasts { top: 100px; width: min(92vw, 360px); }
  .hud__topleft { left: 14px; top: 14px; }
  .hud__topright { right: 14px; top: 20px; }
  .intro { padding: 22px 20px; }
}

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