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

:root {
  --bg: #0f0e17;
  --card: #1a1828;
  --accent: #ff8906;
  --accent2: #e53170;
  --text: #fffffe;
  --muted: #a7a9be;
  --tile: #232136;
  --tile-border: #3d3a5a;
  --tile-hover: #2d2a4a;
  --correct: #3da34e;
}

html,
body {
  width: 100%;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'Nunito', sans-serif;
  overflow-x: hidden;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse 60% 50% at 20% 30%, rgba(229, 49, 112, 0.12) 0%, transparent 70%),
    radial-gradient(ellipse 50% 40% at 80% 70%, rgba(255, 137, 6, 0.10) 0%, transparent 70%);
  pointer-events: none;
  z-index: 0;
}

#app {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem 1rem;
}

.logo {
  font-family: 'Fredoka One', cursive;
  font-size: clamp(2rem, 6vw, 3.5rem);
  letter-spacing: 0.02em;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent2) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 0.25rem;
}

.tagline {
  color: var(--muted);
  font-size: 0.95rem;
  margin-bottom: 2.5rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.intro-card {
  background: var(--card);
  border: 1px solid var(--tile-border);
  border-radius: 20px;
  padding: 2.5rem 2rem;
  max-width: 480px;
  width: 100%;
  text-align: center;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.5);
}

.intro-card h2 {
  font-family: 'Fredoka One', cursive;
  font-size: 1.8rem;
  margin-bottom: 1rem;
  color: var(--accent);
}

.intro-card p {
  color: var(--muted);
  line-height: 1.7;
  margin-bottom: 1.5rem;
}

.player-form {
  display: grid;
  gap: 0.55rem;
  margin-bottom: 1.5rem;
  text-align: left;
}

.player-form label {
  color: var(--text);
  font-size: 0.85rem;
  font-weight: 900;
}

.player-name-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.5rem;
}

.player-name-row input {
  min-width: 0;
  padding: 0.7rem 0.85rem;
  border: 2px solid var(--tile-border);
  border-radius: 10px;
  background: var(--tile);
  color: var(--text);
  font-family: 'Nunito', sans-serif;
  font-size: 0.95rem;
  font-weight: 800;
}

.player-name-row input:focus {
  border-color: var(--accent);
  outline: none;
  box-shadow: 0 0 0 3px rgba(255, 137, 6, 0.18);
}

.player-save {
  padding: 0.7rem 0.9rem;
  border: 2px solid var(--tile-border);
  border-radius: 10px;
  background: var(--tile);
  color: var(--muted);
  font-family: 'Nunito', sans-serif;
  font-weight: 900;
  cursor: pointer;
  transition: all 0.2s;
}

.player-save:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.player-save:disabled {
  cursor: default;
  opacity: 0.62;
}

.player-form-end {
  max-width: 460px;
  margin: 0.85rem auto 0;
}

.difficulty {
  display: flex;
  gap: 0.75rem;
  justify-content: center;
  margin-bottom: 1.75rem;
}

.diff-btn {
  padding: 0.5rem 1.25rem;
  border-radius: 999px;
  border: 2px solid var(--tile-border);
  background: var(--tile);
  color: var(--muted);
  font-family: 'Nunito', sans-serif;
  font-weight: 700;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.2s;
}

.diff-btn:hover,
.diff-btn.active {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(255, 137, 6, 0.08);
}

.start-btn {
  width: 100%;
  padding: 1rem;
  border-radius: 12px;
  border: none;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: #fff;
  font-family: 'Fredoka One', cursive;
  font-size: 1.3rem;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  box-shadow: 0 4px 20px rgba(229, 49, 112, 0.35);
}

.start-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 30px rgba(229, 49, 112, 0.5);
}

.start-btn:active {
  transform: translateY(0);
}

.leaderboard {
  margin-top: 1.75rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--tile-border);
  text-align: left;
}

.leaderboard-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.75rem;
}

.leaderboard-header h3 {
  font-family: 'Fredoka One', cursive;
  font-size: 1.05rem;
  color: var(--accent);
}

.leaderboard-refresh {
  padding: 0.35rem 0.75rem;
  border: 1px solid var(--tile-border);
  border-radius: 999px;
  background: var(--tile);
  color: var(--muted);
  font-family: 'Nunito', sans-serif;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
}

.leaderboard-refresh:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.leaderboard-list {
  display: grid;
  gap: 0.5rem;
  list-style-position: inside;
}

.leaderboard-entry {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.15rem 0.75rem;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--tile-border);
  border-radius: 8px;
  background: rgba(35, 33, 54, 0.72);
  color: var(--muted);
  font-size: 0.82rem;
}

.leaderboard-name {
  color: var(--text);
  font-weight: 900;
  min-width: 0;
  overflow-wrap: anywhere;
}

.leaderboard-score {
  color: var(--accent);
  font-weight: 900;
  white-space: nowrap;
}

.leaderboard-detail {
  grid-column: 1 / -1;
}

.leaderboard-empty {
  padding: 0.75rem;
  border: 1px dashed var(--tile-border);
  border-radius: 8px;
  color: var(--muted);
  font-size: 0.85rem;
  list-style: none;
  text-align: center;
}

#game-area {
  display: none;
  width: 100%;
  max-width: 520px;
}

.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
  padding: 0 0.25rem;
}

.game-header h3 {
  font-family: 'Fredoka One', cursive;
  font-size: 1.3rem;
  color: var(--accent);
}

.stats {
  display: flex;
  gap: 1.25rem;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--muted);
}

.stats span {
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.stats .val {
  color: var(--text);
}

#puzzle-grid {
  display: grid;
  gap: 6px;
  margin: 0 auto 1.25rem;
  background: var(--card);
  border: 1px solid var(--tile-border);
  border-radius: 16px;
  padding: 12px;
  box-shadow: 0 6px 30px rgba(0, 0, 0, 0.4);
}

.tile {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--tile);
  border: 2px solid var(--tile-border);
  border-radius: 10px;
  font-family: 'Fredoka One', cursive;
  font-size: clamp(1rem, 4vw, 1.6rem);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
  user-select: none;
  color: var(--text);
}

.tile:hover {
  background: var(--tile-hover);
  border-color: var(--accent);
}

.tile:active {
  transform: scale(0.96);
}

.tile.empty {
  background: rgba(255, 137, 6, 0.05);
  border: 2px dashed rgba(255, 137, 6, 0.2);
  cursor: default;
}

.tile.empty:hover {
  background: rgba(255, 137, 6, 0.05);
  border-color: rgba(255, 137, 6, 0.2);
}

.tile.correct {
  border-color: var(--correct);
  color: var(--correct);
}

.game-actions {
  display: flex;
  gap: 0.75rem;
}

.action-btn {
  flex: 1;
  padding: 0.7rem;
  border-radius: 10px;
  border: 2px solid var(--tile-border);
  background: var(--tile);
  color: var(--muted);
  font-family: 'Nunito', sans-serif;
  font-weight: 700;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.2s;
}

.action-btn:hover {
  border-color: var(--accent2);
  color: var(--accent2);
}

.progress-bar-wrap {
  margin-bottom: 1rem;
  background: var(--tile);
  border-radius: 999px;
  height: 8px;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  border-radius: 999px;
  transition: width 0.4s ease;
  width: 0%;
}

#rickroll {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 9999;
  background:
    radial-gradient(ellipse 58% 46% at 22% 18%, rgba(229, 49, 112, 0.22) 0%, transparent 68%),
    radial-gradient(ellipse 52% 44% at 82% 78%, rgba(255, 137, 6, 0.18) 0%, transparent 70%),
    linear-gradient(180deg, #161421 0%, var(--bg) 48%, #09080d 100%);
  flex-direction: column;
  align-items: center;
  justify-content: center;
  animation: flashIn 0.1s ease;
}

#rickroll::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    linear-gradient(90deg, rgba(15, 14, 23, 0.88), rgba(15, 14, 23, 0.22) 28%, rgba(15, 14, 23, 0.22) 72%, rgba(15, 14, 23, 0.88)),
    radial-gradient(circle at 50% 100%, rgba(229, 49, 112, 0.16), transparent 42%);
  pointer-events: none;
}

#rickroll.active {
  display: flex;
}

@keyframes flashIn {
  0% {
    opacity: 0;
    transform: scale(1.05);
  }

  100% {
    opacity: 1;
    transform: scale(1);
  }
}

#rickroll-inner {
  position: relative;
  z-index: 1;
  width: min(100vw, 56.25dvh);
  height: 100dvh;
  padding: 0;
  box-shadow: 0 0 70px rgba(229, 49, 112, 0.16);
}

#yt-frame {
  display: block;
  width: 100%;
  height: 100%;
  aspect-ratio: 9/16;
  border: none;
  border-radius: 0;
  overflow: hidden;
}

.rickroll-panel {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 3;
  padding: clamp(4rem, 11vh, 7.5rem) clamp(1rem, 5vw, 2.5rem) clamp(1rem, 3.5vh, 2rem);
  background:
    linear-gradient(
      180deg,
      rgba(15, 14, 23, 0) 0%,
      rgba(15, 14, 23, 0.42) 24%,
      rgba(26, 24, 40, 0.88) 58%,
      rgba(15, 14, 23, 0.98) 100%
    ),
    radial-gradient(ellipse 90% 70% at 14% 88%, rgba(255, 137, 6, 0.18), transparent 62%),
    radial-gradient(ellipse 88% 70% at 86% 86%, rgba(229, 49, 112, 0.24), transparent 64%);
  pointer-events: none;
}

.karaoke-stage {
  position: absolute;
  right: clamp(0.75rem, 3vw, 1.25rem);
  bottom: clamp(14rem, 31vh, 20rem);
  left: clamp(0.75rem, 3vw, 1.25rem);
  z-index: 2;
  display: grid;
  gap: 0.35rem;
  text-align: center;
  opacity: 0;
  transform: translateY(1.25rem);
  transition: opacity 0.22s ease, transform 0.22s ease;
  pointer-events: none;
}

.karaoke-stage.is-active {
  opacity: 1;
  transform: translateY(0);
}

.karaoke-now {
  position: relative;
  display: block;
  justify-self: center;
  max-width: 100%;
  font-family: 'Fredoka One', cursive;
  font-size: clamp(1.35rem, 6.8vw, 2.6rem);
  line-height: 1.05;
  text-transform: uppercase;
}

.karaoke-now.is-entering {
  animation: lyricRise 0.34s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

.karaoke-now.is-swapping {
  animation: lyricSwap 0.42s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

.karaoke-base {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.05em 0.24em;
  overflow-wrap: anywhere;
}

.karaoke-fill {
  display: none;
}

.karaoke-word {
  --word-progress: 0%;
  display: inline-block;
  color: transparent;
  background:
    linear-gradient(
      90deg,
      var(--accent2) 0%,
      var(--accent) var(--word-progress),
      rgba(255, 255, 254, 0.92) var(--word-progress),
      rgba(255, 255, 254, 0.92) 100%
    );
  background-clip: text;
  -webkit-background-clip: text;
  filter: drop-shadow(0 3px 0 rgba(15, 14, 23, 0.78)) drop-shadow(0 0 18px rgba(229, 49, 112, 0.32));
  animation: lyricPulse 1s infinite alternate;
  transition: transform 0.12s ease;
}

.karaoke-word.is-active {
  transform: translateY(-0.04em) scale(1.04);
}

.karaoke-next {
  color: rgba(255, 255, 254, 0.78);
  font-size: 0.9rem;
  font-weight: 900;
  text-shadow:
    0 2px 12px rgba(15, 14, 23, 0.85),
    0 0 18px rgba(255, 137, 6, 0.2);
  transform: translateY(0);
  transition: opacity 0.22s ease, transform 0.22s ease;
}

.karaoke-now.is-swapping + .karaoke-next {
  opacity: 0.45;
  transform: translateY(0.4rem);
}

@keyframes lyricRise {
  from {
    opacity: 0;
    transform: translateY(1.35rem) scale(0.96);
    filter: blur(4px);
  }

  to {
    opacity: 1;
    transform: translateY(0) scale(1);
    filter: blur(0);
  }
}

@keyframes lyricSwap {
  from {
    opacity: 0;
    transform: translateY(0.8rem) scale(0.98);
    filter: blur(3px);
  }

  45% {
    opacity: 1;
    transform: translateY(-0.2rem) scale(1.015);
    filter: blur(0);
  }

  to {
    opacity: 1;
    transform: translateY(0) scale(1);
    filter: blur(0);
  }
}

@keyframes lyricPulse {
  from {
    filter: drop-shadow(0 3px 0 rgba(15, 14, 23, 0.78)) drop-shadow(0 0 20px rgba(255, 137, 6, 0.5));
  }

  to {
    filter: drop-shadow(0 3px 0 rgba(15, 14, 23, 0.78)) drop-shadow(0 0 36px rgba(229, 49, 112, 0.82));
  }
}

.rickroll-panel .player-form,
.rickroll-panel .score-result {
  pointer-events: auto;
}

.rickroll-sub {
  color: var(--muted);
  text-align: center;
  font-size: 0.9rem;
}

.score-result {
  color: var(--text);
  text-align: center;
  margin: 0.65rem auto 0;
  max-width: 460px;
  font-weight: 900;
}

@media (max-width: 480px) {
  .intro-card {
    padding: 1.75rem 1.25rem;
  }

  .player-name-row {
    grid-template-columns: 1fr;
  }

  .leaderboard-entry {
    grid-template-columns: 1fr;
  }

  .leaderboard-score {
    white-space: normal;
  }

  .rickroll-panel {
    padding: 3.25rem 0.85rem 0.85rem;
  }

  .karaoke-stage {
    bottom: 15.75rem;
  }

  .karaoke-now {
    font-size: clamp(1.15rem, 8vw, 1.85rem);
  }

  .karaoke-next {
    font-size: 0.78rem;
  }

  .rickroll-sub,
  .score-result {
    font-size: 0.82rem;
  }
}
