:root {
  --ink: #d9f2ff;
  --foam: #1d4d6e;
  --teal: #2dd4ff;
  --deep: #aee0ff;
  --gold: #ffd166;
  --pink: #ff8ad8;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  width: 100%;
  background:
    radial-gradient(
      ellipse at 50% 0%,
      #ffffff 0%,
      #eaf7ff 55%,
      #d9f2ff 100%
    )
    fixed;
  color: var(--foam);
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -webkit-user-select: none;
  user-select: none;
  touch-action: none;
  overscroll-behavior: none;
}

/* Layered light shafts behind the canvas — gives the page real depth */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background:
    /* Volumetric light shafts from above */
    linear-gradient(
      105deg,
      transparent 0%,
      rgba(255, 255, 255, 0.4) 18%,
      transparent 28%,
      transparent 48%,
      rgba(255, 255, 255, 0.3) 60%,
      transparent 70%,
      transparent 82%,
      rgba(255, 255, 255, 0.5) 92%,
      transparent 100%
    ),
    /* Soft caustic glow at the top */
    radial-gradient(
      ellipse 60% 30% at 50% -5%,
      rgba(255, 255, 255, 0.8),
      transparent 60%
    );
  filter: blur(1px);
}

/* Slow drifting bokeh “bubbles” */
body::after {
  content: "";
  position: fixed;
  inset: -10% 0 -10% 0;
  pointer-events: none;
  z-index: 0;
  background-image:
    radial-gradient(circle at 12% 80%, rgba(255, 255, 255, 0.6) 0 8px, transparent 9px),
    radial-gradient(circle at 78% 65%, rgba(255, 255, 255, 0.4) 0 6px, transparent 7px),
    radial-gradient(circle at 35% 95%, rgba(255, 255, 255, 0.5) 0 7px, transparent 8px),
    radial-gradient(circle at 88% 30%, rgba(255, 255, 255, 0.7) 0 5px, transparent 6px),
    radial-gradient(circle at 6%  40%, rgba(255, 255, 255, 0.4) 0 7px, transparent 8px),
    radial-gradient(circle at 50% 10%, rgba(255, 255, 255, 0.3) 0 6px, transparent 7px);
  background-size: 100% 100%;
  animation: drift 24s linear infinite;
  opacity: 0.9;
}

@keyframes drift {
  0%   { transform: translateY(0); }
  100% { transform: translateY(-12%); }
}

#app {
  position: fixed;
  inset: 0;
  z-index: 1;
}

#home-btn {
  position: fixed;
  top: 18px;
  left: 18px;
  z-index: 10;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.8);
  border: 1px solid rgba(45, 212, 255, 0.4);
  color: var(--foam);
  font-family: "Fredoka", "Inter", sans-serif;
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 0.22em;
  text-decoration: none;
  text-transform: uppercase;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: 0 4px 14px rgba(29, 77, 110, 0.1);
  transition: all .2s cubic-bezier(0.34, 1.56, 0.64, 1);
  animation: floatBtn 4s ease-in-out infinite;
}
@keyframes floatBtn {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}
#home-btn:hover {
  transform: translateY(-2px) scale(1.05);
  background: rgba(255, 255, 255, 1);
  color: var(--teal);
  box-shadow: 0 8px 20px rgba(45, 212, 255, 0.3);
  animation-play-state: paused;
}

#game-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
}

#game-container canvas {
  display: block;
  margin: 0 auto;
  border-radius: 18px;
  box-shadow:
    0 0 0 1px rgba(45, 212, 255, 0.35),
    0 0 40px rgba(45, 212, 255, 0.18),
    0 0 160px rgba(45, 212, 255, 0.10),
    0 40px 90px rgba(0, 0, 0, 0.7),
    inset 0 0 0 1px rgba(255, 255, 255, 0.06);
}

/* Side branding for wide screens — only shows when canvas leaves space */
.side-brand {
  position: fixed;
  pointer-events: none;
  z-index: 3;
  top: 50%;
  display: none;
  align-items: center;
  gap: 14px;
  font-family: "Fredoka", "Inter", sans-serif;
  font-weight: 600;
  letter-spacing: 0.42em;
  color: var(--foam-2);
  font-size: 12px;
  text-transform: uppercase;
  white-space: nowrap;
}
.side-brand.left  { left: 36px;  writing-mode: vertical-rl; transform: translateY(-50%) rotate(180deg); }
.side-brand.right { right: 36px; writing-mode: vertical-rl; transform: translateY(-50%); }
.side-brand .dot {
  width: 6px; height: 6px; border-radius: 999px;
  background: var(--teal);
  box-shadow: 0 0 12px var(--teal);
}
@media (min-width: 1100px) {
  .side-brand { display: inline-flex; }
}

/* --- Loading overlay --- */
#loading-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(
    ellipse at 50% 30%,
    #ffffff 0%,
    #eaf7ff 65%,
    #d9f2ff 100%
  );
  z-index: 50;
  transition: opacity 0.6s ease, visibility 0s 0.6s;
}

#loading-overlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.loading-inner {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 22px;
  padding: 32px 56px;
  border-radius: 28px;
  background: rgba(255, 255, 255, 0.8);
  border: 1px solid rgba(45, 212, 255, 0.4);
  box-shadow:
    0 0 40px rgba(45, 212, 255, 0.15),
    inset 0 0 40px rgba(45, 212, 255, 0.1);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 14px;
  font-family: "Fredoka", "Inter", sans-serif;
  font-weight: 700;
  letter-spacing: 0.08em;
  font-size: clamp(38px, 8vw, 92px);
  text-shadow: 0 4px 20px rgba(45, 212, 255, 0.3);
}

.brand-fini {
  background: linear-gradient(180deg, #1d4d6e 0%, #2dd4ff 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  -webkit-text-stroke: 1px rgba(11, 58, 92, 0.1);
}

.brand-frenzy {
  font-size: 0.7em;
  color: #ff8a3d;
  text-shadow: 0 2px 0 #b97a00, 0 4px 20px rgba(255, 138, 61, 0.3);
  letter-spacing: 0.12em;
}

.loading-bar {
  width: min(60vw, 380px);
  height: 14px;
  background: rgba(29, 77, 110, 0.1);
  border: 1px solid rgba(45, 212, 255, 0.4);
  border-radius: 999px;
  overflow: hidden;
  box-shadow: inset 0 1px 4px rgba(0, 0, 0, 0.1);
}

.loading-fill {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, #2dd4ff, #aee0ff, #ffd166);
  background-size: 200% 100%;
  animation: shimmer 2s linear infinite;
  transition: width 0.2s ease;
  border-radius: 999px;
  box-shadow: 0 0 16px rgba(45, 212, 255, 0.5);
}

@keyframes shimmer {
  0%   { background-position: 0% 0%; }
  100% { background-position: 200% 0%; }
}

.loading-tip {
  color: var(--foam-2);
  font-size: 13px;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  font-weight: 700;
}

/* =========================================================================
   AUTH OVERLAYS — sign-in gate, username picker, wallet prompt
   ========================================================================= */

.auth-overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(ellipse at 50% 0%, rgba(255,255,255,0.96) 0%, rgba(234,247,255,0.94) 60%, rgba(217,242,255,0.92) 100%);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  animation: authFade 240ms ease-out;
}
.auth-overlay.hidden { display: none; }

@keyframes authFade {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.auth-card {
  position: relative;
  width: min(440px, 100%);
  max-height: calc(100vh - 48px);
  overflow-y: auto;
  padding: 36px 32px 30px;
  border-radius: 28px;
  background: linear-gradient(180deg, #ffffff 0%, #f7fcff 100%);
  border: 1px solid rgba(45, 212, 255, 0.4);
  box-shadow:
    0 30px 80px rgba(29, 77, 110, 0.18),
    0 8px 24px rgba(45, 212, 255, 0.18),
    inset 0 1px 0 rgba(255, 255, 255, 0.9);
  text-align: center;
  animation: authPop 320ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

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

.auth-card--gate {
  width: min(480px, 100%);
  padding: 40px 36px 30px;
}

.auth-card__sparks {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  border-radius: 28px;
}
.auth-card__sparks span {
  position: absolute;
  width: 6px; height: 6px; border-radius: 999px;
  background: var(--gold);
  box-shadow: 0 0 18px var(--gold);
  opacity: 0.6;
  animation: sparkFloat 6s ease-in-out infinite;
}
.auth-card__sparks span:nth-child(1) { top: 14%; left: 10%;  animation-delay: 0s;   background: var(--teal); box-shadow: 0 0 18px var(--teal); }
.auth-card__sparks span:nth-child(2) { top: 22%; right: 14%; animation-delay: 1.2s; }
.auth-card__sparks span:nth-child(3) { top: 70%; left: 18%;  animation-delay: 2.4s; background: var(--pink); box-shadow: 0 0 18px var(--pink); }
.auth-card__sparks span:nth-child(4) { top: 80%; right: 22%; animation-delay: 3.6s; }

@keyframes sparkFloat {
  0%, 100% { transform: translateY(0) scale(1); opacity: 0.55; }
  50%      { transform: translateY(-14px) scale(1.2); opacity: 1; }
}

.auth-brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 22px;
  padding: 8px 16px;
  background: rgba(45, 212, 255, 0.06);
  border: 1px solid rgba(45, 212, 255, 0.18);
  border-radius: 999px;
}
.auth-brand__logo {
  width: 28px; height: 28px;
  border-radius: 999px;
  display: block;
}
.auth-brand__text {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  font-family: "Fredoka", "Inter", sans-serif;
  font-weight: 700;
  font-size: 18px;
  letter-spacing: 0.06em;
  line-height: 1;
}

.auth-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 56px; height: 56px;
  margin: 0 auto 16px;
  border-radius: 999px;
  background: linear-gradient(180deg, rgba(45,212,255,0.18) 0%, rgba(255,209,102,0.18) 100%);
  border: 1px solid rgba(45, 212, 255, 0.4);
  color: var(--foam);
  box-shadow:
    0 8px 22px rgba(45, 212, 255, 0.2),
    inset 0 1px 0 rgba(255, 255, 255, 0.7);
}

.auth-title {
  margin: 0 0 8px;
  font-family: "Fredoka", "Inter", sans-serif;
  font-weight: 700;
  font-size: 30px;
  color: #0e3a58;
  letter-spacing: 0.01em;
  text-shadow: 0 2px 12px rgba(45, 212, 255, 0.12);
}

.auth-subtitle {
  margin: 0 0 22px;
  font-size: 14px;
  line-height: 1.55;
  color: #557891;
  font-weight: 500;
}

.btn-x {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  width: 100%;
  padding: 16px 22px;
  border: 0;
  border-radius: 16px;
  background: linear-gradient(180deg, #15181c 0%, #000000 100%);
  color: #fff;
  font-family: "Fredoka", "Inter", sans-serif;
  font-weight: 700;
  font-size: 16px;
  letter-spacing: 0.04em;
  cursor: pointer;
  box-shadow:
    0 12px 28px rgba(0, 0, 0, 0.35),
    inset 0 1px 0 rgba(255, 255, 255, 0.18);
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}
.btn-x:hover {
  transform: translateY(-2px);
  box-shadow:
    0 16px 36px rgba(0, 0, 0, 0.45),
    inset 0 1px 0 rgba(255, 255, 255, 0.25);
}
.btn-x:active { transform: translateY(0); }
.btn-x svg { color: #fff; }

.auth-demo {
  margin-top: 18px;
  padding: 16px;
  border-radius: 16px;
  background: rgba(255, 245, 200, 0.55);
  border: 1px dashed rgba(255, 158, 30, 0.5);
  text-align: left;
}
.auth-demo__label {
  font-family: "Fredoka", "Inter", sans-serif;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.18em;
  color: #b06a00;
  text-transform: uppercase;
  margin-bottom: 10px;
}
.auth-demo__row {
  display: flex;
  align-items: stretch;
  gap: 8px;
  background: #fff;
  border: 1px solid rgba(255, 158, 30, 0.4);
  border-radius: 12px;
  padding: 4px;
}
.auth-demo__at {
  display: inline-flex;
  align-items: center;
  padding: 0 10px;
  font-weight: 700;
  color: #b06a00;
}
.auth-demo__row input {
  flex: 1;
  border: 0;
  outline: 0;
  background: transparent;
  font-family: "Inter", sans-serif;
  font-size: 14px;
  font-weight: 600;
  color: #1d4d6e;
  padding: 8px 4px;
}
.auth-demo__hint {
  margin-top: 8px;
  font-size: 11px;
  color: #8a6300;
}
.auth-demo__hint code {
  background: rgba(255, 255, 255, 0.7);
  padding: 1px 6px;
  border-radius: 4px;
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
  font-size: 10.5px;
}

.auth-foot {
  margin-top: 18px;
  font-size: 11.5px;
  color: #8aa9be;
  letter-spacing: 0.06em;
}

/* ─── Inputs ─── */
.auth-input {
  display: flex;
  align-items: stretch;
  margin-top: 6px;
  background: #fff;
  border: 2px solid rgba(45, 212, 255, 0.4);
  border-radius: 14px;
  overflow: hidden;
  transition: border-color 0.16s ease, box-shadow 0.16s ease;
}
.auth-input:focus-within {
  border-color: var(--teal);
  box-shadow: 0 0 0 4px rgba(45, 212, 255, 0.18);
}
.auth-input__prefix {
  display: inline-flex;
  align-items: center;
  padding: 0 12px;
  background: rgba(45, 212, 255, 0.1);
  color: var(--foam);
  font-weight: 700;
  font-size: 16px;
  font-family: "Fredoka", "Inter", sans-serif;
}
.auth-input input {
  flex: 1;
  min-width: 0;
  padding: 14px 16px;
  border: 0;
  outline: 0;
  background: transparent;
  font-family: "Inter", sans-serif;
  font-weight: 600;
  font-size: 16px;
  color: #1d4d6e;
}

.auth-error {
  min-height: 18px;
  margin: 8px 0 4px;
  font-size: 12.5px;
  font-weight: 600;
  color: #c4366d;
  letter-spacing: 0.02em;
}

.auth-rules {
  margin-top: 12px;
  font-size: 11.5px;
  color: #8aa9be;
  letter-spacing: 0.04em;
}

/* ─── Buttons (modal CTAs) ─── */
.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  margin-top: 14px;
  padding: 14px 22px;
  border: 0;
  border-radius: 14px;
  background: linear-gradient(180deg, #ffd166 0%, #ff9f1c 100%);
  color: #4a2c00;
  font-family: "Fredoka", "Inter", sans-serif;
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.04em;
  cursor: pointer;
  box-shadow:
    0 10px 22px rgba(255, 159, 28, 0.35),
    inset 0 1px 0 rgba(255, 255, 255, 0.55);
  transition: transform 0.16s ease, box-shadow 0.16s ease;
}
.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow:
    0 14px 30px rgba(255, 159, 28, 0.5),
    inset 0 1px 0 rgba(255, 255, 255, 0.6);
}
.btn-primary:active { transform: translateY(0); }
.btn-primary:disabled {
  opacity: 0.7;
  cursor: progress;
  transform: none;
}

.btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 12px 18px;
  border: 1.5px solid rgba(45, 212, 255, 0.5);
  border-radius: 14px;
  background: #fff;
  color: var(--foam);
  font-family: "Fredoka", "Inter", sans-serif;
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: all 0.16s ease;
}
.btn-secondary:hover {
  background: rgba(45, 212, 255, 0.1);
  transform: translateY(-1px);
}

.auth-actions {
  display: flex;
  gap: 10px;
  margin-top: 14px;
}
.auth-actions .btn-primary { margin-top: 0; flex: 1; }
.auth-actions .btn-secondary { flex: 0 0 auto; }

/* ─── Modal close button ─── */
.auth-modal__close {
  position: absolute;
  top: 14px; right: 16px;
  width: 32px; height: 32px;
  border: 0;
  border-radius: 999px;
  background: rgba(45, 212, 255, 0.1);
  color: var(--foam);
  font-size: 22px;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  transition: all 0.16s ease;
}
.auth-modal__close:hover {
  background: rgba(45, 212, 255, 0.22);
  transform: rotate(90deg);
}

/* =========================================================================
   PROFILE CHIP (top-right corner)
   ========================================================================= */
.profile-chip {
  position: fixed;
  top: 18px; right: 18px;
  z-index: 10;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 6px 14px 6px 6px;
  border: 1px solid rgba(45, 212, 255, 0.4);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  color: var(--foam);
  font-family: "Fredoka", "Inter", sans-serif;
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.04em;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(29, 77, 110, 0.1);
  transition: all .2s ease;
}
.profile-chip.hidden { display: none; }
.profile-chip:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 20px rgba(45, 212, 255, 0.3);
  background: rgba(255, 255, 255, 1);
}
.profile-chip__avatar {
  display: inline-flex;
  width: 28px; height: 28px;
  border-radius: 999px;
  overflow: hidden;
  background: linear-gradient(135deg, #2dd4ff, #ff8ad8);
  border: 1.5px solid #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}
.profile-chip__avatar img {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
}
.profile-chip__caret { color: #5a7d94; }

.profile-menu {
  position: fixed;
  top: 60px; right: 18px;
  z-index: 10;
  min-width: 180px;
  padding: 6px;
  border: 1px solid rgba(45, 212, 255, 0.3);
  border-radius: 16px;
  background: #fff;
  box-shadow: 0 14px 40px rgba(29, 77, 110, 0.18);
  animation: menuPop 160ms cubic-bezier(0.34, 1.56, 0.64, 1);
}
.profile-menu.hidden { display: none; }
@keyframes menuPop {
  from { transform: translateY(-8px) scale(0.96); opacity: 0; }
  to   { transform: translateY(0) scale(1); opacity: 1; }
}
.profile-menu__item {
  display: block;
  width: 100%;
  padding: 10px 14px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  text-align: left;
  font-family: "Inter", sans-serif;
  font-weight: 600;
  font-size: 13.5px;
  color: var(--foam);
  cursor: pointer;
  transition: background 0.12s ease;
}
.profile-menu__item:hover {
  background: rgba(45, 212, 255, 0.1);
}
.profile-menu__item--danger { color: #c4366d; }
.profile-menu__item--danger:hover { background: rgba(255, 138, 184, 0.15); }
.profile-menu__divider {
  height: 1px;
  margin: 4px 8px;
  background: rgba(45, 212, 255, 0.2);
}

/* On narrow screens, scoot the home button down so it doesn't collide
   with the profile chip when both stack on the same edge. */
@media (max-width: 540px) {
  .auth-card { padding: 28px 22px; }
  .auth-title { font-size: 26px; }
  .auth-subtitle { font-size: 13px; }
  .profile-chip { font-size: 12px; padding: 5px 12px 5px 5px; }
  .profile-chip__handle { max-width: 100px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}
