/* Auth + game shell — fundo partilhado + responsivo (carrega depois de TemplateData/style.css) */

:root {
  --bg-deep: #12100e;
  --bg-panel: #1c1916;
  --bg-elevated: #252220;
  --border: rgba(255, 245, 230, 0.08);
  --text: #f4eee6;
  --text-muted: #9a9188;
  --accent: #d4a574;
  --accent-dim: #9a7350;
  --accent-glow: rgba(212, 165, 116, 0.18);
  --danger: #e07a6b;
  --radius: 14px;
  --font: "DM Sans", system-ui, sans-serif;
  --font-display: "Fraunces", Georgia, serif;
  --page-pad: clamp(0.75rem, 4vw, 2rem);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  height: 100%;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100%;
  min-height: 100dvh;
  position: relative;
  font-family: var(--font);
  font-size: clamp(15px, 2.8vw, 16px);
  line-height: 1.5;
  color: var(--text);
  background-color: #0a0908;
}

/* Plano de fundo fixo — visível no login e no jogo */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -2;
  background-color: #0e0c0a;
  background-image:
    radial-gradient(ellipse 120% 70% at 50% 105%, rgba(120, 75, 45, 0.35) 0%, transparent 48%),
    radial-gradient(ellipse 90% 55% at 15% 15%, rgba(212, 165, 116, 0.12) 0%, transparent 52%),
    radial-gradient(ellipse 70% 45% at 88% 22%, rgba(90, 120, 160, 0.09) 0%, transparent 48%),
    radial-gradient(ellipse 60% 40% at 50% -5%, rgba(212, 165, 116, 0.06) 0%, transparent 55%),
    linear-gradient(165deg, #161311 0%, #0d0b09 38%, #12100e 72%, #0a0807 100%);
}

body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  opacity: 0.55;
  background-image:
    radial-gradient(1px 1px at 8% 18%, rgba(255, 248, 235, 0.22), transparent),
    radial-gradient(1px 1px at 22% 62%, rgba(255, 248, 235, 0.15), transparent),
    radial-gradient(1px 1px at 41% 35%, rgba(255, 248, 235, 0.12), transparent),
    radial-gradient(1px 1px at 67% 12%, rgba(255, 248, 235, 0.18), transparent),
    radial-gradient(1px 1px at 78% 88%, rgba(255, 248, 235, 0.1), transparent),
    radial-gradient(1px 1px at 93% 44%, rgba(255, 248, 235, 0.14), transparent),
    repeating-linear-gradient(
      -12deg,
      transparent,
      transparent 3px,
      rgba(0, 0, 0, 0.06) 3px,
      rgba(0, 0, 0, 0.06) 5px
    );
  mix-blend-mode: soft-light;
}

#login-container {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: max(var(--page-pad), env(safe-area-inset-top))
    max(var(--page-pad), env(safe-area-inset-right))
    max(var(--page-pad), env(safe-area-inset-bottom))
    max(var(--page-pad), env(safe-area-inset-left));
}

#login-container.is-hidden {
  display: none !important;
}

.auth-shell {
  width: 100%;
  max-width: min(420px, 100%);
}

.auth-brand {
  text-align: center;
  margin-bottom: clamp(1.25rem, 4vw, 2rem);
}

.auth-brand h1 {
  margin: 0 0 0.35rem;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: clamp(1.45rem, 5vw, 2rem);
  letter-spacing: -0.02em;
  color: var(--text);
  text-wrap: balance;
}

.auth-brand p {
  margin: 0;
  font-size: clamp(0.88rem, 2.5vw, 0.95rem);
  color: var(--text-muted);
}

.auth-card {
  background: rgba(28, 25, 22, 0.82);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: clamp(1.25rem, 4vw, 1.75rem) clamp(1.1rem, 4vw, 1.5rem);
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.05) inset,
    0 24px 48px -24px rgba(0, 0, 0, 0.65);
}

.auth-tabs {
  display: flex;
  gap: 0.35rem;
  margin-bottom: 1.5rem;
  padding: 0.25rem;
  background: rgba(14, 12, 10, 0.65);
  border-radius: 10px;
  border: 1px solid var(--border);
}

.auth-tabs button {
  flex: 1;
  min-height: 44px;
  padding: 0.65rem 0.5rem;
  font-family: inherit;
  font-size: clamp(0.85rem, 2.5vw, 0.9rem);
  font-weight: 600;
  color: var(--text-muted);
  background: transparent;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.auth-tabs button[aria-selected="true"] {
  color: var(--text);
  background: var(--bg-elevated);
  box-shadow: 0 0 0 1px var(--border);
}

.auth-tabs button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.auth-panel {
  display: none;
}

.auth-panel.is-active {
  display: block;
}

.auth-banner {
  margin-bottom: 1.25rem;
  overflow: hidden;
  border-radius: 8px;
  border: 1px solid var(--border);
  line-height: 0;
}

.auth-banner img {
  width: 100%;
  height: auto;
  object-fit: cover;
  transition: transform 0.3s ease;
}

.auth-banner:hover img {
  transform: scale(1.02);
}

.field {
  margin-bottom: 1rem;
}

.field label {
  display: block;
  margin-bottom: 0.35rem;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.field input {
  width: 100%;
  min-height: 44px;
  padding: 0.65rem 0.85rem;
  font-family: inherit;
  font-size: 16px;
  color: var(--text);
  background: rgba(14, 12, 10, 0.75);
  border: 1px solid var(--border);
  border-radius: 10px;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.field input::placeholder {
  color: #6b655c;
}

.field input:hover {
  border-color: rgba(212, 165, 116, 0.35);
}

.field input:focus {
  outline: none;
  border-color: var(--accent-dim);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.btn-primary {
  width: 100%;
  min-height: 48px;
  margin-top: 0.25rem;
  padding: 0.85rem 1rem;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 600;
  color: #1a1512;
  background: linear-gradient(160deg, #e8c49a 0%, var(--accent) 45%, #b8895e 100%);
  border: none;
  border-radius: 10px;
  cursor: pointer;
  transition: transform 0.12s, filter 0.12s, box-shadow 0.12s;
  box-shadow: 0 2px 12px rgba(212, 165, 116, 0.25);
  -webkit-tap-highlight-color: transparent;
}

.btn-primary:hover {
  filter: brightness(1.05);
  transform: translateY(-1px);
  box-shadow: 0 4px 20px rgba(212, 165, 116, 0.35);
}

.btn-primary:active {
  transform: translateY(0);
}

.btn-primary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

#toast {
  position: fixed;
  bottom: max(1.5rem, env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%) translateY(120%);
  max-width: min(90vw, 360px);
  padding: 0.75rem 1.1rem;
  font-size: 0.9rem;
  color: var(--text);
  background: rgba(37, 34, 32, 0.95);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
  opacity: 0;
  transition: transform 0.25s ease, opacity 0.25s ease;
  z-index: 1000;
  pointer-events: none;
}

#toast.is-visible {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

#toast.toast-error {
  border-color: rgba(224, 122, 107, 0.45);
  color: #f5c4bc;
}

/* Game — sobrescreve posicionamento do Unity template */
#unity-container {
  display: none;
}

#unity-container.unity-visible {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  left: auto;
  top: auto;
  transform: none;
  width: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  padding: max(var(--page-pad), env(safe-area-inset-top))
    max(var(--page-pad), env(safe-area-inset-right))
    max(1.25rem, env(safe-area-inset-bottom))
    max(var(--page-pad), env(safe-area-inset-left));
  box-sizing: border-box;
}

.game-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(0.65rem, 2vw, 0.85rem);
  width: 100%;
  max-width: min(1024px, 100%);
}

.game-canvas-wrap {
  position: relative;
  line-height: 0;
  width: 100%;
  max-width: min(1024px, calc(100vw - 2 * var(--page-pad)));
  aspect-ratio: 1024 / 768;
  max-height: min(
    calc(100dvh - 7rem - env(safe-area-inset-top) - env(safe-area-inset-bottom)),
    calc((min(1024px, 100vw - 2 * var(--page-pad))) * 768 / 1024)
  );
}

.unity-loading {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  border-radius: clamp(8px, 2vw, 12px);
  background: rgba(18, 15, 12, 0.94);
  backdrop-filter: blur(6px);
  z-index: 2;
}

.unity-loading[hidden] {
  display: none !important;
}

.unity-loading__spinner {
  width: clamp(36px, 8vw, 44px);
  height: clamp(36px, 8vw, 44px);
  border: 3px solid rgba(212, 165, 116, 0.2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: unity-spin 0.85s linear infinite;
}

@keyframes unity-spin {
  to {
    transform: rotate(360deg);
  }
}

.unity-loading__text {
  margin: 0;
  font-size: clamp(0.82rem, 2.5vw, 0.9rem);
  color: var(--text-muted);
  padding: 0 0.75rem;
  text-align: center;
}

#unity-canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
  max-width: 100%;
  border-radius: clamp(8px, 2vw, 12px);
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.06),
    0 24px 60px rgba(0, 0, 0, 0.55);
  object-fit: contain;
  background: #231f20;
}

.game-toolbar {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.5rem;
  width: 100%;
  margin-top: 1rem;
  padding: 1.5rem;
  background: rgba(28, 25, 22, 0.4);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  backdrop-filter: blur(10px);
}

.toolbar-header {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

.toolbar-header h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.25rem;
  color: var(--text);
  letter-spacing: -0.01em;
}

.toolbar-header .badge {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #1a1512;
  background: var(--accent);
  border-radius: 4px;
  box-shadow: 0 0 15px var(--accent-glow);
}

.toolbar-links {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.75rem;
  width: 100%;
}

.game-toolbar .btn-logout {
  min-height: 44px;
  padding: 0.55rem 1.35rem;
  font-family: inherit;
  font-size: clamp(0.82rem, 2.5vw, 0.875rem);
  font-weight: 600;
  color: var(--text-muted);
  background: rgba(28, 25, 22, 0.75);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.game-toolbar .btn-logout:hover {
  color: var(--text);
  border-color: rgba(212, 165, 116, 0.35);
  background: var(--bg-elevated);
}

.game-toolbar .btn-logout:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.game-toolbar .btn-link {
  min-height: 44px;
  padding: 0.55rem 1.35rem;
  font-family: inherit;
  font-size: clamp(0.82rem, 2.5vw, 0.875rem);
  font-weight: 600;
  text-decoration: none;
  color: #1a1512;
  background: linear-gradient(160deg, #e8c49a 0%, var(--accent) 45%, #b8895e 100%);
  border: none;
  border-radius: 999px;
  cursor: pointer;
  transition: transform 0.12s, filter 0.12s, box-shadow 0.12s;
  box-shadow: 0 2px 10px rgba(212, 165, 116, 0.2);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.game-toolbar .btn-link:hover {
  filter: brightness(1.05);
  transform: translateY(-1px);
  box-shadow: 0 4px 15px rgba(212, 165, 116, 0.3);
}

.game-toolbar .btn-link:active {
  transform: translateY(0);
}

.game-toolbar .btn-secondary {
  min-height: 44px;
  padding: 0.55rem 1.35rem;
  font-family: inherit;
  font-size: clamp(0.82rem, 2.5vw, 0.875rem);
  font-weight: 600;
  text-decoration: none;
  color: var(--text);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.game-toolbar .btn-secondary:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: var(--accent-dim);
}

/* Telas baixas / landscape em telemóvel */
@media (max-height: 520px) and (orientation: landscape) {
  #login-container {
    align-items: flex-start;
    padding-top: max(0.75rem, env(safe-area-inset-top));
  }

  .auth-brand {
    margin-bottom: 1rem;
  }

  .auth-brand h1 {
    font-size: 1.35rem;
  }

  #unity-container.unity-visible {
    padding-top: 0.5rem;
    padding-bottom: 0.5rem;
  }

  .game-canvas-wrap {
    max-height: calc(100dvh - 4.5rem - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  }
}

@media (max-width: 380px) {
  .auth-tabs button {
    padding: 0.5rem 0.35rem;
  }
}
