: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; }
body.auth-pending #rotate-device-prompt { display: none; }
.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: 0;
  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-card > *, .auth-brand div, .auth-horizontal-flow > *, #auth-form > label { min-width: 0; }
.auth-brand strong, .auth-status, .auth-panel-heading p { overflow-wrap: anywhere; }
.auth-scene h1, .auth-scene p { display: none; }
.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: calc(100dvh - max(16px,env(safe-area-inset-top)) - max(16px,env(safe-area-inset-bottom))); margin: 0; 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; }
}

/* v3.9.6: landscape-first horizontal account and onboarding flow. */
.auth-panel-heading { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 4px 18px; }
.auth-panel-heading h2 { margin-bottom: 4px; }
.auth-panel-heading p { margin: 0; text-align: right; }
.auth-horizontal-flow { display: grid; gap: 18px; }
.auth-provider-column { display: grid; align-content: center; }
.auth-onboarding-panel { text-align: center; animation: auth-slide-in .28s ease both; }
.auth-onboarding-panel > img { width: 112px; height: 112px; object-fit: contain; filter: drop-shadow(0 18px 20px rgba(0,0,0,.42)); }
.auth-onboarding-panel h2 { margin: 8px 0; color: #f6d98f; font-size: clamp(27px,4vw,44px); }
.auth-onboarding-panel > p { max-width: 520px; margin: 0 auto 20px; line-height: 1.6; }
.auth-onboarding-panel .auth-primary { max-width: 440px; }
.auth-name-panel { width: min(520px,100%); margin: auto; }
.auth-name-panel > label { display: block; margin: 8px 0 6px; color: #c9d5e7; font-size: 13px; font-weight: 800; text-align: left; }
.auth-name-panel > input { width: 100%; min-height: 50px; padding: 0 16px; border: 1px solid var(--auth-line); border-radius: 13px; box-sizing: border-box; outline: 0; color: #fff; background: rgba(3,11,27,.82); font: 700 16px/1 system-ui,sans-serif; }
.auth-name-panel > input:focus { border-color: var(--auth-accent); box-shadow: 0 0 0 3px rgba(118,228,196,.12); }
.auth-name-panel .auth-name-rule { margin: 9px 0 15px; color: #f6d98f; font-size: 13px; }
.auth-gate[data-onboarding-stage="welcome"] .auth-scene,
.auth-gate[data-onboarding-stage="name"] .auth-scene,
.auth-gate[data-onboarding-stage="welcome"] .auth-brand,
.auth-gate[data-onboarding-stage="name"] .auth-brand,
.auth-gate[data-onboarding-stage="welcome"] .auth-language,
.auth-gate[data-onboarding-stage="name"] .auth-language { display: none; }
.auth-gate[data-onboarding-stage="welcome"] .auth-card { width: min(760px,92vw); margin: auto; overflow: visible; border-color: rgba(226,191,111,.42); background: linear-gradient(155deg,rgba(13,31,59,.88),rgba(5,16,36,.84)); }
.auth-gate[data-onboarding-stage="name"] .auth-card { width: min(590px,92vw); margin: auto; overflow: visible; border-color: rgba(226,191,111,.42); }
@keyframes auth-slide-in { from { opacity: 0; transform: translateX(28px); } to { opacity: 1; transform: translateX(0); } }

@media (min-width: 861px) {
  .auth-card { width: min(820px,100%); }
  .auth-horizontal-flow { grid-template-columns: minmax(0,1.2fr) minmax(210px,.8fr); }
  .auth-provider-column { padding-left: 18px; border-left: 1px solid var(--auth-line); }
}

@media (orientation: landscape) and (max-height: 650px) {
  .auth-gate { overflow: hidden; padding: max(10px,env(safe-area-inset-top)) max(12px,env(safe-area-inset-right)) max(10px,env(safe-area-inset-bottom)) max(12px,env(safe-area-inset-left)); background-position: center; }
  .auth-scene { width: 27vw; padding: 22px; justify-content: flex-end; }
  .auth-scene p { display: none; }
  .auth-scene h1 { display: none; }
  .auth-scene > span:last-child { display: block; max-width: 24vw; font-size: 11px; line-height: 1.4; }
  .auth-heroes { top: 8%; left: 14%; opacity: 1; }
  .auth-heroes img { width: clamp(78px,10vw,116px); }
  .auth-heroes img + img { width: clamp(68px,9vw,104px); margin-left: -18px; }
  .auth-card { position: relative; display: grid; grid-template-columns: minmax(0,1fr) auto; align-items: start; gap: 10px 14px; width: min(880px,100%); height: auto; max-height: calc(100dvh - max(10px,env(safe-area-inset-top)) - max(10px,env(safe-area-inset-bottom))); margin: 0; padding: 14px 18px; overflow-x: hidden; overflow-y: auto; border-radius: 20px; }
  .auth-card > :not(.auth-language):not(.auth-brand) { grid-column: 1 / -1; }
  .auth-gate[data-onboarding-stage="account"] .auth-card { max-width: none; }
  .auth-language { position: static; grid-column: 2; grid-row: 1; align-self: center; margin: 0; }
  .auth-language select { min-height: 30px; }
  .auth-brand { position: static; grid-column: 1; grid-row: 1; max-width: none; margin: 0; gap: 8px; }
  .auth-brand img { width: 34px; height: 34px; border-radius: 10px; }
  .auth-brand strong { font-size: 12px; line-height: 1.4; white-space: normal; }
  .auth-brand small { font-size: 9px; }
  #auth-form-panel:not(.hidden) { display: grid; grid-template-columns: minmax(0,1.2fr) minmax(180px,.8fr); gap: 12px; animation: auth-slide-in .24s ease both; }
  .auth-tabs { width: 100%; box-sizing: border-box; padding: 3px; border-radius: 11px; }
  .auth-tabs button { min-height: 40px; border-radius: 8px; font-size: 12px; }
  .auth-panel-heading { position: static; width: auto; display: block; align-self: center; }
  .auth-panel-heading h2 { margin: 0; font-size: 17px; }
  .auth-panel-heading p { margin-top: 2px; font-size: 9px; line-height: 1.25; text-align: left; }
  .auth-horizontal-flow { grid-column: 1 / -1; grid-template-columns: minmax(0,1.2fr) minmax(180px,.8fr); gap: 12px; }
  .auth-provider-column { min-width: 0; padding-left: 12px; border-left: 1px solid var(--auth-line); }
  #auth-form { margin-top: 0; gap: 6px; align-content: start; }
  #auth-form-panel.register-mode #auth-form { grid-template-columns: 1fr 1fr; }
  #auth-form-panel.register-mode #auth-form > label:first-child,
  #auth-form-panel.register-mode #auth-register-consent,
  #auth-form-panel.register-mode #auth-submit { grid-column: 1 / -1; }
  #auth-form > label { gap: 3px; font-size: 10px; }
  #auth-form input[type="email"], #auth-form input[type="password"], #auth-form input[type="text"] { min-height: 40px; padding: 0 10px; border-radius: 9px; font-size: 13px; }
  .auth-consent { gap: 3px; padding: 5px 7px; border-radius: 9px; }
  .auth-consent label { grid-template-columns: 15px minmax(0,1fr); gap: 5px; font-size: 11px; line-height: 1.4; }
  .auth-consent input { width: 14px; height: 14px; }
  .auth-primary, .auth-google, .auth-apple { min-height: 44px; border-radius: 10px; font-size: 12px; }
  .auth-text-button { margin-top: 0; font-size: 11px; }
  .auth-divider { margin: 6px 0; }
  .auth-status { min-height: 14px; margin-top: 5px; font-size: 11px; line-height: 1.5; }
  .auth-legal-note { margin-top: 6px; padding-top: 5px; font-size: 8px; line-height: 1.3; }
  .auth-loading, .auth-state-panel { padding: 18px 0 6px; }
  .auth-state-panel .auth-consent { margin: 10px 0 8px; }
  .auth-state-icon { width: 42px; height: 42px; border-radius: 13px; font-size: 20px; }
  .auth-gate[data-onboarding-stage="welcome"] .auth-card { display: grid; grid-template-columns: minmax(0,1fr); place-items: center; width: min(740px,92vw); height: auto; min-height: min(330px,calc(100dvh - 20px)); padding: 20px 28px; overflow-y: auto; }
  .auth-gate[data-onboarding-stage="name"] .auth-card { display: grid; grid-template-columns: minmax(0,1fr); place-items: center; width: min(560px,90vw); height: auto; min-height: min(330px,calc(100dvh - 20px)); padding: 16px 26px; overflow-y: auto; }
  .auth-onboarding-panel > img { width: 78px; height: 78px; }
  .auth-onboarding-panel h2 { margin: 3px 0; font-size: clamp(23px,4vw,34px); }
  .auth-onboarding-panel > p { margin-bottom: 10px; font-size: 11px; }
  .auth-onboarding-panel .auth-primary { min-height: 44px; font-size: 14px; }
  .auth-name-panel { display: grid; grid-template-columns: 76px minmax(0,1fr); column-gap: 16px; text-align: left; }
  .auth-name-panel > img { grid-row: 1 / 6; align-self: center; width: 76px; height: 76px; }
  .auth-name-panel h2 { grid-column: 2; }
  .auth-name-panel > label, .auth-name-panel > input, .auth-name-panel > p, .auth-name-panel > button { grid-column: 2; }
  .auth-name-panel > label { margin: 4px 0 3px; font-size: 10px; }
  .auth-name-panel > input { min-height: 40px; font-size: 13px; }
  .auth-name-panel .auth-name-rule { margin: 5px 0 8px; font-size: 10px; }
}

@media (prefers-reduced-motion: reduce) { .auth-onboarding-panel, #auth-form-panel:not(.hidden) { animation: none; } }
