/* Auth teaser: starfield canvas + centered logo (from website/src/style.css). Scoped to #auth-overlay. */

#auth-overlay #canvas-container {
  position: absolute;
  inset: 0;
  z-index: 0;
}

#auth-overlay .pixel-canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.auth-teaser-bg {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
}

#auth-overlay .auth-teaser-bg .overlay {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  padding: 24px;
}

#auth-overlay .logo {
  position: relative;
  z-index: 2;
  margin: 0;
  font-family: "Press Start 2P", monospace;
  text-align: center;
  line-height: 1.16;
  transform-origin: center center;
  opacity: 1;
}

#auth-overlay .logo__text {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.48em;
  overflow: visible;
}

#auth-overlay .logo__lines {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.48em;
  /* One N→E sweep, then 5s pause, then repeat (13 letters: --i 0…12, divisor 12). */
  --logo-sweep: 3.5s;
  --logo-pause: 5s;
  --logo-cycle: calc(var(--logo-sweep) + var(--logo-pause));
  --logo-shine: linear-gradient(
    118deg,
    transparent 0%,
    transparent 32%,
    rgba(255, 255, 255, 0.22) 42%,
    rgba(248, 254, 255, 0.82) 49%,
    rgba(150, 228, 255, 0.65) 52%,
    rgba(90, 200, 255, 0.28) 58%,
    transparent 68%,
    transparent 100%
  );
}

/* One row of letters; shine runs per character with stagger via --i */
#auth-overlay .logo-line {
  display: inline-flex;
  flex-wrap: nowrap;
  align-items: baseline;
  justify-content: center;
  width: max-content;
  max-width: 100%;
}

#auth-overlay .logo-line--primary {
  font-size: clamp(1.18rem, 6vw, 2.58rem);
  --logo-char-fill: linear-gradient(
    180deg,
    #eafbff 0%,
    #eafbff 28%,
    #5ad4ff 28%,
    #5ad4ff 58%,
    #0c3a78 58%,
    #061428 100%
  );
}

#auth-overlay .logo-line--sub {
  font-size: clamp(0.54rem, 2.45vw, 0.92rem);
  gap: 0.36em;
  padding-inline: 0.2em;
  --logo-char-fill: linear-gradient(
    180deg,
    #d8f6ff 0%,
    #d8f6ff 30%,
    #48c8f0 30%,
    #48c8f0 60%,
    #0a3268 60%,
    #040c20 100%
  );
}

#auth-overlay .logo-char {
  display: inline-block;
  color: transparent;
  background-image: var(--logo-shine), var(--logo-char-fill);
  background-size: 220% 100%, 100% 100%;
  background-position: 100% 0, 0 0;
  background-repeat: no-repeat, no-repeat;
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-stroke: 2.75px #07080c;
  paint-order: stroke fill;
  transform-origin: center center;
  will-change: transform, filter, background-position;
  text-shadow:
    0 0 1px rgba(240, 248, 255, 0.45),
    0 0 5px rgba(170, 215, 255, 0.35),
    0 0 12px rgba(90, 160, 230, 0.22),
    0 0 20px rgba(45, 100, 185, 0.14);
  animation: logoCharShineSweep var(--logo-cycle) ease-in-out infinite;
  /* Negative delay phases letters along the shared sweep window (N first, E last). */
  animation-delay: calc((var(--i, 0) / 12) * -1 * var(--logo-sweep));
}

#auth-overlay .logo-line--primary .logo-char {
  -webkit-text-stroke: 3.35px #07080c;
}

#auth-overlay .logo-line--sub .logo-char {
  -webkit-text-stroke: 2.35px #07080c;
}

/*
 * Keyframes span full --logo-cycle; only the first (sweep / cycle * 100)% is active.
 * 3.5s / 8.5s ≈ 41.18% — then hold idle through 100% (5s pause).
 */
@keyframes logoCharShineSweep {
  0% {
    background-position: 100% 0, 0 0;
    filter: brightness(1);
    transform: scale(1);
    text-shadow:
      0 0 1px rgba(240, 248, 255, 0.45),
      0 0 5px rgba(170, 215, 255, 0.35),
      0 0 12px rgba(90, 160, 230, 0.22),
      0 0 20px rgba(45, 100, 185, 0.14);
  }
  9% {
    filter: brightness(1.06);
    transform: scale(1.025);
  }
  18.5% {
    background-position: -95% 0, 0 0;
    filter: brightness(1.28);
    transform: scale(1.055);
    text-shadow:
      0 0 2px rgba(255, 255, 255, 0.55),
      0 0 10px rgba(190, 235, 255, 0.42),
      0 0 20px rgba(100, 210, 255, 0.3),
      0 0 30px rgba(60, 140, 220, 0.18);
  }
  29% {
    filter: brightness(1.05);
    transform: scale(1.02);
  }
  41.18%,
  100% {
    background-position: 100% 0, 0 0;
    filter: brightness(1);
    transform: scale(1);
    text-shadow:
      0 0 1px rgba(240, 248, 255, 0.45),
      0 0 5px rgba(170, 215, 255, 0.35),
      0 0 12px rgba(90, 160, 230, 0.22),
      0 0 20px rgba(45, 100, 185, 0.14);
  }
}

@keyframes logoCharEnterGameReduced {
  0% {
    opacity: 1;
    transform: translate3d(0, 0, 0) scale(1);
  }
  100% {
    opacity: 0;
    transform: translate3d(0, 12px, 0) scale(0.96);
  }
}

/* Teaser `logoLinesDeconstruct` intro only (no rebuild tail); game shards use one flight vector + fade. */
@keyframes authLogoLinesShatterEnter {
  0%,
  6% {
    opacity: 1;
    filter: none;
    transform: none;
  }
  10% {
    opacity: 0.35;
    filter: contrast(2.2) blur(0.5px);
    transform: translateY(2px) scale(0.99);
  }
  14%,
  100% {
    opacity: 0;
    filter: blur(3px);
    transform: translateY(6px) scale(0.97);
    visibility: hidden;
  }
}

@keyframes authLogoLinesShatterEnterReduced {
  0% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    visibility: hidden;
  }
}

@media (prefers-reduced-motion: reduce) {
  #auth-overlay {
    --shatter-ms: 0.35s;
    --enter-curtain-ms: 0.14s;
    --enter-game-ms: calc(var(--shatter-ms) + var(--enter-curtain-ms));
  }

  #auth-overlay .logo-char {
    animation: none;
    will-change: auto;
    filter: none;
    transform: none;
    background-size: 100% 100%;
    background-position: 0 0;
    background-image: var(--logo-char-fill);
  }

  #auth-overlay.auth-overlay--enter-game .auth-glass-shard {
    display: none;
  }

  #auth-overlay.auth-overlay--enter-game .logo__lines {
    animation: authLogoLinesShatterEnterReduced var(--shatter-ms) ease-out forwards;
  }

  #auth-overlay.auth-overlay--enter-game .logo-char {
    animation: none !important;
    will-change: auto;
    filter: none;
  }

  #auth-overlay.auth-overlay--enter-game .auth-overlay__enter-curtain {
    animation: authEnterCurtainFade var(--enter-curtain-ms) linear forwards;
    animation-delay: var(--shatter-ms);
  }
}

/* Layout: logo center (background layer), account panels on the right between logo and screen edge */
#auth-overlay {
  /* Logo break + single-hop shard flight to one random spot, then curtain */
  --shatter-ms: 1.1s;
  --enter-curtain-ms: 0.52s;
  --enter-game-ms: calc(var(--shatter-ms) + var(--enter-curtain-ms));
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent 0%, transparent 42%, rgba(5, 3, 13, 0.55) 72%, rgba(5, 3, 13, 0.82) 100%);
  display: flex;
  flex-direction: column;
  min-height: 0;
  z-index: 30;
  padding: 16px;
  color: #e5e7eb;
  font: 14px "Press Start 2P", monospace;
  cursor: none;
}

#auth-overlay input,
#auth-overlay select,
#auth-overlay textarea {
  cursor: none;
}

/* Native cursor hidden; pixel pointer drawn on #auth-cursor-layer (see main.js syncAuthCursorLayer). */
#auth-overlay button {
  cursor: none;
}

#auth-overlay .btn {
  cursor: none;
}

#auth-overlay label.remember-row {
  cursor: none;
}

/* Pixel window chrome scrollbars (match in-game backpack / menus). */
#auth-overlay,
#auth-overlay * {
  scrollbar-width: thin;
  scrollbar-color: #52525b #0f0f12;
}
#auth-overlay *::-webkit-scrollbar {
  width: 10px;
  height: 10px;
  cursor: none;
}
#auth-overlay *::-webkit-scrollbar-track {
  background: #0f0f12;
  border: 1px solid #27272a;
  cursor: none;
}
#auth-overlay *::-webkit-scrollbar-thumb {
  background: #52525b;
  border: 1px solid #3f3f46;
  box-shadow: inset 1px 1px 0 #71717a;
  border-radius: 0;
  cursor: none;
}
#auth-overlay *::-webkit-scrollbar-thumb:hover {
  background: #71717a;
  cursor: none;
}
#auth-overlay *::-webkit-scrollbar-corner {
  background: #0f0f12;
  cursor: none;
}
#auth-overlay *::-webkit-scrollbar-button {
  display: none;
  width: 0;
  height: 0;
  cursor: none;
}

#auth-overlay .custom-select {
  position: relative;
}

#auth-overlay .custom-select-native {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
  opacity: 0;
  pointer-events: none;
}

#auth-overlay .custom-select-trigger {
  display: block;
  width: 100%;
  text-align: left;
  background: #0a1323;
  border: 1px solid #4b5563;
  color: #f9fafb;
  border-radius: 4px;
  padding: 9px 8px;
  font: 12px "Press Start 2P", monospace;
  box-shadow: inset 0 -1px 0 rgba(0, 0, 0, 0.28);
  cursor: none;
}

#auth-overlay .custom-select-trigger:focus {
  outline: none;
  border-color: #60a5fa;
  box-shadow: 0 0 0 1px rgba(96, 165, 250, 0.3), inset 0 -1px 0 rgba(0, 0, 0, 0.28);
}

#auth-overlay .custom-select-list {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 4px);
  z-index: 10;
  margin: 0;
  padding: 4px 0;
  list-style: none;
  background: #0a1323;
  border: 1px solid #4b5563;
  border-radius: 4px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.45);
  max-height: 200px;
  overflow-y: auto;
  cursor: none;
}

#auth-overlay .custom-select-option {
  padding: 8px 10px;
  font: 12px "Press Start 2P", monospace;
  color: #f9fafb;
  cursor: none;
}

#auth-overlay .custom-select-option:hover,
#auth-overlay .custom-select-option.custom-select-option--selected {
  background: rgba(96, 165, 250, 0.2);
  color: #e0f2fe;
}

.auth-layout {
  position: relative;
  z-index: 2;
  flex: 1;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: flex-start;
  min-height: 0;
  width: 100%;
  pointer-events: none;
  /* Keep rails clear of the bottom auth footer stack */
  padding-bottom: clamp(64px, 12vh, 96px);
  box-sizing: border-box;
}

.auth-layout__spacer {
  flex: 1;
  min-width: 0;
}

.auth-rail {
  pointer-events: auto;
  flex: 0 0 auto;
  /* Narrow viewports: nearly full width; wider screens: cap width to the right half so panels stay between center logo and right edge */
  width: min(440px, 92vw);
  max-height: 100%;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  /* Rugged panel corners extend ~12px past each edge (::after); gap must clear BL/BR + TL/TR between stacked widgets */
  gap: 36px;
  /* Extra inline padding so panel corner bumpers (::after, negative inset) are not clipped */
  padding: 10px 16px 12px 16px;
}

.auth-rail--left {
  /* Mirror right rail; docked encyclopedia sits opposite login/character select */
  justify-content: center;
  width: min(620px, calc(52vw - 32px));
}

@media (min-width: 720px) {
  .auth-rail {
    width: min(440px, calc(50vw - 48px));
  }
  .auth-rail--left {
    width: min(620px, calc(52vw - 32px));
  }
}

@media (max-width: 900px) {
  .auth-layout {
    flex-wrap: wrap;
    justify-content: center;
    align-content: flex-start;
    overflow-y: auto;
    padding-bottom: 12px;
  }
  .auth-layout__spacer {
    display: none;
  }
  .auth-rail {
    width: min(440px, 92vw);
  }
  .auth-rail--left {
    width: min(620px, 92vw);
  }
  .auth-footer {
    position: static;
    transform: none;
    margin-top: 12px;
    margin-bottom: 8px;
  }
}

/* `.panel` rugged frame comes from `index.html` (do not override background/border here). */

/* Login / Register submit + character-slot Play / Create Here — same NO-LIFE cyan gradient & typography */
#auth-overlay #login-form .btn[type="submit"],
#auth-overlay #register-form .btn[type="submit"],
#auth-overlay #character-panel #character-slots .slot .slot-primary-btn {
  margin-top: 8px;
  width: 100%;
  box-sizing: border-box;
  border-radius: 4px;
  font-family: "Press Start 2P", monospace;
  text-transform: uppercase;
  cursor: none;
  font-size: 12px;
  letter-spacing: 0.55px;
  padding: 12px 12px;
  background-color: #256896;
  background-image: linear-gradient(
    180deg,
    #f4fcff 0%,
    #e9f8ff 11%,
    #d7f1ff 22%,
    #b9e6ff 33%,
    #92d7f8 44%,
    #6bc4ef 54%,
    #4aaddf 64%,
    #3592ca 74%,
    #2a7ab5 84%,
    #256896 100%
  );
  color: #111;
  text-shadow:
    0 1px 0 rgba(255, 255, 255, 0.55),
    0 0 12px rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(130, 210, 255, 0.42);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.22),
    inset 0 -2px 0 rgba(0, 0, 0, 0.12),
    0 2px 0 rgba(0, 0, 0, 0.22);
}

/* Same footprint for Play vs Create Here (short label vs wrapped two-line label) */
#auth-overlay #character-panel #character-slots .slot .slot-primary-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  line-height: 1.35;
  min-height: 56px;
}

/* Single-line PLAY scales up to feel closer to stacked CREATE / HERE at 12px */
#auth-overlay #character-panel #character-slots .slot .slot-primary-btn--play {
  font-size: 15px;
  letter-spacing: 0.65px;
}

#auth-overlay #login-form .btn[type="submit"]:hover,
#auth-overlay #register-form .btn[type="submit"]:hover,
#auth-overlay #character-panel #character-slots .slot .slot-primary-btn:hover {
  filter: brightness(1.05) saturate(1.03);
}

#auth-overlay #login-form .btn[type="submit"]:active,
#auth-overlay #register-form .btn[type="submit"]:active,
#auth-overlay #character-panel #character-slots .slot .slot-primary-btn:active {
  transform: translateY(1px);
  box-shadow:
    inset 0 -1px 0 rgba(0, 0, 0, 0.22),
    0 1px 0 rgba(0, 0, 0, 0.3);
}

/* --- Enter game (Play): logo → star-square bits (shatter → fall → fade) → curtain → inGame --- */
.auth-logo-stage {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: min(44vh, 380px);
  width: 100%;
}

#auth-overlay .auth-fall-stars {
  position: absolute;
  inset: -8% -5% 0;
  pointer-events: none;
  z-index: 0;
  overflow: visible;
}

#auth-overlay .auth-glass-shards {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  overflow: visible;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

#auth-overlay .auth-glass-shard {
  position: absolute;
  box-sizing: border-box;
  border-radius: 0;
  border: none;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  /* `background` set in JS to match logo letter fills (NO-LIFE / ONLINE rows) */
  box-shadow: none;
  transform-origin: center center;
  opacity: 1;
  will-change: transform, opacity;
}

/* --dx / --dy / --rot: one random destination on the overlay, then quick fade */
#auth-overlay.auth-overlay--enter-game .auth-glass-shard {
  animation: authLogoShardFlight var(--shatter-ms) cubic-bezier(0.2, 0.75, 0.15, 1) forwards;
}

@keyframes authLogoShardFlight {
  0% {
    opacity: 1;
    transform: translate3d(0, 0, 0) rotate(0deg);
  }
  78% {
    opacity: 1;
    transform: translate3d(var(--dx, 0px), var(--dy, 0px), 0) rotate(var(--rot, 0deg));
  }
  100% {
    opacity: 0;
    transform: translate3d(var(--dx, 0px), var(--dy, 0px), 0) rotate(var(--rot, 0deg));
  }
}

.auth-footer {
  position: absolute;
  left: 50%;
  bottom: clamp(10px, 2.6vh, 20px);
  z-index: 32;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  transform: translateX(-50%);
  pointer-events: none;
  max-width: min(560px, calc(100vw - 24px));
  text-align: center;
}

.auth-dev-status {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin: 0;
  padding: 4px 0;
  pointer-events: none;
  animation: authDevStatusPulse 3.6s ease-in-out infinite;
}

.auth-footer__credit {
  margin: 0;
  font: clamp(6px, 1.15vw, 8px) / 1.55 "Press Start 2P", monospace;
  letter-spacing: 0.12em;
  color: #94a3b8;
  text-shadow: 0 1px 0 rgba(2, 8, 20, 0.95), 0 0 10px rgba(2, 8, 20, 0.55);
}

.auth-footer__name {
  color: #eafbff;
  text-shadow:
    0 0 8px rgba(90, 212, 255, 0.55),
    0 1px 0 rgba(2, 8, 20, 0.95);
}

.auth-footer__links {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  pointer-events: auto;
}

.auth-footer__link {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 9px;
  border: 1px solid #334155;
  background: rgba(10, 19, 35, 0.9);
  color: #cbd5e1;
  font: clamp(6px, 1.1vw, 8px) / 1.2 "Press Start 2P", monospace;
  letter-spacing: 0.06em;
  text-decoration: none;
  cursor: none;
  box-shadow: 0 0 0 1px rgba(6, 20, 40, 0.75);
  transition:
    border-color 0.16s ease,
    color 0.16s ease,
    box-shadow 0.16s ease,
    transform 0.16s ease,
    background 0.16s ease;
}

.auth-footer__icon {
  width: 10px;
  height: 10px;
  flex-shrink: 0;
  fill: currentColor;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.auth-footer__link--x:hover,
.auth-footer__link--x:focus-visible {
  border-color: #5ad4ff;
  color: #eafbff;
  background: rgba(12, 40, 72, 0.95);
  box-shadow:
    0 0 0 1px rgba(6, 20, 40, 0.75),
    0 0 14px rgba(90, 212, 255, 0.35);
  transform: translateY(-1px);
  outline: none;
}

.auth-footer__link--coffee:hover,
.auth-footer__link--coffee:focus-visible {
  border-color: #fbbf24;
  color: #fef3c7;
  background: rgba(56, 36, 12, 0.95);
  box-shadow:
    0 0 0 1px rgba(20, 12, 4, 0.75),
    0 0 14px rgba(251, 191, 36, 0.32);
  transform: translateY(-1px);
  outline: none;
}

.auth-dev-status__mark {
  width: 6px;
  height: 6px;
  flex-shrink: 0;
  background: #5ad4ff;
  box-shadow: 0 0 6px rgba(90, 212, 255, 0.55);
  transform: rotate(45deg);
}

.auth-dev-status__text {
  font: clamp(7px, 1.35vw, 9px) / 1.2 "Press Start 2P", monospace;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  white-space: nowrap;
  color: transparent;
  background-image:
    linear-gradient(
      118deg,
      transparent 0%,
      transparent 36%,
      rgba(255, 255, 255, 0.22) 44%,
      rgba(248, 254, 255, 0.85) 50%,
      rgba(180, 240, 255, 0.55) 54%,
      transparent 64%,
      transparent 100%
    ),
    linear-gradient(
      180deg,
      #ffffff 0%,
      #eafbff 35%,
      #9ae8ff 70%,
      #5ad4ff 100%
    );
  background-size: 200% 100%, 100% 100%;
  background-position: 0% 0, 0 0;
  background-repeat: repeat, no-repeat;
  -webkit-background-clip: text;
  background-clip: text;
  filter: drop-shadow(0 1px 0 rgba(2, 8, 20, 0.9));
  animation: authDevStatusShine 5.5s ease-in-out infinite;
}

@keyframes authDevStatusPulse {
  0%,
  100% {
    opacity: 0.85;
  }
  50% {
    opacity: 1;
  }
}

@keyframes authDevStatusShine {
  0%,
  18% {
    background-position: 0% 0, 0 0;
  }
  42% {
    background-position: 200% 0, 0 0;
  }
  100% {
    background-position: 200% 0, 0 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .auth-dev-status,
  .auth-dev-status__text {
    animation: none;
  }
  .auth-dev-status {
    opacity: 0.92;
  }
  .auth-dev-status__text {
    background-image: linear-gradient(
      180deg,
      #ffffff 0%,
      #eafbff 35%,
      #9ae8ff 70%,
      #5ad4ff 100%
    );
    background-size: 100% 100%;
    background-position: 0 0;
  }
}

.auth-overlay__enter-curtain {
  position: absolute;
  inset: 0;
  z-index: 35;
  pointer-events: none;
  background: #020108;
  opacity: 0;
}

#auth-overlay.auth-overlay--enter-game .auth-overlay__enter-curtain {
  animation: none;
  opacity: 0;
}

@keyframes authEnterCurtainFade {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

#auth-overlay.auth-overlay--enter-game .auth-teaser-bg {
  filter: none;
  transition: none;
}

#auth-overlay.auth-overlay--enter-game .auth-rail {
  pointer-events: auto;
  opacity: 1;
  transition: none;
  filter: none;
}

#auth-overlay.auth-overlay--enter-game .auth-footer {
  opacity: 0;
  transition: opacity 0.28s ease-out;
  pointer-events: none;
}

#auth-overlay.auth-overlay--enter-game .auth-footer .auth-dev-status {
  animation: none;
}

/* Stop per-letter shine; teaser-style break runs on `.logo__lines` instead */
#auth-overlay.auth-overlay--enter-game .logo-char {
  animation: none !important;
}

#auth-overlay.auth-overlay--enter-game .logo__lines {
  animation: authLogoLinesShatterEnter var(--shatter-ms) ease-in-out forwards;
  will-change: opacity, filter, transform;
}
