@font-face {
  font-family: 'FontNotas';
  src: url('../fonts/fontnotas.ttf') format('truetype');
  font-display: swap;
}

:root {
  --bg-top: #312c77;
  --bg-bottom: #0f1344;
  --surface: rgba(255, 255, 255, 0.14);
  --line: rgba(255, 255, 255, 0.25);
  --text: #f7f7ff;
  --muted: #dae0ff;
  --ok: #5cf4b0;
  --bad: #ff7d9d;
  --cta: #4fd9ff;
  --cta-2: #2f8cff;
  --hud-bg: rgba(7, 15, 58, 0.74);
  --hud-line: rgba(144, 230, 255, 0.4);
  --panel-deep: rgba(5, 12, 48, 0.62);
  --tower-1: linear-gradient(150deg, #95f1ff, #a793ff);
  --tower-2: linear-gradient(150deg, #ffd38f, #ff8fbd);
}

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

body {
  position: relative;
  min-height: 100dvh;
  font-family: 'Nunito', sans-serif;
  color: var(--text);
  overflow-x: hidden;
  background:
    radial-gradient(circle at 20% 8%, rgba(150, 207, 255, 0.27), transparent 28%),
    radial-gradient(circle at 80% 96%, rgba(96, 187, 255, 0.2), transparent 33%),
    linear-gradient(180deg, #4541a1 0%, #1e246d 42%, #111745 100%);
  padding: 16px;
}

body::before,
body::after {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
}

body::before {
  background:
    repeating-linear-gradient(0deg,
      rgba(255, 255, 255, 0.02) 0,
      rgba(255, 255, 255, 0.02) 1px,
      transparent 1px,
      transparent 5px);
  opacity: 0.38;
  z-index: -1;
}

body::after {
  background: radial-gradient(circle at 50% 120%, rgba(8, 8, 35, 0.62), transparent 52%);
  z-index: -1;
}

body.game-mode {
  padding: 0;
  overflow: hidden;
}

.screen {
  width: min(1080px, 100%);
  margin: 0 auto;
}

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

.fontnotas {
  font-family: 'FontNotas', sans-serif;
}

#setup-area {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.back-btn {
  color: var(--muted);
  text-decoration: none;
  font-weight: 800;
  font-size: 0.92rem;
  width: fit-content;
}

.hero {
  text-align: center;
  margin-top: 6px;
}

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.72rem;
  color: #f6d6ff;
  margin-bottom: 6px;
  font-weight: 900;
}

.hero h1 {
  font-family: 'Baloo 2', sans-serif;
  font-size: clamp(2rem, 4.8vw, 3rem);
  line-height: 0.95;
  text-shadow: 0 8px 24px rgba(20, 15, 70, 0.35);
}

.hero-logo {
  display: block;
  margin: 0 auto 2px;
  max-width: min(420px, 88vw);
  height: auto;
  border-radius: 18px;
  box-shadow: 0 12px 36px rgba(10, 8, 40, 0.45);
}

.subtitle {
  margin-top: 8px;
  color: var(--muted);
  font-size: 1.02rem;
  font-weight: 700;
}

.panel {
  margin: 6px auto 0;
  width: min(720px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 18px;
  backdrop-filter: blur(8px);
  box-shadow: 0 18px 40px rgba(19, 17, 59, 0.25);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.section {
  display: flex;
  flex-direction: column;
  gap: 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.13);
  padding-bottom: 14px;
}

.section:last-of-type {
  border-bottom: 0;
  padding-bottom: 0;
}

.section h2 {
  font-size: 1rem;
  font-weight: 900;
  color: #fef8ff;
}

.row {
  display: flex;
  gap: 10px;
}

.row.two-cols label {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.row.two-cols span,
.inline-row label,
.slider-row label {
  font-size: 0.9rem;
  color: var(--muted);
  font-weight: 800;
}

input[type='text'],
select {
  border: 1px solid rgba(255, 255, 255, 0.32);
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 0.95rem;
  font-family: inherit;
  font-weight: 700;
  color: #201f53;
  background: rgba(255, 255, 255, 0.93);
}

.inline-row {
  align-items: center;
}

.inline-row select {
  width: 140px;
}

.slider-row {
  flex-direction: column;
  gap: 8px;
}

input[type='range'] {
  width: 100%;
  accent-color: #76d5ff;
}

.figures-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.fig-toggle {
  position: relative;
}

.fig-toggle input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.fig-toggle span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 52px;
  min-height: 42px;
  padding: 4px 10px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.24);
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  font-family: 'FontNotas', sans-serif;
  font-size: 1.3rem;
  cursor: pointer;
}

.fig-toggle input:checked+span {
  background: rgba(150, 235, 255, 0.28);
  border-color: rgba(170, 242, 255, 0.88);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.25);
}

.btn {
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 11px 18px;
  font-size: 0.94rem;
  font-family: inherit;
  font-weight: 900;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s, opacity 0.2s;
}

.btn:hover:not(:disabled) {
  transform: translateY(-1px);
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn.primary {
  color: #051e3a;
  border-color: rgba(179, 240, 255, 0.55);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.34), rgba(255, 255, 255, 0) 45%),
    linear-gradient(125deg, var(--cta), var(--cta-2));
  box-shadow: 0 10px 22px rgba(67, 184, 255, 0.42), inset 0 -2px 0 rgba(16, 36, 85, 0.22);
}

.btn.ghost {
  color: #e7f8ff;
  background: rgba(112, 182, 255, 0.14);
  border: 1px solid rgba(145, 222, 255, 0.35);
}

.btn:active:not(:disabled) {
  transform: translateY(1px) scale(0.985);
}

#game-area {
  display: flex;
  flex-direction: column;
  gap: 14px;
  border-radius: 24px;
  border: 1px solid rgba(145, 222, 255, 0.3);
  background:
    radial-gradient(circle at 50% -10%, rgba(157, 209, 255, 0.24), transparent 42%),
    linear-gradient(180deg, rgba(21, 23, 82, 0.78), rgba(14, 19, 70, 0.83));
  box-shadow: 0 24px 58px rgba(6, 9, 40, 0.45), inset 0 0 0 1px rgba(255, 255, 255, 0.07);
  padding: 14px;
}

body.game-mode #game-area {
  display: grid;
  grid-template-rows: auto auto 1fr;
  gap: clamp(8px, 1.6vh, 14px);
  width: 100vw;
  max-width: none;
  min-height: 100dvh;
  margin: 0;
  border-radius: 0;
  border-left: 0;
  border-right: 0;
  border-bottom: 0;
  padding: clamp(10px, 2vh, 16px) clamp(12px, 2vw, 22px);
  box-shadow: none;
}

.game-topbar {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  background: var(--hud-bg);
  border: 1px solid var(--hud-line);
  border-radius: 14px;
  padding: 10px 12px;
  font-weight: 800;
  color: #f7f8ff;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.06);
}

#turn-indicator,
#remaining-indicator {
  border-radius: 999px;
  background: rgba(151, 224, 255, 0.12);
  border: 1px solid rgba(160, 233, 255, 0.35);
  padding: 6px 10px;
  font-weight: 900;
}

.scoreboard {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.score-pill {
  border-radius: 14px;
  border: 1px solid rgba(150, 228, 255, 0.35);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.14), rgba(255, 255, 255, 0.05)),
    rgba(15, 27, 86, 0.72);
  padding: 10px 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 900;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.06);
}

.score-pill span {
  letter-spacing: 0.01em;
}

.score-pill strong {
  min-width: 28px;
  text-align: center;
  border-radius: 999px;
  padding: 3px 8px;
  background: rgba(159, 231, 255, 0.16);
  border: 1px solid rgba(159, 231, 255, 0.3);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.05);
}

.score-pill.active {
  border-color: rgba(170, 249, 255, 0.98);
  box-shadow: 0 0 0 2px rgba(131, 229, 255, 0.22), 0 0 26px rgba(118, 206, 255, 0.3);
  transform: translateY(-1px);
}

.game-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  align-items: stretch;
}

body.game-mode .game-layout {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding-bottom: clamp(4px, 1vh, 12px);
  overflow: hidden;
  flex: 1;
  min-height: 0;
}

.challenge-card,
.tower-card {
  border-radius: 20px;
  border: 1px solid rgba(155, 230, 255, 0.24);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0.01)),
    var(--panel-deep);
  backdrop-filter: blur(6px);
  padding: 16px;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.05);
}

body.game-mode .tower-card {
  width: min(96vw, 680px);
  display: flex;
  flex-direction: column;
  margin: 0 auto;
  height: 100%;
  min-height: 0;
  padding: 10px;
  border-radius: 24px;
}

body.game-mode .tower-card h2 {
  display: none;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  background: rgba(8, 8, 30, 0.45);
  backdrop-filter: blur(2px);
  padding: 14px;
}

.modal-overlay[hidden] {
  display: none !important;
}

.modal-card {
  width: min(460px, calc(100vw - 28px));
  border-radius: 18px;
  border: 1px solid rgba(255, 255, 255, 0.24);
  background: rgba(20, 16, 63, 0.94);
  box-shadow: 0 20px 34px rgba(8, 8, 30, 0.45);
  padding: 14px;
}

.modal-close {
  position: absolute;
  top: 9px;
  right: 10px;
  border: 0;
  background: transparent;
  color: #d7e8ff;
  font-size: 1.7rem;
  line-height: 1;
  cursor: pointer;
}

.challenge-card {
  position: relative;
}

.challenge-card h2,
.tower-card h2 {
  font-family: 'Baloo 2', sans-serif;
  font-size: clamp(1.55rem, 3.2vw, 2.05rem);
  letter-spacing: 0.02em;
  text-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
  margin-bottom: 10px;
}

.challenge-block {
  border-radius: 16px;
  border: 2px solid rgba(20, 16, 63, 0.6);
  background: linear-gradient(145deg, #8ef1ff, #a58dff 70%);
  min-height: 160px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: inset 0 0 0 3px rgba(255, 255, 255, 0.15), 0 14px 24px rgba(14, 12, 58, 0.3);
  position: relative;
}

.challenge-block.player-0 {
  background: var(--tower-1);
}

.challenge-block.player-1 {
  background: var(--tower-2);
}

.challenge-block::before,
.challenge-block::after {
  content: '';
  position: absolute;
  top: 35%;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: #fff;
  box-shadow: inset 0 0 0 3px #20205e;
}

.challenge-block::before {
  left: 24%;
}

.challenge-block::after {
  right: 24%;
}

.challenge-block.listening {
  animation: pulse-glow 0.55s ease-in-out infinite alternate;
}

.challenge-block.spawn {
  animation: block-spawn 0.34s ease;
}

@keyframes block-spawn {
  0% {
    opacity: 0;
    transform: translateY(-18px) scale(0.92);
  }

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

@keyframes pulse-glow {
  from {
    box-shadow: inset 0 0 0 3px rgba(255, 255, 255, 0.15), 0 10px 22px rgba(14, 12, 58, 0.25);
  }

  to {
    box-shadow: inset 0 0 0 3px rgba(255, 255, 255, 0.25), 0 18px 36px rgba(126, 195, 255, 0.38);
  }
}

.rhythm-display {
  font-size: clamp(2.2rem, 6vw, 3.1rem);
  letter-spacing: 0.12em;
  color: #0b0f4f;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.35);
}

.rhythm-note {
  display: inline-block;
  transition: transform 0.12s, color 0.15s;
}

.rhythm-note+.rhythm-note {
  margin-left: 6px;
}

.rhythm-note.active {
  color: #101563;
  transform: translateY(-4px) scale(1.1);
}

.rhythm-note.ok {
  color: #0f9155;
}

.rhythm-note.bad {
  color: #a9194e;
}

.controls {
  margin-top: 12px;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.btn.tap {
  min-width: 110px;
  color: #fff;
  background: linear-gradient(135deg, #2e2f95, #4b65d4);
  box-shadow: 0 10px 20px rgba(30, 35, 116, 0.4);
}

.btn.tap.active {
  transform: scale(0.97);
}

.message {
  margin-top: 10px;
  min-height: 24px;
  font-weight: 900;
  color: var(--muted);
}

.message.ok {
  color: var(--ok);
}

.message.bad {
  color: var(--bad);
}

.message.info {
  color: #d8efff;
}

.tower-scene {
  position: relative;
  min-height: 460px;
  border-radius: 16px;
  border: 1px solid rgba(151, 231, 255, 0.25);
  background:
    radial-gradient(circle at 50% -25%, rgba(211, 238, 255, 0.3), transparent 52%),
    linear-gradient(180deg, rgba(64, 87, 157, 0.52), rgba(23, 31, 96, 0.7));
  overflow: hidden;
  box-shadow: inset 0 -36px 60px rgba(6, 11, 47, 0.45), inset 0 0 0 1px rgba(255, 255, 255, 0.05);
}

body.game-mode .tower-scene {
  width: 100%;
  flex: 1;
  min-height: 0;
  border-radius: 22px;
}

body.game-mode .scoreboard {
  width: min(96vw, 680px);
  margin: 0 auto;
}

.tower-scene::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 0;
  background:
    linear-gradient(0deg, rgba(8, 15, 50, 0.74) 0%, rgba(8, 15, 50, 0) 42%),
    repeating-linear-gradient(90deg,
      rgba(149, 216, 255, 0.08) 0,
      rgba(149, 216, 255, 0.08) 2px,
      transparent 2px,
      transparent 38px);
}

.tower-scene::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 22%;
  z-index: 0;
  background:
    linear-gradient(180deg, rgba(15, 19, 69, 0), rgba(15, 19, 69, 0.84)),
    radial-gradient(circle at 10% 100%, rgba(94, 176, 255, 0.18), transparent 35%);
}

.tower-scene.drop-ready {
  cursor: pointer;
  box-shadow:
    inset 0 -36px 60px rgba(6, 11, 47, 0.45),
    inset 0 0 0 2px rgba(158, 239, 255, 0.45),
    0 0 24px rgba(95, 196, 255, 0.25);
}

.tower-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 3;
}

.manual-hints {
  position: absolute;
  inset: 0;
  z-index: 4;
  pointer-events: none;
}

.scene-arrow {
  position: absolute;
  top: 42%;
  width: 62px;
  height: 62px;
  border-radius: 50%;
  border: 1px solid rgba(160, 233, 255, 0.65);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.24), rgba(255, 255, 255, 0) 36%),
    rgba(84, 170, 255, 0.42);
  color: #e9fbff;
  font-size: 1.45rem;
  font-weight: 900;
  box-shadow: 0 8px 22px rgba(29, 56, 136, 0.4), inset 0 0 0 1px rgba(255, 255, 255, 0.15);
  transform: translateY(-50%);
  animation: arrow-pulse 0.95s ease-in-out infinite alternate;
  pointer-events: auto;
  cursor: pointer;
}

.scene-arrow-left {
  left: 10px;
}

.scene-arrow-right {
  right: 10px;
}

@keyframes arrow-pulse {
  from {
    opacity: 0.55;
    transform: translateY(-50%) scale(0.93);
    box-shadow: 0 6px 16px rgba(29, 56, 136, 0.28), inset 0 0 0 1px rgba(255, 255, 255, 0.12);
  }

  to {
    opacity: 1;
    transform: translateY(-50%) scale(1);
    box-shadow: 0 10px 26px rgba(80, 164, 255, 0.42), inset 0 0 0 1px rgba(255, 255, 255, 0.2);
  }
}

.tower-piece {
  position: absolute;
  left: 50%;
  width: 150px;
  height: 34px;
  border-radius: 12px;
  border: 2px solid rgba(15, 12, 68, 0.7);
  color: #121356;
  box-shadow: 0 8px 16px rgba(17, 14, 59, 0.28);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 900;
  transform: translateX(-50%);
  animation: drop-in 0.38s ease;
}

.tower-piece.player-0 {
  background: var(--tower-1);
}

.tower-piece.player-1 {
  background: var(--tower-2);
}

.tower-piece .tower-rhythm {
  font-family: 'FontNotas', sans-serif;
  font-size: 1.08rem;
  letter-spacing: 0.06em;
}

.tower-piece.tower-pending {
  border-style: dashed;
  box-shadow: 0 0 0 2px rgba(220, 245, 255, 0.25), 0 8px 18px rgba(12, 10, 50, 0.34);
  animation: pending-float 0.9s ease-in-out infinite alternate;
}

@keyframes pending-float {
  from {
    transform: translateX(-50%) translateY(0);
  }

  to {
    transform: translateX(-50%) translateY(-8px);
  }
}

@keyframes drop-in {
  from {
    opacity: 0;
    transform: translate(-50%, -36px);
  }

  to {
    opacity: 1;
    transform: translate(-50%, 0);
  }
}

.tower-base {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: 28px;
  width: min(380px, 95%);
  height: 44px;
  border-radius: 10px;
  border: 2px solid rgba(151, 225, 255, 0.44);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.52), rgba(255, 255, 255, 0) 35%),
    linear-gradient(180deg, #dde6ff, #b5c8fb);
  box-shadow: 0 10px 18px rgba(8, 10, 47, 0.45), 0 0 0 2px rgba(26, 38, 94, 0.4);
  pointer-events: none;
  z-index: 2;
}

.collapse-card {
  text-align: center;
  border-color: rgba(255, 171, 195, 0.42);
  background:
    linear-gradient(180deg, rgba(255, 195, 214, 0.14), rgba(255, 132, 164, 0.02)),
    rgba(38, 14, 63, 0.94);
}

.collapse-card h2 {
  font-family: 'Baloo 2', sans-serif;
  margin-bottom: 6px;
}

.collapse-card p {
  color: #dce9ff;
  font-weight: 800;
  margin-bottom: 12px;
}

@media (max-width: 920px) {
  .tower-scene {
    min-height: 380px;
  }

  body.game-mode .tower-scene {
    min-height: 0;
  }
}

@media (max-width: 640px) {
  body {
    padding: 12px;
  }

  .panel,
  .challenge-card,
  .tower-card {
    padding: 14px;
  }

  .row.two-cols {
    flex-direction: column;
  }

  .scoreboard {
    grid-template-columns: 1fr;
  }

  .tower-piece {
    width: 136px;
    height: 32px;
  }

  .scene-arrow {
    width: 54px;
    height: 54px;
    font-size: 1.3rem;
  }
}

/* ── Premium Locks ── */
.locked-premium {
  position: relative !important;
  opacity: 0.65;
  cursor: not-allowed !important;
}

.locked-premium>* {
  pointer-events: none;
}

.locked-premium::after {
  content: "";
  position: absolute;
  top: 50%;
  right: 12px;
  transform: translateY(-50%);
  width: 14px;
  height: 14px;
  background-color: rgba(255, 255, 255, 0.45);
  mask-image: url('data:image/svg+xml;utf8,<svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M12 2C9.243 2 7 4.243 7 7V10H6V20H18V10H17V7C17 4.243 14.757 2 12 2ZM9 7C9 5.346 10.346 4 12 4C13.654 4 15 5.346 15 7V10H9V7ZM12 17C10.895 17 10 16.105 10 15C10 13.895 10.895 13 12 13C13.105 13 14 13.895 14 15C14 16.105 13.105 17 12 17Z" fill="white"/></svg>');
  -webkit-mask-image: url('data:image/svg+xml;utf8,<svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M12 2C9.243 2 7 4.243 7 7V10H6V20H18V10H17V7C17 4.243 14.757 2 12 2ZM9 7C9 5.346 10.346 4 12 4C13.654 4 15 5.346 15 7V10H9V7ZM12 17C10.895 17 10 16.105 10 15C10 13.895 10.895 13 12 13C13.105 13 14 13.895 14 15C14 16.105 13.105 17 12 17Z" fill="white"/></svg>');
  mask-size: contain;
  -webkit-mask-size: contain;
  mask-repeat: no-repeat;
  -webkit-mask-repeat: no-repeat;
  mask-position: center;
  -webkit-mask-position: center;
  pointer-events: none;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.6));
}

/* For form inputs and labels specifically */
label:has(input.locked-premium) {
  opacity: 0.65;
  cursor: not-allowed !important;
  position: relative;
}

label:has(input.locked-premium)::after {
  content: '🔒';
  position: absolute;
  top: 50%;
  right: -10px;
  transform: translate(0, -50%);
  font-size: 1rem;
  z-index: 10;
  pointer-events: none;
}