@import url('https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700;900&display=swap');

:root {
  --bg-deep: #050508;
  --glass: rgba(255, 255, 255, 0.06);
  --glass-border: rgba(255, 255, 255, 0.12);
  --glow-pink: #ff2d95;
  --glow-cyan: #00f5ff;
  --glow-violet: #a855f7;
  --glow-amber: #fbbf24;
  --text: #f4f4f8;
  --muted: rgba(244, 244, 248, 0.55);
}

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

html {
  scroll-behavior: smooth;
}

body {
  min-height: 100vh;
  font-family: 'Roboto', system-ui, sans-serif;
  background: var(--bg-deep);
  color: var(--text);
  overflow-x: hidden;
}

/* ─── Animated background ─── */
.bg-canvas {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
}

.bg-mesh {
  position: fixed;
  inset: 0;
  z-index: 0;
  background:
    radial-gradient(ellipse 80% 60% at 20% 10%, rgba(168, 85, 247, 0.35) 0%, transparent 55%),
    radial-gradient(ellipse 70% 50% at 85% 20%, rgba(0, 245, 255, 0.2) 0%, transparent 50%),
    radial-gradient(ellipse 60% 70% at 50% 90%, rgba(255, 45, 149, 0.25) 0%, transparent 55%),
    radial-gradient(ellipse 50% 40% at 70% 60%, rgba(251, 191, 36, 0.12) 0%, transparent 45%);
  animation: meshShift 18s ease-in-out infinite alternate;
}

.bg-orbs {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
}

.orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.5;
  animation: orbFloat 20s ease-in-out infinite;
}

.orb--1 {
  width: 420px;
  height: 420px;
  background: var(--glow-violet);
  top: -10%;
  left: -5%;
  animation-delay: 0s;
}

.orb--2 {
  width: 320px;
  height: 320px;
  background: var(--glow-cyan);
  top: 40%;
  right: -8%;
  animation-delay: -7s;
}

.orb--3 {
  width: 380px;
  height: 380px;
  background: var(--glow-pink);
  bottom: -15%;
  left: 30%;
  animation-delay: -14s;
}

@keyframes meshShift {
  0% { opacity: 0.85; transform: scale(1); }
  100% { opacity: 1; transform: scale(1.08); }
}

@keyframes orbFloat {
  0%, 100% { transform: translate(0, 0) scale(1); }
  33% { transform: translate(40px, -30px) scale(1.05); }
  66% { transform: translate(-25px, 25px) scale(0.95); }
}

/* ─── Layout ─── */
.page {
  position: relative;
  z-index: 1;
  max-width: 720px;
  margin: 0 auto;
  padding: clamp(2rem, 6vw, 4rem) clamp(1.25rem, 4vw, 2rem);
  padding-left: max(1.25rem, env(safe-area-inset-left));
  padding-right: max(1.25rem, env(safe-area-inset-right));
  padding-bottom: max(2rem, env(safe-area-inset-bottom));
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.page--cloud {
  max-width: 100%;
  justify-content: flex-start;
  padding-top: clamp(1.5rem, 4vw, 2.5rem);
}

.page--cloud .title,
.page--cloud .hint {
  animation: fadeSlideDown 0.9s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.page--cloud .hint {
  animation-delay: 0.12s;
}

@keyframes fadeSlideDown {
  from {
    opacity: 0;
    transform: translateY(-18px);
  }
}

/* ─── Typography ─── */
.title {
  font-family: 'Roboto', sans-serif;
  font-size: clamp(2.5rem, 8vw, 4rem);
  font-weight: 800;
  line-height: 1.05;
  letter-spacing: -0.03em;
  margin-bottom: 0.75rem;
  background: linear-gradient(135deg, #fff 0%, #fff 40%, var(--glow-cyan) 70%, var(--glow-pink) 100%);
  background-size: 200% auto;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  animation: titleShine 6s linear infinite;
}

.title--sm {
  font-size: clamp(1.75rem, 5vw, 2.75rem);
  text-align: center;
}

@keyframes titleShine {
  0% { background-position: 0% center; }
  100% { background-position: 200% center; }
}

.hint {
  font-size: 1.05rem;
  font-weight: 300;
  color: var(--muted);
  margin-bottom: 2.5rem;
  max-width: 28ch;
  line-height: 1.6;
}

.hint--status {
  margin-top: -1rem;
  margin-bottom: 1.25rem;
  max-width: none;
  font-size: 0.95rem;
}

.hint--error {
  color: #fca5a5;
}

.page--cloud .hint {
  text-align: center;
  max-width: none;
  margin-left: auto;
  margin-right: auto;
}

/* ─── Glass card ─── */
.card {
  background: var(--glass);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border: 1px solid var(--glass-border);
  border-radius: 24px;
  padding: clamp(1.5rem, 4vw, 2rem);
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.04) inset,
    0 25px 80px rgba(0, 0, 0, 0.5),
    0 0 60px rgba(168, 85, 247, 0.08);
  animation: cardIn 0.8s cubic-bezier(0.16, 1, 0.3, 1) both;
}

@keyframes cardIn {
  from {
    opacity: 0;
    transform: translateY(30px) scale(0.96);
  }
}

/* ─── Form ─── */
.form {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.input-wrap {
  flex: 1;
  min-width: 220px;
  position: relative;
}

.input-wrap::before {
  content: '';
  position: absolute;
  inset: -2px;
  border-radius: 16px;
  background: linear-gradient(135deg, var(--glow-cyan), var(--glow-pink), var(--glow-violet));
  opacity: 0;
  transition: opacity 0.35s ease;
  z-index: 0;
}

.input-wrap:focus-within::before {
  opacity: 1;
  animation: borderGlow 2s linear infinite;
}

@keyframes borderGlow {
  0%, 100% { filter: hue-rotate(0deg); }
  50% { filter: hue-rotate(30deg); }
}

.form input {
  position: relative;
  z-index: 1;
  width: 100%;
  padding: 1rem 1.25rem;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 14px;
  background: rgba(5, 5, 8, 0.85);
  color: var(--text);
  font-family: inherit;
  font-size: 1.1rem;
  font-weight: 400;
  transition: background 0.3s;
}

.form input::placeholder {
  color: rgba(244, 244, 248, 0.3);
}

.form input:focus {
  outline: none;
  background: rgba(5, 5, 8, 0.95);
}

.btn-glow {
  position: relative;
  padding: 1rem 1.75rem;
  border: none;
  border-radius: 14px;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 600;
  color: #050508;
  cursor: pointer;
  overflow: hidden;
  background: linear-gradient(135deg, var(--glow-cyan), #7dd3fc);
  box-shadow: 0 0 30px rgba(0, 245, 255, 0.4);
  transition: transform 0.2s, box-shadow 0.3s;
  animation: btnPulse 3s ease-in-out infinite;
}

@keyframes btnPulse {
  0%, 100% { box-shadow: 0 0 24px rgba(0, 245, 255, 0.35); }
  50% { box-shadow: 0 0 40px rgba(0, 245, 255, 0.55); }
}

.btn-glow::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(105deg, transparent 40%, rgba(255, 255, 255, 0.5) 50%, transparent 60%);
  transform: translateX(-100%);
  transition: transform 0.6s;
}

.btn-glow:hover {
  transform: translateY(-2px) scale(1.02);
  box-shadow: 0 0 50px rgba(0, 245, 255, 0.6);
}

.btn-glow:hover::after {
  transform: translateX(100%);
}

.btn-glow:active {
  transform: scale(0.98);
}

/* ─── Toast message ─── */
.message {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-top: 1.25rem;
  padding: 0.85rem 1.1rem;
  border-radius: 12px;
  font-weight: 500;
  background: rgba(34, 197, 94, 0.12);
  border: 1px solid rgba(34, 197, 94, 0.35);
  color: #86efac;
  animation: toastIn 0.5s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.message--error {
  background: rgba(248, 113, 113, 0.12);
  border-color: rgba(248, 113, 113, 0.4);
  color: #fca5a5;
}

.message[hidden] {
  display: none !important;
}

.message-icon {
  font-size: 1.2rem;
}

@keyframes toastIn {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.95);
  }
}

/* ─── Stats strip ─── */
.stats {
  display: flex;
  gap: 1rem;
  margin-top: 1.5rem;
  flex-wrap: wrap;
}

.stat-pill {
  flex: 1;
  min-width: 120px;
  padding: 0.75rem 1rem;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.stat-pill strong {
  display: block;
  font-family: 'Roboto', sans-serif;
  font-size: 1.5rem;
  background: linear-gradient(90deg, var(--glow-cyan), var(--glow-pink));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.stat-pill span {
  font-size: 0.8rem;
  color: var(--muted);
}

/* ─── Nav links ─── */
.nav {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: center;
  margin-top: 2rem;
}

.page--cloud .nav {
  animation: fadeSlideDown 0.9s cubic-bezier(0.16, 1, 0.3, 1) 0.35s both;
}

.nav--center {
  justify-content: center;
}

.btn-link {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.85rem 1.5rem;
  border-radius: 100px;
  font-family: inherit;
  font-weight: 600;
  font-size: 0.95rem;
  text-decoration: none;
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  transition: all 0.3s ease;
  cursor: pointer;
}

button.btn-link {
  appearance: none;
}

.btn-link:hover {
  background: rgba(0, 245, 255, 0.12);
  border-color: rgba(0, 245, 255, 0.4);
  box-shadow: 0 0 30px rgba(0, 245, 255, 0.2);
  transform: translateX(4px);
}

.btn-link--ghost {
  background: transparent;
  border-color: rgba(248, 113, 113, 0.3);
  color: #fca5a5;
}

.btn-link--ghost:hover {
  background: rgba(248, 113, 113, 0.1);
  border-color: rgba(248, 113, 113, 0.5);
  box-shadow: 0 0 20px rgba(248, 113, 113, 0.15);
  transform: none;
}

/* ─── Tag cloud arena ─── */
.cloud-arena {
  position: relative;
  width: 100%;
  max-width: 1000px;
  margin: 0 auto 2rem;
  aspect-ratio: 1;
  min-height: min(65vh, 560px);
  max-height: min(85vh, 820px);
  animation: arenaIn 1.1s cubic-bezier(0.16, 1, 0.3, 1) 0.2s both;
}

@keyframes arenaIn {
  from {
    opacity: 0;
    transform: scale(0.88);
  }
}

.cloud-ring {
  position: absolute;
  inset: 50%;
  width: 90%;
  height: 90%;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  border: 1px dashed rgba(255, 255, 255, 0.06);
  opacity: 0.4;
  animation: ringSpin 90s linear infinite;
}

.cloud-ring--inner {
  width: 55%;
  height: 55%;
  opacity: 0.25;
  animation: ringSpin 70s linear infinite reverse;
}

@keyframes ringSpin {
  from { transform: translate(-50%, -50%) rotate(0deg); }
  to { transform: translate(-50%, -50%) rotate(360deg); }
}

.tag-cloud {
  position: absolute;
  inset: 0;
}

.tag-measure-layer {
  position: absolute;
  left: 50%;
  top: 50%;
  visibility: hidden;
  pointer-events: none;
}

.tag--measure {
  position: relative;
  left: auto;
  top: auto;
  transform: scale(var(--tag-scale, 1));
  animation: none;
}

.tag--measure .tag-count {
  opacity: 1;
  transform: scale(1);
}

.tag {
  --tag-scale: 1;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%) translate(var(--tx, 0), var(--ty, 0)) scale(var(--tag-scale, 1));
  font-family: 'Roboto', sans-serif;
  font-weight: 800;
  white-space: nowrap;
  cursor: default;
  user-select: none;
  padding: 0.2em 0.45em;
  line-height: 1.2;
  background: linear-gradient(120deg, var(--tag-c1), var(--tag-c2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  will-change: transform, filter;
  transition: font-size 0.4s ease, opacity 0.4s ease;
  animation:
    tagFadeIn 0.4s ease both,
    tagDrift var(--float-dur, 20s) ease-in-out infinite,
    tagGlowPulse var(--pulse-dur, 4s) ease-in-out infinite;
  animation-delay: var(--enter-delay, 0s), var(--float-delay, 0s), var(--pulse-delay, 0s);
}

.tag--grown {
  z-index: 2;
}

.tag--grown .tag-count {
  opacity: 1;
  transform: scale(1);
  background: rgba(0, 245, 255, 0.25);
  border: 1px solid rgba(0, 245, 255, 0.4);
}

.tag:hover {
  z-index: 10;
  opacity: 0.92;
}

.tag-count {
  position: absolute;
  top: -0.5em;
  right: -0.3em;
  font-family: 'Roboto', sans-serif;
  font-size: 0.35em;
  font-weight: 600;
  padding: 0.15em 0.45em;
  border-radius: 100px;
  background: rgba(255, 255, 255, 0.15);
  -webkit-text-fill-color: #fff;
  backdrop-filter: blur(8px);
  opacity: 0;
  transform: scale(0.8);
  transition: opacity 0.25s, transform 0.25s;
}

.tag:hover .tag-count,
.tag:focus-visible .tag-count {
  opacity: 1;
  transform: scale(1);
}

@keyframes tagFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* Плавное покачивание + лёгкий «вдох» масштаба */
@keyframes tagDrift {
  0%, 100% {
    transform: translate(-50%, -50%) translate(var(--tx, 0), var(--ty, 0))
      scale(calc(var(--tag-scale, 1) * 1));
  }
  25% {
    transform: translate(-50%, -50%)
      translate(calc(var(--tx, 0) + var(--fx, 5px)), calc(var(--ty, 0) + var(--fy, -6px)))
      scale(calc(var(--tag-scale, 1) * 1.03));
  }
  50% {
    transform: translate(-50%, -50%)
      translate(calc(var(--tx, 0) + var(--fx2, 2px)), calc(var(--ty, 0) + var(--fy2, 5px)))
      scale(calc(var(--tag-scale, 1) * 1.05));
  }
  75% {
    transform: translate(-50%, -50%)
      translate(calc(var(--tx, 0) - var(--fx, 5px)), calc(var(--ty, 0) + var(--fy2, 2px)))
      scale(calc(var(--tag-scale, 1) * 1.03));
  }
}

/* Мягкая пульсация яркости */
@keyframes tagGlowPulse {
  0%, 100% {
    filter: brightness(1) saturate(1);
  }
  50% {
    filter: brightness(1.18) saturate(1.12);
  }
}

/* ─── Empty state ─── */
.empty-state {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 2rem;
  animation: cardIn 0.6s ease both;
}

.empty-state[hidden] {
  display: none !important;
}

.empty-icon {
  font-size: 4rem;
  margin-bottom: 1rem;
  animation: emptyBob 3s ease-in-out infinite;
}

@keyframes emptyBob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-12px); }
}

.empty-state p {
  color: var(--muted);
  font-size: 1.1rem;
  margin-bottom: 1.5rem;
}

.empty-state a {
  color: var(--glow-cyan);
  text-decoration: none;
  font-weight: 600;
  padding: 0.75rem 1.5rem;
  border-radius: 100px;
  border: 1px solid rgba(0, 245, 255, 0.4);
  transition: all 0.3s;
}

.empty-state a:hover {
  background: rgba(0, 245, 255, 0.12);
  box-shadow: 0 0 30px rgba(0, 245, 255, 0.25);
}

/* ─── Confetti canvas ─── */
#confetti {
  position: fixed;
  inset: 0;
  z-index: 100;
  pointer-events: none;
}

/* ─── Responsive ─── */
@media (max-width: 768px) {
  .orb--1 {
    width: 260px;
    height: 260px;
  }

  .orb--2 {
    width: 200px;
    height: 200px;
  }

  .orb--3 {
    width: 240px;
    height: 240px;
  }

  .title {
    font-size: clamp(2rem, 10vw, 3rem);
  }

  .hint {
    font-size: 0.95rem;
    margin-bottom: 1.75rem;
  }

  .card {
    border-radius: 20px;
    padding: 1.25rem;
  }

  .btn-link,
  .btn-glow {
    min-height: 48px;
  }

  .cloud-arena {
    min-height: min(62dvh, 480px);
    max-height: min(80dvh, 620px);
  }

  .tag-count {
    opacity: 1;
    transform: scale(1);
    animation: none;
  }

  .tag {
    -webkit-tap-highlight-color: transparent;
  }
}

@media (max-width: 520px) {
  .page {
    padding-top: max(1.5rem, env(safe-area-inset-top));
    justify-content: flex-start;
  }

  .page:not(.page--cloud) {
    padding-top: clamp(2.5rem, 12vh, 4rem);
  }

  .form {
    flex-direction: column;
  }

  .input-wrap {
    min-width: 100%;
  }

  .btn-glow {
    width: 100%;
  }

  .stats {
    flex-direction: column;
  }

  .stat-pill {
    min-width: 100%;
  }

  .nav {
    flex-direction: column;
    width: 100%;
  }

  .nav .btn-link {
    width: 100%;
    justify-content: center;
  }

  .cloud-arena {
    aspect-ratio: 1;
    min-height: 62dvh;
    max-height: none;
    margin-bottom: 1rem;
  }

  .page--cloud .title--sm {
    font-size: 1.65rem;
  }

  .page--cloud .hint {
    margin-bottom: 1rem;
  }

  .empty-icon {
    font-size: 3rem;
  }

  .empty-state p {
    font-size: 1rem;
  }
}

@media (max-width: 380px) {
  .title {
    font-size: 1.75rem;
  }

  .form input {
    font-size: 1rem;
    padding: 0.9rem 1rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .tag,
  .cloud-ring,
  .title,
  .card,
  .cloud-arena {
    animation: none !important;
  }

  .tag {
    transition: font-size 0.3s ease;
  }
}

@media (hover: none) and (pointer: coarse) {
  .tag:hover {
    opacity: 1;
  }

  .btn-link:hover {
    transform: none;
  }
}
