:root {
  --night: #05060f;
  --night-glow: #121a3d;
  --emoji-font: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", "Twemoji Mozilla", sans-serif;
  --letter-font: ui-rounded, "SF Pro Rounded", "Arial Rounded MT Bold", "Nunito", "Trebuchet MS", system-ui, sans-serif;
  color-scheme: dark;
}

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

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  background: radial-gradient(ellipse at 50% 35%, var(--night-glow) 0%, var(--night) 70%) fixed, var(--night);
  color: #fff;
  font-family: system-ui, sans-serif;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
}

/* Stage and layers ---------------------------------------------------------- */

.stage {
  position: fixed;
  inset: 0;
  cursor: pointer;
}

.starfield,
.sparks,
.layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.starfield { z-index: 0; }
.layer--shapes { z-index: 1; }
.layer--emoji { z-index: 2; }
.sparks { z-index: 3; }

/* Letters in shapes --------------------------------------------------------- */

.shape {
  position: absolute;
  rotate: var(--rotation, 0deg);
  animation: shape-pop 550ms cubic-bezier(0.34, 1.56, 0.64, 1) both;
  filter: drop-shadow(0 0.6vmin 1.4vmin rgba(0, 0, 0, 0.45));
}

.shape svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.shape__letter {
  fill: #fff;
  stroke: rgba(20, 10, 40, 0.45);
  stroke-width: 3px;
  paint-order: stroke fill;
  font-family: var(--letter-font);
  font-weight: 900;
}

.shape--leaving {
  animation: shape-leave 700ms ease-in forwards;
}

@keyframes shape-pop {
  from {
    opacity: 0;
    scale: 0.1;
    rotate: calc(var(--rotation, 0deg) - 45deg);
  }
  to {
    opacity: 1;
    scale: 1;
    rotate: var(--rotation, 0deg);
  }
}

@keyframes shape-leave {
  from {
    opacity: 1;
    scale: 1;
  }
  to {
    opacity: 0;
    scale: 0.4;
  }
}

/* Emoji --------------------------------------------------------------------- */

.emoji {
  position: absolute;
  line-height: 1.25;
  animation: emoji-life var(--lifetime, 5000ms) ease-in-out forwards;
}

.emoji__glyph {
  display: block;
  font-family: var(--emoji-font);
  transform-origin: 50% 0%;
  animation: emoji-swing var(--swing-duration, 1.6s) ease-in-out infinite alternate;
  filter: drop-shadow(0 0.6vmin 1vmin rgba(0, 0, 0, 0.4));
}

@keyframes emoji-life {
  0% {
    opacity: 0;
    scale: 0.6;
  }
  8%,
  88% {
    opacity: 1;
    scale: 1;
  }
  100% {
    opacity: 0;
    scale: 0.9;
  }
}

/* Held by the pause button: fully visible, still swinging, until resumed. */
.emoji--held {
  animation: none;
  opacity: 1;
  scale: 1;
}

.emoji--leaving {
  animation: emoji-leave 700ms ease-in forwards;
}

@keyframes emoji-leave {
  from { opacity: 1; scale: 1; }
  to { opacity: 0; scale: 0.9; }
}

@keyframes emoji-swing {
  from { rotate: -7deg; }
  to { rotate: 7deg; }
}

/* Fullscreen button --------------------------------------------------------- */

.fullscreen-button {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 10;
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  cursor: pointer;
  backdrop-filter: blur(6px);
  transition: background 150ms ease, transform 150ms ease;
}

.fullscreen-button[hidden] {
  display: none;
}

.fullscreen-button:hover {
  background: rgba(255, 255, 255, 0.24);
  transform: scale(1.05);
}

.fullscreen-button:focus-visible {
  outline: 3px solid #8fb4ff;
  outline-offset: 2px;
}

.fullscreen-button svg {
  width: 26px;
  height: 26px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Pause button ------------------------------------------------------------- */

.pause-button {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 10;
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  cursor: pointer;
  opacity: 0.5;
  backdrop-filter: blur(6px);
  transition: background 150ms ease, transform 150ms ease;
}

.pause-button:hover {
  background: rgba(255, 255, 255, 0.24);
  transform: scale(1.05);
}

.pause-button:focus-visible {
  outline: 3px solid #8fb4ff;
  outline-offset: 2px;
}

.pause-button svg {
  width: 24px;
  height: 24px;
  fill: currentColor;
}

.pause-button__play,
.pause-button[aria-pressed="true"] .pause-button__pause {
  display: none;
}

.pause-button[aria-pressed="true"] .pause-button__play {
  display: block;
}

/* Settings dialog ----------------------------------------------------------- */

.settings {
  width: min(420px, calc(100vw - 32px));
  padding: 28px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 20px;
  background: #161b33;
  color: #fff;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.6);
  user-select: text;
  -webkit-user-select: text;
}

.settings::backdrop {
  background: rgba(3, 4, 12, 0.7);
  backdrop-filter: blur(4px);
}

.settings h2 {
  margin: 0 0 8px;
  font-size: 1.6rem;
}

.settings p {
  margin: 0 0 24px;
  color: rgba(255, 255, 255, 0.75);
}

.settings__close {
  padding: 10px 22px;
  border: 0;
  border-radius: 999px;
  background: #6c8cff;
  color: #fff;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.settings__close:hover {
  background: #8aa3ff;
}

.settings__close:focus-visible {
  outline: 3px solid #fff;
  outline-offset: 2px;
}

/* Emoji names (shown per the language picker) ------------------------------ */

.emoji {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.emoji__label {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-top: 0.02em;
  font-family: var(--letter-font);
  font-size: max(20px, 0.2em);
  font-weight: 900;
  line-height: 1.15;
  white-space: nowrap;
  text-shadow: 0 0.06em 0.18em rgba(0, 0, 0, 0.7);
  -webkit-text-stroke: 0.04em rgba(20, 10, 40, 0.45);
  paint-order: stroke fill;
}

.emoji__name { display: none; }
.emoji__name--en { color: #fff; }
.emoji__name--es { color: #ffd84d; }

.stage--en .emoji__name--en,
.stage--es .emoji__name--es {
  display: block;
}

/* Language picker ------------------------------------------------------------ */

.flag-defs {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

.language-picker {
  position: fixed;
  left: 16px;
  bottom: 16px;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
}

.language-button,
.language-menu__option {
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.12);
  cursor: pointer;
  backdrop-filter: blur(6px);
  transition: background 150ms ease, transform 150ms ease, opacity 150ms ease;
}

.language-button {
  width: 48px;
  height: 48px;
  opacity: 0.5;
}

.language-button[aria-expanded="true"] {
  opacity: 1;
}

.language-button:hover,
.language-menu__option:hover {
  background: rgba(255, 255, 255, 0.24);
  transform: scale(1.05);
}

.language-button:focus-visible,
.language-menu__option:focus-visible {
  outline: 3px solid #8fb4ff;
  outline-offset: 2px;
}

.language-button .flag {
  width: 30px;
  height: 20px;
  border-radius: 3px;
}

.language-menu {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 16px;
  background: rgba(22, 27, 51, 0.85);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(8px);
  animation: language-menu-in 150ms ease-out;
}

.language-menu[hidden] {
  display: none;
}

.language-menu__option {
  position: relative;
  width: 72px;
  height: 52px;
  opacity: 0.45;
}

.language-menu__option[aria-pressed="true"] {
  opacity: 1;
  border-color: #8fb4ff;
  background: rgba(143, 180, 255, 0.22);
}

.language-menu__option[aria-pressed="true"]::after {
  content: "✓";
  position: absolute;
  top: -7px;
  right: -7px;
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #6c8cff;
  color: #fff;
  font-size: 13px;
  font-weight: 800;
}

.language-menu__option .flag {
  width: 48px;
  height: 32px;
  border-radius: 4px;
}

@keyframes language-menu-in {
  from { opacity: 0; translate: 0 8px; }
  to { opacity: 1; translate: 0 0; }
}
