/* ============================================
   Ready Girl — LG webOS Smart TV App
   Dark Theme + Glassmorphism + TV Layout
   ============================================ */

/* --- CSS Variables --- */
:root {
  /* Fondos */
  --bg-primary: #0D0D14;
  --bg-gradient: linear-gradient(135deg, #0D0D14 0%, #1A0D1F 50%, #0D0D14 100%);
  --surface: #1A1A2E;
  --surface-border: #2A2A40;
  --surface-hover: #252540;

  /* Glass */
  --glass-bg: rgba(255, 255, 255, 0.06);
  --glass-border: rgba(255, 255, 255, 0.10);
  --glass-blur: blur(20px);

  /* Texto */
  --text-primary: #F5F5F5;
  --text-secondary: #A0A0B8;
  --text-tertiary: #6B6B80;

  /* Acentos */
  --rosa: #FF4D6A;
  --rosa-cta: #FF3A5C;
  --rosa-soft: rgba(255, 77, 106, 0.3);
  --verde: #22C55E;
  --amber: #F59E0B;

  /* QR */
  --qr-bg: #FFFFFF;

  /* Layout */
  --safe-zone: 48px;

  /* Transitions */
  --transition-fast: 0.15s ease;
  --transition-normal: 0.25s ease;
  --transition-slow: 0.4s ease;
}

/* --- Reset & Base --- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  width: 100%;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: -apple-system, 'Helvetica Neue', 'LG Smart UI', Arial, sans-serif;
  font-size: 22px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  background: var(--bg-gradient);
}

/* --- Typography Scale (TV) --- */
.text-display  { font-size: 56px; font-weight: 700; line-height: 1.1; }
.text-headline { font-size: 40px; font-weight: 700; line-height: 1.2; }
.text-title    { font-size: 28px; font-weight: 600; line-height: 1.3; }
.text-body     { font-size: 22px; font-weight: 400; line-height: 1.5; }
.text-label    { font-size: 18px; font-weight: 500; line-height: 1.4; }

/* --- Safe Zone --- */
/* Google TV guidelines: 48px minimum, we use 60px for breathing room */
.safe-zone {
  padding: 48px 60px;
  width: 100%;
  height: 100%;
  position: relative;
}

/* --- TV Canvas ---
   Fijo 1920×1080. JS setea --tv-scale = min(innerWidth/1920, innerHeight/1080).
   Así el diseño original se ve igual en cualquier tamaño landscape.
*/
#tv-canvas {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 1920px;
  height: 1080px;
  transform-origin: center center;
  transform: translate(-50%, -50%) scale(var(--tv-scale, 1));
}

/* --- Screen System --- */
.screen {
  display: none;
  width: 1920px;
  height: 1080px;
  position: absolute;
  top: 0;
  left: 0;
  overflow: hidden;
}

.screen.active {
  display: flex;
}

/* --- Glassmorphism Components --- */
.glass-card {
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-border);
  border-radius: 16px;
  padding: 24px 28px;
}

.glass-pill {
  background: var(--glass-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--glass-border);
  border-radius: 24px;
  padding: 8px 20px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

/* Fallback para webOS < 4.x sin backdrop-filter */
@supports not (backdrop-filter: blur(1px)) {
  .glass-card,
  .glass-pill {
    background: var(--surface);
    border: 1px solid var(--surface-border);
  }
}

/* --- Focus System --- */
.focusable {
  outline: none;
  cursor: pointer;
  transition: box-shadow var(--transition-normal), transform var(--transition-normal);
}

.focusable.focused {
  box-shadow: 0 0 0 3px var(--rosa), 0 0 20px var(--rosa-soft);
  transform: scale(1.03);
}

.focusable:hover {
  box-shadow: 0 0 0 3px var(--rosa), 0 0 20px var(--rosa-soft);
  transform: scale(1.03);
}

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 14px 36px;
  border-radius: 12px;
  font-size: 22px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: all var(--transition-normal);
}

.btn-primary {
  background: var(--rosa-cta);
  color: #FFFFFF;
}

.btn-primary.focused {
  background: #FF5A75;
  box-shadow: 0 0 0 3px var(--rosa), 0 0 30px var(--rosa-soft);
}

.btn-secondary {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--surface-border);
}

.btn-secondary.focused {
  color: var(--text-primary);
  border-color: var(--rosa);
}

/* ============================================
   QR SCREEN
   ============================================ */
/* Google TV layout: 2-column with generous spacing */
#screen-qr .safe-zone {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  gap: 120px;
}

/* Left pane: instructions */
.qr-instructions {
  flex: 1 1 auto;
  max-width: 820px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.qr-instructions .logo {
  height: 100px;
  object-fit: contain;
  align-self: flex-start;
  margin-bottom: 82px;
}

.qr-instructions h1 {
  font-size: 56px;
  font-weight: 700;
}

.steps-list {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.step-card {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 16px 0;
}

.step-number {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--rosa);
  color: #FFFFFF;
  font-size: 24px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.step-text {
  font-size: 26px;
  color: var(--text-secondary);
}

.step-text strong {
  color: var(--text-primary);
  font-size: 28px;
}

/* Right pane: QR — top aligned with "Conecta tu clase" heading */
.qr-panel {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 28px;
  padding-top: 210px;
}

.qr-card {
  padding: 40px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
}

#qr-container {
  width: 360px;
  height: 360px;
  background: var(--qr-bg);
  border-radius: 16px;
  padding: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
}

#qr-container img,
#qr-container canvas {
  width: 320px !important;
  height: 320px !important;
}

/* Status badge */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  font-size: 22px;
  color: var(--text-secondary);
}

.status-badge .spinner {
  width: 18px;
  height: 18px;
  border: 2px solid var(--text-tertiary);
  border-top-color: var(--rosa);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

.status-badge.connected {
  color: var(--verde);
}

.status-badge.expired {
  color: var(--amber);
}

/* App download hint */
.app-download-card {
  text-align: center;
  max-width: 340px;
}

.app-download-card p {
  margin-bottom: 14px;
}

.store-badges {
  display: flex;
  justify-content: center;
  gap: 16px;
  margin-top: 12px;
}

.store-badges img {
  height: 52px;
  opacity: 0.85;
  transition: opacity var(--transition-normal);
}

.store-badges img:hover {
  opacity: 1;
}

#btn-new-qr {
  display: none;
  margin-top: 8px;
}

/* ============================================
   VIDEO PLAYER SCREEN — Netflix-style
   ============================================ */
#screen-player {
  background: #000;
  position: relative;
}

#video-player {
  width: 1920px;
  height: 1080px;
  object-fit: contain;
  background: #000;
}

/* --- Overlay container --- */
.player-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 10;
  pointer-events: none;
  opacity: 1;
  transition: opacity 0.3s ease-out;
}

.player-overlay.visible {
  pointer-events: auto;
}

.player-overlay.fade-out {
  opacity: 0;
  pointer-events: none;
}

/* --- Top gradient zone --- */
.player-gradient-top {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 140px;
  padding: 48px 48px 0;
  background: linear-gradient(to bottom, rgba(0,0,0,0.6) 0%, transparent 100%);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
}

.player-title {
  font-size: 36px;
  font-weight: 700;
  color: #FFFFFF;
  text-shadow: 0 2px 8px rgba(0,0,0,0.5);
  max-width: 70%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.player-logo {
  height: 52px;
  object-fit: contain;
  opacity: 0.7;
}

/* --- Center play icon (paused state) --- */
.player-center-play {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 11;
  opacity: 1;
  transition: opacity 0.25s ease;
}

.player-center-play.hidden {
  opacity: 0;
  pointer-events: none;
}

.center-play-btn {
  width: 120px;
  height: 120px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid rgba(255,255,255,0.15);
}

/* --- Unmute prompt (autoplay con audio bloqueado) --- */
.unmute-prompt {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 13;
  transition: opacity 0.25s ease;
}

.unmute-prompt.hidden {
  opacity: 0;
  pointer-events: none;
}

.unmute-btn {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 20px 36px;
  border-radius: 999px;
  background: var(--rosa-cta);
  color: #fff;
  font-size: 24px;
  font-weight: 600;
  box-shadow: 0 10px 40px rgba(255, 77, 106, 0.5);
  cursor: pointer;
}

.unmute-btn:hover,
.unmute-btn.focused {
  background: #FF5A75;
  transform: scale(1.03);
}

/* --- Seek indicator --- */
.seek-indicator {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 12;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-radius: 12px;
  padding: 16px 28px;
  opacity: 1;
  transition: opacity 0.3s ease;
}

.seek-indicator.hidden {
  opacity: 0;
  pointer-events: none;
}

.seek-indicator span {
  font-size: 30px;
  font-weight: 600;
  color: white;
}

/* --- Bottom gradient zone --- */
.player-gradient-bottom {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 60px 48px 48px;
  background: linear-gradient(to top, rgba(0,0,0,0.75) 0%, rgba(0,0,0,0.3) 60%, transparent 100%);
}

/* --- Progress bar --- */
.progress-track {
  width: 100%;
  height: 6px;
  background: rgba(255,255,255,0.2);
  border-radius: 3px;
  position: relative;
  cursor: pointer;
  transition: height 0.2s ease;
  margin-bottom: 24px;
}

.progress-track.focused {
  height: 10px;
}

.progress-buffer {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  background: rgba(255,255,255,0.35);
  border-radius: 2px;
  width: 0%;
  transition: width 0.3s linear;
}

.progress-fill {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  background: #FF4D6A;
  border-radius: 2px;
  width: 0%;
  transition: width 0.3s linear;
}

.progress-thumb {
  width: 18px;
  height: 18px;
  background: #FFFFFF;
  border-radius: 50%;
  position: absolute;
  right: -7px;
  top: 50%;
  transform: translateY(-50%);
  box-shadow: 0 0 6px rgba(0,0,0,0.4);
  opacity: 0;
  transition: opacity 0.2s ease;
}

.player-overlay.visible .progress-thumb {
  opacity: 1;
}

/* --- Controls row --- */
.player-controls-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.player-controls-left {
  display: flex;
  align-items: center;
  gap: 32px;
}

.player-controls-right {
  display: flex;
  align-items: center;
}

/* --- Player buttons --- */
.player-btn {
  width: 56px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  border-radius: 50%;
  transition: background 0.15s ease, transform 0.15s ease;
}

.player-btn:hover,
.player-btn.focused {
  background: rgba(255,255,255,0.12);
  transform: scale(1.15);
}

.player-btn svg {
  display: block;
  width: 44px;
  height: 44px;
}

/* --- Time display --- */
.player-time {
  font-size: 24px;
  color: rgba(255,255,255,0.7);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.5px;
}

/* --- Brand label --- */
.player-brand {
  font-size: 20px;
  color: rgba(255,255,255,0.35);
  font-weight: 500;
  letter-spacing: 0.5px;
}

/* ============================================
   COMPLETION SCREEN — Screenshot-worthy
   ============================================ */
#screen-complete {
  position: relative;
  overflow: hidden;
}

/* Rosa glow behind text */
.complete-glow {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 60%;
  height: 40%;
  background: radial-gradient(ellipse, rgba(255,77,106,0.08) 0%, transparent 70%);
  pointer-events: none;
  z-index: 1;
}

/* Main content container */
.complete-content {
  position: relative;
  z-index: 3;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 0;
}

/* Logo / Trophy */
.trophy-icon {
  height: 150px;
  object-fit: contain;
  opacity: 0;
  animation: bounce-in 0.8s ease-out 0.3s forwards;
}

/* Title — BIG and CLEAR */
.complete-title {
  font-size: 48px;
  font-weight: 700;
  color: #FFFFFF;
  max-width: 80%;
  line-height: 1.2;
  margin-top: 24px;
  opacity: 0;
  animation: fadeUp 0.6s ease-out 0.5s forwards;
}

/* Subtitle */
.complete-subtitle {
  font-size: 28px;
  font-weight: 400;
  color: rgba(255,255,255,0.7);
  max-width: 70%;
  line-height: 1.5;
  margin-top: 20px;
  opacity: 0;
  animation: fadeUp 0.6s ease-out 0.7s forwards;
}

/* Countdown */
.complete-countdown {
  font-size: 18px;
  color: rgba(255,255,255,0.35);
  margin-top: 40px;
  opacity: 0;
  animation: fadeUp 0.4s ease-out 0.9s forwards;
}

/* Button */
.complete-btn {
  margin-top: 20px;
  padding: 14px 40px;
  font-size: 22px;
  opacity: 0;
  animation: fadeUp 0.5s ease-out 1s forwards;
}

/* Logo corner */
.complete-logo-corner {
  position: absolute;
  bottom: 48px;
  right: 60px;
  z-index: 3;
}

.complete-logo-corner img {
  height: 32px;
  opacity: 0.25;
}

/* Confetti */
.confetti-container {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  overflow: hidden;
  z-index: 2;
}

.confetti {
  position: absolute;
  animation: confetti-fall 3s ease-in forwards;
}

/* ============================================
   ERROR MODAL
   ============================================ */
.modal-backdrop {
  display: none;
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.6);
  z-index: 100;
  align-items: center;
  justify-content: center;
}

.modal-backdrop.active {
  display: flex;
}

.modal-content {
  padding: 40px 48px;
  text-align: center;
  max-width: 520px;
  animation: slideUp 0.3s ease-out;
}

.modal-icon {
  font-size: 60px;
  margin-bottom: 16px;
}

.modal-content h2 {
  font-size: 32px;
  font-weight: 700;
  margin-bottom: 12px;
}

.modal-content p {
  font-size: 22px;
  color: var(--text-secondary);
  margin-bottom: 28px;
}

/* ============================================
   ANIMATIONS
   ============================================ */
@keyframes spin {
  to { transform: rotate(360deg); }
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

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

@keyframes bounce-in {
  0% { transform: scale(0.3); opacity: 0; }
  60% { transform: scale(1.15); opacity: 1; }
  80% { transform: scale(0.95); }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes confetti-fall {
  0% {
    transform: translateY(-100px) rotate(0deg);
    opacity: 1;
  }
  100% {
    transform: translateY(1100px) rotate(720deg);
    opacity: 0;
  }
}

/* --- Utility --- */
.hidden { display: none !important; }
.fade-in { animation: fadeIn 0.4s ease-out; }

/* ============================================
   PORTRAIT MOBILE OVERRIDE
   Landscape → canvas escalado (ver #tv-canvas). Portrait mobile → reflow en
   columna porque escalar un 16:9 a un viewport 9:16 lo hace ilegible.
   Triggered por body.tv-stacked (setteado desde app.js cuando w/h < 0.75).
   ============================================ */
body.tv-stacked #tv-canvas {
  position: static;
  width: 100%;
  height: auto;
  min-height: 100vh;
  min-height: 100dvh;
  transform: none;
}

body.tv-stacked .screen {
  position: relative;
  width: 100%;
  height: auto;
  min-height: 100vh;
  min-height: 100dvh;
}

body.tv-stacked html,
body.tv-stacked { font-size: 16px; }
body.tv-stacked .safe-zone { padding: 24px 20px; height: auto; }

body.tv-stacked #screen-qr .safe-zone {
  flex-direction: column;
  align-items: center;
  gap: 32px;
}

body.tv-stacked .qr-instructions {
  max-width: 100%;
  width: 100%;
  gap: 16px;
}
body.tv-stacked .qr-instructions .logo { height: 56px; margin-bottom: 16px; }
body.tv-stacked .qr-instructions h1 { font-size: 32px; }
body.tv-stacked .step-card { padding: 8px 0; gap: 14px; }
body.tv-stacked .step-number { width: 40px; height: 40px; font-size: 18px; }
body.tv-stacked .step-text { font-size: 17px; }
body.tv-stacked .step-text strong { font-size: 19px; }
body.tv-stacked .step-text br + span { font-size: 14px !important; }

body.tv-stacked .qr-panel {
  padding-top: 0;
  width: 100%;
  align-items: center;
}
body.tv-stacked .qr-card { padding: 24px; gap: 16px; }
body.tv-stacked #qr-container { width: 260px; height: 260px; padding: 14px; }
body.tv-stacked #qr-container img,
body.tv-stacked #qr-container canvas { width: 232px !important; height: 232px !important; }
body.tv-stacked .status-badge { font-size: 16px; text-align: center; }
body.tv-stacked .app-download-card { display: none; }

/* Player y Complete: también stacked, video ocupa todo el viewport */
body.tv-stacked #screen-player,
body.tv-stacked #screen-complete {
  height: 100vh;
  min-height: 100dvh;
}
body.tv-stacked .player-gradient-top,
body.tv-stacked .player-gradient-bottom { padding: 20px !important; }
body.tv-stacked .player-title { font-size: 18px !important; }
body.tv-stacked .player-time { font-size: 14px !important; }
body.tv-stacked .complete-title { font-size: 44px !important; }
body.tv-stacked .complete-subtitle { font-size: 18px !important; }
