/* ============================================================
   TOUCHLIGHT  –  style.css
   ============================================================ */

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

:root {
  --accent:  #b06fff;
  --accent2: #00d4ff;
}

html, body {
  height: 100%;
  background: #000;
  overflow: hidden;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ============================================================
   GRID  — full-bleed square, centred
   ============================================================ */
#grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  /* Square sized to the smaller viewport dimension, symmetrically
     centred by the body's flexbox. The 95 cap leaves a small margin
     so it never clips; dvh tracks mobile browser-chrome so the
     bottom row stays visible when address bars show/hide. */
  width:  min(100vw, 95vh);
  width:  min(100vw, 95dvh);
  aspect-ratio: 1;
  background: #000;
  flex-shrink: 0;
}

/* ============================================================
   TILE + OCTAGON
   ============================================================ */
.tile {
  background: #000;
  aspect-ratio: 1;
  position: relative;
  cursor: pointer;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  outline: none;
}

.octagon {
  position: absolute;
  inset: 6.5%;
  clip-path: polygon(
    29.3% 0%,  70.7% 0%,
    100%  29.3%, 100%  70.7%,
    70.7% 100%, 29.3% 100%,
    0%    70.7%, 0%    29.3%
  );
  background-color: var(--color);
  background-image:
    linear-gradient(148deg,
      rgba(255,255,255,0.52) 0%,
      rgba(255,255,255,0.18) 10%,
      transparent 32%
    ),
    linear-gradient(328deg,
      rgba(0,0,0,0.28) 0%,
      transparent 36%
    );
  /* Static filter only — transitions on class change, never per-frame.
     All per-frame glow/pulse work lives on the #fx canvas. */
  transition: filter 0.25s ease;
}

/* Guided-mode target: gentle static lift; the breathing halo is canvas-drawn */
.octagon.guided-active {
  filter: brightness(1.3) saturate(1.15);
}

.note-label {
  position: absolute;
  bottom: 19%;
  left: 50%;
  transform: translateX(-50%);
  font-size: clamp(0.38rem, 1.5vw, 0.62rem);
  font-weight: 700;
  color: rgba(0,0,0,0.32);
  pointer-events: none;
  white-space: nowrap;
  font-family: 'Orbitron', monospace;
}

/* ============================================================
   FLOATING MODE BUTTON
   ============================================================ */
/* ============================================================
   FLOATING MUSIC HUB (Song Selector)
   ============================================================ */
#music-hub {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: 'Orbitron', sans-serif;
}

#active-song-pill {
  padding: 8px 16px;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.15);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  color: #fff;
  font-size: clamp(0.7rem, 2vw, 0.85rem);
  font-weight: 700;
  letter-spacing: 0.05em;
  text-shadow: 0 0 8px rgba(255, 255, 255, 0.5);
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.3s ease;
  will-change: transform, opacity;
}

.mode-btn-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.5));
  transition: filter 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.mode-btn-wrapper::before {
  content: '';
  position: absolute;
  inset: -6px;
  background: radial-gradient(circle, rgba(255, 215, 0, 0.5) 0%, transparent 70%);
  border-radius: 50%;
  filter: blur(10px);
  z-index: 0;
  pointer-events: none;
  animation: mode-btn-glow-back 3.2s ease-in-out infinite;
  transition: background 0.3s, filter 0.3s, opacity 0.3s;
}

@keyframes mode-btn-glow-back {
  0%, 100% {
    transform: scale(0.88);
    opacity: 0.35;
  }
  50% {
    transform: scale(1.22);
    opacity: 0.95;
  }
}

#mode-btn {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  width:  clamp(48px, 13vw, 56px);
  height: clamp(48px, 13vw, 56px);
  padding: 0;
  background: transparent;
  border: none;
  /* Octagon clip path */
  clip-path: polygon(
    29.3% 0%,  70.7% 0%,
    100%  29.3%, 100%  70.7%,
    70.7% 100%, 29.3% 100%,
    0%    70.7%, 0%    29.3%
  );
  color: rgba(255, 255, 255, 0.85);
  cursor: pointer;
  transition: color 0.2s, transform 0.12s;
  -webkit-tap-highlight-color: transparent;
  outline: none;
}
#mode-btn svg.music-icon {
  width: 50%;
  height: 50%;
  transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  z-index: 2;
}

.mode-btn-bg {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  pointer-events: none;
}

.bg-polygon {
  fill: #000; /* Opaque black to block back-glow from shining through */
  stroke: rgba(255, 255, 255, 0.2);
  stroke-width: 3px;
  vector-effect: non-scaling-stroke;
  transition: fill 0.2s, stroke 0.2s;
}

.mode-btn-wrapper:hover {
  filter: drop-shadow(0 4px 14px rgba(0, 0, 0, 0.6));
}

.mode-btn-wrapper:hover::before {
  background: radial-gradient(circle, rgba(255, 215, 0, 0.75) 0%, transparent 70%);
  transform: scale(1.3);
}

#mode-btn:hover {
  color: #fff;
  transform: translateY(-2px);
}

#mode-btn:hover .bg-polygon {
  fill: #121212; /* Dark feedback on hover */
  stroke: url(#idle-gradient);
}
#mode-btn:hover svg.music-icon {
  transform: scale(1.1);
}

/* Active guided mode state (uses same gradient as progress bar) */
.mode-btn-wrapper.active::before {
  background: radial-gradient(circle, rgba(176, 111, 255, 0.55) 0%, rgba(0, 212, 255, 0.55) 50%, transparent 75%);
  animation: active-glow-back 2.4s ease-in-out infinite;
}

@keyframes active-glow-back {
  0%, 100% {
    transform: scale(0.9);
    opacity: 0.5;
  }
  50% {
    transform: scale(1.25);
    opacity: 0.95;
  }
}

#mode-btn.active svg.music-icon {
  fill: url(#active-gradient);
}

#mode-btn.active .bg-polygon {
  fill: #000; /* Block back-glow in active state */
  stroke: url(#active-gradient);
}

#mode-btn:active {
  transform: scale(0.92);
}

/* ============================================================
   PROGRESS BAR  (top edge, 2px)
   ============================================================ */
#progress-bar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: rgba(255,255,255,0.05);
  z-index: 50;
}
#progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  width: 0%;
  transition: width 0.25s ease-out;
  box-shadow: 0 0 6px var(--accent2);
}

.hidden { display: none !important; }

/* ============================================================
   FX CANVAS  — all glow, ripples, sparks and ambient stars are
   drawn here (fx.js) in one rAF loop with additive blending.
   The old per-tile filter/drop-shadow keyframe animations are gone:
   they repainted 25 clipped elements every frame and their
   class + setTimeout restarts raced each other on fast taps.
   ============================================================ */
#fx {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 10;
}

/* ============================================================
   MESSAGE OVERLAY  (kept for potential future use, hidden by default)
   ============================================================ */
#overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  z-index: 50;
  opacity: 0;
  transition: opacity 0.28s;
}
#overlay.visible { opacity: 1; }
#overlay-text {
  font-family: 'Orbitron', sans-serif;
  font-size: clamp(1.4rem, 5vw, 2.8rem);
  font-weight: 900;
  letter-spacing: 0.1em;
  text-align: center;
  color: #fff;
  text-shadow: 0 0 40px rgba(255,255,255,0.6);
  background: rgba(0,0,0,0.8);
  padding: 16px 40px;
  border-radius: 12px;
}

::-webkit-scrollbar { display: none; }
