:root {
  --bg: #0a0e14;
  --panel: #ffffff;
  --ink: #1b2533;
  --muted: #8899aa;
  --line: #d5dbe4;
  --accent: #d4a24e;
  --accent-light: #f0d48a;
  --accent-dark: #9e7328;
  --bad: #e05555;
  --good: #3dbd7d;
  --glass-bg: rgba(12, 18, 30, 0.72);
  --glass-border: rgba(212, 162, 78, 0.25);
  --glass-glow: rgba(212, 162, 78, 0.08);
  --sat: env(safe-area-inset-top);
  --sar: env(safe-area-inset-right);
  --sab: env(safe-area-inset-bottom);
  --sal: env(safe-area-inset-left);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg);
  color: var(--ink);
  font-family: "PingFang SC", "Microsoft YaHei", "Segoe UI", Arial, sans-serif;
}

/* ===== shell layout ===== */

.shell {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: 1fr;
}

.stage {
  position: relative;
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  overflow: hidden;
  background: var(--bg);
}

#canvas {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #0a0e14;
  touch-action: none;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

/* ===== overlay ===== */

#overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 10;
  transition: opacity 0.5s ease;
  /* safe area padding for notch / home bar */
  padding-top: var(--sat);
  padding-bottom: var(--sab);
  padding-left: var(--sal);
  padding-right: var(--sar);
}

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

/* ===== login background ===== */

.login-bg {
  position: absolute;
  inset: 0;
  z-index: 0;
  overflow: hidden;
}

.login-bg__image {
  position: absolute;
  inset: -20px;
  background: url("/miniGame1/platform/loadingBg/loadingBg.jpg") center / cover no-repeat;
  filter: brightness(0.55) saturate(1.2);
  animation: bgZoom 25s ease-in-out infinite alternate;
}

@keyframes bgZoom {
  0% { transform: scale(1); }
  100% { transform: scale(1.08); }
}

.login-bg__vignette {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse at center, transparent 30%, rgba(10, 14, 20, 0.7) 100%),
    linear-gradient(to bottom, rgba(10, 14, 20, 0.3) 0%, rgba(10, 14, 20, 0.1) 40%, rgba(10, 14, 20, 0.6) 100%);
}

.login-bg__particles {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.login-bg__particles::before,
.login-bg__particles::after {
  content: "";
  position: absolute;
  border-radius: 50%;
  background: rgba(212, 162, 78, 0.35);
  animation: floatUp linear infinite;
}
.login-bg__particles::before {
  width: 3px; height: 3px;
  left: 20%; bottom: -10px;
  animation-duration: 12s;
}
.login-bg__particles::after {
  width: 2px; height: 2px;
  left: 70%; bottom: -10px;
  animation-duration: 16s;
  animation-delay: 4s;
}

@keyframes floatUp {
  0% { transform: translateY(0) scale(1); opacity: 0; }
  10% { opacity: 1; }
  90% { opacity: 0.6; }
  100% { transform: translateY(-100vh) scale(0.5); opacity: 0; }
}

/* ===== glass card (shared login + boot) ===== */

.glass-card {
  position: relative;
  z-index: 1;
  width: calc(100% - 48px);
  max-width: 380px;
  max-height: calc(100dvh - var(--sat) - var(--sab) - 32px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 32px 24px 24px;
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: 20px;
  backdrop-filter: blur(24px) saturate(1.4);
  -webkit-backdrop-filter: blur(24px) saturate(1.4);
  box-shadow:
    0 0 40px var(--glass-glow),
    0 20px 60px rgba(0, 0, 0, 0.4),
    inset 0 1px 0 rgba(255, 255, 255, 0.06);
  animation: cardIn 0.7s cubic-bezier(0.16, 1, 0.3, 1) both;
}

/* fallback for browsers without backdrop-filter support */
@supports not (backdrop-filter: blur(1px)) {
  .glass-card {
    background: rgba(12, 18, 30, 0.92);
  }
}

/* hide scrollbar on card */
.glass-card::-webkit-scrollbar { display: none; }
.glass-card { -ms-overflow-style: none; scrollbar-width: none; }

@keyframes cardIn {
  from {
    opacity: 0;
    transform: translateY(30px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* ===== card header ===== */

.card-header {
  text-align: center;
  margin-bottom: 24px;
}

.card-logo {
  width: 56px;
  height: 56px;
  margin: 0 auto 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--accent-dark), var(--accent-light));
  border-radius: 16px;
  box-shadow:
    0 4px 20px rgba(212, 162, 78, 0.3),
    inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

.logo-icon {
  font-size: 26px;
  color: #fff;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

.game-title {
  font-size: 24px;
  font-weight: 800;
  letter-spacing: 4px;
  background: linear-gradient(135deg, #f5e0a8, #d4a24e, #f5e0a8);
  background-size: 200% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  animation: shimmer 4s ease-in-out infinite;
  margin-bottom: 6px;
}

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

.game-subtitle {
  color: rgba(200, 210, 225, 0.7);
  font-size: 13px;
  letter-spacing: 1px;
  line-height: 1.5;
}

.user-name {
  color: var(--accent-light);
  font-weight: 600;
}

/* ===== card body (form) ===== */

.card-body {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.auth-field {
  position: relative;
  width: 100%;
}

.field-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 16px;
  color: var(--accent);
  opacity: 0.6;
  pointer-events: none;
}

.auth-field input {
  width: 100%;
  height: 48px;
  padding: 0 14px 0 42px;
  border: 1px solid rgba(212, 162, 78, 0.15);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.04);
  color: #dce8f5;
  font-size: 16px; /* >=16px prevents iOS zoom on focus */
  outline: none;
  transition: all 0.25s ease;
  -webkit-appearance: none;
  appearance: none;
}

.auth-field input::placeholder {
  color: rgba(160, 175, 195, 0.5);
}

.auth-field input:focus {
  border-color: var(--accent);
  background: rgba(255, 255, 255, 0.07);
  box-shadow: 0 0 0 3px rgba(212, 162, 78, 0.1), 0 0 20px rgba(212, 162, 78, 0.06);
}

/* ===== buttons ===== */

.auth-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 4px;
}

.btn-primary {
  height: 48px;
  border: none;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent-dark), var(--accent), var(--accent-light));
  background-size: 200% 100%;
  color: #fff;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 4px;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 4px 15px rgba(212, 162, 78, 0.3);
  position: relative;
  overflow: hidden;
  -webkit-appearance: none;
}

.btn-primary::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.15), transparent);
  transform: translateX(-100%);
  transition: transform 0.5s ease;
}

@media (hover: hover) {
  .btn-primary:hover::after { transform: translateX(100%); }
  .btn-primary:hover {
    background-position: 100% 50%;
    box-shadow: 0 6px 25px rgba(212, 162, 78, 0.45);
    transform: translateY(-1px);
  }
}

.btn-primary:active {
  transform: scale(0.97);
  box-shadow: 0 2px 10px rgba(212, 162, 78, 0.25);
}

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.btn-outline {
  height: 48px;
  border: 1px solid rgba(212, 162, 78, 0.35);
  border-radius: 12px;
  background: rgba(212, 162, 78, 0.06);
  color: var(--accent-light);
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 4px;
  cursor: pointer;
  transition: all 0.25s ease;
  -webkit-appearance: none;
}

@media (hover: hover) {
  .btn-outline:hover {
    background: rgba(212, 162, 78, 0.12);
    border-color: var(--accent);
  }
}

.btn-outline:active {
  background: rgba(212, 162, 78, 0.18);
  transform: scale(0.97);
}

.btn-outline:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* enter game button */
.btn-enter {
  width: 100%;
  height: 54px;
  border: none;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--accent-dark), var(--accent), var(--accent-light));
  background-size: 200% 100%;
  color: #fff;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 6px;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 6px 25px rgba(212, 162, 78, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  position: relative;
  overflow: hidden;
  -webkit-appearance: none;
}

.btn-enter .btn-arrow {
  font-size: 16px;
  opacity: 0;
  transform: translateX(-8px);
  transition: all 0.3s ease;
}

@media (hover: hover) {
  .btn-enter:hover .btn-arrow { opacity: 1; transform: translateX(0); }
  .btn-enter:hover {
    background-position: 100% 50%;
    box-shadow: 0 8px 35px rgba(212, 162, 78, 0.5);
    transform: translateY(-2px);
  }
}

.btn-enter:active {
  transform: scale(0.97);
}

.btn-logout {
  width: 100%;
  height: 40px;
  font-size: 13px;
  letter-spacing: 2px;
  margin-top: 4px;
}

/* ===== error text ===== */

.auth-error {
  color: var(--bad);
  font-size: 13px;
  min-height: 18px;
  text-align: center;
  padding-top: 2px;
}

/* ===== card footer ===== */

.card-footer {
  margin-top: 20px;
  text-align: center;
}

.footer-line {
  color: rgba(140, 155, 175, 0.4);
  font-size: 11px;
  letter-spacing: 2px;
}

/* ===== hidden utility ===== */

.hidden {
  display: none !important;
}

/* ===== inspect panel (desktop only) ===== */

.inspect {
  display: none;
}

.inspect header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

#state-pill {
  border-radius: 999px;
  padding: 4px 10px;
  background: #edf4ff;
  color: var(--ink);
  font-size: 12px;
}

h3 {
  font-size: 14px;
  margin-bottom: 8px;
}

.metric {
  font-size: 28px;
  font-weight: 700;
}

#gap-list {
  display: grid;
  gap: 6px;
  padding-left: 18px;
  color: var(--bad);
  font-size: 13px;
}

#log-box {
  min-height: 300px;
  max-height: 56vh;
  overflow: auto;
  padding: 10px;
  white-space: pre-wrap;
  border-radius: 6px;
  background: #111820;
  color: #dce8f5;
  font-size: 12px;
  line-height: 1.45;
}

/* ===== mobile: small screens (< 400px width) ===== */

@media (max-width: 399px) {
  .glass-card {
    width: calc(100% - 32px);
    padding: 24px 18px 20px;
    border-radius: 16px;
  }

  .card-logo {
    width: 48px;
    height: 48px;
    border-radius: 12px;
  }

  .logo-icon { font-size: 22px; }

  .game-title {
    font-size: 20px;
    letter-spacing: 3px;
  }

  .game-subtitle { font-size: 12px; }

  .auth-field input { height: 44px; font-size: 16px; }

  .btn-primary, .btn-outline {
    height: 44px;
    font-size: 14px;
    letter-spacing: 3px;
  }

  .btn-enter {
    height: 48px;
    font-size: 16px;
    letter-spacing: 4px;
  }
}

/* ===== mobile: short screens (landscape / small height) ===== */

@media (max-height: 580px) {
  .glass-card {
    padding: 20px 20px 16px;
  }

  .card-header { margin-bottom: 16px; }
  .card-logo { width: 40px; height: 40px; margin-bottom: 10px; border-radius: 10px; }
  .logo-icon { font-size: 20px; }
  .game-title { font-size: 18px; letter-spacing: 2px; margin-bottom: 4px; }
  .game-subtitle { font-size: 11px; }
  .card-body { gap: 8px; }
  .auth-field input { height: 40px; }
  .btn-primary, .btn-outline { height: 40px; font-size: 14px; }
  .btn-enter { height: 44px; font-size: 15px; }
  .card-footer { margin-top: 12px; }
}

/* ===== mobile: very short (landscape phone) ===== */

@media (max-height: 420px) {
  .glass-card { padding: 14px 16px 12px; }
  .card-header { margin-bottom: 10px; }
  .card-logo { width: 32px; height: 32px; margin-bottom: 6px; }
  .logo-icon { font-size: 16px; }
  .game-title { font-size: 16px; letter-spacing: 2px; margin-bottom: 2px; }
  .game-subtitle { display: none; }
  .card-body { gap: 6px; }
  .auth-field input { height: 36px; font-size: 14px; border-radius: 8px; }
  .btn-primary, .btn-outline { height: 36px; font-size: 13px; letter-spacing: 2px; border-radius: 8px; }
  .btn-enter { height: 38px; font-size: 14px; letter-spacing: 3px; border-radius: 10px; }
  .card-footer { margin-top: 8px; }
}

/* ===== desktop layout ===== */

@media (min-width: 960px) and (hover: hover) {
  #canvas {
    width: min(100%, 520px);
    height: auto;
    aspect-ratio: 9 / 16;
    border-radius: 8px;
    object-fit: fill;
  }

  #overlay {
    padding: 0;
  }

  .glass-card {
    width: 90%;
    max-width: 380px;
  }
}

/* ===== iOS Safari fixes ===== */

@supports (-webkit-touch-callout: none) {
  /* Fix 100vh on iOS Safari */
  .shell {
    height: 100dvh;
  }
}

/* ===== landscape phone: force portrait-like card ===== */

@media (max-width: 599px) and (orientation: landscape) {
  .glass-card {
    max-height: calc(100dvh - 16px);
    max-width: 340px;
    padding: 16px 20px;
  }
  .card-logo { width: 36px; height: 36px; margin-bottom: 8px; }
  .logo-icon { font-size: 18px; }
  .game-title { font-size: 18px; }
  .game-subtitle { font-size: 11px; }
  .card-header { margin-bottom: 12px; }
}
