@font-face {
  font-family: 'Poppins';
  font-style: normal;
  font-weight: 400 800;
  font-display: swap;
  src: local('Poppins');
}

:root {
  --bg-0: #060815;
  --bg-1: #0b0f22;
  --bg-2: #121736;
  --violet: #7c3aed;
  --violet-2: #a78bfa;
  --cyan: #22d3ee;
  --pink: #f472b6;
  --gold: #fbbf24;
  --green: #34d399;
  --red: #f87171;
  --text: #e9ecff;
  --text-dim: #9aa3c7;
  --panel: rgba(18, 23, 54, 0.82);
  --border: rgba(167, 139, 250, 0.25);
  --shadow-glow: 0 0 24px rgba(124, 58, 237, 0.45);
  --radius-lg: 22px;
  --radius-md: 14px;
  --radius-sm: 10px;
  font-size: 16px;
}

* { box-sizing: border-box; }
/* The `hidden` attribute must always win over a component's own
   `display` declaration (.modal/.nickname-form/.highscore-banner etc.
   all set their own `display` for the visible state, which otherwise
   silently out-prioritizes the browser's default `[hidden]{display:none}`
   UA rule since both are normal-weight author-vs-UA-origin, not a
   specificity tie broken by source order). Toggle visibility with
   `el.hidden` everywhere and this guarantees it actually hides. */
[hidden] { display: none !important; }
html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg-0);
  color: var(--text);
  font-family: 'Poppins', 'Segoe UI', system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

a { color: var(--cyan); }

.app {
  position: relative;
  min-height: 100dvh;
  min-height: 100vh;
  overflow: hidden;
  background:
    radial-gradient(1200px 700px at 15% -10%, rgba(124, 58, 237, 0.28), transparent 60%),
    radial-gradient(900px 600px at 100% 10%, rgba(34, 211, 238, 0.16), transparent 55%),
    linear-gradient(180deg, var(--bg-0), var(--bg-1) 60%, var(--bg-2));
}

.screen {
  display: none;
  min-height: 100dvh;
  min-height: 100vh;
  flex-direction: column;
  position: relative;
}
.screen.active { display: flex; }

/* ---------------- Buttons ---------------- */
.btn {
  font-family: inherit;
  font-weight: 700;
  letter-spacing: 0.04em;
  font-size: 0.95rem;
  padding: 14px 22px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  cursor: pointer;
  color: var(--text);
  background: rgba(255, 255, 255, 0.04);
  transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.12s ease;
  min-height: 44px;
  -webkit-user-select: none;
  user-select: none;
}
.btn:hover { transform: translateY(-1px); background: rgba(255, 255, 255, 0.08); }
.btn:active { transform: translateY(0) scale(0.98); }
.btn-primary {
  background: linear-gradient(135deg, var(--violet), #5b21b6 70%);
  border-color: rgba(167, 139, 250, 0.6);
  color: #fff;
  box-shadow: 0 6px 20px rgba(124, 58, 237, 0.35);
}
.btn-glow { box-shadow: var(--shadow-glow), 0 6px 20px rgba(124, 58, 237, 0.35); }
.btn-secondary {
  background: rgba(34, 211, 238, 0.08);
  border-color: rgba(34, 211, 238, 0.35);
}
.btn-ghost { background: transparent; }
.btn-small { padding: 12px 16px; font-size: 0.85rem; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  font-size: 1.1rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.icon-btn.active { border-color: var(--cyan); box-shadow: 0 0 12px rgba(34, 211, 238, 0.5); }

/* ---------------- Home ---------------- */
.screen-home { align-items: center; justify-content: center; padding: 32px 16px; text-align: center; }
.bg-fx { position: absolute; inset: 0; overflow: hidden; pointer-events: none; z-index: 0; }
.floating-letter {
  position: absolute;
  font-weight: 800;
  color: rgba(167, 139, 250, 0.14);
  font-size: clamp(2.5rem, 8vw, 5rem);
  animation: floatUp linear infinite;
}
.floating-letter:nth-child(1) { left: 6%; top: 110%; animation-duration: 18s; animation-delay: 0s; }
.floating-letter:nth-child(2) { left: 18%; top: 110%; animation-duration: 22s; animation-delay: 2s; }
.floating-letter:nth-child(3) { left: 30%; top: 110%; animation-duration: 16s; animation-delay: 4s; }
.floating-letter:nth-child(4) { left: 44%; top: 110%; animation-duration: 24s; animation-delay: 1s; }
.floating-letter:nth-child(5) { left: 58%; top: 110%; animation-duration: 19s; animation-delay: 3s; }
.floating-letter:nth-child(6) { left: 70%; top: 110%; animation-duration: 21s; animation-delay: 5s; }
.floating-letter:nth-child(7) { left: 82%; top: 110%; animation-duration: 17s; animation-delay: 2.5s; }
.floating-letter:nth-child(8) { left: 92%; top: 110%; animation-duration: 23s; animation-delay: 0.5s; }
.floating-letter:nth-child(9) { left: 50%; top: 110%; animation-duration: 20s; animation-delay: 6s; }
@keyframes floatUp {
  0% { transform: translateY(0) rotate(0deg); opacity: 0; }
  10% { opacity: 1; }
  90% { opacity: 1; }
  100% { transform: translateY(-140vh) rotate(20deg); opacity: 0; }
}

.home-content { position: relative; z-index: 1; display: flex; flex-direction: column; align-items: center; gap: 22px; max-width: 420px; width: 100%; }
.logo-title {
  font-size: clamp(2.6rem, 11vw, 4.2rem);
  font-weight: 800;
  margin: 0;
  letter-spacing: 0.03em;
  color: #fff;
  text-shadow: 0 0 30px rgba(124, 58, 237, 0.7);
}
.logo-title span { color: var(--cyan); text-shadow: 0 0 30px rgba(34, 211, 238, 0.7); }
.logo-tagline { margin: 6px 0 0; color: var(--text-dim); letter-spacing: 0.3em; font-size: 0.8rem; font-weight: 700; }

.stat-pill {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 10px 26px;
}
.stat-pill-label { font-size: 0.65rem; letter-spacing: 0.15em; color: var(--text-dim); }
.stat-pill-value { font-size: 1.6rem; font-weight: 800; color: var(--gold); }

.menu-buttons { display: flex; flex-direction: column; gap: 12px; width: 100%; }

/* ---------------- Gameplay ---------------- */
.screen-game { padding: 10px 12px 16px; gap: 10px; }
.hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 14px;
}
.hud-stat { display: flex; flex-direction: column; align-items: center; min-width: 54px; }
.hud-label { font-size: 0.6rem; letter-spacing: 0.12em; color: var(--text-dim); }
.hud-value { font-size: 1.15rem; font-weight: 800; }
#hud-combo { color: var(--pink); transition: transform 0.15s ease; }
#hud-combo-wrap.pulse #hud-combo { transform: scale(1.35); }
.hud-actions { display: flex; gap: 8px; }

.bars { display: flex; flex-direction: column; gap: 6px; }
.timer-bar-wrap { height: 10px; border-radius: 6px; background: rgba(255, 255, 255, 0.08); overflow: hidden; }
.timer-bar { height: 100%; width: 100%; background: linear-gradient(90deg, var(--cyan), var(--violet-2)); transition: width 0.2s linear, background 0.3s ease; }
.timer-bar.warn { background: linear-gradient(90deg, var(--red), var(--gold)); animation: pulseWarn 0.6s ease-in-out infinite; }
@keyframes pulseWarn { 0%, 100% { filter: brightness(1); } 50% { filter: brightness(1.5); } }

.stability-bar-wrap { display: flex; align-items: center; gap: 8px; }
.bar-label { font-size: 0.6rem; letter-spacing: 0.12em; color: var(--text-dim); width: 70px; }
.stability-bar-track { flex: 1; height: 8px; border-radius: 6px; background: rgba(255, 255, 255, 0.08); overflow: hidden; }
.stability-bar { height: 100%; width: 100%; background: linear-gradient(90deg, var(--green), var(--cyan)); transition: width 0.25s ease, background 0.25s ease; }

.tower-area {
  position: relative;
  flex: 1;
  min-height: 220px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: radial-gradient(circle at 50% 100%, rgba(124, 58, 237, 0.16), transparent 65%), rgba(6, 8, 21, 0.55);
  overflow: hidden;
}
.fx-canvas { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 3; }
.tower-scroll {
  position: absolute;
  inset: 0 0 18px 0;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  overflow-y: auto;
  overflow-x: hidden;
  flex-direction: column-reverse;
  scrollbar-width: none;
}
.tower-scroll::-webkit-scrollbar { display: none; }
.tower-stack { display: flex; flex-direction: column-reverse; align-items: center; gap: 4px; padding: 8px 10px 0; width: 100%; }
.tower-base {
  position: absolute;
  left: 10%;
  right: 10%;
  bottom: 0;
  height: 14px;
  border-radius: 8px;
  background: linear-gradient(180deg, rgba(124, 58, 237, 0.5), rgba(124, 58, 237, 0.15));
  box-shadow: 0 0 20px rgba(124, 58, 237, 0.4);
}

.tower-block {
  min-width: 90px;
  max-width: 92%;
  padding: 8px 16px;
  text-align: center;
  font-weight: 800;
  letter-spacing: 0.08em;
  border-radius: 10px;
  color: #0b0f22;
  background: linear-gradient(135deg, var(--cyan), var(--violet-2));
  box-shadow: 0 4px 14px rgba(34, 211, 238, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.5);
  transform-origin: bottom center;
  animation: blockLand 0.35s cubic-bezier(0.2, 1.4, 0.4, 1);
}
.tower-block.gold {
  background: linear-gradient(135deg, #fde68a, var(--gold));
  box-shadow: 0 4px 18px rgba(251, 191, 36, 0.55), inset 0 1px 0 rgba(255, 255, 255, 0.6);
}
.tower-block.perfect { outline: 2px solid #fff; }
@keyframes blockLand {
  0% { transform: scale(0.4) translateY(-30px); opacity: 0; }
  60% { transform: scale(1.08) translateY(4px); opacity: 1; }
  100% { transform: scale(1) translateY(0); }
}

.tower-area.shake { animation: towerShake 0.35s ease; }
@keyframes towerShake {
  0%, 100% { transform: translateX(0) rotate(0deg); }
  20% { transform: translateX(-6px) rotate(-0.6deg); }
  40% { transform: translateX(5px) rotate(0.5deg); }
  60% { transform: translateX(-4px) rotate(-0.4deg); }
  80% { transform: translateX(3px) rotate(0.3deg); }
}
.tower-area.wobble .tower-stack { animation: towerWobble 0.5s ease infinite; }
@keyframes towerWobble {
  0%, 100% { transform: rotate(0deg); }
  50% { transform: rotate(1.4deg); }
}
.tower-area.collapsing .tower-stack { animation: towerCollapse 0.9s ease forwards; }
@keyframes towerCollapse {
  0% { transform: translateY(0) rotate(0deg); opacity: 1; }
  40% { transform: translateY(10px) rotate(6deg); opacity: 1; }
  100% { transform: translateY(220px) rotate(24deg); opacity: 0; }
}

.banner-layer { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; pointer-events: none; z-index: 4; }
.milestone-banner, .special-banner, .powerup-banner {
  font-weight: 800;
  padding: 10px 24px;
  border-radius: 999px;
  font-size: 1.1rem;
  letter-spacing: 0.08em;
  color: #0b0f22;
  background: linear-gradient(135deg, var(--gold), var(--pink));
  box-shadow: 0 0 30px rgba(251, 191, 36, 0.6);
  animation: bannerPop 1.1s ease forwards;
}
@keyframes bannerPop {
  0% { transform: scale(0.4); opacity: 0; }
  20% { transform: scale(1.15); opacity: 1; }
  30% { transform: scale(1); }
  80% { opacity: 1; }
  100% { transform: scale(1.05) translateY(-30px); opacity: 0; }
}

.word-preview {
  min-height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  font-weight: 800;
  letter-spacing: 0.18em;
  color: var(--text);
}
.word-preview.invalid-shake { animation: previewShake 0.35s ease; color: var(--red); }
@keyframes previewShake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-8px); }
  75% { transform: translateX(8px); }
}

.letters-row { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; padding: 4px 0; }
.letter-tile {
  min-width: 48px;
  min-height: 48px;
  padding: 0 4px;
  border-radius: 12px;
  border: none;
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--text);
  background: linear-gradient(160deg, rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0.02));
  border: 1px solid var(--border);
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.15);
  cursor: pointer;
  transition: transform 0.08s ease, opacity 0.15s ease;
}
.letter-tile:active { transform: translateY(2px); }
.letter-tile.used { opacity: 0.28; pointer-events: none; transform: scale(0.92); }
.letter-tile.special-gold { background: linear-gradient(160deg, #fde68a, var(--gold)); color: #3b2b00; box-shadow: 0 0 16px rgba(251, 191, 36, 0.7), 0 4px 0 rgba(120, 80, 0, 0.4); }
.letter-tile.special-time { background: linear-gradient(160deg, #a5f3fc, var(--cyan)); color: #002b33; box-shadow: 0 0 16px rgba(34, 211, 238, 0.7), 0 4px 0 rgba(0, 70, 80, 0.4); }
.letter-tile.special-fire { background: linear-gradient(160deg, #fecaca, #ef4444); color: #3b0000; box-shadow: 0 0 16px rgba(239, 68, 68, 0.7), 0 4px 0 rgba(90, 0, 0, 0.4); }

.controls-row { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }

/* ---------------- Game Over ---------------- */
.screen-gameover { align-items: center; justify-content: center; padding: 24px 14px; }
.gameover-panel {
  width: 100%;
  max-width: 440px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 26px 22px;
  text-align: center;
  box-shadow: var(--shadow-glow);
}
.gameover-title { margin: 0 0 4px; font-size: 1.8rem; font-weight: 800; color: var(--pink); text-shadow: 0 0 20px rgba(244, 114, 182, 0.5); }
.gameover-subtitle { margin: 0 0 14px; color: var(--text-dim); }
.highscore-banner {
  display: inline-block;
  margin-bottom: 14px;
  padding: 8px 18px;
  border-radius: 999px;
  font-weight: 800;
  background: linear-gradient(135deg, var(--gold), var(--pink));
  color: #0b0f22;
  animation: bannerPop 1.6s ease infinite;
}
.gameover-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 18px; }
.gameover-stats div { background: rgba(255, 255, 255, 0.04); border-radius: 10px; padding: 10px; }
.gameover-stats span { display: block; font-size: 0.6rem; letter-spacing: 0.1em; color: var(--text-dim); }
.gameover-stats strong { font-size: 1.2rem; }

.nickname-form { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.nickname-label { font-size: 0.7rem; letter-spacing: 0.12em; color: var(--text-dim); text-align: left; }
#nickname-input {
  font-family: inherit;
  font-size: 1rem;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
}
.nickname-hint { font-size: 0.65rem; color: var(--text-dim); margin: 0; text-align: left; }
.submitted-rank { margin: 8px 0; font-weight: 700; color: var(--cyan); }

.gameover-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 6px; }

/* ---------------- Modals ---------------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(3, 4, 12, 0.72); backdrop-filter: blur(3px); z-index: 20; }
.modal { position: fixed; inset: 0; z-index: 21; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal-panel {
  position: relative;
  width: 100%;
  max-width: 440px;
  max-height: 82vh;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 26px 22px;
  box-shadow: var(--shadow-glow);
}
.modal-close { position: absolute; top: 14px; right: 14px; background: transparent; border: none; color: var(--text-dim); font-size: 1.2rem; cursor: pointer; }
.modal-panel h3 { margin-top: 0; letter-spacing: 0.08em; }
.howto-steps { padding-left: 20px; display: flex; flex-direction: column; gap: 10px; }
.howto-extra { color: var(--text-dim); font-size: 0.9rem; }

.lb-tabs { display: flex; gap: 6px; margin-bottom: 14px; flex-wrap: wrap; }
.lb-tab {
  flex: 1;
  min-width: 70px;
  padding: 8px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-dim);
  font-weight: 700;
  font-size: 0.75rem;
  cursor: pointer;
}
.lb-tab.active { background: rgba(124, 58, 237, 0.3); color: #fff; }
.lb-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; max-height: 320px; overflow-y: auto; }
.lb-list li { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; background: rgba(255, 255, 255, 0.03); }
.lb-list li.me { background: rgba(124, 58, 237, 0.25); border: 1px solid rgba(167, 139, 250, 0.5); }
.lb-rank { width: 26px; font-weight: 800; color: var(--text-dim); }
.lb-name { flex: 1; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-score { font-weight: 800; color: var(--gold); }
.lb-empty { justify-content: center; color: var(--text-dim); }

.ad-slot { min-height: 0; }
.ad-slot-home, .ad-slot-gameover, .ad-slot-leaderboard { margin-top: 10px; }

/* ---------------- SEO content / footer ---------------- */
.seo-content {
  max-width: 780px;
  margin: 0 auto;
  padding: 40px 20px 20px;
  color: var(--text-dim);
  line-height: 1.7;
}
.seo-content h2, .seo-content h3 { color: var(--text); }
.seo-content dt { font-weight: 700; color: var(--text); margin-top: 10px; }
.seo-content dd { margin: 2px 0 0; }
.site-footer { text-align: center; color: var(--text-dim); font-size: 0.8rem; padding: 20px; }
