:root {
  --app-dvh: 100dvh;
  --studio-bg-top: #071226;
  --studio-bg-bottom: #0F2347;
  --gold-frame: #D4AF37;
  --gold-light: #FACC15;
  --board-inner: #0A1A36;
  --clue-blue: #0369A1;
  --tile-empty: #0D3254;
  --tile-ivory: #F8F5E9;
  --tile-blue-glow: #0EA5E9;
}

*,
*::before,
*::after {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: var(--app-dvh);
  overflow: hidden;
  background:
    radial-gradient(circle at 20% 0%, rgba(56, 189, 248, 0.14), transparent 45%),
    radial-gradient(circle at 80% 0%, rgba(250, 204, 21, 0.12), transparent 42%),
    radial-gradient(circle at 50% 25%, var(--studio-bg-bottom) 0%, var(--studio-bg-top) 78%);
  color: #F8FAFC;
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  user-select: none;
}

/* Shell principal tablet-first sin scroll */
.app-shell {
  width: 100%;
  height: var(--app-dvh);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
}

/* Banda 1: Barra Superior (8% alto, mín. 44px) */
.top-bar {
  flex: 0 0 8%;
  min-height: 44px;
  max-height: 64px;
  padding: 0 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: linear-gradient(180deg, rgba(7, 18, 38, 0.96), rgba(10, 26, 54, 0.9));
  border-bottom: 1px solid rgba(212, 175, 55, 0.45);
  z-index: 20;
}

.timer-pill {
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.04em;
}

.timer-urgent {
  animation: pulseTimer 0.75s ease-in-out infinite alternate;
  color: #FCA5A5 !important;
  border-color: rgba(239, 68, 68, 0.85) !important;
  background: rgba(153, 27, 27, 0.45) !important;
}

@keyframes pulseTimer {
  from { transform: scale(1); }
  to { transform: scale(1.04); }
}

/* Banda 2: Zona Central — El Gran Panel (52% alto) */
.board-zone {
  flex: 1 1 52%;
  min-height: 0;
  padding: 8px 14px 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  position: relative;
}

.board-stage {
  width: 100%;
  flex: 1 1 auto;
  min-height: 0;
  container-type: size;
  display: flex;
  align-items: center;
  justify-content: center;
}

.board-frame {
  /* Mantiene proporción exacta 4x14 sin recorte en iPad 4:3, 16:10, 16:9 y portrait */
  width: min(100cqw, calc(100cqh * 14 / 4.85), 1040px);
  height: auto;
  max-height: 100cqh;
  aspect-ratio: 14 / 4.85;
  padding: clamp(5px, 1.1vh, 11px);
  border-radius: 16px;
  background: linear-gradient(145deg, #FDE047 0%, #D4AF37 35%, #926D1B 70%, #D4AF37 100%);
  box-shadow:
    0 12px 30px rgba(0, 0, 0, 0.55),
    0 0 22px rgba(212, 175, 55, 0.25),
    inset 0 1px 2px rgba(255, 255, 255, 0.6);
  display: flex;
}

.board-inner-bg {
  flex: 1;
  border-radius: 10px;
  background: radial-gradient(circle at center, #0F2B56 0%, var(--board-inner) 85%);
  padding: clamp(5px, 0.9vh, 10px);
  border: 2px solid rgba(56, 189, 248, 0.28);
  box-shadow: inset 0 4px 16px rgba(0, 0, 0, 0.65);
  display: flex;
}

.board-grid {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(14, minmax(0, 1fr));
  grid-template-rows: repeat(4, minmax(0, 1fr));
  gap: clamp(3px, 0.6vh, 6px);
}

/* Casillas del Gran Panel 3D */
.board-tile {
  perspective: 700px;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
}

.tile-inner {
  width: 100%;
  height: 100%;
  border-radius: 5px;
  transform-style: preserve-3d;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.tile-char {
  font-weight: 900;
  line-height: 1;
  font-size: clamp(1rem, 3.1vh, 2.25rem);
  letter-spacing: -0.02em;
  backface-visibility: hidden;
}

.tile-blocked .tile-inner {
  background: transparent;
  border: none;
  box-shadow: none;
}

.tile-empty .tile-inner {
  background: linear-gradient(180deg, #0E4B68 0%, #09354B 100%);
  border: 1px solid rgba(56, 189, 248, 0.24);
  box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.45);
}

.tile-hidden .tile-inner {
  background: linear-gradient(180deg, #FFFDF7 0%, #ECE6D3 100%);
  border: 1.5px solid #CBD5E1;
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.9),
    inset 0 -3px 0 rgba(148, 163, 184, 0.45),
    0 2px 4px rgba(0, 0, 0, 0.4);
}

.tile-highlight-blue .tile-inner {
  background: radial-gradient(circle at center, #7DD3FC 0%, var(--tile-blue-glow) 60%, #0284C7 100%) !important;
  border-color: #BAE6FD !important;
  box-shadow:
    0 0 14px rgba(14, 165, 233, 0.95),
    inset 0 0 10px rgba(255, 255, 255, 0.7) !important;
}

.tile-revealed .tile-inner {
  background: linear-gradient(180deg, #FFFFFF 0%, var(--tile-ivory) 100%);
  border: 1.5px solid #D4AF37;
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.95),
    inset 0 -2px 0 rgba(212, 175, 55, 0.35),
    0 2px 5px rgba(0, 0, 0, 0.45);
}

.tile-revealed .tile-char {
  color: #091326;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.8);
}

.tile-gold-flash .tile-inner {
  background: linear-gradient(180deg, #FEF08A 0%, #FACC15 55%, #EAB308 100%) !important;
  border: 2px solid #FFFFFF !important;
  box-shadow:
    0 0 18px rgba(250, 204, 21, 0.95),
    inset 0 0 8px rgba(255, 255, 255, 0.9) !important;
}

/* Barra de Pista y tira de letras dichas */
.clue-bar {
  flex: 0 0 auto;
  width: min(100%, 840px);
  padding: 5px 16px;
  border-radius: 999px;
  background: linear-gradient(90deg, #075985 0%, var(--clue-blue) 50%, #075985 100%);
  border: 2px solid var(--gold-frame);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.45), inset 0 1px 1px rgba(255, 255, 255, 0.3);
  text-align: center;
}

.clue-text {
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-size: clamp(0.75rem, 1.75vh, 1.05rem);
  color: #FFFFFF;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.65);
}

.guessed-strip {
  flex: 0 0 auto;
  width: min(100%, 960px);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 4px;
  min-height: 22px;
}

.guessed-chip {
  font-size: 0.7rem;
  font-weight: 800;
  padding: 1px 6px;
  border-radius: 5px;
  line-height: 1.3;
}

.guessed-hit {
  background: rgba(16, 185, 129, 0.24);
  color: #6EE7B7;
  border: 1px solid rgba(16, 185, 129, 0.55);
}

.guessed-miss {
  background: rgba(71, 85, 105, 0.35);
  color: #94A3B8;
  border: 1px solid rgba(100, 116, 139, 0.4);
  text-decoration: line-through;
}

/* Barra flotante de Respuesta (bajo el Gran Panel) */
.answer-bar {
  width: min(100%, 860px);
  flex: 0 0 auto;
  padding: 8px 12px;
  border-radius: 12px;
  background: rgba(7, 18, 38, 0.96);
  border: 2px solid #FACC15;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.75);
  display: flex;
  align-items: center;
  gap: 8px;
  z-index: 30;
}

.answer-bar.hidden {
  display: none !important;
}

/* Banda 3: Zona Inferior (40% alto) */
.bottom-zone {
  flex: 0 0 40%;
  min-height: 0;
  padding: 6px 14px 10px;
  display: grid;
  grid-template-columns: 62fr 38fr;
  gap: 12px;
  background: linear-gradient(180deg, rgba(7, 18, 38, 0.25) 0%, rgba(4, 11, 24, 0.85) 100%);
  border-top: 1px solid rgba(212, 175, 55, 0.28);
}

/* Atriles de Jugadores */
.podiums-panel {
  min-height: 0;
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, 1fr);
  gap: 10px;
  align-items: stretch;
}

.podium-card {
  position: relative;
  border-radius: 14px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  border: 2px solid rgba(255, 255, 255, 0.16);
  background: rgba(10, 26, 54, 0.86);
  transition: transform 0.2s ease, opacity 0.2s ease, box-shadow 0.2s ease;
  opacity: 0.78;
  min-width: 0;
}

.podium-card.podium-active {
  opacity: 1;
  transform: translateY(-4px);
}

.podium-blue {
  border-color: rgba(56, 189, 248, 0.45);
  background: linear-gradient(180deg, rgba(0, 87, 184, 0.42) 0%, rgba(10, 26, 54, 0.92) 100%);
}
.podium-blue.podium-active {
  border-color: #38BDF8;
  box-shadow: 0 8px 22px rgba(0, 87, 184, 0.55), 0 0 0 1px rgba(56, 189, 248, 0.4);
}

.podium-red {
  border-color: rgba(248, 113, 113, 0.45);
  background: linear-gradient(180deg, rgba(214, 40, 40, 0.4) 0%, rgba(10, 26, 54, 0.92) 100%);
}
.podium-red.podium-active {
  border-color: #F87171;
  box-shadow: 0 8px 22px rgba(214, 40, 40, 0.52), 0 0 0 1px rgba(248, 113, 113, 0.4);
}

.podium-yellow {
  border-color: rgba(250, 204, 21, 0.45);
  background: linear-gradient(180deg, rgba(202, 138, 4, 0.4) 0%, rgba(10, 26, 54, 0.92) 100%);
}
.podium-yellow.podium-active {
  border-color: #FACC15;
  box-shadow: 0 8px 22px rgba(202, 138, 4, 0.5), 0 0 0 1px rgba(250, 204, 21, 0.45);
}

.led-score {
  font-variant-numeric: tabular-nums;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-weight: 900;
  font-size: clamp(1.4rem, 3.6vh, 2.3rem);
  line-height: 1.05;
  text-shadow: 0 0 10px rgba(255, 255, 255, 0.25);
}

.perk-chip {
  min-height: 28px;
  padding: 2px 7px;
  border-radius: 6px;
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
}

/* Consola Dinámica de Turno */
.console-panel {
  min-height: 0;
  border-radius: 14px;
  background: rgba(10, 26, 54, 0.9);
  border: 1px solid rgba(212, 175, 55, 0.4);
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  overflow: hidden;
}

.letter-grid {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 4px;
  overflow-y: auto;
}

.letter-btn {
  min-height: 44px;
  min-width: 34px;
  border-radius: 8px;
  font-weight: 800;
  font-size: 0.95rem;
  background: linear-gradient(180deg, #1E3A8A 0%, #172554 100%);
  border: 1px solid rgba(147, 197, 253, 0.4);
  color: #FFFFFF;
  cursor: pointer;
  transition: transform 0.1s ease, background 0.15s ease, opacity 0.15s ease;
}

.letter-btn:active:not(:disabled) {
  transform: scale(0.94);
}

.letter-btn.letter-hit {
  background: rgba(16, 185, 129, 0.25);
  border-color: rgba(16, 185, 129, 0.6);
  color: #6EE7B7;
}

.letter-btn.letter-miss {
  background: rgba(51, 65, 85, 0.35);
  border-color: rgba(100, 116, 139, 0.35);
  color: #64748B;
  text-decoration: line-through;
}

.letter-btn:disabled {
  opacity: 0.48;
  cursor: not-allowed;
}

.vowel-btn {
  min-height: 44px;
  border-radius: 10px;
  font-weight: 900;
  font-size: 1rem;
  background: linear-gradient(180deg, #B45309 0%, #78350F 100%);
  border: 1px solid rgba(250, 204, 21, 0.65);
  color: #FEF08A;
  cursor: pointer;
}

.vowel-btn:disabled {
  opacity: 0.42;
  cursor: not-allowed;
}

.touch-btn {
  min-height: 44px;
  min-width: 44px;
}

/* Ficha voladora de Supercomodín */
.flying-supercomodin {
  position: fixed;
  transform: translate(-50%, -50%);
  padding: 6px 12px;
  border-radius: 999px;
  background: linear-gradient(90deg, #FEF08A, #FACC15);
  color: #422006;
  font-weight: 900;
  font-size: 0.85rem;
  border: 2px solid #FFFFFF;
  box-shadow: 0 0 20px rgba(250, 204, 21, 0.9);
  pointer-events: none;
  z-index: 90;
}

/* Modo teclado virtual activo (window.visualViewport): oculta banda de atriles y garantiza 100% tablero visible */
body.keyboard-open .bottom-zone {
  display: none !important;
}

body.keyboard-open .top-bar {
  flex: 0 0 auto;
  min-height: 40px;
  padding: 2px 12px;
}

body.keyboard-open .board-zone {
  flex: 1 1 auto;
  padding: 6px 10px;
  gap: 5px;
}

body.keyboard-open .guessed-strip {
  display: none;
}

/* Adaptación vertical (Portrait) */
@media (orientation: portrait) {
  .top-bar {
    flex: 0 0 auto;
    min-height: 48px;
  }

  .board-zone {
    flex: 0 0 42%;
    padding: 6px 8px;
  }

  .board-frame {
    width: 100%;
    height: auto;
    max-height: 100%;
  }

  .bottom-zone {
    flex: 1 1 50%;
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
    gap: 8px;
    padding: 6px 8px 10px;
  }

  .podiums-panel {
    gap: 6px;
  }

  .podium-card {
    padding: 6px 8px;
  }

  .led-score {
    font-size: 1.25rem;
  }

  .letter-grid {
    grid-template-columns: repeat(6, minmax(0, 1fr));
  }
}
