:root {
  --bg: #14111f;
  --ink: #f6eadf;
  --ink-soft: rgba(246, 234, 223, 0.7);
  --ink-faint: rgba(246, 234, 223, 0.45);
  --glass: rgba(24, 18, 40, 0.38);
  --glass-hover: rgba(40, 30, 62, 0.5);
  --line: rgba(255, 232, 214, 0.2);
  --line-strong: rgba(255, 232, 214, 0.5);
  --glow: rgba(255, 214, 170, 0.35);
  --amber: #ffdcb4;
  --leaf: #e8b866;
  --serif: "Cormorant Garamond", "Times New Roman", serif;
  --kb: 0px;
  --shade: 0.7;
  --ease: cubic-bezier(0.45, 0, 0.25, 1);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--serif);
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
}

button { font: inherit; color: inherit; }

#scene { position: fixed; left: 0; top: 0; display: block; }

.veil {
  position: fixed;
  inset: 0;
  background: var(--bg);
  pointer-events: none;
  animation: veil 1.8s ease-out 0.1s forwards;
}

@keyframes veil { to { opacity: 0; visibility: hidden; } }
@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}

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

/* ---------- panel ---------- */

main { position: fixed; inset: 0; pointer-events: none; }

.panel {
  position: absolute;
  left: 50%;
  bottom: calc(max(20px, env(safe-area-inset-bottom)) + var(--kb));
  width: min(560px, calc(100% - 32px));
  transform: translateX(-50%);
  text-align: center;
  pointer-events: auto;
  transition: opacity 0.9s var(--ease), transform 0.9s var(--ease), visibility 0s;
}

.panel.is-hidden {
  opacity: 0;
  visibility: hidden;
  transform: translate(-50%, 12px);
  pointer-events: none;
  transition: opacity 0.7s var(--ease), transform 0.7s var(--ease), visibility 0s 0.7s;
}

.invite {
  margin: 0 0 14px;
  font-size: clamp(22px, 4.2vw, 30px);
  font-weight: 400;
  font-style: italic;
  letter-spacing: 0.01em;
  text-shadow: 0 1px 14px rgba(20, 10, 30, var(--shade));
  opacity: 0;
  animation: rise 1.6s var(--ease) 0.9s forwards;
}

textarea {
  display: block;
  width: 100%;
  min-height: 104px;
  padding: 14px 18px;
  resize: none;
  font: 400 20px/1.45 var(--serif);
  color: var(--ink);
  background: var(--glass);
  border: 1px solid var(--line);
  border-radius: 16px;
  outline: none;
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  transition: border-color 0.4s, box-shadow 0.4s;
  opacity: 0;
  animation: rise 1.6s var(--ease) 1.3s forwards;
}

textarea::placeholder { color: var(--ink-faint); font-style: italic; }

textarea:focus {
  border-color: var(--line-strong);
  box-shadow: 0 0 0 4px rgba(255, 214, 170, 0.08), 0 8px 40px rgba(255, 190, 150, 0.08);
}

.count {
  display: block;
  min-height: 1.2em;
  margin-top: 4px;
  font-size: 14px;
  text-align: right;
  color: var(--ink-faint);
}

/* ---------- nút giữ để thả ---------- */

.hold-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  opacity: 0;
  animation: rise 1.6s var(--ease) 1.7s forwards;
}

.hold {
  position: relative;
  width: 76px;
  height: 76px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  color: var(--leaf);
  background: radial-gradient(circle at 50% 40%, rgba(255, 226, 196, 0.16), rgba(30, 22, 48, 0.55));
  cursor: pointer;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  transition: transform 0.6s cubic-bezier(0.3, 0.7, 0.3, 1), box-shadow 0.6s;
}

.hold:hover { box-shadow: 0 0 24px rgba(255, 214, 170, 0.18); }
.hold.holding { transform: scale(0.94); box-shadow: 0 0 44px var(--glow); }
.hold:focus-visible { outline: 2px solid var(--line-strong); outline-offset: 4px; }

.hold-ring { position: absolute; inset: 0; transform: rotate(-90deg); }
.ring-bg { fill: none; stroke: var(--line); stroke-width: 2; }
.ring {
  fill: none;
  stroke: var(--amber);
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-dasharray: 213.63;
  stroke-dashoffset: 213.63;
  filter: drop-shadow(0 0 4px rgba(255, 210, 160, 0.7));
}

.hold-leaf { position: absolute; inset: 0; width: 30px; height: 30px; margin: auto; }

.hold-label { margin: 10px 0 0; font-size: 17px; letter-spacing: 0.04em; color: var(--ink-soft); }

.hint {
  min-height: 1.3em;
  margin: 2px 0 0;
  font-size: 16px;
  font-style: italic;
  color: var(--amber);
  opacity: 0;
  transition: opacity 0.5s;
}
.hint.show { opacity: 1; }

.privacy { margin: 6px 0 0; font-size: 14px; color: var(--ink-faint); }

.presence {
  min-height: 1.3em;
  margin: 0 0 6px;
  font-size: 15px;
  font-style: italic;
  color: var(--amber);
  opacity: 0.85;
  text-shadow: 0 1px 10px rgba(20, 10, 30, var(--shade));
  transition: opacity 0.6s;
}
.presence:empty { opacity: 0; }

.presence.top {
  position: fixed;
  top: calc(max(14px, env(safe-area-inset-top)) + 12px);
  left: 50%;
  width: min(560px, calc(100% - 150px));
  margin: 0;
  transform: translateX(-50%);
  text-align: center;
  line-height: 1.35;
  pointer-events: none;
}

body.og-mode .presence { display: none; }

@media (max-width: 640px) {
  .presence.top {
    top: calc(max(14px, env(safe-area-inset-top)) + 54px);
    width: calc(100% - 32px);
  }
}

/* ---------- sau khi thả ---------- */

.together { margin: -14px 0 22px; }

.consolation {
  margin: 0 0 26px;
  font-size: clamp(24px, 4.8vw, 34px);
  font-style: italic;
  line-height: 1.35;
  text-shadow: 0 1px 16px rgba(20, 10, 30, var(--shade));
}

.actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 1s var(--ease) 1.6s, transform 1s var(--ease) 1.6s;
}
#settled:not(.is-hidden) .actions { opacity: 1; transform: none; }

.ghost {
  min-height: 44px;
  padding: 11px 22px;
  font-size: 18px;
  font-weight: 500;
  background: var(--glass);
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  transition: border-color 0.3s, background 0.3s;
}
.ghost:hover { border-color: var(--line-strong); background: var(--glass-hover); }
.ghost:focus-visible { outline: 2px solid var(--line-strong); outline-offset: 3px; }

/* ---------- âm thanh ---------- */

.sound {
  position: fixed;
  top: max(14px, env(safe-area-inset-top));
  right: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  height: 44px;
  padding: 0 14px 0 12px;
  font-size: 15px;
  font-weight: 500;
  background: var(--glass);
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  opacity: 0;
  animation: rise 1.4s var(--ease) 2.2s forwards;
  transition: border-color 0.3s, background 0.3s, padding 0.4s;
}
.sound:hover { border-color: var(--line-strong); background: var(--glass-hover); }
.sound:focus-visible { outline: 2px solid var(--line-strong); outline-offset: 3px; }
.sound svg { width: 22px; height: 22px; flex: none; }
.sound .speaker { fill: currentColor; }
.sound .wave, .sound .mute { fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; }
.sound[aria-pressed="false"] .wave { display: none; }
.sound[aria-pressed="true"] .mute { display: none; }
.sound-label { overflow: hidden; white-space: nowrap; max-width: 140px; transition: max-width 0.4s, opacity 0.3s; }
.sound[aria-pressed="true"] { padding: 0 11px; }
.sound[aria-pressed="true"] .sound-label { max-width: 0; opacity: 0; }

/* ---------- linh tinh ---------- */

.fly {
  position: fixed;
  z-index: 5;
  padding: 14px 18px;
  font: 400 20px/1.45 var(--serif);
  color: var(--ink);
  text-align: center;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  text-shadow: 0 0 12px rgba(255, 214, 170, 0.6);
  pointer-events: none;
}

.toast {
  position: fixed;
  top: calc(max(14px, env(safe-area-inset-top)) + 58px);
  left: 50%;
  max-width: calc(100% - 32px);
  padding: 10px 18px;
  font-size: 17px;
  text-align: center;
  background: rgba(24, 18, 40, 0.75);
  border: 1px solid var(--line);
  border-radius: 999px;
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  opacity: 0;
  transform: translate(-50%, -8px);
  transition: opacity 0.5s, transform 0.5s var(--ease);
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.noscript { position: fixed; inset: auto 0 40% 0; text-align: center; font-size: 20px; }

body.og-mode main,
body.og-mode .sound,
body.og-mode .veil { display: none; }
body.og-mode #scene { cursor: pointer; }

@media (max-height: 640px) {
  .invite { margin-bottom: 8px; font-size: 22px; }
  textarea { min-height: 78px; font-size: 18px; }
  .privacy { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-delay: 0s !important;
    transition-duration: 0.2s !important;
    transition-delay: 0s !important;
  }
}
