/* ===================================================================
   FLAPPY UNICORN - 10-FOOT TV STYLESHEET
   Optimized for 1080p, 1440p, and 4K displays with Xbox Gamepad Focus
   =================================================================== */

:root {
  --bg-deep: #0e0720;
  --bg-dark: #190e38;
  --bg-card: rgba(32, 16, 68, 0.82);
  --card-border: rgba(255, 175, 235, 0.35);
  --glow-pink: #ff66c4;
  --glow-purple: #a855f7;
  --glow-cyan: #38bdf8;
  --glow-gold: #fbbf24;
  --text-primary: #ffffff;
  --text-secondary: #e2d9f3;
  --text-muted: #a797c4;

  --xbox-a: #107c10;
  --xbox-b: #d83b01;
  --xbox-x: #0078d7;
  --xbox-y: #ffb900;

  --tv-safe-top: 5vh;
  --tv-safe-side: 5vw;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: var(--bg-deep);
  font-family: 'Segoe UI', system-ui, -apple-system, BlinkMacSystemFont, Roboto, sans-serif;
  color: var(--text-primary);
}

/* Ambient fantasy glow behind the game */
.tv-ambient-bg {
  position: fixed;
  inset: 0;
  background: radial-gradient(circle at 50% 30%, #3b185f 0%, #17092c 60%, #080312 100%);
  z-index: 1;
  pointer-events: none;
}

/* 16:9 Viewport Stage Container */
.tv-viewport-container {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
}

.game-stage {
  position: relative;
  width: 100vw;
  height: 56.25vw; /* 16:9 ratio */
  max-height: 100vh;
  max-width: 177.78vh; /* 16:9 ratio */
  box-shadow: 0 0 60px rgba(168, 85, 247, 0.25), 0 20px 50px rgba(0, 0, 0, 0.8);
  border-radius: 8px;
  overflow: hidden;
  background: #000;
}

/* High DPI Game Canvas */
#game-canvas {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
}

/* ===================================================================
   TV HUD OVERLAY (Safe Area Inset)
   =================================================================== */
.tv-hud-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  padding: 32px 48px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  pointer-events: none;
  z-index: 10;
}

.hud-panel {
  background: rgba(22, 11, 46, 0.75);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 2px solid rgba(255, 255, 255, 0.15);
  border-radius: 20px;
  padding: 10px 24px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  gap: 12px;
}

.hearts-panel {
  font-size: 32px;
  gap: 8px;
}

.heart-icon {
  display: inline-block;
  transition: transform 0.2s ease, filter 0.2s ease, opacity 0.2s ease;
  filter: drop-shadow(0 0 8px rgba(255, 105, 180, 0.8));
}

.heart-icon.lost {
  opacity: 0.25;
  filter: grayscale(1) drop-shadow(none);
  transform: scale(0.85);
}

.heart-icon.bounce {
  animation: heartBump 0.3s ease;
}

@keyframes heartBump {
  0% { transform: scale(1); }
  50% { transform: scale(1.4); }
  100% { transform: scale(1); }
}

.mode-badge {
  margin-top: 10px;
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 1.5px;
  color: var(--glow-gold);
  border-color: rgba(251, 191, 36, 0.3);
  padding: 4px 16px;
  border-radius: 12px;
  display: inline-block;
}

/* Huge TV Center Score */
.hud-center {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.score-display-wrapper {
  text-align: center;
}

.current-score {
  font-size: 88px;
  font-weight: 900;
  line-height: 1;
  color: #ffffff;
  text-shadow:
    0 0 20px rgba(255, 102, 196, 0.9),
    0 0 40px rgba(168, 85, 247, 0.8),
    0 4px 8px rgba(0, 0, 0, 0.9);
  letter-spacing: 2px;
}

.score-streak {
  font-size: 20px;
  font-weight: 800;
  letter-spacing: 2px;
  color: #fef08a;
  background: rgba(245, 158, 11, 0.35);
  border: 1px solid rgba(251, 191, 36, 0.6);
  padding: 4px 18px;
  border-radius: 20px;
  margin-top: 6px;
  text-shadow: 0 0 10px rgba(245, 158, 11, 0.8);
  animation: streakPulse 1.5s infinite alternate ease-in-out;
}

@keyframes streakPulse {
  0% { transform: scale(0.96); }
  100% { transform: scale(1.04); }
}

/* Star Gems Panel */
.hud-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 12px;
}

.gem-counter-panel {
  font-size: 26px;
  font-weight: 800;
  color: #fef08a;
  border-color: rgba(251, 191, 36, 0.3);
}

.gem-icon {
  font-size: 30px;
  filter: drop-shadow(0 0 10px #fbbf24);
  animation: spinSlow 6s infinite linear;
}

@keyframes spinSlow {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

.star-power-container {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}

.star-power-bar {
  width: 200px;
  height: 16px;
  background: rgba(0, 0, 0, 0.6);
  border: 2px solid #fff;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 0 15px rgba(255, 105, 180, 0.8);
}

.star-power-fill {
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, #ff007f, #ff7700, #ffdd00, #00ffaa, #00bbff, #b700ff);
  background-size: 200% 100%;
  animation: rainbowScroll 2s linear infinite;
  transition: width 0.1s linear;
}

@keyframes rainbowScroll {
  0% { background-position: 0% 50%; }
  100% { background-position: 200% 50%; }
}

.star-power-label {
  font-size: 15px;
  font-weight: 900;
  letter-spacing: 1.5px;
  color: #fff;
  text-shadow: 0 0 12px #ff007f, 0 0 20px #00ffff;
}

/* ===================================================================
   SCREEN OVERLAYS (Title, Pause, GameOver)
   =================================================================== */
.screen-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(14, 7, 32, 0.75);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  z-index: 20;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.screen-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

/* TITLE SCREEN CARD */
.title-card {
  position: relative;
  background: var(--bg-card);
  border: 3px solid var(--card-border);
  border-radius: 36px;
  padding: 48px 64px;
  text-align: center;
  max-width: 820px;
  width: 90%;
  box-shadow:
    0 25px 70px rgba(0, 0, 0, 0.7),
    0 0 60px rgba(255, 102, 196, 0.25);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
}

.unicorn-hero-badge {
  font-size: 80px;
  line-height: 1;
  animation: floatHover 3s ease-in-out infinite alternate;
  filter: drop-shadow(0 0 30px rgba(255, 102, 196, 0.8));
}

@keyframes floatHover {
  0% { transform: translateY(-8px) scale(0.98); }
  100% { transform: translateY(8px) scale(1.04); }
}

.game-title {
  font-size: 64px;
  font-weight: 900;
  letter-spacing: 3px;
  line-height: 1.05;
  background: linear-gradient(135deg, #ffffff 0%, #ffc6ef 35%, #93c5fd 70%, #fde047 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  text-shadow: 0 0 35px rgba(255, 102, 196, 0.6);
  margin-top: -6px;
}

.game-subtitle {
  font-size: 19px;
  font-weight: 800;
  letter-spacing: 5px;
  color: var(--text-secondary);
  text-shadow: 0 0 10px rgba(168, 85, 247, 0.7);
}

.title-prompt-box {
  margin: 12px 0 6px 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.main-prompt {
  background: linear-gradient(135deg, #a855f7 0%, #ec4899 100%);
  color: #ffffff;
  padding: 18px 48px;
  border-radius: 50px;
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: 26px;
  font-weight: 900;
  letter-spacing: 1.5px;
  box-shadow: 0 0 35px rgba(236, 72, 153, 0.6), 0 10px 25px rgba(0, 0, 0, 0.4);
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.main-prompt:hover, .main-prompt.focused {
  transform: scale(1.05);
  box-shadow: 0 0 50px rgba(236, 72, 153, 0.9), 0 14px 30px rgba(0, 0, 0, 0.5);
}

.touch-prompt-text {
  font-size: 15px;
  color: var(--text-muted);
  font-weight: 600;
}

.mode-select-row {
  display: flex;
  gap: 16px;
  margin-top: 4px;
}

.mode-select-btn {
  background: rgba(255, 255, 255, 0.08);
  border: 2px solid rgba(255, 255, 255, 0.18);
  border-radius: 18px;
  padding: 12px 24px;
  color: var(--text-primary);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.mode-select-btn .mode-name {
  font-size: 17px;
  font-weight: 800;
}

.mode-select-btn small {
  font-size: 12px;
  color: var(--text-muted);
}

.mode-select-btn.active {
  background: rgba(168, 85, 247, 0.25);
  border-color: var(--glow-pink);
  box-shadow: 0 0 25px rgba(255, 102, 196, 0.4);
}

.high-score-banner {
  background: rgba(0, 0, 0, 0.4);
  padding: 10px 24px;
  border-radius: 16px;
  font-size: 17px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.high-score-banner strong {
  color: var(--glow-gold);
  font-size: 20px;
}

.title-bottom-actions {
  display: flex;
  gap: 18px;
  margin-top: 8px;
}

.action-btn-tv {
  background: rgba(255, 255, 255, 0.08);
  border: 2px solid rgba(255, 255, 255, 0.18);
  border-radius: 16px;
  padding: 10px 22px;
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.action-btn-tv:hover, .action-btn-tv.focused {
  background: rgba(255, 255, 255, 0.2);
  border-color: #fff;
  transform: scale(1.05);
}

/* ===================================================================
   MODAL DIALOGS (Pause & Game Over & Leaderboard)
   =================================================================== */
.menu-modal-panel {
  background: var(--bg-card);
  border: 3px solid var(--card-border);
  border-radius: 32px;
  padding: 30px 48px;
  width: 90%;
  max-width: 600px;
  max-height: 88vh;
  overflow-y: auto;
  box-shadow:
    0 25px 80px rgba(0, 0, 0, 0.8),
    0 0 50px rgba(168, 85, 247, 0.3);
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  animation: popIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

/* GAMEOVER MODAL PANEL - TAILORED FOR 16:9 & LANDSCAPE TV DISPLAYS */
.gameover-modal-panel {
  background: var(--bg-card);
  border: 3px solid var(--card-border);
  border-radius: 28px;
  padding: 22px 34px;
  width: 92%;
  max-width: 880px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow:
    0 25px 80px rgba(0, 0, 0, 0.8),
    0 0 60px rgba(168, 85, 247, 0.35);
  display: flex;
  flex-direction: column;
  gap: 16px;
  animation: popIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes popIn {
  0% { transform: scale(0.9); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

.menu-title {
  font-size: 38px;
  font-weight: 900;
  letter-spacing: 2px;
  color: #fff;
  text-shadow: 0 0 20px var(--glow-purple);
}

.menu-desc {
  font-size: 16px;
  color: var(--text-secondary);
  margin-top: -6px;
}

.menu-buttons-list {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* 10-FOOT TV FOCUSABLE BUTTONS */
.tv-menu-btn {
  width: 100%;
  height: 54px;
  background: rgba(255, 255, 255, 0.08);
  border: 2px solid rgba(255, 255, 255, 0.15);
  border-radius: 18px;
  color: var(--text-primary);
  font-size: 20px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  cursor: pointer;
  transition: all 0.18s cubic-bezier(0.16, 1, 0.3, 1);
  position: relative;
}

.tv-menu-btn:hover,
.tv-menu-btn.focused {
  background: linear-gradient(90deg, rgba(168, 85, 247, 0.45), rgba(236, 72, 153, 0.45));
  border-color: #ffffff;
  box-shadow: 0 0 30px rgba(236, 72, 153, 0.75), inset 0 0 15px rgba(255, 255, 255, 0.2);
  transform: scale(1.03);
  color: #ffffff;
}

.tv-menu-btn.btn-primary-action {
  background: linear-gradient(135deg, #9333ea, #db2777);
  border-color: #f472b6;
}

.tv-menu-btn.btn-primary-action:hover,
.tv-menu-btn.btn-primary-action.focused {
  background: linear-gradient(135deg, #a855f7, #ec4899);
  box-shadow: 0 0 35px rgba(236, 72, 153, 0.9);
}

.tv-menu-btn.btn-danger {
  border-color: rgba(239, 68, 68, 0.4);
}

.tv-menu-btn.btn-danger:hover,
.tv-menu-btn.btn-danger.focused {
  background: rgba(239, 68, 68, 0.35);
  border-color: #ef4444;
  box-shadow: 0 0 25px rgba(239, 68, 68, 0.7);
}

.menu-tip-bar {
  font-size: 14px;
  color: var(--text-muted);
  font-weight: 600;
}

/* ===================================================================
   LANDSCAPE GAMEOVER LAYOUT (2-COLUMN GRID)
   =================================================================== */
.gameover-header {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  padding-bottom: 10px;
}

.gameover-title-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.gameover-icon {
  font-size: 34px;
  line-height: 1;
}

.gameover-title {
  font-size: 30px;
  font-weight: 900;
  letter-spacing: 2px;
  color: #fff;
  text-shadow: 0 0 20px rgba(255, 102, 196, 0.8);
}

.gameover-badges-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.new-record-badge {
  font-size: 14px;
  font-weight: 900;
  letter-spacing: 1.5px;
  color: #000;
  background: linear-gradient(90deg, #fef08a, #f59e0b);
  padding: 4px 14px;
  border-radius: 16px;
  box-shadow: 0 0 20px rgba(245, 158, 11, 0.9);
  animation: badgeThrob 1s infinite alternate;
}

@keyframes badgeThrob {
  0% { transform: scale(0.95); }
  100% { transform: scale(1.05); }
}

.gameover-body-grid {
  display: grid;
  grid-template-columns: 1.15fr 1fr;
  gap: 20px;
  width: 100%;
  align-items: stretch;
}

.stats-scoreboard {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
}

.stat-card {
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 16px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
}

.stat-card.primary {
  grid-column: 1 / -1;
  background: rgba(168, 85, 247, 0.22);
  border-color: rgba(244, 114, 182, 0.45);
  padding: 14px 18px;
}

.stat-card .stat-label {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 1.5px;
  color: var(--text-muted);
}

.stat-card .stat-value {
  font-size: 24px;
  font-weight: 900;
  color: #fff;
  line-height: 1.1;
}

.stat-card.primary .stat-value {
  font-size: 52px;
  color: var(--glow-gold);
  text-shadow: 0 0 22px rgba(251, 191, 36, 0.85);
}

.gameover-actions-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  justify-content: center;
}

.gameover-actions-list .tv-menu-btn {
  height: 50px;
  font-size: 18px;
  border-radius: 16px;
}

@media (max-width: 680px), (max-height: 520px) {
  .gameover-header {
    flex-direction: column;
    gap: 8px;
  }
  .gameover-body-grid {
    grid-template-columns: 1fr;
    gap: 14px;
  }
  .stats-scoreboard {
    grid-template-columns: 1fr 1fr;
  }
}

/* ===================================================================
   XBOX CONTROLLER HUD BUTTONS & BADGES
   =================================================================== */
.xbox-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  font-size: 16px;
  font-weight: 900;
  color: #ffffff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.5), inset 0 1px 1px rgba(255, 255, 255, 0.4);
  flex-shrink: 0;
}

.btn-a { background: var(--xbox-a); }
.btn-b { background: var(--xbox-b); }
.btn-x { background: var(--xbox-x); }
.btn-y { background: var(--xbox-y); color: #000; }

.xbox-btn.btn-rb, .xbox-btn.btn-menu {
  width: auto;
  border-radius: 12px;
  padding: 0 8px;
  font-size: 12px;
  background: #374151;
}

/* BOTTOM CONTROLLER TV LEGEND BAR */
.tv-controller-hud-bar {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 58px;
  background: rgba(14, 7, 32, 0.9);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  padding: 0 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 15;
  font-size: 15px;
  font-weight: 700;
  color: var(--text-secondary);
}

.legend-group {
  display: flex;
  align-items: center;
  gap: 24px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
}

.legend-item .xbox-btn {
  width: 24px;
  height: 24px;
  font-size: 12px;
}

.controller-status-box {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  color: var(--text-muted);
}

.status-indicator {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #64748b;
  transition: all 0.3s ease;
}

.status-indicator.connected {
  background: #22c55e;
  box-shadow: 0 0 10px #22c55e;
}

/* ===================================================================
   LEADERBOARD MODAL & TV HALL OF FAME
   =================================================================== */
.leaderboard-modal-panel {
  max-width: 780px !important;
  padding: 36px 44px !important;
}

.leaderboard-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.leaderboard-table-container {
  width: 100%;
  max-height: 420px;
  overflow-y: auto;
  border-radius: 20px;
  background: rgba(0, 0, 0, 0.45);
  border: 1px solid rgba(255, 255, 255, 0.14);
  margin-top: 10px;
}

.tv-leaderboard-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 19px;
}

.tv-leaderboard-table th {
  background: rgba(255, 255, 255, 0.08);
  padding: 14px 20px;
  font-weight: 800;
  letter-spacing: 1.5px;
  color: var(--glow-gold);
  border-bottom: 2px solid rgba(255, 255, 255, 0.15);
  font-size: 14px;
}

.tv-leaderboard-table td {
  padding: 14px 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  color: #ffffff;
  font-weight: 700;
}

.tv-leaderboard-table tr:nth-child(1) td {
  color: #fde047;
  font-weight: 900;
  background: rgba(251, 191, 36, 0.08);
}
.tv-leaderboard-table tr:nth-child(2) td {
  color: #f1f5f9;
  background: rgba(255, 255, 255, 0.04);
}
.tv-leaderboard-table tr:nth-child(3) td {
  color: #fdba74;
  background: rgba(251, 146, 60, 0.04);
}

.rank-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  font-weight: 900;
  font-size: 15px;
}

.rank-pill.rank-1 {
  background: #eab308;
  color: #000;
  box-shadow: 0 0 14px rgba(234, 179, 8, 0.9);
}
.rank-pill.rank-2 {
  background: #94a3b8;
  color: #000;
}
.rank-pill.rank-3 {
  background: #d97706;
  color: #fff;
}

.backend-rank-badge {
  font-size: 16px;
  font-weight: 800;
  color: var(--glow-cyan);
  background: rgba(2, 132, 199, 0.25);
  border: 1px solid rgba(56, 189, 248, 0.4);
  padding: 4px 18px;
  border-radius: 20px;
  margin-top: 4px;
}
