:root {
  --bg: #0a0a0f;
  --bg-glow: #1a1030;
  --fg: #e8e6f0;
  --dim: #8a86a0;
  --accent: #ff4d6d;
  --term: #6dffb0;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  background:
    radial-gradient(1200px 600px at 50% -10%, var(--bg-glow), transparent 70%),
    var(--bg);
  color: var(--fg);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 1.5rem;
  overflow-x: hidden;
}

/* --- The box / card ------------------------------------------------------ */

.box {
  position: relative;
  z-index: 1;
  width: min(640px, 100%);
  text-align: center;
  background: rgba(20, 16, 35, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 20px;
  padding: clamp(1.5rem, 5vw, 3rem);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(6px);
}

.lid {
  position: relative;
  width: clamp(120px, 32vw, 168px);
  aspect-ratio: 1 / 1;
  margin: 0 auto;
  transition: transform 0.4s ease;
}

.box-face {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  transition: opacity 0.5s ease, transform 0.5s ease;
}

/* The open box starts hidden and slightly small, behind the sealed one. */
.box-face--open {
  opacity: 0;
  transform: scale(0.86);
}

.lid.opened .box-face--sealed {
  opacity: 0;
}

.lid.opened .box-face--open {
  opacity: 1;
  transform: scale(1);
}

/* A quick burst when the box springs open. */
.lid.opening {
  animation: pop 0.55s ease;
}

@keyframes pop {
  0% { transform: scale(1); }
  35% { transform: scale(1.16) rotate(-2deg); }
  70% { transform: scale(0.97) rotate(1deg); }
  100% { transform: scale(1) rotate(0); }
}

.lid.shut {
  animation: slam 0.5s ease;
}

@keyframes slam {
  0% { transform: translateY(-40px) rotate(-8deg); }
  60% { transform: translateY(6px) rotate(2deg); }
  100% { transform: translateY(0) rotate(0); }
}

/* --- Terminal boot log --------------------------------------------------- */

.log {
  font-family: var(--mono);
  font-size: clamp(0.8rem, 2.6vw, 1rem);
  color: var(--term);
  text-align: left;
  margin: 1.5rem auto 0;
  line-height: 1.5;
  /* Reserve room for all 7 lines so the reveal below doesn't shift as the
     reports fill in later. */
  min-height: 10.5em;
  white-space: pre-wrap;
  text-shadow: 0 0 8px rgba(109, 255, 176, 0.35);
}

.cursor {
  display: inline-block;
  width: 0.6ch;
  background: var(--term);
  animation: blink 1s steps(1) infinite;
}

@keyframes blink {
  50% { opacity: 0; }
}

.spinner {
  display: inline-block;
  width: 1ch; /* fixed width so the frames don't jitter the line */
  color: var(--term);
}

/* --- The reveal ---------------------------------------------------------- */

.reveal {
  animation: rise 0.6s ease both;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

.title {
  font-size: clamp(1.8rem, 7vw, 3rem);
  margin: 0.5rem 0 0.25rem;
  letter-spacing: -0.02em;
}

.sub {
  color: var(--dim);
  margin: 0 0 1.75rem;
  font-size: clamp(0.95rem, 3vw, 1.1rem);
}

.counter {
  margin: 0 0 2rem;
  line-height: 1.5;
}

.count {
  display: block;
  font-family: var(--mono);
  font-size: clamp(2rem, 9vw, 3.5rem);
  font-weight: 700;
  color: var(--accent);
  text-shadow: 0 0 24px rgba(255, 77, 109, 0.45);
  font-variant-numeric: tabular-nums;
}

.counter-text {
  color: var(--dim);
  font-size: clamp(0.9rem, 3vw, 1.05rem);
}

.reseal {
  font: inherit;
  font-weight: 600;
  color: var(--fg);
  background: linear-gradient(180deg, #2a2342, #1d1830);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 999px;
  padding: 0.7rem 1.5rem;
  cursor: pointer;
  transition: transform 0.1s ease, border-color 0.2s ease;
}

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

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

.reseal:disabled {
  cursor: not-allowed;
  opacity: 0.7;
}

.reseal-note {
  min-height: 1.4em;
  margin: 0.9rem 0 0;
  color: var(--accent);
  font-size: 0.95rem;
}

/* --- Goblin rain --------------------------------------------------------- */

.rain {
  position: fixed;
  inset: 0;
  z-index: 3; /* above the card so demons visibly pour out of the box */
  pointer-events: none;
  overflow: hidden;
}

.demon {
  position: absolute;
  top: 0;
  left: 0;
  will-change: transform;
  user-select: none;
  filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.5));
  pointer-events: auto; /* catchable, while gaps in the rain pass clicks through */
  cursor: pointer;
}

/* --- "Deployed on FastAPI Cloud" badge ---------------------------------- */

.deployed {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 4; /* above the roaming demons so it stays readable */
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.75rem;
  border-radius: 999px;
  background: rgba(20, 16, 35, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(6px);
  text-decoration: none;
  color: var(--dim);
  font-size: 0.8rem;
  transition: border-color 0.2s ease, color 0.2s ease;
}

.deployed:hover {
  color: var(--fg);
  border-color: rgba(255, 255, 255, 0.2);
}

/* Hide the corner UI while the last-chance gate is still up. */
.gate:not(.hidden) ~ .deployed,
.gate:not(.hidden) ~ .score,
.gate:not(.hidden) ~ .mute {
  display: none;
}

/* --- Catch-the-creatures HUD -------------------------------------------- */

.score {
  position: fixed;
  top: 1rem;
  left: 1rem;
  z-index: 4; /* above the roaming creatures */
  padding: 0.4rem 0.8rem;
  border-radius: 999px;
  background: rgba(20, 16, 35, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(6px);
  color: var(--fg);
  font-size: 0.9rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.mute {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 4;
  width: 2.3rem;
  height: 2.3rem;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: rgba(20, 16, 35, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(6px);
  font-size: 1.05rem;
  line-height: 1;
  cursor: pointer;
  transition: border-color 0.2s ease, transform 0.1s ease;
}

.mute:hover {
  border-color: rgba(255, 255, 255, 0.2);
}

.mute:active {
  transform: scale(0.92);
}

.deployed-logo {
  height: 0.95rem;
  width: auto;
  display: block;
  opacity: 0.92;
}

/* --- Last-chance confirmation gate -------------------------------------- */

.gate {
  position: fixed;
  inset: 0;
  z-index: 10; /* over everything, including the badge */
  display: grid;
  place-items: center;
  padding: 1.5rem;
  background: rgba(5, 4, 10, 0.78);
  backdrop-filter: blur(8px);
  animation: gate-fade 0.4s ease both;
}

.gate.hidden {
  display: none;
}

@keyframes gate-fade {
  from { opacity: 0; }
  to { opacity: 1; }
}

.gate-card {
  width: min(440px, 100%);
  text-align: center;
  background: rgba(20, 16, 35, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 18px;
  padding: clamp(1.5rem, 5vw, 2.25rem);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
}

.gate-title {
  margin: 0 0 0.6rem;
  font-size: clamp(1.4rem, 5vw, 1.9rem);
  letter-spacing: -0.01em;
  color: var(--accent);
}

.gate-text {
  margin: 0 0 1.6rem;
  color: var(--dim);
  font-size: 1.02rem;
  line-height: 1.55;
}

.gate-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  justify-content: center;
}

.gate-btn {
  font: inherit;
  font-weight: 600;
  border-radius: 999px;
  padding: 0.7rem 1.4rem;
  cursor: pointer;
  border: 1px solid transparent;
  transition: transform 0.1s ease, border-color 0.2s ease, filter 0.2s ease;
}

.gate-btn:active {
  transform: scale(0.96);
}

.gate-btn--leave {
  background: transparent;
  border-color: rgba(255, 255, 255, 0.18);
  color: var(--fg);
}

.gate-btn--leave:hover {
  border-color: var(--term);
  color: var(--term);
}

.gate-btn--open {
  background: linear-gradient(180deg, #ff5d7a, #e23355);
  color: #fff;
}

.gate-btn--open:hover {
  filter: brightness(1.08);
}

/* --- Teleport-to-safe-zone overlay -------------------------------------- */

.teleport {
  position: fixed;
  inset: 0;
  z-index: 11; /* over everything, including the gate */
  display: grid;
  place-items: center;
  padding: 1.5rem;
  background: rgba(4, 8, 6, 0.86);
  backdrop-filter: blur(8px);
  animation: gate-fade 0.4s ease both;
}

.teleport-card {
  width: min(440px, 100%);
  text-align: center;
  background: rgba(16, 26, 22, 0.92);
  border: 1px solid rgba(109, 255, 176, 0.25);
  border-radius: 18px;
  padding: clamp(1.5rem, 5vw, 2.25rem);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
}

.teleport-title {
  margin: 0 0 0.5rem;
  font-size: clamp(1.4rem, 5vw, 1.9rem);
  color: var(--term);
  text-shadow: 0 0 18px rgba(109, 255, 176, 0.4);
}

.teleport-text {
  margin: 0 0 1.5rem;
  color: var(--dim);
  font-size: 1.02rem;
}

.teleport-bar {
  width: 100%;
  height: 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  overflow: hidden;
}

.teleport-fill {
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: linear-gradient(90deg, #2ad17f, var(--term));
  box-shadow: 0 0 16px rgba(109, 255, 176, 0.6);
  transition: width 3.5s linear;
}

.teleport.go .teleport-fill {
  width: 100%;
}

/* The base .teleport sets display:grid, which would override the `hidden`
   attribute — keep it genuinely hidden until JS reveals it. */
.teleport[hidden] {
  display: none;
}

/* --- Respect reduced-motion --------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  .lid.shut,
  .lid.opening,
  .reveal,
  .gate,
  .teleport { animation: none; }
  .cursor { animation: none; }
  .box-face { transition: none; }
  /* Demons are placed but do not roam when reduced motion is requested,
     so keep them behind the card to avoid sitting on the text. */
  .rain { z-index: 0; }
}
