:root {
  --navy: #0b1f5c;
  --ink: #f4f1ea;
  --ink-soft: rgba(244, 241, 234, 0.72);
  --ink-dim: rgba(244, 241, 234, 0.45);
  --glass: rgba(170, 200, 255, 0.08);
  --glass-line: rgba(255, 255, 255, 0.42);
  --gold: #e9c98a;
  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);
  --font-th: "Noto Serif Thai", "Anuphan", serif;
  --font-ui: "Anuphan", "Noto Sans Thai", system-ui, sans-serif;
  --font-display: "Italiana", "Cormorant Garamond", serif;
  --font-serif: "Cormorant Garamond", "Noto Serif Thai", serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #071a4d;
  color: var(--ink);
  font-family: var(--font-ui);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

body.has-custom-cursor, body.has-custom-cursor * { cursor: none !important; }

button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
button:focus-visible, input:focus-visible, li:focus-visible {
  outline: 1px solid var(--gold);
  outline-offset: 4px;
}

.sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}
.sr-only:focus-within { position: fixed !important; }

#scene {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

/* ---------- Loader ---------- */
.loader {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  background: radial-gradient(120% 80% at 50% 65%, #123a8f 0%, #0a2366 45%, #050f33 100%);
}
.loader__inner { text-align: center; }
.loader__th { font-family: var(--font-th); font-size: 22px; font-weight: 500; letter-spacing: 0.02em; margin: 28px 0 2px; }
.loader__en { font-family: var(--font-display); font-size: 17px; letter-spacing: 0.22em; text-transform: uppercase; color: var(--ink-soft); margin: 0 0 26px; }
.loader__bar { width: 180px; height: 1px; margin: 0 auto; background: rgba(255, 255, 255, 0.18); overflow: hidden; }
.loader__bar span { display: block; height: 100%; width: 0%; background: linear-gradient(90deg, transparent, var(--gold)); transition: width 0.4s var(--ease); }
.loader__flame { position: relative; width: 18px; height: 42px; margin: 0 auto; }
.loader__flame span {
  position: absolute; inset: 0;
  border-radius: 50% 50% 45% 45% / 70% 70% 30% 30%;
  background: radial-gradient(circle at 50% 78%, #fff8e0 0%, #ffd27a 30%, #ff9a3c 58%, rgba(255, 110, 30, 0) 75%);
  filter: blur(0.4px);
  animation: loader-flicker 1.6s ease-in-out infinite;
  transform-origin: 50% 100%;
}
.loader__flame::after {
  content: ""; position: absolute; left: 50%; top: 60%;
  width: 120px; height: 120px; transform: translate(-50%, -50%);
  background: radial-gradient(circle, rgba(255, 190, 110, 0.28), transparent 65%);
  pointer-events: none;
}
@keyframes loader-flicker {
  0%, 100% { transform: scale(1, 1) skewX(0deg); }
  30% { transform: scale(0.94, 1.05) skewX(2deg); }
  60% { transform: scale(1.03, 0.96) skewX(-1.5deg); }
}

/* ---------- Overlay ---------- */
.ui { position: fixed; inset: 0; z-index: 10; pointer-events: none; }
.ui > * { pointer-events: auto; }
.ui .hero, .ui .hint { pointer-events: none; }

.topbar {
  position: absolute;
  top: calc(16px + var(--safe-top));
  left: 20px; right: 20px;
  display: flex; justify-content: space-between; align-items: center;
  pointer-events: none;
}
.topbar > * { pointer-events: auto; }

.lang { display: flex; align-items: center; gap: 8px; font-size: 19px; }
.lang button { color: var(--ink-dim); font-weight: 400; transition: color 0.4s var(--ease); }
.lang button[aria-pressed="true"] { color: var(--ink); font-weight: 600; }
.lang__sep { color: var(--ink-dim); font-size: 14px; }

.sound-hint {
  font-size: 12px; letter-spacing: 0.08em;
  color: var(--ink-dim);
  padding: 7px 14px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 99px;
  transition: color 0.4s var(--ease), border-color 0.4s var(--ease);
}
.sound-hint[aria-pressed="true"] { color: var(--ink); border-color: var(--gold); }

.hero {
  position: absolute;
  top: calc(28px + var(--safe-top));
  left: 0; right: 0;
  text-align: center;
  transition: opacity 0.9s var(--ease), transform 0.9s var(--ease);
}
.hero__title {
  font-family: var(--font-th);
  font-weight: 600;
  font-size: clamp(30px, 4.4vw, 50px);
  line-height: 1.25;
  margin: 0;
  text-shadow: 0 2px 24px rgba(4, 16, 60, 0.55);
}
.hero__sub {
  width: min(760px, calc(100% - 40px));
  margin: 6px auto 0;
  font-family: var(--font-ui);
  font-weight: 300;
  font-size: clamp(16px, 1.7vw, 21px);
  letter-spacing: 0.02em;
  color: var(--ink-soft);
}
html[lang="en"] .hero__title { font-family: var(--font-display); font-weight: 400; letter-spacing: 0.04em; }

.hint {
  position: absolute;
  left: 0; right: 0;
  bottom: calc(96px + var(--safe-bottom));
  margin: 0;
  text-align: center;
  font-size: 13px;
  letter-spacing: 0.16em;
  color: var(--ink-dim);
  text-transform: uppercase;
  transition: opacity 0.8s var(--ease);
}
html[lang="th"] .hint { text-transform: none; letter-spacing: 0.04em; font-size: 14px; }

.realms {
  position: absolute;
  left: 50%;
  bottom: calc(28px + var(--safe-bottom));
  transform: translateX(-50%);
  display: flex;
  gap: 4px;
  padding: 5px;
  border-radius: 99px;
  background: rgba(8, 26, 80, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.16);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  transition: opacity 0.7s var(--ease), transform 0.7s var(--ease);
}
.realm {
  padding: 9px 18px;
  border-radius: 99px;
  font-size: 14px;
  white-space: nowrap;
  color: var(--ink-soft);
  transition: background 0.5s var(--ease), color 0.5s var(--ease);
}
.realm[aria-current="true"] { background: rgba(255, 255, 255, 0.92); color: var(--navy); font-weight: 500; }

.ui[data-state="intro"] .hero,
.ui[data-state="intro"] .realms,
.ui[data-state="intro"] .hint { opacity: 0; }
.ui[data-state="focus"] .hero { opacity: 0; transform: translateY(-14px); }
.ui[data-state="focus"] .hint,
.ui[data-state="release"] .hint { opacity: 0; }
.ui[data-state="focus"] .realms,
.ui[data-state="release"] .realms { opacity: 0; transform: translate(-50%, 20px); pointer-events: none; }
.ui[data-state="release"] .hero { opacity: 0.35; }

/* ---------- Wish panel (glass, as in the mockups) ---------- */
.panel {
  position: absolute;
  top: 50%;
  right: clamp(20px, 5vw, 80px);
  width: min(400px, 92vw);
  max-height: calc(100% - 140px);
  transform: translate(30px, -50%);
  opacity: 0;
  visibility: hidden;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 26px 24px 22px;
  border-radius: 30px;
  border: 1px solid var(--glass-line);
  background: linear-gradient(180deg, rgba(120, 160, 240, 0.16), rgba(40, 70, 160, 0.14));
  backdrop-filter: blur(16px) saturate(1.2);
  -webkit-backdrop-filter: blur(16px) saturate(1.2);
  box-shadow: 0 30px 80px rgba(2, 10, 40, 0.45);
  transition: opacity 0.7s var(--ease), transform 0.7s var(--ease), visibility 0s linear 0.7s;
}
.panel.is-open {
  opacity: 1;
  visibility: visible;
  transform: translate(0, -50%);
  transition: opacity 0.8s var(--ease) 0.25s, transform 0.8s var(--ease) 0.25s, visibility 0s;
}

.round-btn {
  width: 64px; height: 40px;
  border-radius: 99px;
  background: #fff;
  color: #0b0f1e;
  display: grid; place-items: center;
  box-shadow: 0 8px 24px rgba(2, 10, 40, 0.28);
  transition: transform 0.4s var(--ease);
}
.round-btn svg { width: 30px; height: 16px; }
.round-btn:hover { transform: translateX(-3px); }
.panel__back { position: absolute; top: -20px; left: 22px; }

.panel__head { text-align: center; padding-top: 8px; }
.panel__theme { margin: 0; font-size: 12px; letter-spacing: 0.2em; text-transform: uppercase; color: var(--gold); }
html[lang="th"] .panel__theme { letter-spacing: 0.06em; font-size: 13px; }
.panel__title { margin: 6px 0 0; font-family: var(--font-th); font-weight: 600; font-size: 26px; line-height: 1.3; }
html[lang="en"] .panel__title { font-family: var(--font-display); font-weight: 400; font-size: 30px; letter-spacing: 0.03em; }
.panel__name-en { margin: 2px 0 0; font-family: var(--font-serif); font-style: italic; font-size: 17px; color: var(--ink-soft); }

.field input {
  width: 100%;
  height: 48px;
  border-radius: 99px;
  border: 1px solid var(--glass-line);
  background: rgba(255, 255, 255, 0.1);
  color: var(--ink);
  text-align: center;
  font: 500 19px var(--font-ui);
  outline: none;
  transition: background 0.4s var(--ease), border-color 0.4s var(--ease);
}
.field input::placeholder { color: var(--ink-dim); font-weight: 400; }
.field input:focus { background: rgba(255, 255, 255, 0.16); border-color: var(--gold); }

.wishbox {
  position: relative;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 22px;
  padding: 22px 0 10px;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.wishbox { border-top-color: transparent; }
.wishbox__title {
  position: absolute;
  top: -15px; left: 0; right: 0;
  display: flex;
  align-items: center;
  gap: 14px;
  margin: 0;
  padding: 0 20px;
  white-space: nowrap;
  font-weight: 500;
  font-size: 22px;
  line-height: 30px;
}
.wishbox__title::before, .wishbox__title::after {
  content: "";
  flex: 1;
  height: 1px;
  background: rgba(255, 255, 255, 0.28);
}
.wishes {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  scrollbar-width: none;
  max-height: 38vh;
}
.wishes::-webkit-scrollbar { display: none; }
.wishes li {
  position: relative;
  text-align: center;
  padding: 6px 12px;
  font-size: 17px;
  font-weight: 300;
  color: var(--ink);
  transition: color 0.35s var(--ease);
  cursor: pointer;
  outline-offset: -3px;
}
.wishes li::before {
  content: "";
  position: absolute;
  inset: 1px 0;
  background: linear-gradient(90deg, rgba(160, 205, 255, 0) 0%, rgba(190, 225, 255, 0.95) 50%, rgba(160, 205, 255, 0) 100%);
  opacity: 0;
  transform: scaleX(0.6);
  transition: opacity 0.45s var(--ease), transform 0.45s var(--ease);
  z-index: -1;
}
.wishes li[aria-selected="true"] { color: var(--navy); font-weight: 600; }
.wishes li[aria-selected="true"]::before { opacity: 1; transform: scaleX(1); }
.wishes li:hover:not([aria-selected="true"]) { color: #fff; text-shadow: 0 0 12px rgba(255, 220, 160, 0.6); }

.pill-btn {
  align-self: center;
  margin-top: 4px;
  padding: 12px 34px;
  border-radius: 99px;
  background: #fff;
  color: var(--navy);
  font-size: 22px;
  font-weight: 600;
  box-shadow: 0 10px 30px rgba(2, 10, 40, 0.3), 0 0 0 0 rgba(255, 214, 150, 0.5);
  transition: transform 0.4s var(--ease), box-shadow 0.6s var(--ease);
}
.pill-btn:hover { transform: translateY(-2px); box-shadow: 0 14px 34px rgba(2, 10, 40, 0.35), 0 0 34px 4px rgba(255, 214, 150, 0.35); }

.toast {
  position: absolute;
  left: 50%;
  bottom: calc(40px + var(--safe-bottom));
  transform: translate(-50%, 10px);
  padding: 12px 22px;
  border-radius: 99px;
  background: rgba(8, 26, 80, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.2);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  font-size: 15px;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.8s var(--ease), transform 0.8s var(--ease);
  max-width: 90vw;
}
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Custom cursor ---------- */
.cursor { position: fixed; left: 0; top: 0; z-index: 100; pointer-events: none; display: none; }
body.has-custom-cursor .cursor { display: block; }
.cursor__dot, .cursor__ring {
  position: absolute; left: 0; top: 0;
  border-radius: 50%;
  will-change: transform;
}
.cursor__dot {
  width: 5px; height: 5px; margin: -2.5px 0 0 -2.5px;
  background: #fff4dc;
  box-shadow: 0 0 10px 2px rgba(255, 200, 120, 0.55);
  transition: opacity 0.3s var(--ease), background 0.3s var(--ease);
}
.cursor__ring {
  width: 34px; height: 34px; margin: -17px 0 0 -17px;
  border: 1px solid rgba(255, 244, 220, 0.45);
  transition: width 0.5s var(--ease), height 0.5s var(--ease), margin 0.5s var(--ease), border-color 0.5s var(--ease), background 0.5s var(--ease);
  display: grid; place-items: center;
}
.cursor__label {
  position: absolute; top: 100%; left: 50%;
  transform: translate(-50%, 10px);
  font-size: 11px; letter-spacing: 0.2em; text-transform: uppercase;
  white-space: nowrap;
  color: var(--gold);
  opacity: 0;
  transition: opacity 0.4s var(--ease), transform 0.4s var(--ease);
}
.cursor.is-hover .cursor__ring {
  width: 64px; height: 64px; margin: -32px 0 0 -32px;
  border-color: rgba(233, 201, 138, 0.9);
  background: radial-gradient(circle, rgba(255, 210, 140, 0.14), transparent 70%);
}
.cursor.is-hover .cursor__dot { background: var(--gold); }
.cursor.is-hover .cursor__label { opacity: 1; transform: translate(-50%, 4px); }
.cursor.is-ui .cursor__ring { width: 22px; height: 22px; margin: -11px 0 0 -11px; border-color: rgba(255, 255, 255, 0.8); }
.cursor.is-down .cursor__ring { width: 26px; height: 26px; margin: -13px 0 0 -13px; }

.noscript { position: fixed; inset: 0; display: grid; place-items: center; margin: 0; }

/* ---------- Mobile ---------- */
@media (max-width: 760px) {
  .topbar { left: 16px; right: 16px; }
  .lang { font-size: 17px; }
  .hero { top: calc(20px + var(--safe-top)); }
  .hero__title { font-size: 34px; }
  .hero__sub { width: calc(100% - 28px); font-size: 15px; line-height: 1.35; }
  .realm { padding: 8px 12px; font-size: 13px; }
  .hint { bottom: calc(84px + var(--safe-bottom)); font-size: 12px; }

  .panel {
    top: auto;
    bottom: 0;
    right: 0; left: 0;
    width: 100%;
    max-height: 60%;
    border-radius: 28px 28px 0 0;
    border-bottom: 0;
    padding: 30px 18px calc(18px + var(--safe-bottom));
    gap: 10px;
    transform: translateY(40px);
  }
  .panel.is-open { transform: translateY(0); }
  .panel__back { top: -20px; left: 18px; }
  .panel__head { padding-top: 0; }
  .panel__title { font-size: 21px; }
  html[lang="en"] .panel__title { font-size: 24px; }
  .panel__name-en { font-size: 15px; }
  .field input { height: 42px; font-size: 17px; }
  .wishes { max-height: 22vh; }
  .wishes li { font-size: 15.5px; padding: 5px 10px; }
  .wishbox__title { font-size: 18px; top: -13px; line-height: 26px; }
  .pill-btn { font-size: 19px; padding: 10px 30px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; }
}
