:root {
  --auth-ink: #edf5ff;
  --auth-muted: #9eacc6;
  --auth-line: rgba(156, 184, 235, .18);
  --auth-accent: #76e4c4;
  --auth-accent-2: #73a8ff;
  --auth-danger: #ff8b97;
}

.auth-pending { overflow: hidden; }
.auth-pending #game-root { pointer-events: none; filter: blur(10px) saturate(.65); transform: scale(1.02); }
.auth-gate {
  position: fixed;
  inset: 0;
  z-index: 5000;
  display: grid;
  place-items: center;
  min-height: 100dvh;
  padding: clamp(18px, 3vw, 44px);
  box-sizing: border-box;
  overflow: hidden;
  isolation: isolate;
  color: var(--auth-ink);
  background:
    linear-gradient(90deg, rgba(3, 12, 29, .25), rgba(4, 13, 32, .55) 48%, rgba(4, 12, 28, .82)),
    url("../assets/ui/menu-bg.webp") center / cover no-repeat,
    #07162e;
}
.auth-gate.hidden { display: none; }
.auth-scene {
  position: absolute;
  inset: 0;
  z-index: -1;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: clamp(34px, 5vw, 76px);
  box-sizing: border-box;
  overflow: hidden;
  pointer-events: none;
}
.auth-scene::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background: linear-gradient(to top, rgba(2, 9, 23, .92), transparent 55%);
}
.auth-scene p {
  margin: 0 0 12px;
  color: #7ee5c8;
  font-size: 12px;
  font-weight: 900;
  letter-spacing: .22em;
}
.auth-scene h1 { max-width: min(520px, 40vw); margin: 0 0 12px; font-size: clamp(34px, 4.2vw, 66px); line-height: 1.04; }
.auth-scene > span:last-child { max-width: 500px; color: #c8d7eb; font-size: clamp(15px, 1.5vw, 20px); }
.auth-heroes { position: absolute; top: 10%; left: 26%; display: flex; align-items: flex-end; transform: translateX(-50%); }
.auth-heroes img { width: clamp(125px, 13vw, 220px); filter: drop-shadow(0 28px 26px rgba(0,0,0,.42)); animation: auth-float 4.8s ease-in-out infinite; }
.auth-heroes img + img { width: clamp(105px, 12vw, 200px); margin-left: -28px; animation-delay: -.9s; }
.auth-orb { position: absolute; width: 260px; height: 260px; border-radius: 50%; filter: blur(1px); opacity: .45; background: radial-gradient(circle at 35% 30%, #9ef8dc, #427ad7 42%, transparent 70%); }
.orb-one { top: 3%; left: 3%; }
.orb-two { right: -80px; bottom: 13%; width: 340px; height: 340px; opacity: .24; }

.auth-card {
  width: min(520px, calc(100% - 40px));
  max-height: calc(100dvh - clamp(36px, 6vw, 88px));
  margin-left: auto;
  margin-right: clamp(0px, 7vw, 124px);
  padding: clamp(24px, 3vw, 42px);
  overflow-x: hidden;
  overflow-y: auto;
  scrollbar-gutter: stable;
  border: 1px solid var(--auth-line);
  border-radius: 30px;
  box-sizing: border-box;
  background: linear-gradient(155deg, rgba(13, 27, 53, .94), rgba(7, 19, 42, .9));
  box-shadow: 0 30px 90px rgba(0, 0, 0, .38);
  backdrop-filter: blur(22px);
}
.auth-language { display: flex; align-items: center; justify-content: flex-end; gap: 9px; margin: -6px 0 16px; color: var(--auth-muted); font-size: 11px; font-weight: 800; }
.auth-language select { min-height: 34px; padding: 0 32px 0 11px; border: 1px solid var(--auth-line); border-radius: 10px; outline: none; color: #eef7ff; background: rgba(4,14,32,.8); }
.auth-language select:focus { border-color: var(--auth-accent); box-shadow: 0 0 0 3px rgba(118,228,196,.1); }
.auth-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 30px; }
.auth-brand img { width: 50px; height: 50px; object-fit: contain; border-radius: 15px; background: rgba(255,255,255,.06); }
.auth-brand div { display: grid; }
.auth-brand strong { font-size: 18px; }
.auth-brand small { color: var(--auth-muted); }
.auth-card h2 { margin: 20px 0 7px; font-size: 28px; }
.auth-card p { color: var(--auth-muted); }
.auth-tabs { display: grid; grid-template-columns: 1fr 1fr; padding: 4px; border: 1px solid var(--auth-line); border-radius: 14px; background: rgba(2, 10, 26, .45); }
.auth-tabs button { min-height: 42px; border: 0; border-radius: 10px; color: var(--auth-muted); background: transparent; font-weight: 850; cursor: pointer; }
.auth-tabs button.active { color: #07192a; background: linear-gradient(135deg, var(--auth-accent), #aaf0db); box-shadow: 0 8px 22px rgba(82, 223, 184, .2); }
#auth-form { display: grid; gap: 14px; margin-top: 22px; }
#auth-form > label { display: grid; gap: 7px; color: #c9d5e7; font-size: 13px; font-weight: 750; }
#auth-form input[type="email"],
#auth-form input[type="password"],
#auth-form input[type="text"] {
  width: 100%;
  min-height: 48px;
  padding: 0 14px;
  border: 1px solid var(--auth-line);
  border-radius: 12px;
  box-sizing: border-box;
  outline: 0;
  color: #fff;
  background: rgba(3, 11, 27, .7);
  font: inherit;
}
#auth-form input:focus { border-color: rgba(118, 228, 196, .75); box-shadow: 0 0 0 3px rgba(118, 228, 196, .11); }
.auth-primary, .auth-google, .auth-apple {
  width: 100%;
  min-height: 50px;
  border: 0;
  border-radius: 13px;
  cursor: pointer;
  font: 850 15px/1 system-ui, sans-serif;
}
.auth-primary { color: #061c2a; background: linear-gradient(135deg, var(--auth-accent), #8cb8ff); box-shadow: 0 12px 28px rgba(84, 181, 216, .2); }
.auth-primary:disabled, .auth-google:disabled, .auth-apple:disabled { cursor: wait; opacity: .55; }
.auth-google { display: flex; align-items: center; justify-content: center; gap: 12px; color: #172033; background: #fff; }
.auth-google b { display: grid; place-items: center; width: 25px; height: 25px; border-radius: 50%; color: #4285f4; font-size: 20px; }
.auth-apple { display: flex; align-items: center; justify-content: center; gap: 12px; margin-top: 10px; color: #fff; background: #050505; border: 1px solid rgba(255,255,255,.18); }
.auth-apple b { width: 25px; color: #fff; font-size: 18px; line-height: 1; }
.auth-text-button { display: block; margin: 12px auto 0; border: 0; color: #9fd7ff; background: transparent; cursor: pointer; font-weight: 750; }
.auth-divider { display: flex; align-items: center; gap: 12px; margin: 18px 0; color: #6f7f9d; font-size: 12px; }
.auth-divider::before, .auth-divider::after { content: ""; flex: 1; height: 1px; background: var(--auth-line); }
.auth-consent { display: grid; gap: 10px; padding: 14px; border: 1px solid var(--auth-line); border-radius: 13px; background: rgba(4, 13, 30, .52); }
.auth-consent label { display: grid; grid-template-columns: 19px minmax(0, 1fr); gap: 8px; align-items: start; color: #c9d5e7; font-size: 12px; line-height: 1.55; }
.auth-consent label > span { min-width: 0; overflow-wrap: anywhere; }
.auth-consent input { width: 17px; height: 17px; margin: 1px 0 0; accent-color: var(--auth-accent); }
.auth-consent a { color: #8edcff; }
.auth-status { min-height: 20px; margin: 12px 0 0; font-size: 13px; text-align: center; }
.auth-status.error { color: var(--auth-danger); }
.auth-status.success { color: var(--auth-accent); }
.auth-retry { display: block; min-height: 40px; margin: 8px auto 0; padding: 0 18px; border: 1px solid rgba(255,139,151,.45); border-radius: 11px; color: #fff; background: rgba(255,139,151,.12); cursor: pointer; font-weight: 800; }
.auth-debug-panel { margin-top: 14px; padding: 10px 12px; border: 1px solid rgba(255,190,105,.32); border-radius: 12px; color: #ffd7a3; background: rgba(35,20,10,.72); font: 700 11px/1.45 ui-monospace, SFMono-Regular, Consolas, monospace; }
.auth-debug-panel summary { cursor: pointer; font-size: 12px; }
.auth-debug-panel dl { display: grid; gap: 5px; margin: 10px 0; }
.auth-debug-panel dl div { display: grid; grid-template-columns: minmax(145px, .9fr) minmax(0, 1.4fr); gap: 10px; }
.auth-debug-panel dt { color: #d4ad7d; }
.auth-debug-panel dd { min-width: 0; margin: 0; color: #fff1d8; overflow-wrap: anywhere; }
.auth-debug-panel small { color: #c3a98b; }
.auth-legal-note { margin: 20px 0 0; padding-top: 16px; border-top: 1px solid var(--auth-line); font-size: 11px; line-height: 1.6; text-align: center; }
.auth-loading, .auth-state-panel { padding: 32px 0 12px; text-align: center; }
.auth-loading { display: flex; justify-content: center; align-items: center; gap: 12px; color: var(--auth-muted); }
.auth-loading i { width: 22px; height: 22px; border: 3px solid rgba(255,255,255,.15); border-top-color: var(--auth-accent); border-radius: 50%; animation: auth-spin .8s linear infinite; }
.auth-state-icon { display: grid; place-items: center; width: 62px; height: 62px; margin: 0 auto; border-radius: 20px; color: #0a2030; background: linear-gradient(135deg, var(--auth-accent), #9ebeff); font-size: 28px; font-weight: 900; }
.auth-state-panel .auth-consent { margin: 22px 0 16px; text-align: left; }
.auth-state-panel > p { line-height: 1.65; }
.auth-state-panel .auth-primary { margin-top: 14px; }
.hidden { display: none !important; }

.account-strip { display: grid; grid-template-columns: 36px 1fr auto; align-items: center; gap: 10px; margin: -4px 0 14px; padding: 9px 10px; border: 1px solid rgba(146,177,228,.16); border-radius: 14px; background: rgba(6,17,38,.5); }
.account-strip img { width: 36px; height: 36px; border-radius: 10px; object-fit: cover; background: rgba(255,255,255,.05); }
.account-strip div { display: grid; min-width: 0; }
.account-strip strong, .account-strip small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-strip strong { color: #eef6ff; font-size: 13px; }
.account-strip small { color: #8fa1bd; font-size: 10px; }
.account-strip button, .danger-link { border: 0; color: #a9cbea; background: transparent; cursor: pointer; font-weight: 750; }
.danger-link { width: 100%; padding: 12px; border: 1px solid rgba(255,106,120,.25); border-radius: 12px; color: #ff9da7; text-align: center; }

@keyframes auth-spin { to { transform: rotate(360deg); } }
@keyframes auth-float { 50% { transform: translateY(-14px) rotate(1deg); } }

@media (max-width: 860px) {
  .auth-gate { overflow: auto; padding: max(16px, env(safe-area-inset-top)) 14px max(16px, env(safe-area-inset-bottom)); background-position: 38% center; }
  .auth-scene p, .auth-scene h1, .auth-scene > span:last-child { display: none; }
  .auth-heroes { top: 3%; left: 50%; opacity: .24; }
  .auth-card { width: min(520px, 100%); max-height: none; margin: auto; padding: 24px; border-radius: 24px; }
}
@media (max-height: 800px) and (min-width: 861px) {
  .auth-card { margin-block: 20px; padding: 24px 30px; }
  .auth-brand { margin-bottom: 14px; }
  .auth-card h2 { margin-top: 12px; font-size: 23px; }
  #auth-form { margin-top: 14px; gap: 9px; }
  #auth-form input[type="email"], #auth-form input[type="password"], #auth-form input[type="text"] { min-height: 42px; }
  .auth-primary, .auth-google { min-height: 44px; }
  .auth-divider { margin: 10px 0; }
  .auth-legal-note { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .auth-heroes img { animation: none; }
}
