/* Hexapuss Portal Tap — mobile portrait */

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

html, body {
  width: 100%;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  background: #000;
  color: #f2eef8;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

#app {
  position: relative;
  width: 100%;
  height: 100%;
  height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  background: #000;
  overflow: hidden;
  padding:
    env(safe-area-inset-top, 0px)
    env(safe-area-inset-right, 0px)
    env(safe-area-inset-bottom, 0px)
    env(safe-area-inset-left, 0px);
}

.screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.screen.is-on {
  display: flex;
}

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

/* ---------- Title ---------- */

#screen-title {
  background: #000;
}

.title-vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse at center, transparent 40%, rgba(0,0,0,0.75) 100%);
}

/* Purple glow from OUTER screen edges only — transparent center (no wash under logo) */
.edge-glow {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background:
    linear-gradient(
      to right,
      rgba(194, 75, 255, 0.55) 0%,
      rgba(194, 75, 255, 0.18) 8%,
      transparent 18%,
      transparent 82%,
      rgba(194, 75, 255, 0.18) 92%,
      rgba(194, 75, 255, 0.55) 100%
    ),
    linear-gradient(
      to bottom,
      rgba(194, 75, 255, 0.5) 0%,
      rgba(194, 75, 255, 0.16) 7%,
      transparent 16%,
      transparent 84%,
      rgba(194, 75, 255, 0.16) 93%,
      rgba(194, 75, 255, 0.5) 100%
    );
}


.title-content {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  padding: 1.5rem;
  text-align: center;
  width: 100%;
}

.logo-play {
  appearance: none;
  border: none;
  background: rgba(0, 0, 0, 0.25);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.85rem;
  padding: 0.5rem;
  touch-action: manipulation;
}

.logo-play:focus-visible {
  outline: 2px solid #c24bff;
  outline-offset: 6px;
  border-radius: 12px;
}

.logo {
  width: min(58vw, 240px);
  height: auto;
  display: block;
  /* No glow under the logo — blacks must match center blacks.
     Purple glow comes only from outer screen edges (.edge-glow). */
  filter: none;
  transition: transform 0.15s ease;
}

.logo-play:active .logo {
  transform: scale(0.96);
}

.play-hint {
  font-size: 0.95rem;
  letter-spacing: 0.35em;
  font-weight: 700;
  color: #ff6a12;
  text-shadow: 0 0 12px rgba(255, 106, 18, 0.5);
  padding: 0.55rem 1.4rem;
  border: 1px solid rgba(255, 106, 18, 0.55);
  border-radius: 999px;
  background: rgba(255, 106, 18, 0.08);
}

.subtitle {
  margin-top: 0.35rem;
  font-size: 1.15rem;
  letter-spacing: 0.42em;
  font-weight: 700;
  color: #e8e0f2;
}

.tagline {
  font-size: 0.85rem;
  color: rgba(242, 238, 248, 0.55);
  letter-spacing: 0.04em;
  max-width: 16rem;
}

/* ---------- Game ---------- */

#screen-game {
  background: #000;
}

#blackout {
  position: absolute;
  inset: 0;
  background: #000;
  z-index: 2;
  opacity: 1;
  transition: opacity 0.35s ease;
  pointer-events: none;
}

#blackout.is-clear {
  opacity: 0;
  visibility: hidden;
  z-index: 0; /* never sit above circles after clear */
}

.reward-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  background: #000;
  z-index: 1;
  pointer-events: none;
}

#circles {
  position: absolute;
  inset: 0;
  z-index: 12;
  pointer-events: none;
}

/* Once gameplay starts, circles are always the top interactive layer (above blackout/video) */
#screen-game.is-gameplay #circles {
  z-index: 30;
}

#screen-game.is-gameplay #blackout {
  opacity: 0 !important;
  visibility: hidden !important;
  z-index: 0 !important;
  pointer-events: none !important;
}

#screen-game.is-gameplay #reward-video,
#screen-game.is-gameplay .reward-video {
  z-index: 1;
}

.circle {
  position: absolute;
  width: var(--circle-size, 96px);
  height: var(--circle-size, 96px);
  margin-left: calc(var(--circle-size, 96px) / -2);
  margin-top: calc(var(--circle-size, 96px) / -2);
  border: none;
  outline: none;
  box-shadow: none;
  border-radius: 50%;
  padding: 0;
  background: transparent;
  pointer-events: auto;
  cursor: pointer;
  touch-action: manipulation;
  transform: scale(0.7);
  opacity: 0;
  transition: opacity 0.2s ease, transform 0.2s ease;
  will-change: transform, opacity, filter;
}

.circle img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
}

.circle.is-live {
  opacity: 1;
  transform: scale(1);
  animation: circle-pulse 1.4s ease-in-out infinite;
}

.circle.is-hit {
  opacity: 0;
  transform: scale(1.35);
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
  animation: none;
}

/* Expired / missed: quick ripple / audio-wave fizz-out */
.circle.is-fizz {
  pointer-events: none;
  animation: circle-fizz 0.28s ease-out forwards;
}

@keyframes circle-fizz {
  0% {
    opacity: 1;
    transform: scale(1);
    filter: brightness(1.1);
  }
  35% {
    opacity: 0.55;
    transform: scale(1.28);
    filter: brightness(1.35);
  }
  100% {
    opacity: 0;
    transform: scale(1.55);
    filter: brightness(1.6);
  }
}

/* White sigil + phase glow (works on black pupil / file://) */
.circle.phase-orange img {
  filter:
    drop-shadow(0 0 2px #ff6a12)
    drop-shadow(0 0 10px #ff6a12)
    drop-shadow(0 0 22px rgba(255, 106, 18, 0.95));
}

.circle.phase-green img {
  filter:
    drop-shadow(0 0 2px #3dff7a)
    drop-shadow(0 0 10px #3dff7a)
    drop-shadow(0 0 22px rgba(61, 255, 122, 0.95));
}

.circle.phase-purple img {
  filter:
    drop-shadow(0 0 2px #c24bff)
    drop-shadow(0 0 12px #c24bff)
    drop-shadow(0 0 24px rgba(194, 75, 255, 0.98));
}

/* WHITE PHASE (circle 10) */
.circle.phase-white img {
  filter:
    drop-shadow(0 0 2px #ffffff)
    drop-shadow(0 0 12px #ffffff)
    drop-shadow(0 0 28px rgba(255, 255, 255, 0.98))
    drop-shadow(0 0 48px rgba(194, 75, 255, 0.55));
}

.circle.phase-white {
  border: none;
  box-shadow: none;
}

.circle.phase-white.is-live {
  animation: circle-pulse-white 1.1s ease-in-out infinite;
}

@keyframes circle-pulse-white {
  0%, 100% { transform: scale(1); filter: brightness(1); }
  50% { transform: scale(1.08); filter: brightness(1.25); }
}

#hud-phase.phase-white {
  color: #ffffff;
  text-shadow: 0 0 12px rgba(255, 255, 255, 0.85), 0 0 18px rgba(194, 75, 255, 0.55);
}


@keyframes circle-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.06); }
}

/* HUD */

#hud {
  position: absolute;
  top: calc(0.75rem + env(safe-area-inset-top, 0px));
  left: 0;
  right: 0;
  z-index: 11;
  display: flex;
  justify-content: space-between;
  padding: 0 1rem;
  font-size: 0.75rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-weight: 600;
  color: rgba(242, 238, 248, 0.8);
  text-shadow: 0 1px 4px rgba(0,0,0,0.8);
  pointer-events: none;
}

#hud[hidden] {
  display: none !important;
}

#hud-phase.phase-orange { color: #ff6a12; }
#hud-phase.phase-green  { color: #3dff7a; }
#hud-phase.phase-purple { color: #c24bff; }

/* Flash */

#flash {
  position: absolute;
  inset: 0;
  z-index: 6;
  pointer-events: none;
  opacity: 0;
  background: #fff;
}

#flash.flash-orange { background: #ff6a12; }
#flash.flash-green  { background: #3dff7a; }
#flash.flash-purple { background: #c24bff; }
#flash.flash-white  { background: #ffffff; }

#flash.is-on {
  animation: hit-flash 0.28s ease-out forwards;
}

#flash.is-strong {
  animation: hit-flash-strong 0.42s ease-out forwards;
}

#flash.is-win {
  animation: hit-flash-win 0.7s ease-out forwards;
}

@keyframes hit-flash {
  0% { opacity: 0.55; }
  100% { opacity: 0; }
}

@keyframes hit-flash-strong {
  0% { opacity: 0.75; }
  100% { opacity: 0; }
}

@keyframes hit-flash-win {
  0% { opacity: 0.95; }
  40% { opacity: 0.55; }
  100% { opacity: 0; }
}

/* Win overlay */

.overlay {
  position: absolute;
  inset: 0;
  z-index: 7;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  background: rgba(0, 0, 0, 0.72);
  text-align: center;
  padding: 1.5rem;
}

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

.win-kicker { display: none; }

.overlay h2 {
  font-size: 1.75rem;
  letter-spacing: 0.08em;
  font-weight: 800;
}

.win-sub {
  font-size: 0.9rem;
  color: rgba(255, 154, 74, 0.85);
  margin-bottom: 0.75rem;
}

.btn-again {
  appearance: none;
  border: 1px solid rgba(255, 106, 18, 0.65);
  background: rgba(255, 106, 18, 0.12);
  color: #ff6a12;
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.28em;
  padding: 0.7rem 1.6rem;
  border-radius: 999px;
  cursor: pointer;
  touch-action: manipulation;
}

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

/* Desktop widen a bit but keep portrait feel */
@media (min-width: 481px) {
  #app {
    box-shadow: 0 0 0 1px rgba(255,255,255,0.06), 0 0 60px rgba(0,0,0,0.8);
  }
}

/* ---------- Win leaderboard / name entry ---------- */

#screen-win.overlay {
  justify-content: flex-start;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding:
    calc(1.25rem + env(safe-area-inset-top, 0px))
    1.25rem
    calc(1.5rem + env(safe-area-inset-bottom, 0px));
  gap: 0.45rem;
  background: rgba(4, 2, 8, 0.88);
}

.win-clear-time {
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: #ff6a12;
  text-shadow: 0 0 12px rgba(255, 106, 18, 0.45);
  margin: 0.15rem 0 0.35rem;
}

.win-name-row {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  width: min(100%, 320px);
  margin: 0.25rem 0 0.5rem;
  padding: 0.45rem 0.55rem;
  box-sizing: border-box;
  background: rgba(18, 12, 22, 0.95);
  border: 1px solid rgba(232, 214, 168, 0.45);
  border-radius: 10px;
}

.win-name-label {
  flex: 0 0 auto;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  color: #fff6d8;
}

.win-name-input {
  flex: 1 1 auto;
  min-width: 0;
  appearance: none;
  border: 1px solid rgba(106, 90, 72, 0.85);
  border-radius: 6px;
  background: #1a1218;
  color: #fff4e0;
  font: bold 15px system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding: 0.45rem 0.55rem;
  outline: none;
  user-select: text;
  -webkit-user-select: text;
}

.win-name-input:focus {
  border-color: #c24bff;
  box-shadow: 0 0 0 1px rgba(194, 75, 255, 0.35);
}

.btn-submit-score {
  flex: 0 0 auto;
  appearance: none;
  border: 0;
  border-radius: 8px;
  background: #ece4d6;
  color: #141014;
  font: bold 14px system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding: 0.45rem 0.85rem;
  cursor: pointer;
  touch-action: manipulation;
}

.btn-submit-score:active {
  transform: scale(0.97);
}

.lb-heading {
  margin-top: 0.35rem;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.22em;
  color: #ff6a12;
  text-shadow: 0 0 10px rgba(255, 106, 18, 0.35);
}

.win-leaderboard {
  list-style: none;
  width: min(100%, 320px);
  max-height: min(38vh, 240px);
  overflow-y: auto;
  margin: 0.15rem 0 0.65rem;
  padding: 0.25rem 0;
  border: 1px solid rgba(194, 75, 255, 0.28);
  border-radius: 10px;
  background: rgba(10, 6, 14, 0.72);
  text-align: left;
}

.win-leaderboard li {
  display: grid;
  grid-template-columns: 1.6rem 1fr auto;
  gap: 0.4rem;
  align-items: center;
  padding: 0.38rem 0.65rem;
  font-size: 0.82rem;
  color: rgba(242, 238, 248, 0.82);
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.win-leaderboard li:last-child {
  border-bottom: 0;
}

.win-leaderboard .lb-rank {
  color: rgba(242, 238, 248, 0.45);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.win-leaderboard .lb-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.win-leaderboard .lb-time {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: #ff6a12;
}

.win-leaderboard li.is-you {
  background: linear-gradient(90deg, rgba(61, 255, 122, 0.22), rgba(61, 255, 122, 0.08));
  box-shadow: inset 0 0 0 1px rgba(61, 255, 122, 0.65);
  color: #eafff2;
}

.win-leaderboard li.is-you .lb-rank {
  color: #3dff7a;
}

.win-leaderboard li.is-you .lb-time {
  color: #3dff7a;
  text-shadow: 0 0 8px rgba(61, 255, 122, 0.45);
}

.win-leaderboard .lb-empty {
  display: block;
  padding: 0.75rem 0.85rem;
  text-align: center;
  color: rgba(242, 238, 248, 0.45);
  font-size: 0.8rem;
}

#screen-win .btn-again {
  margin-top: 0.15rem;
}

#screen-win .win-sub {
  margin-bottom: 0.15rem;
}


/* Full-screen white bloom — covers letterboxing; then fades to black win UI */
#white-bloom {
  position: absolute;
  inset: 0;
  /* Idle below circles — only rise during bloom so early circles stay visible */
  z-index: 3;
  pointer-events: none;
  background: #fff;
  opacity: 0;
  visibility: hidden;
}

#white-bloom.is-on,
#white-bloom.is-hold {
  z-index: 25;
  visibility: visible;
  opacity: 1;
  transition: opacity 0.12s linear;
}

#white-bloom.is-out {
  z-index: 25;
  visibility: hidden; /* fully out of the way once faded — don't leave a top layer */
  opacity: 0;
  transition: opacity 0.35s ease, visibility 0s linear 0.35s;
  background: #000;
}

/* Win / Play Again — title-like, pure black center, edge purple only */
#screen-win.overlay.win-screen {
  justify-content: flex-start;
  background: #000;
  gap: 0.4rem;
}

#screen-win .edge-glow {
  z-index: 0;
}

#screen-win .win-logo {
  position: relative;
  z-index: 1;
  width: min(48vw, 200px);
  margin: 0.35rem 0 0.15rem;
  filter: none;
}

#screen-win h2,
#screen-win .win-sub,
#screen-win .win-clear-time,
#screen-win .win-name-row,
#screen-win .lb-heading,
#screen-win .win-leaderboard,
#screen-win .btn-again,
#screen-win .btn-submit-score {
  position: relative;
  z-index: 1;
}

#screen-title .title-content {
  position: relative;
  z-index: 1;
}

/* End-screen text: orange family. Green only for current LB row. */
#screen-win.overlay.win-screen h2 {
  color: #ff6a12;
  text-shadow: 0 0 18px rgba(255, 106, 18, 0.4);
}

#screen-win .win-name-label {
  color: #ff9a4a;
}

#screen-win .win-name-input {
  border-color: rgba(255, 106, 18, 0.45);
  color: #ffe0c2;
}

#screen-win .win-name-input:focus {
  border-color: #ff6a12;
  box-shadow: 0 0 0 1px rgba(255, 106, 18, 0.4);
}

#screen-win .win-name-row {
  border-color: rgba(255, 106, 18, 0.4);
}

#screen-win .btn-submit-score {
  background: #ff6a12;
  color: #140a04;
}

#screen-win .win-leaderboard {
  border-color: rgba(255, 106, 18, 0.35);
}

#screen-win .win-leaderboard li {
  color: rgba(255, 176, 112, 0.9);
}

#screen-win .win-leaderboard .lb-rank {
  color: rgba(255, 106, 18, 0.55);
}

#screen-win .win-leaderboard .lb-name {
  color: #ffb070;
}

#screen-win .win-leaderboard .lb-time {
  color: #ff6a12;
}

#screen-win .win-leaderboard .lb-empty {
  color: rgba(255, 154, 74, 0.5);
}

/* ONLY green = current player's row */
#screen-win .win-leaderboard li.is-you {
  background: linear-gradient(90deg, rgba(61, 255, 122, 0.22), rgba(61, 255, 122, 0.08));
  box-shadow: inset 0 0 0 1px rgba(61, 255, 122, 0.65);
  color: #eafff2;
}

#screen-win .win-leaderboard li.is-you .lb-rank,
#screen-win .win-leaderboard li.is-you .lb-name,
#screen-win .win-leaderboard li.is-you .lb-time {
  color: #3dff7a;
  text-shadow: 0 0 8px rgba(61, 255, 122, 0.45);
}

/* Inline name edit inside green is-you row — only name control on end screen */
.win-leaderboard li.is-you .lb-name-edit {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  min-width: 0;
}

.win-leaderboard .lb-inline-input {
  flex: 1 1 auto;
  min-width: 0;
  max-width: 100%;
  appearance: none;
  border: 1px solid rgba(61, 255, 122, 0.65);
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.45);
  color: #3dff7a;
  font: bold 13px system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding: 0.28rem 0.4rem;
  outline: none;
}

.win-leaderboard .lb-inline-input:focus {
  border-color: #3dff7a;
  box-shadow: 0 0 0 1px rgba(61, 255, 122, 0.35);
}

.win-leaderboard .lb-inline-ok {
  flex: 0 0 auto;
  appearance: none;
  border: 0;
  border-radius: 6px;
  background: #3dff7a;
  color: #04140a;
  font: bold 12px system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding: 0.28rem 0.55rem;
  cursor: pointer;
  touch-action: manipulation;
}

.win-leaderboard .lb-inline-ok:active {
  transform: scale(0.97);
}

/* Hide legacy separate name row if any leftover markup */
#screen-win .win-name-row {
  display: none !important;
}
