/* Portal: portrait mobile first, desktop in a centered phone column */

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

:root {
  --orange: #ff8a1f;
  --green: #3ddc84;
  --purple: #a855f7;
  --ink: #f2eef8;
  --dim: rgba(242, 238, 248, 0.6);
}

html, body {
  width: 100%;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  background: #000;
  color: var(--ink);
  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;
}

@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); }
}

#scene {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  z-index: 0;
}

.screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 2;
  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.is-on { display: flex; }
.screen[hidden] { display: none !important; }

/* ---------- Title ---------- */
.edge-glow {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(to right, rgba(194,75,255,0.5) 0%, rgba(194,75,255,0.16) 8%, transparent 18%, transparent 82%, rgba(194,75,255,0.16) 92%, rgba(194,75,255,0.5) 100%),
    linear-gradient(to bottom, rgba(194,75,255,0.45) 0%, rgba(194,75,255,0.14) 7%, transparent 16%, transparent 84%, rgba(194,75,255,0.14) 93%, rgba(194,75,255,0.45) 100%);
}
#screen-title { background: rgba(0,0,0,0.35); }
.title-content {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.9rem;
  padding: 1.5rem;
  text-align: center;
  width: 100%;
}
.title {
  font-size: clamp(2.2rem, 11vw, 3.1rem);
  font-weight: 800;
  letter-spacing: 0.12em;
  color: #eeeeee;
  text-shadow: 0 0 18px rgba(255, 138, 31, 0.45);
}
.logo-play {
  appearance: none;
  border: none;
  background: transparent;
  color: inherit;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  padding: 0.5rem;
  touch-action: manipulation;
}
.logo-play:focus-visible { outline: 2px solid #c24bff; outline-offset: 6px; border-radius: 12px; }
.title-sigil {
  width: min(62vw, 250px);
  height: auto;
  display: block;
  filter: drop-shadow(0 0 2px var(--orange)) drop-shadow(0 0 12px var(--orange)) drop-shadow(0 0 26px rgba(255,138,31,0.9));
  animation: sigil-spin 24s linear infinite;
}
.logo-play:active .title-sigil { transform: scale(0.96); }
@keyframes sigil-spin { to { transform: rotate(360deg); } }
.play-hint {
  font-size: 0.95rem;
  letter-spacing: 0.35em;
  font-weight: 700;
  color: var(--orange);
  text-shadow: 0 0 12px rgba(255,138,31,0.5);
  padding: 0.6rem 1.5rem;
  border: 1px solid rgba(255,138,31,0.6);
  border-radius: 999px;
  background: rgba(255,138,31,0.1);
}
.tagline { font-size: 0.9rem; color: var(--dim); max-width: 19rem; line-height: 1.4; }
.site-url { font-size: 0.75rem; color: rgba(242,238,248,0.42); letter-spacing: 0.04em; }

/* ---------- Game ---------- */
#screen-game { justify-content: flex-start; }

#hud {
  position: absolute;
  top: calc(0.7rem + env(safe-area-inset-top, 0px));
  left: 0;
  right: 0;
  z-index: 20;
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0 1rem;
  font-size: 0.75rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  font-weight: 700;
  color: rgba(242,238,248,0.85);
  text-shadow: 0 1px 4px rgba(0,0,0,0.9);
  pointer-events: none;
  font-variant-numeric: tabular-nums;
}
#hud-progress.phase-orange { color: var(--orange); }
#hud-progress.phase-green { color: var(--green); }
#hud-progress.phase-purple { color: var(--purple); }
#hud-progress.phase-white { color: #fff; text-shadow: 0 0 10px rgba(255,255,255,0.8); }

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

.circle {
  position: absolute;
  width: 110px;
  height: 110px;
  margin-left: -55px;
  margin-top: -55px;
  border: none;
  outline: 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;
}
.circle img { width: 100%; height: 100%; display: block; object-fit: contain; pointer-events: 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.4); pointer-events: none; transition: opacity 0.18s ease, transform 0.18s ease; animation: none; }
.circle.is-fizz { pointer-events: none; animation: circle-fizz 0.26s ease-out forwards; }
@keyframes circle-pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.06); } }
@keyframes circle-fizz {
  0% { opacity: 1; transform: scale(1); filter: brightness(1.1); }
  40% { opacity: 0.5; transform: scale(1.25) rotate(8deg); filter: brightness(1.4); }
  100% { opacity: 0; transform: scale(1.5) rotate(-6deg); filter: brightness(1.6); }
}
.circle.phase-orange img { filter: drop-shadow(0 0 2px var(--orange)) drop-shadow(0 0 10px var(--orange)) drop-shadow(0 0 22px rgba(255,138,31,0.95)); }
.circle.phase-green img { filter: drop-shadow(0 0 2px var(--green)) drop-shadow(0 0 10px var(--green)) drop-shadow(0 0 22px rgba(61,220,132,0.95)); }
.circle.phase-purple img { filter: drop-shadow(0 0 2px var(--purple)) drop-shadow(0 0 12px var(--purple)) drop-shadow(0 0 24px rgba(168,85,247,0.98)); }
.circle.phase-white img { filter: drop-shadow(0 0 2px #fff) drop-shadow(0 0 12px #fff) drop-shadow(0 0 28px rgba(255,255,255,0.98)) drop-shadow(0 0 46px rgba(194,75,255,0.55)); }

/* ---------- Vault puzzle ---------- */
#vault-ui {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  padding: calc(2.4rem + env(safe-area-inset-top, 0px)) 0.85rem calc(0.8rem + env(safe-area-inset-bottom, 0px));
  gap: 0.4rem;
  visibility: hidden;
  opacity: 0;
  transition: opacity 0.35s ease;
}
#vault-ui.is-on { visibility: visible; opacity: 1; }
#vault-ui.is-locked #dials, #vault-ui.is-locked #objective { opacity: 0.35; pointer-events: none; }

#objective { text-align: center; transition: opacity 0.3s ease; }
#objective-heading { font-size: 1.05rem; letter-spacing: 0.16em; text-transform: uppercase; color: #fff; }
#objective-instructions { font-size: 0.82rem; color: var(--dim); margin-top: 0.15rem; }
#objective-values { display: flex; flex-wrap: wrap; justify-content: center; gap: 0.3rem; margin-top: 0.4rem; }
.target {
  font-size: 0.78rem;
  font-weight: 700;
  padding: 0.22rem 0.55rem;
  border-radius: 999px;
  border: 1px solid currentColor;
  background: rgba(0,0,0,0.5);
  font-variant-numeric: tabular-nums;
}
.target.v0 { color: var(--orange); }
.target.v1 { color: var(--green); }
.target.v2 { color: var(--purple); }
.target.tempo { color: #fff; }

#portal-slot { position: relative; flex: 1 1 auto; min-height: 180px; }
#portal-btn {
  position: absolute;
  left: 50%;
  top: 50%;
  width: var(--portal-d, 260px);
  height: var(--portal-d, 260px);
  transform: translate(-50%, -50%);
  border-radius: 50%;
  border: none;
  background: transparent;
  cursor: pointer;
  touch-action: manipulation;
}
#portal-btn:focus-visible { outline: 2px dashed rgba(255,255,255,0.5); outline-offset: 4px; }

#hint {
  min-height: 1.3em;
  text-align: center;
  font-size: 0.86rem;
  color: #ffd2a6;
  text-shadow: 0 0 10px rgba(255,138,31,0.35);
}
#hint.is-good { color: #b8ffd6; text-shadow: 0 0 10px rgba(61,220,132,0.5); }

#dials {
  background: rgba(6, 4, 12, 0.78);
  border: 1px solid rgba(194,75,255,0.28);
  border-radius: 14px;
  padding: 0.55rem 0.5rem 0.6rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  transition: opacity 0.3s ease;
}
#rhythm-dials { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.35rem; }
.rhythm-dial { display: flex; flex-direction: column; align-items: center; gap: 0.25rem; }
.dial-name { font-size: 0.7rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--dim); }
.rhythm-dial .dial-name { display: flex; align-items: center; gap: 0.3rem; }
.swatch { width: 0.6rem; height: 0.6rem; border-radius: 50%; box-shadow: 0 0 8px currentColor; background: currentColor; }
.stepper { display: flex; align-items: center; gap: 0.2rem; }
.step {
  appearance: none;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.22);
  background: rgba(255,255,255,0.06);
  color: #fff;
  font-size: 1.25rem;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;
}
.step:active { transform: scale(0.94); background: rgba(255,255,255,0.14); }
.count { min-width: 1.9rem; text-align: center; font-size: 1.25rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.rhythm-dial.v0 .count, .rhythm-dial.v0 .swatch { color: var(--orange); }
.rhythm-dial.v1 .count, .rhythm-dial.v1 .swatch { color: var(--green); }
.rhythm-dial.v2 .count, .rhythm-dial.v2 .swatch { color: var(--purple); }
.sound-lock { font-size: 0.68rem; color: rgba(242,238,248,0.55); white-space: nowrap; }
.tempo-dial { display: grid; grid-template-columns: auto auto 1fr auto 2.6rem; align-items: center; gap: 0.35rem; padding: 0 0.15rem; }
.tempo-dial input[type=range] { width: 100%; accent-color: #c24bff; height: 2rem; }
#tempo-val { font-size: 1.05rem; font-weight: 800; text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- Flash ---------- */
#flash { position: absolute; inset: 0; z-index: 30; pointer-events: none; opacity: 0; background: #fff; }
#flash.flash-orange { background: var(--orange); }
#flash.flash-green { background: var(--green); }
#flash.flash-purple { background: var(--purple); }
#flash.flash-white { background: #fff; }
#flash.is-on { animation: hit-flash 0.28s ease-out forwards; }
#flash.is-strong { animation: hit-flash-strong 0.5s ease-out forwards; }
@keyframes hit-flash { 0% { opacity: 0.4; } 100% { opacity: 0; } }
@keyframes hit-flash-strong { 0% { opacity: 0.9; } 100% { opacity: 0; } }

/* ---------- Win ---------- */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 40;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 0.45rem;
  background: #000;
  text-align: center;
  overflow-y: auto;
  padding: calc(1.4rem + env(safe-area-inset-top, 0px)) 1.25rem calc(1.5rem + env(safe-area-inset-bottom, 0px));
}
.overlay[hidden] { display: none !important; }
.overlay > *:not(.edge-glow) { position: relative; z-index: 1; }
.win-sigil { width: min(40vw, 160px); filter: drop-shadow(0 0 2px #fff) drop-shadow(0 0 14px var(--purple)) drop-shadow(0 0 30px rgba(255,138,31,0.6)); margin: 0.3rem 0; }
.overlay h2 { font-size: 1.6rem; letter-spacing: 0.08em; font-weight: 800; color: var(--orange); text-shadow: 0 0 18px rgba(255,138,31,0.4); }
.win-sub { font-size: 0.92rem; color: rgba(255,176,112,0.9); }
.win-clear-time { font-size: 1.1rem; font-weight: 700; letter-spacing: 0.05em; color: var(--orange); }
.lb-heading { margin-top: 0.35rem; font-size: 0.7rem; font-weight: 700; letter-spacing: 0.22em; color: var(--orange); }
.win-leaderboard {
  list-style: none;
  width: min(100%, 330px);
  max-height: min(36vh, 240px);
  overflow-y: auto;
  padding: 0.25rem 0;
  border: 1px solid rgba(255,138,31,0.35);
  border-radius: 10px;
  background: rgba(10,6,14,0.72);
  text-align: left;
}
.win-leaderboard li {
  display: grid;
  grid-template-columns: 1.5rem 1fr auto auto;
  gap: 0.45rem;
  align-items: center;
  padding: 0.38rem 0.65rem;
  font-size: 0.82rem;
  color: rgba(255,176,112,0.9);
  border-bottom: 1px solid rgba(255,255,255,0.05);
}
.win-leaderboard li:last-child { border-bottom: 0; }
.lb-rank { color: rgba(255,138,31,0.55); font-weight: 600; font-variant-numeric: tabular-nums; }
.lb-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; color: #ffb070; }
.lb-vaults, .lb-time { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--orange); }
.lb-empty { display: block !important; padding: 0.75rem; text-align: center; color: rgba(255,154,74,0.5); }
.win-leaderboard li.is-you { background: linear-gradient(90deg, rgba(61,220,132,0.22), rgba(61,220,132,0.08)); box-shadow: inset 0 0 0 1px rgba(61,220,132,0.65); }
.win-leaderboard li.is-you span { color: var(--green); }
.lb-name-edit { display: flex; align-items: center; gap: 0.3rem; min-width: 0; }
.lb-inline-input {
  flex: 1 1 auto;
  min-width: 0;
  border: 1px solid rgba(61,220,132,0.65);
  border-radius: 6px;
  background: rgba(0,0,0,0.45);
  color: var(--green);
  font: bold 13px system-ui, sans-serif;
  padding: 0.25rem 0.4rem;
  outline: none;
  user-select: text;
  -webkit-user-select: text;
}
.lb-inline-ok { border: 0; border-radius: 6px; background: var(--green); color: #04140a; font: bold 12px system-ui, sans-serif; padding: 0.28rem 0.5rem; cursor: pointer; }
.btn-again {
  appearance: none;
  margin-top: 0.4rem;
  border: 1px solid rgba(255,138,31,0.65);
  background: rgba(255,138,31,0.12);
  color: var(--orange);
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.28em;
  padding: 0.75rem 1.6rem;
  border-radius: 999px;
  cursor: pointer;
}
.btn-again:active { transform: scale(0.97); }

@media (max-width: 420px) {
  .step { width: 2.15rem; height: 2.4rem; }
  .count { min-width: 1.6rem; }
  #rhythm-dials { gap: 0.2rem; }
  #dials { padding-left: 0.35rem; padding-right: 0.35rem; }
}

@media (max-height: 700px) {
  #objective-instructions { display: none; }
  .step { width: 2.2rem; height: 2.2rem; }
  #vault-ui { gap: 0.25rem; }
}

@media (prefers-reduced-motion: reduce) {
  .title-sigil { animation: none; }
  .circle.is-live { animation: none; }
}
