/* CyberTV - Universal Smart TV Styles v4.2 */
/* Base: 1920x1080 | Scales: 720p to 8K */
/* --tv-scale and --tv-font-scale set dynamically by tv-core.js */

:root {
  --safe-x: 5vw;
  --safe-y: 5vh;
  --tv-scale: 1;
  --tv-font-scale: 1;
  --tv-base-font: calc(16px * var(--tv-font-scale));
  --color-bg: #0d0d12;
  --color-surface: #16161e;
  --color-surface-2: #1e1e28;
  --color-surface-3: #262633;
  --color-accent: #0ea5e9;
  --color-accent-glow: rgba(14, 165, 233, 0.3);
  --color-accent-2: #f97316;
  --color-text: #f0f0f5;
  --color-text-2: rgba(240, 240, 245, 0.7);
  --color-text-3: rgba(240, 240, 245, 0.4);
  --color-border: rgba(255, 255, 255, 0.08);
  --color-success: #22c55e;
  --color-danger: #ef4444;
  --color-warning: #f59e0b;
  --radius: 0.6vw;
  --radius-lg: 1vw;
  --transition: all 0.15s ease;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html {
  font-size: var(--tv-base-font, 16px);
}

html, body {
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Arial, Helvetica, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  -webkit-font-smoothing: antialiased;
  -webkit-user-select: none;
  user-select: none;
}

body {
  transform-origin: top left;
}

/* ============================================
   SAFE ZONE - Enforced global wrapper
   All page content should be inside .safe-zone
   Prevents TV overscan from clipping content
   ============================================ */
.safe-zone {
  position: absolute;
  top: var(--safe-y);
  left: var(--safe-x);
  right: var(--safe-x);
  bottom: var(--safe-y);
  width: auto;
  height: auto;
}

.safe-zone-flex {
  display: flex;
  flex-direction: column;
  position: absolute;
  top: var(--safe-y);
  left: var(--safe-x);
  right: var(--safe-x);
  bottom: var(--safe-y);
}

.safe-zone-full {
  padding: var(--safe-y) var(--safe-x);
  width: 100%;
  height: 100%;
  box-sizing: border-box;
}

/* Scrollbar Hide */
.no-scrollbar::-webkit-scrollbar { display: none; }
.no-scrollbar { -ms-overflow-style: none; scrollbar-width: none; }

/* ============================================
   FOCUS STATES - Spatial Navigation
   Applies to ALL focusable elements with data-nav
   or .focusable class, or explicit .focused class
   ============================================ */
[data-nav],
.focusable {
  outline: none;
  transition: var(--transition);
  cursor: pointer;
}

[data-nav].focused,
.focusable.focused {
  outline: 0.2vw solid var(--color-accent);
  outline-offset: 0.15vw;
  box-shadow: 0 0 1.5vw var(--color-accent-glow), inset 0 0 0.5vw rgba(14, 165, 233, 0.1);
  transform: scale(1.03);
  z-index: 10;
}

/* ============================================
   BUTTONS
   ============================================ */
.tv-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.6vw;
  padding: 1.2vh 2.5vw;
  font-size: 1.3vw;
  font-weight: 600;
  border: none;
  border-radius: var(--radius);
  background: var(--color-accent);
  color: #fff;
  cursor: pointer;
  white-space: nowrap;
}

.tv-btn.btn-secondary {
  background: var(--color-surface-3);
  color: var(--color-text);
}

.tv-btn.btn-outline {
  background: transparent;
  border: 0.12vw solid var(--color-border);
  color: var(--color-text-2);
}

.tv-btn.btn-danger {
  background: var(--color-danger);
  color: #fff;
}

.tv-btn.btn-success {
  background: var(--color-success);
  color: #fff;
}

.tv-btn.focused {
  outline: 0.2vw solid #fff;
  outline-offset: 0.1vw;
  transform: scale(1.05);
}

/* ============================================
   CARDS
   ============================================ */
.tv-card {
  background: var(--color-surface);
  border: 0.08vw solid var(--color-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  transition: var(--transition);
}

.tv-card.focused {
  border-color: var(--color-accent);
  box-shadow: 0 0 2vw var(--color-accent-glow);
  transform: scale(1.04);
}

/* ============================================
   INPUT FIELDS
   ============================================ */
.tv-input {
  width: 100%;
  padding: 1.3vh 1vw;
  font-size: 1.2vw;
  background: var(--color-surface-2);
  border: 0.1vw solid var(--color-border);
  border-radius: var(--radius);
  color: var(--color-text);
  outline: none;
}

.tv-input.active,
.tv-input.focused {
  border-color: var(--color-accent);
  background: rgba(14, 165, 233, 0.08);
}

.tv-input.completed {
  border-color: var(--color-success);
  background: rgba(34, 197, 94, 0.08);
}

/* ============================================
   HEADER BAR
   ============================================ */
.tv-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 2vw;
  height: 7vh;
  background: var(--color-surface);
  border-bottom: 0.08vw solid var(--color-border);
  flex-shrink: 0;
}

.tv-header .logo {
  height: 4.5vh;
  object-fit: contain;
}

.tv-header-left,
.tv-header-right {
  display: flex;
  align-items: center;
  gap: 1.5vw;
}

.header-icon-btn {
  width: 4vh;
  height: 4vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-surface-2);
  border: 0.08vw solid var(--color-border);
  border-radius: 50%;
  cursor: pointer;
}

.header-icon-btn svg {
  width: 2.2vh;
  height: 2.2vh;
  stroke: var(--color-text-2);
  fill: none;
  stroke-width: 2;
}

.header-icon-btn.focused {
  border-color: var(--color-accent);
  background: var(--color-surface-3);
}
.header-icon-btn.focused svg {
  stroke: var(--color-accent);
}

/* ============================================
   VIRTUAL KEYBOARD
   ============================================ */
.vkb-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0;
  width: 100vw; height: 100vh;
  background: rgba(0, 0, 0, 0.92);
  z-index: 9999;
  align-items: center;
  justify-content: center;
  flex-direction: column;
}
.vkb-overlay.active { display: flex; }

.vkb-input-display {
  width: 40vw;
  padding: 1.5vh 2vw;
  font-size: 1.8vw;
  text-align: center;
  background: var(--color-surface);
  border: 0.15vw solid var(--color-accent);
  border-radius: var(--radius);
  color: var(--color-text);
  margin-bottom: 3vh;
}

.vkb-container {
  background: var(--color-surface);
  padding: 2vh 2vw;
  border-radius: var(--radius-lg);
  border: 0.08vw solid var(--color-border);
}

.vkb-row {
  display: flex;
  justify-content: center;
  gap: 0.4vw;
  margin-bottom: 0.6vh;
}

.vkb-key {
  min-width: 3.8vw;
  height: 4.5vh;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2vw;
  font-weight: 600;
  background: var(--color-surface-3);
  border: 0.08vw solid var(--color-border);
  border-radius: 0.3vw;
  color: var(--color-text);
  cursor: pointer;
}

.vkb-key.special { min-width: 7vw; background: var(--color-surface-2); font-size: 1vw; }
.vkb-key.space { min-width: 18vw; }

.vkb-key.focused {
  background: var(--color-accent);
  color: #000;
  border-color: #fff;
  box-shadow: 0 0 1vw var(--color-accent-glow);
  transform: scale(1.08);
}

/* ============================================
   CATEGORY LIST
   ============================================ */
.cat-list {
  overflow-y: auto;
  height: 100%;
}

.cat-item {
  display: flex;
  align-items: center;
  gap: 0.8vw;
  padding: 1vh 1vw;
  font-size: 1.1vw;
  color: var(--color-text-2);
  border-radius: var(--radius);
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  border: 0.08vw solid transparent;
}

.cat-item.focused {
  background: var(--color-accent);
  color: #fff;
  border-color: transparent;
  transform: none;
  outline: none;
  box-shadow: none;
}

.cat-item.selected {
  background: rgba(14, 165, 233, 0.15);
  color: var(--color-accent);
  border-color: rgba(14, 165, 233, 0.3);
}

/* ============================================
   CONTENT GRID (Movies, Series)
   ============================================ */
.content-grid {
  display: grid;
  gap: 1.2vw;
  padding: 1vh 0;
}

.content-grid.grid-4 { grid-template-columns: repeat(4, 1fr); }
.content-grid.grid-5 { grid-template-columns: repeat(5, 1fr); }
.content-grid.grid-6 { grid-template-columns: repeat(6, 1fr); }

.grid-card {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--color-surface);
  border: 0.1vw solid var(--color-border);
  aspect-ratio: 2/3;
  cursor: pointer;
}

.grid-card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.grid-card .card-info {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 1vh 0.8vw;
  background: linear-gradient(transparent, rgba(0,0,0,0.9));
}

.grid-card .card-title {
  font-size: 0.9vw;
  font-weight: 600;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.grid-card .card-rating {
  font-size: 0.7vw;
  color: var(--color-accent-2);
  margin-top: 0.2vh;
}

.grid-card.focused {
  border-color: var(--color-accent);
  box-shadow: 0 0 2vw var(--color-accent-glow);
  transform: scale(1.06);
  z-index: 5;
}

/* ============================================
   CHANNEL LIST (Live TV)
   ============================================ */
.channel-item {
  display: flex;
  align-items: center;
  gap: 0.8vw;
  padding: 0.8vh 0.8vw;
  border-radius: var(--radius);
  border: 0.08vw solid transparent;
  cursor: pointer;
  overflow: hidden;
}

.channel-item .ch-logo {
  width: 3.5vw;
  height: 3.5vw;
  border-radius: 0.3vw;
  object-fit: contain;
  background: var(--color-surface-3);
  flex-shrink: 0;
}

.channel-item .ch-name {
  font-size: 1vw;
  font-weight: 500;
  color: var(--color-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

.channel-item .ch-number {
  font-size: 0.8vw;
  color: var(--color-text-3);
  width: 2.5vw;
  text-align: right;
  flex-shrink: 0;
}

.channel-item.focused {
  background: var(--color-accent);
  border-color: transparent;
  transform: none;
  outline: none;
  box-shadow: none;
}

.channel-item.focused .ch-name,
.channel-item.focused .ch-number {
  color: #fff;
}

.channel-item.active {
  background: rgba(14, 165, 233, 0.12);
  border-color: rgba(14, 165, 233, 0.3);
}

/* ============================================
   EPG (Electronic Program Guide)
   ============================================ */
.epg-item {
  padding: 0.8vh 1vw;
  border-bottom: 0.05vw solid var(--color-border);
}

.epg-time {
  font-size: 0.85vw;
  color: var(--color-accent);
  font-weight: 600;
}

.epg-title {
  font-size: 0.95vw;
  color: var(--color-text);
  margin-top: 0.2vh;
}

.epg-item.now {
  background: rgba(14, 165, 233, 0.1);
  border-left: 0.2vw solid var(--color-accent);
}

/* ============================================
   VIDEO PREVIEW
   ============================================ */
.video-preview {
  position: relative;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  aspect-ratio: 16/9;
}

.video-preview video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.video-preview .overlay-info {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 1.5vh 1.5vw;
  background: linear-gradient(transparent, rgba(0,0,0,0.85));
}

.video-preview .channel-name-overlay {
  font-size: 1.3vw;
  font-weight: 700;
  color: #fff;
}

.video-preview .live-badge {
  display: inline-block;
  background: var(--color-danger);
  color: #fff;
  font-size: 0.7vw;
  font-weight: 700;
  padding: 0.2vh 0.6vw;
  border-radius: 0.2vw;
  margin-left: 0.5vw;
  vertical-align: middle;
  text-transform: uppercase;
  letter-spacing: 0.05vw;
}

/* ============================================
   LOADING / EMPTY STATES
   ============================================ */
.loading-spinner {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--color-text-3);
  font-size: 1.3vw;
  gap: 1vw;
}

.spinner {
  width: 2vw;
  height: 2vw;
  border: 0.2vw solid var(--color-surface-3);
  border-top-color: var(--color-accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--color-text-3);
  font-size: 1.2vw;
  gap: 1vh;
}

/* ============================================
   MESSAGE POPUP
   ============================================ */
.msg-popup {
  display: none;
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--color-surface);
  border: 0.12vw solid var(--color-accent);
  border-radius: var(--radius-lg);
  padding: 3vh 4vw;
  z-index: 9990;
  text-align: center;
  max-width: 40vw;
  box-shadow: 0 0 5vw rgba(0, 0, 0, 0.8);
}

.msg-popup .msg-text {
  font-size: 1.4vw;
  color: var(--color-text);
  line-height: 1.6;
}

/* ============================================
   STATUS BAR / FOOTER
   ============================================ */
.tv-footer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3vw;
  padding: 0.8vh 2vw;
  background: var(--color-surface);
  border-top: 0.05vw solid var(--color-border);
  font-size: 0.9vw;
  color: var(--color-text-3);
}

.footer-key {
  display: inline-flex;
  align-items: center;
  gap: 0.4vw;
}

.footer-key .key-icon {
  display: inline-block;
  width: 1.8vw;
  height: 2.2vh;
  border-radius: 0.2vw;
  text-align: center;
  line-height: 2.2vh;
  font-size: 0.75vw;
  font-weight: 700;
}

.key-red { background: #e74c3c; color: #fff; }
.key-green { background: #2ecc71; color: #fff; }
.key-yellow { background: #f1c40f; color: #000; }
.key-blue { background: #3498db; color: #fff; }

/* ============================================
   ANIMATIONS
   ============================================ */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

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

.anim-fadeIn { animation: fadeIn 0.4s ease; }
.anim-slideUp { animation: slideUp 0.4s ease; }

/* ============================================
   MEDIA QUERIES (Safe Zone adjustments)
   ============================================ */
@media (max-width: 1280px) {
  :root {
    --safe-x: 3vw;
    --safe-y: 3vh;
  }
}

@media (max-width: 960px) {
  :root {
    --safe-x: 2vw;
    --safe-y: 2vh;
  }
}
