/* NetComTV Tesla rear-screen watch app.
   Dark slate-navy kiosk theme — large touch targets for an in-car touchscreen,
   landscape-first, high contrast for a bright/varied cabin. */

:root {
  --bg:        #0b1220;
  --bg-2:      #0e1626;
  --surface:   #172236;
  --surface-2: #1e2c44;
  --line:      #26344e;
  --ink:       #e9eef7;
  --ink-mute:  #93a4bd;
  --accent:    #3d8bff;
  --accent-2:  #7db4ff;
  --lock:      #f0a23b;
  --live:      #ff4d5e;
  --radius:    16px;
  --gap:       clamp(12px, 1.4vw, 20px);
  --tap:       56px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
img { max-width: 100%; }
button { font-family: inherit; cursor: pointer; }

#app {
  min-height: 100%;
  display: flex; flex-direction: column;
  background:
    radial-gradient(1200px 600px at 12% -10%, #14203a 0%, transparent 60%),
    radial-gradient(1000px 500px at 100% 0%, #101a30 0%, transparent 55%),
    var(--bg);
}

/* ---------- Top bar ---------- */
.topstick {
  position: sticky; top: 0; z-index: 20;
  background: rgba(11, 18, 32, 0.94);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
#topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px;
  padding: clamp(12px, 1.8vw, 20px) clamp(18px, 3vw, 40px) clamp(10px, 1.2vw, 14px);
  padding-top: max(env(safe-area-inset-top), clamp(12px, 1.8vw, 20px));
}

/* Category chips + search */
.chanbar {
  display: flex; align-items: center; gap: 14px;
  padding: 0 clamp(18px, 3vw, 40px) clamp(12px, 1.4vw, 16px);
}
.chips {
  display: flex; gap: 10px; flex: 1; min-width: 0;
  overflow-x: auto; padding-bottom: 2px;
  scrollbar-width: none; -webkit-overflow-scrolling: touch;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto;
  border: 1px solid var(--line); background: var(--surface);
  color: var(--ink-mute); border-radius: 999px;
  min-height: 46px; padding: 0 clamp(16px, 1.8vw, 22px);
  font-size: clamp(14px, 1.4vw, 17px); font-weight: 650; white-space: nowrap;
  transition: transform .08s ease, background .15s ease, color .15s ease, border-color .15s ease;
}
.chip:active { transform: scale(0.95); }
.chip[aria-selected="true"] { background: var(--accent); color: #fff; border-color: var(--accent); }
.chip:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.search {
  flex: 0 0 auto; display: flex; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 999px; height: 46px; padding: 0 14px;
  width: clamp(190px, 22vw, 300px);
  transition: border-color .15s ease;
}
.search:focus-within { border-color: var(--accent); }
.search-ico { color: var(--ink-mute); flex: 0 0 auto; }
#search {
  flex: 1; min-width: 0; background: transparent; border: 0; outline: none;
  color: var(--ink); font-size: 16px; font-family: inherit;
}
#search::placeholder { color: var(--ink-mute); }
#search::-webkit-search-cancel-button { display: none; }
.search-clear {
  flex: 0 0 auto; background: none; border: 0; color: var(--ink-mute);
  font-size: 26px; line-height: 1; width: 30px; height: 30px; border-radius: 8px;
}
.search-clear:active { color: var(--ink); }

@media (max-width: 620px) {
  .chanbar { flex-wrap: wrap; }
  .search { width: 100%; order: -1; }
}
.brand-logo { height: clamp(30px, 3.4vw, 46px); width: auto; display: block; }
.topbar-right { display: flex; align-items: center; gap: 14px; }
.lineup-note { color: var(--ink-mute); font-size: clamp(13px, 1.3vw, 16px); font-weight: 500; }

.btn {
  border: 0; border-radius: 999px;
  min-height: var(--tap); padding: 0 clamp(20px, 2.4vw, 30px);
  font-size: clamp(15px, 1.5vw, 18px); font-weight: 650;
  display: inline-flex; align-items: center; gap: 10px;
  transition: transform .08s ease, background .15s ease, opacity .15s ease;
}
.btn:active { transform: scale(0.97); }
.btn-accent { background: var(--accent); color: #fff; box-shadow: 0 6px 20px rgba(61,139,255,0.35); }
.btn-accent:hover { background: var(--accent-2); }
.btn-ghost { background: var(--surface-2); color: var(--ink); }

.account-chip {
  display: inline-flex; align-items: center; gap: 10px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 999px; min-height: var(--tap); padding: 0 20px;
  font-size: clamp(14px, 1.4vw, 17px); font-weight: 600;
}
.account-chip .dot { width: 10px; height: 10px; border-radius: 50%; background: #35d07f; box-shadow: 0 0 10px #35d07f; }

/* ---------- Channel grid ---------- */
#grid-wrap { flex: 1; padding: clamp(8px, 1.4vw, 18px) clamp(18px, 3vw, 40px) clamp(28px, 4vw, 56px); }
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(clamp(140px, 15vw, 200px), 1fr));
  gap: var(--gap);
}
.tile {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  aspect-ratio: 16 / 10;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 14px;
  overflow: hidden;
  transition: transform .1s ease, border-color .15s ease, background .15s ease;
}
.tile:active { transform: scale(0.96); }
.tile:hover { border-color: #3a4d70; background: var(--surface-2); }
.tile:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.tile-logo {
  max-width: 78%; max-height: 58%; object-fit: contain;
  filter: drop-shadow(0 2px 6px rgba(0,0,0,0.4));
}
.tile-name {
  margin-top: 10px; font-size: clamp(12px, 1.15vw, 15px); font-weight: 600;
  color: var(--ink); text-align: center;
  max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.tile-badge {
  position: absolute; top: 10px; left: 10px;
  font-size: 10px; font-weight: 800; letter-spacing: .08em;
  padding: 4px 8px; border-radius: 6px;
  background: var(--live); color: #fff; text-transform: uppercase;
}
.tile-fallback {
  font-size: clamp(15px, 1.6vw, 20px); font-weight: 700; color: var(--ink);
  text-align: center; padding: 4px; line-height: 1.15;
}
.tile.skeleton { background: var(--surface); animation: pulse 1.4s ease-in-out infinite; border-color: transparent; }
@keyframes pulse { 0%,100%{opacity:.5} 50%{opacity:.85} }

.empty { text-align: center; padding: 12vh 20px; color: var(--ink-mute); }
.empty-title { font-size: 22px; font-weight: 700; color: var(--ink); }
.empty-sub { margin-top: 8px; }

/* ---------- Player ---------- */
.player { position: fixed; inset: 0; z-index: 40; background: #000; }
#video { width: 100%; height: 100%; object-fit: contain; background: #000; }
.player-overlay {
  position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(180deg, rgba(0,0,0,0.55), transparent 22%, transparent 78%, rgba(0,0,0,0.45));
  opacity: 1; transition: opacity .35s ease;
  display: flex; align-items: flex-start; gap: 18px;
  padding: max(env(safe-area-inset-top), 22px) 28px;
}
.player.controls-hidden .player-overlay { opacity: 0; }
.player-back {
  pointer-events: auto;
  display: inline-flex; align-items: center; gap: 8px;
  background: rgba(16,24,40,0.72); color: var(--ink);
  border: 1px solid rgba(255,255,255,0.12); border-radius: 999px;
  min-height: var(--tap); padding: 0 22px 0 14px;
  font-size: 17px; font-weight: 650; backdrop-filter: blur(6px);
}
.player-title {
  color: #fff; font-size: clamp(18px, 2vw, 26px); font-weight: 700;
  align-self: center; text-shadow: 0 2px 12px rgba(0,0,0,0.6);
}
.player-error {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 18px; background: rgba(0,0,0,0.7);
}
.player-error-title { font-size: 22px; font-weight: 700; }

/* Spinner */
.spinner { position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none; }
.ring {
  width: 58px; height: 58px; border-radius: 50%;
  border: 4px solid rgba(255,255,255,0.18); border-top-color: var(--accent);
  animation: spin .9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Pairing modal ---------- */
.modal {
  position: fixed; inset: 0; z-index: 60;
  display: grid; place-items: center; padding: 24px;
  background: rgba(6,10,18,0.78); backdrop-filter: blur(10px);
}
.modal-card {
  position: relative; width: min(760px, 94vw);
  background: linear-gradient(180deg, var(--surface-2), var(--surface));
  border: 1px solid var(--line); border-radius: 24px;
  padding: clamp(24px, 4vw, 44px);
  box-shadow: 0 30px 80px rgba(0,0,0,0.55);
}
.modal-card h2 { margin: 0 0 8px; font-size: clamp(24px, 3vw, 34px); font-weight: 750; }
.modal-lead { margin: 0 0 26px; color: var(--ink-mute); font-size: clamp(15px, 1.6vw, 19px); line-height: 1.5; }
.modal-lead strong { color: var(--accent-2); font-weight: 700; }
.modal-close {
  position: absolute; top: 14px; right: 16px;
  background: none; border: 0; color: var(--ink-mute);
  font-size: 40px; line-height: 1; width: 52px; height: 52px; border-radius: 12px;
}
.modal-close:hover { color: var(--ink); background: rgba(255,255,255,0.06); }
.pair-body { display: flex; gap: clamp(20px, 3vw, 40px); align-items: center; flex-wrap: wrap; }
.pair-qr {
  background: #fff; border-radius: 16px; padding: 14px;
  width: clamp(180px, 22vw, 240px); height: clamp(180px, 22vw, 240px);
  flex: 0 0 auto; display: grid; place-items: center;
}
.pair-qr img { width: 100%; height: 100%; display: block; }
.pair-code-wrap { flex: 1; min-width: 220px; }
.pair-code-label { text-transform: uppercase; letter-spacing: .12em; font-size: 13px; color: var(--ink-mute); font-weight: 700; }
.pair-code {
  font-size: clamp(40px, 6vw, 64px); font-weight: 800; letter-spacing: .08em;
  font-variant-numeric: tabular-nums; margin: 8px 0 16px; color: #fff;
}
.pair-status { color: var(--ink-mute); font-size: 16px; display: flex; align-items: center; gap: 10px; }
.pair-status.ok { color: #35d07f; }
.pair-status::before {
  content: ""; width: 9px; height: 9px; border-radius: 50%;
  background: var(--accent); animation: blink 1.2s ease-in-out infinite;
}
.pair-status.ok::before { background: #35d07f; animation: none; }
@keyframes blink { 0%,100%{opacity:.3} 50%{opacity:1} }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 32px; transform: translateX(-50%);
  z-index: 80; background: var(--surface-2); border: 1px solid var(--line);
  color: var(--ink); padding: 14px 22px; border-radius: 999px;
  font-size: 16px; font-weight: 600; box-shadow: 0 12px 30px rgba(0,0,0,0.4);
}

[hidden] { display: none !important; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}
