:root {
  --bg-void: #05070d;
  --bg-deep: #0a0e1a;
  --panel: rgba(16, 22, 38, .72);
  --panel-border: rgba(0, 229, 255, .25);
  --cyan: #00e5ff;
  --magenta: #ff2ec4;
  --green: #00ff9c;
  --red: #ff3b5c;
  --amber: #ffb020;
  --text: #e9f1ff;
  --text-dim: #8ea0c4;
  --font-display: 'Orbitron', 'Space Grotesk', sans-serif;
  --font-body: 'Space Grotesk', system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  width: 100%;
  background: var(--bg-void);
  color: var(--text);
  font-family: var(--font-body);
  overflow-x: hidden;
  position: relative;
}

/* ---------- Fundo 3D animado ---------- */
.grid-field {
  position: fixed;
  inset: 0;
  z-index: 0;
  background-image:
    linear-gradient(rgba(0, 229, 255, .12) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0, 229, 255, .12) 1px, transparent 1px);
  background-size: 56px 56px;
  transform: rotateX(62deg) translateY(-10%) scale(1.6);
  transform-origin: center top;
  animation: gridDrift 14s linear infinite;
  opacity: .35;
  mask-image: radial-gradient(ellipse 80% 60% at 50% 0%, black 40%, transparent 85%);
}

@keyframes gridDrift {
  from { background-position: 0 0; }
  to { background-position: 0 56px; }
}

.glow-orb {
  position: fixed;
  border-radius: 50%;
  filter: blur(90px);
  z-index: 0;
  opacity: .45;
  animation: orbFloat 12s ease-in-out infinite alternate;
}
.glow-orb.one { width: 420px; height: 420px; background: var(--cyan); top: -120px; left: -100px; }
.glow-orb.two { width: 380px; height: 380px; background: var(--magenta); bottom: -140px; right: -80px; animation-delay: -6s; }

@keyframes orbFloat {
  from { transform: translate3d(0, 0, 0) scale(1); }
  to { transform: translate3d(40px, 30px, 0) scale(1.15); }
}

.scanlines {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background: repeating-linear-gradient(
    to bottom,
    rgba(255, 255, 255, .02) 0px,
    rgba(255, 255, 255, .02) 1px,
    transparent 2px,
    transparent 4px
  );
  mix-blend-mode: overlay;
}

.page {
  position: relative;
  z-index: 2;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  perspective: 1400px;
  max-width: 100vw;
  overflow-x: hidden;
}

/* ---------- Header ---------- */
.brand {
  font-family: var(--font-display);
  letter-spacing: .12em;
  font-weight: 900;
  text-transform: uppercase;
  color: var(--text);
}
.brand .accent { color: var(--cyan); text-shadow: 0 0 18px rgba(0, 229, 255, .8); }

/* ---------- Cartões vidro / 3D tilt ---------- */
.glass-card {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 20px;
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  box-shadow: 0 20px 60px rgba(0, 0, 0, .55), inset 0 1px 0 rgba(255, 255, 255, .06);
  transform-style: preserve-3d;
  transition: transform .25s ease, box-shadow .25s ease;
}

.tilt-3d {
  will-change: transform;
}

/* ---------- Visor superior (painel de descoberta) ---------- */
.display-panel {
  padding: 1.75rem 1rem;
  text-align: center;
  position: relative;
  overflow: hidden;
}
.display-panel::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(120deg, transparent 30%, rgba(0, 229, 255, .08) 50%, transparent 70%);
  animation: sweep 4s linear infinite;
}
@keyframes sweep {
  from { transform: translateX(-100%); }
  to { transform: translateX(100%); }
}

.display-digits {
  display: flex;
  justify-content: center;
  gap: .75rem;
  position: relative;
  z-index: 1;
}

.display-slot {
  width: 64px;
  height: 84px;
  border-radius: 14px;
  background: linear-gradient(160deg, rgba(0, 229, 255, .08), rgba(0, 0, 0, .5));
  border: 1px solid var(--panel-border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-size: 2.4rem;
  font-weight: 900;
  color: var(--text-dim);
  box-shadow: inset 0 0 20px rgba(0, 0, 0, .6);
  transform-style: preserve-3d;
  transition: transform .5s cubic-bezier(.2, .9, .3, 1.3), color .3s, text-shadow .3s;
}
.display-slot.filled {
  color: var(--green);
  text-shadow: 0 0 22px rgba(0, 255, 156, .85);
  border-color: rgba(0, 255, 156, .5);
  animation: slotReveal .6s cubic-bezier(.2, .9, .3, 1.3);
}
@keyframes slotReveal {
  0% { transform: rotateY(0deg) scale(1); }
  45% { transform: rotateY(95deg) scale(1.08); }
  55% { transform: rotateY(95deg) scale(1.08); color: var(--green); }
  100% { transform: rotateY(0deg) scale(1); }
}

/* ---------- Tabela de palpites: uma linha por posição ---------- */
.guess-table {
  display: flex;
  flex-direction: column;
  gap: .5rem;
}
.position-board {
  display: flex;
  align-items: center;
  gap: .5rem;
}
.position-label {
  font-family: var(--font-display);
  font-size: .8rem;
  font-weight: 700;
  letter-spacing: .06em;
  color: var(--text-dim);
  text-transform: uppercase;
  width: 1.6rem;
  flex-shrink: 0;
  text-align: center;
}
.digit-row {
  display: flex;
  gap: .3rem;
  flex: 1 1 auto;
  min-width: 0;
}

.digit-flip {
  flex: 1 1 0;
  min-width: 0;
  aspect-ratio: 1 / 1;
  max-width: 34px;
  perspective: 400px;
  cursor: default;
}
.digit-flip-inner {
  width: 100%;
  height: 100%;
  position: relative;
  transform-style: preserve-3d;
  transition: transform .5s cubic-bezier(.3, .9, .3, 1.2);
  border-radius: 8px;
}
.digit-flip.flipped .digit-flip-inner {
  transform: rotateY(180deg);
}
.digit-face {
  position: absolute;
  inset: 0;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: .95rem;
  backface-visibility: hidden;
  border: 1px solid rgba(255, 255, 255, .08);
}
.digit-face.front {
  background: rgba(255, 255, 255, .04);
  color: var(--text-dim);
}
.digit-face.back {
  transform: rotateY(180deg);
}
.digit-flip.state-green .digit-face.back {
  background: radial-gradient(circle at 30% 30%, #26ffb8, #00b871);
  color: #05130c;
  box-shadow: 0 0 16px rgba(0, 255, 156, .8);
}
.digit-flip.state-red .digit-face.back {
  background: radial-gradient(circle at 30% 30%, #ff6d84, #b8102f);
  color: #2a0007;
  box-shadow: 0 0 14px rgba(255, 59, 92, .65);
}
.digit-flip.state-idle .digit-flip-inner { transform: rotateY(0deg); }

.guess-slot {
  width: 44px;
  height: 54px;
  border-radius: 12px;
  background: rgba(255, 255, 255, .03);
  border: 1px solid var(--panel-border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--cyan);
}
.guess-slot.filled {
  color: var(--green);
  text-shadow: 0 0 22px rgba(0, 255, 156, .85);
  border-color: rgba(0, 255, 156, .5);
}

/* ---------- Botão sair ---------- */
.btn-exit {
  padding: .5rem .75rem;
  border-radius: 10px;
  line-height: 1;
}

/* ---------- Botão mostrar/ocultar partilha (topbar) ---------- */
.btn-invite-toggle {
  padding: .5rem .75rem;
  border-radius: 10px;
  line-height: 1;
}

/* ---------- Teclado telefónico (sticky, 3 colunas) + visor lateral ---------- */
.guess-input-dock {
  position: sticky;
  bottom: 0;
  z-index: 6;
  background: linear-gradient(180deg, rgba(10, 14, 26, 0) 0%, var(--bg-deep) 18%);
  padding: .6rem 0 calc(.6rem + env(safe-area-inset-bottom));
}
.guess-dock-inner {
  display: flex;
  align-items: stretch;
  gap: .75rem;
  padding: .75rem;
  border-radius: 18px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  backdrop-filter: blur(18px);
}
.keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: .5rem;
  flex: 0 1 320px;
  min-width: 0;
}
.keypad button {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.15rem;
  padding: .65rem 0;
  min-height: 46px;
  border-radius: 10px;
  border: 1px solid var(--panel-border);
  background: rgba(255, 255, 255, .04);
  color: var(--text);
  transition: transform .15s, box-shadow .15s, background .15s;
}
.keypad button:hover { background: rgba(0, 229, 255, .12); }
.keypad button:active { transform: translateY(1px) scale(.96) rotateX(8deg); }
.keypad button.key-ok {
  color: var(--green);
  border-color: rgba(0, 255, 156, .5);
  background: rgba(0, 255, 156, .08);
}
.keypad button.key-ok:not(:disabled):hover { background: var(--green); color: #05130c; }
.keypad button.key-back {
  color: var(--magenta);
  border-color: rgba(255, 46, 196, .4);
  background: rgba(255, 46, 196, .06);
}

.guess-side {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  flex: 1 1 auto;
  min-width: 0;
}
.guess-status-row {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .2rem;
  text-align: center;
}
.guess-pad-mini {
  display: flex;
  flex-direction: column;
  gap: .3rem;
}
.guess-slot-mini {
  width: 38px;
  height: 30px;
  border-radius: 8px;
  background: rgba(255, 255, 255, .03);
  border: 1px solid var(--panel-border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--cyan);
}
.guess-slot-mini.filled {
  color: var(--green);
  text-shadow: 0 0 12px rgba(0, 255, 156, .7);
  border-color: rgba(0, 255, 156, .5);
}
.btn-clear-mini {
  padding: .4rem .55rem;
  border-radius: 8px;
  font-size: .8rem;
}

/* ---------- Estados / badges ---------- */
.turn-badge {
  font-family: var(--font-display);
  letter-spacing: .1em;
  padding: .45rem 1.1rem;
  border-radius: 999px;
  font-size: .82rem;
  font-weight: 700;
  border: 1px solid transparent;
}
.turn-badge.mine {
  background: rgba(0, 255, 156, .12);
  color: var(--green);
  border-color: rgba(0, 255, 156, .5);
  box-shadow: 0 0 18px rgba(0, 255, 156, .35);
  animation: pulseGlow 1.6s ease-in-out infinite;
}
.turn-badge.theirs {
  background: rgba(255, 176, 32, .08);
  color: var(--amber);
  border-color: rgba(255, 176, 32, .35);
}
@keyframes pulseGlow {
  0%, 100% { box-shadow: 0 0 12px rgba(0, 255, 156, .3); }
  50% { box-shadow: 0 0 26px rgba(0, 255, 156, .7); }
}

.score-pill {
  font-family: var(--font-display);
  font-weight: 900;
  font-size: 1.4rem;
  color: var(--cyan);
  text-shadow: 0 0 14px rgba(0, 229, 255, .6);
}

/* ---------- Histórico ---------- */
.history-item {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .5rem .75rem;
  border-radius: 10px;
  background: rgba(255, 255, 255, .03);
  border: 1px solid rgba(255, 255, 255, .06);
  font-family: var(--font-display);
  font-size: .95rem;
  animation: fadeSlideIn .35s ease;
}
@keyframes fadeSlideIn {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: translateY(0); }
}
.history-digit {
  width: 26px;
  height: 26px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .85rem;
  font-weight: 700;
}
.history-digit.hit { background: rgba(0, 255, 156, .18); color: var(--green); }
.history-digit.miss { background: rgba(255, 59, 92, .12); color: var(--red); }

/* ---------- Botões primários ---------- */
.btn-neon {
  font-family: var(--font-display);
  font-weight: 700;
  letter-spacing: .06em;
  border: 1px solid var(--cyan);
  color: var(--cyan);
  background: rgba(0, 229, 255, .06);
  border-radius: 12px;
  padding: .7rem 1.6rem;
  transition: all .2s;
}
.btn-neon:hover {
  background: var(--cyan);
  color: #001217;
  box-shadow: 0 0 26px rgba(0, 229, 255, .65);
  transform: translateY(-2px);
}

.btn-magenta {
  border-color: var(--magenta);
  color: var(--magenta);
  background: rgba(255, 46, 196, .06);
}
.btn-magenta:hover {
  background: var(--magenta);
  color: #1a0012;
  box-shadow: 0 0 26px rgba(255, 46, 196, .6);
}

/* ---------- Overlay de vitória / espera ---------- */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(4, 6, 12, .82);
  backdrop-filter: blur(6px);
  animation: fadeIn .3s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.result-card {
  text-align: center;
  padding: 3rem 2.5rem;
  max-width: 420px;
  animation: popIn .45s cubic-bezier(.2, .9, .3, 1.3);
}
@keyframes popIn {
  from { transform: scale(.7) rotateX(20deg); opacity: 0; }
  to { transform: scale(1) rotateX(0); opacity: 1; }
}
.result-title {
  font-family: var(--font-display);
  font-size: 2.2rem;
  font-weight: 900;
  margin-bottom: .5rem;
}
.result-title.win { color: var(--green); text-shadow: 0 0 30px rgba(0, 255, 156, .8); }
.result-title.lose { color: var(--red); text-shadow: 0 0 30px rgba(255, 59, 92, .8); }

/* ---------- Confetti simples ---------- */
.confetti-piece {
  position: fixed;
  top: -10px;
  width: 8px;
  height: 14px;
  z-index: 60;
  opacity: .9;
  animation: confettiFall linear forwards;
}
@keyframes confettiFall {
  to { transform: translateY(110vh) rotate(540deg); opacity: 0; }
}

/* ---------- QR / share ---------- */
.qr-wrap {
  background: #fff;
  padding: .6rem;
  border-radius: 14px;
  display: inline-block;
  box-shadow: 0 0 30px rgba(0, 229, 255, .35);
}

.share-input {
  background: rgba(0, 0, 0, .35);
  border: 1px solid var(--panel-border);
  color: var(--text);
  border-radius: 10px;
  padding: .6rem .8rem;
  font-family: var(--font-body);
  font-size: .85rem;
}

/* ---------- Cartão "A minha senha" ---------- */
.my-secret-panel {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .75rem;
}
.my-secret-label { white-space: nowrap; }
.my-secret-digits { flex-wrap: wrap; min-width: 0; }
.my-secret-toggle {
  margin-left: auto;
  white-space: nowrap;
  flex-shrink: 0;
}

/* ---------- Responsivo ---------- */
html, body { max-width: 100%; overflow-x: hidden; }
.page, .container { max-width: 100%; }
.share-input { min-width: 0; }

@media (max-width: 576px) {
  .display-slot { width: 46px; height: 62px; font-size: 1.6rem; }
  .display-digits { gap: .4rem; }
  .digit-flip { max-width: 28px; }
  .digit-row { gap: .2rem; }
  .digit-face { font-size: .7rem; }
  .result-card { padding: 2rem 1.25rem; max-width: 92vw; }
  .result-title { font-size: 1.7rem; }
  .brand { font-size: 1.25rem; }
  .score-pill { font-size: 1.1rem; }
  .glass-card { border-radius: 16px; }
  .qr-wrap img { width: 72px; height: 72px; }

  /* "A minha senha" card: never let the toggle push layout wider than the screen */
  .my-secret-panel { gap: .5rem .75rem; }
  .my-secret-label { font-size: .68rem; flex-basis: 100%; }
  .my-secret-digits { order: 1; }
  .my-secret-toggle { margin-left: 0; padding: .5rem 1rem; font-size: .8rem; }

  .guess-input-dock { padding: .5rem 0 calc(.5rem + env(safe-area-inset-bottom)); }
  .guess-dock-inner { padding: .6rem; gap: .5rem; border-radius: 14px; }
  .keypad { flex-basis: 58%; gap: .35rem; }
  .keypad button { padding: .45rem 0; font-size: .95rem; min-height: 38px; }
  .guess-slot-mini { width: 30px; height: 24px; font-size: .9rem; }
  .turn-badge { padding: .35rem .6rem; font-size: .64rem; }
  #opponent-badge { font-size: .64rem; }
}

@media (max-width: 380px) {
  .position-label { font-size: .7rem; width: 1.3rem; }
  .digit-flip { max-width: 24px; }
  .keypad button { min-height: 34px; font-size: .85rem; }
  .guess-slot-mini { width: 26px; height: 22px; font-size: .78rem; }
  .btn-clear-mini { padding: .3rem .45rem; font-size: .7rem; }
}
