/* ============================================================
   Rafeeq TV — app.css
   Three layouts: TV (html.tv), Desktop (>900px), Phone (<=900px)
   ES2016 / Chromium 63 / Tizen 5 compatible:
   - grid-gap not gap
   - No flex gap (use margin instead)
   ============================================================ */

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

:root {
  --bg: #0d0d14;
  --surface: #161622;
  --surface2: #1e1e2e;
  --border: #2a2a3e;
  --accent: #e63946;
  --accent2: #457b9d;
  --text: #e8e8f0;
  --text2: #9090a8;
  --gold: #f4a261;
  --green: #2a9d8f;
  --red: #e63946;
  --radius: 8px;
  --sidebar-w: 200px;
  --cat-w: 180px;
  --epg-w: 320px;
  --bottom-nav-h: 60px;
}

html, body {
  width: 100%;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 1rem;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

a { color: var(--accent2); text-decoration: none; }
a:hover { text-decoration: underline; }

button { cursor: pointer; border: none; background: none; color: inherit; font: inherit; }
input, select, textarea { font: inherit; color: inherit; background: var(--surface2); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 14px; width: 100%; outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--accent2); box-shadow: 0 0 0 2px rgba(69,123,157,0.25); }
input[type="checkbox"] { width: auto; cursor: pointer; }
select { appearance: none; -webkit-appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M0 0l6 8 6-8z' fill='%239090a8'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 36px; }

h1, h2, h3 { font-weight: 700; line-height: 1.2; }
h2 { font-size: 1.4rem; margin-bottom: 16px; }
h3 { font-size: 1rem; margin-bottom: 12px; color: var(--text2); text-transform: uppercase; letter-spacing: 0.05em; }

/* ---- Scrollbars ---- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text2); }

/* ---- Focus ring ---- */
.focusable:focus, .focusable.focused,
.cat-item:focus, .cat-item.focused,
.ch-row:focus, .ch-row.focused {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  box-shadow: 0 0 0 4px rgba(230,57,70,0.18);
}

/* ============================================================
   LAYOUT — Desktop (default, >900px)
   ============================================================ */

#app {
  display: -webkit-flex;
  display: flex;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
}

/* Sidebar nav */
#sidenav {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  height: 100%;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: -webkit-flex;
  display: flex;
  -webkit-flex-direction: column;
  flex-direction: column;
  padding-top: 0;
  overflow-y: auto;
  overflow-x: hidden;
  z-index: 10;
  flex-shrink: 0;
}

.nav-brand {
  padding: 20px 16px 16px;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--accent);
  border-bottom: 1px solid var(--border);
  letter-spacing: 0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nav-btn {
  display: -webkit-flex;
  display: flex;
  -webkit-align-items: center;
  align-items: center;
  padding: 12px 16px;
  width: 100%;
  font-size: 0.95rem;
  color: var(--text2);
  border-radius: 0;
  transition: background 0.15s, color 0.15s;
  border-left: 3px solid transparent;
  text-align: left;
}

.nav-btn:hover { background: var(--surface2); color: var(--text); }
.nav-btn.active { color: var(--accent); font-weight: 600; border-left-color: var(--accent); background: rgba(230,57,70,0.08); }
.nav-btn:focus, .nav-btn.focused { outline: 2px solid var(--accent); outline-offset: -2px; box-shadow: 0 0 0 4px rgba(230,57,70,0.18); }

.nav-icon { font-size: 1.1rem; margin-right: 10px; flex-shrink: 0; }
.nav-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav-spacer { flex: 1; }
.nav-account { padding: 12px 16px; font-size: 0.8rem; color: var(--text2); border-top: 1px solid var(--border); word-break: break-all; }

/* Bottom nav (phone only — hidden on desktop+TV) */
#bottomnav { display: none; }

/* Main content area */
#main {
  flex: 1;
  display: -webkit-flex;
  display: flex;
  -webkit-flex-direction: column;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
  min-width: 0;
}

/* ---- Screens ---- */
.screen {
  flex: 1;
  display: -webkit-flex;
  display: flex;
  height: 100%;
  overflow: hidden;
  min-width: 0;
}

/* --- LIVE SCREEN --- */
#screen-live {
  -webkit-flex-direction: row;
  flex-direction: row;
}

/* Cat panel */
#cat-panel {
  width: var(--cat-w);
  min-width: var(--cat-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  overflow-x: hidden;
  flex-shrink: 0;
  padding: 8px 0;
}

.cat-item {
  padding: 10px 16px;
  cursor: pointer;
  border-radius: var(--radius);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 0.9rem;
  color: var(--text2);
  transition: background 0.1s, color 0.1s;
  border-left: 3px solid transparent;
  margin: 1px 4px;
}
.cat-item:hover, .cat-item.focused { background: var(--surface2); color: var(--text); }
.cat-item.active { color: var(--accent); font-weight: 600; border-left-color: var(--accent); background: rgba(230,57,70,0.07); }
.cat-item._separator { color: var(--border); font-size: 0.75rem; cursor: default; padding-top: 12px; padding-bottom: 4px; pointer-events: none; }

/* Channel panel */
#channel-panel {
  flex: 1;
  display: -webkit-flex;
  display: flex;
  -webkit-flex-direction: column;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}

#channel-header {
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: -webkit-flex;
  display: flex;
  -webkit-align-items: center;
  align-items: center;
  flex-shrink: 0;
}

#cat-title {
  font-size: 1rem;
  font-weight: 700;
  margin-right: 10px;
}

#channel-count {
  font-size: 0.8rem;
  color: var(--text2);
}

#channel-list-wrap {
  flex: 1;
  position: relative;
  overflow-y: auto;
  overflow-x: hidden;
}

#channel-list {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
}

#channel-list-spacer {
  width: 100%;
  pointer-events: none;
}

/* Channel rows */
.ch-row {
  display: -webkit-flex;
  display: flex;
  -webkit-align-items: center;
  align-items: center;
  padding: 8px 12px;
  height: 64px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background 0.1s;
  border-left: 3px solid transparent;
  position: relative;
}
.ch-row:hover, .ch-row.focused { background: var(--surface2); }
.ch-row.playing { border-left-color: var(--accent); background: rgba(230,57,70,0.07); }
.ch-row:active { background: rgba(230,57,70,0.12); }

.ch-logo {
  width: 40px;
  height: 40px;
  border-radius: 4px;
  object-fit: contain;
  background: var(--surface2);
  margin-right: 12px;
  flex-shrink: 0;
}

.ch-num {
  width: 32px;
  font-size: 0.75rem;
  color: var(--text2);
  text-align: right;
  margin-right: 8px;
  flex-shrink: 0;
}

.ch-info {
  flex: 1;
  overflow: hidden;
  min-width: 0;
}

.ch-name {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 0.95rem;
}

.ch-epg {
  font-size: 0.75rem;
  color: var(--text2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
  display: block;
}

.ch-epg-bar {
  height: 2px;
  background: var(--border);
  border-radius: 1px;
  margin-top: 4px;
}

.ch-epg-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 1px;
  transition: width 0.3s;
}

.ch-fav {
  font-size: 0.85rem;
  margin-left: 8px;
  opacity: 0.4;
  color: var(--gold);
  flex-shrink: 0;
  transition: opacity 0.15s;
}
.ch-fav.on { opacity: 1; }
.ch-row:hover .ch-fav { opacity: 0.7; }

.ch-badge {
  font-size: 0.65rem;
  padding: 2px 5px;
  border-radius: 3px;
  margin-left: 6px;
  vertical-align: middle;
  display: inline-block;
}
.ch-badge.unverified { background: #3a3a0a; color: #c8b400; }
.ch-badge.dead { background: #3a0a0a; color: #c84040; }
.ch-badge.geo { background: #0a1a3a; color: #4080c8; }

/* EPG Panel */
#epg-panel {
  width: var(--epg-w);
  min-width: var(--epg-w);
  background: var(--surface);
  border-left: 1px solid var(--border);
  padding: 20px 16px;
  overflow-y: auto;
  flex-shrink: 0;
}

#epg-logo-wrap {
  margin-bottom: 12px;
  height: 60px;
  display: -webkit-flex;
  display: flex;
  -webkit-align-items: center;
  align-items: center;
}

#epg-logo {
  max-width: 100%;
  max-height: 60px;
  object-fit: contain;
  border-radius: 4px;
}

#epg-ch-name {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 16px;
  color: var(--text);
}

.epg-label {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
  margin-bottom: 4px;
}

#epg-now-block {
  background: var(--surface2);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 10px;
  border: 1px solid var(--border);
}

#epg-now-title {
  font-size: 0.95rem;
  font-weight: 600;
  margin-bottom: 4px;
}

#epg-now-time {
  font-size: 0.78rem;
  color: var(--text2);
  margin-bottom: 8px;
}

#epg-now-bar {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
}

#epg-now-progress {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.5s;
}

#epg-next-block {
  background: rgba(255,255,255,0.03);
  border-radius: var(--radius);
  padding: 12px;
  border: 1px solid var(--border);
  margin-bottom: 12px;
}

#epg-next-title {
  font-size: 0.88rem;
  margin-bottom: 4px;
}

#epg-next-time {
  font-size: 0.75rem;
  color: var(--text2);
}

#epg-health {
  font-size: 0.82rem;
  font-weight: 600;
  margin-top: 8px;
}

/* ---- Favorites & Search ---- */
#screen-favorites, #screen-search {
  -webkit-flex-direction: column;
  flex-direction: column;
  padding: 0;
}

.screen-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

#search-bar {
  padding: 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--surface);
}

#search-input {
  font-size: 1rem;
  background: var(--surface2);
}

.channel-grid {
  flex: 1;
  overflow-y: auto;
}

.empty-state {
  padding: 48px 24px;
  text-align: center;
  color: var(--text2);
  font-size: 0.95rem;
}

/* ---- Settings screen ---- */
#screen-settings {
  -webkit-flex-direction: column;
  flex-direction: column;
  overflow-y: auto;
}

.settings-wrap {
  max-width: 640px;
  padding: 24px 24px 48px;
  width: 100%;
}

.settings-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}

.settings-section h3 { margin-bottom: 14px; }

.setting-row {
  display: -webkit-flex;
  display: flex;
  -webkit-align-items: center;
  align-items: center;
  -webkit-justify-content: space-between;
  justify-content: space-between;
  padding: 10px 0;
  font-size: 0.95rem;
  cursor: pointer;
}

.setting-row span { flex: 1; }
.setting-row input[type="checkbox"] { margin-left: 16px; width: 18px; height: 18px; }
.setting-row select { max-width: 180px; }

.setting-note {
  font-size: 0.8rem;
  color: var(--text2);
  margin-top: 8px;
  line-height: 1.5;
}

.setting-input {
  margin-bottom: 10px;
}

#settings-account-info {
  font-size: 0.88rem;
  color: var(--text2);
  margin-bottom: 12px;
  line-height: 1.6;
}

#settings-source-info {
  font-size: 0.88rem;
  color: var(--text2);
  margin-bottom: 12px;
}

/* Tab row in source form */
.tab-row {
  display: -webkit-flex;
  display: flex;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 14px;
}

.tab-btn {
  flex: 1;
  padding: 10px;
  font-size: 0.88rem;
  color: var(--text2);
  background: var(--surface2);
  border-right: 1px solid var(--border);
  transition: background 0.15s, color 0.15s;
}
.tab-btn:last-child { border-right: none; }
.tab-btn.active { background: var(--accent); color: #fff; font-weight: 600; }
.tab-btn:hover:not(.active) { background: var(--border); color: var(--text); }

/* Buttons */
.btn-primary {
  display: inline-block;
  padding: 10px 20px;
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius);
  font-weight: 600;
  font-size: 0.95rem;
  transition: background 0.15s, transform 0.1s;
  margin-top: 8px;
  margin-right: 8px;
}
.btn-primary:hover { background: #c0242f; }
.btn-primary:active { transform: scale(0.97); }
.btn-primary:focus, .btn-primary.focused { outline: 2px solid var(--accent); outline-offset: 2px; box-shadow: 0 0 0 4px rgba(230,57,70,0.25); }

.btn-ghost {
  display: inline-block;
  padding: 10px 20px;
  background: transparent;
  color: var(--text2);
  border-radius: var(--radius);
  font-size: 0.95rem;
  border: 1px solid var(--border);
  transition: background 0.15s, color 0.15s;
  margin-top: 8px;
  margin-right: 8px;
}
.btn-ghost:hover { background: var(--surface2); color: var(--text); }
.btn-ghost:focus, .btn-ghost.focused { outline: 2px solid var(--accent2); outline-offset: 2px; box-shadow: 0 0 0 4px rgba(69,123,157,0.2); }

.err-text {
  color: var(--red);
  font-size: 0.85rem;
  margin-top: 8px;
}

/* ============================================================
   PLAYER OVERLAY
   ============================================================ */

#player-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: #000;
  z-index: 100;
}

#player-video {
  width: 100%;
  height: 100%;
  display: block;
  background: #000;
  object-fit: contain;
}

#avplay-wrap {
  position: absolute;
  top: 0; left: 0;
  width: 100%;
  height: 100%;
}

#avplay-obj {
  width: 100%;
  height: 100%;
  display: block;
}

#player-yt {
  position: absolute;
  top: 0; left: 0;
  width: 100%;
  height: 100%;
  border: none;
  background: #000;
}

/* Info bar */
#player-info {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  background: linear-gradient(transparent, rgba(0,0,0,0.85));
  padding: 48px 24px 24px;
  display: -webkit-flex;
  display: flex;
  -webkit-align-items: flex-end;
  align-items: flex-end;
  transition: opacity 0.3s;
  z-index: 10;
}
#player-info.hidden { opacity: 0; pointer-events: none; }

#info-left { flex: 1; }
#info-ch-num { font-size: 1.2rem; color: var(--text2); margin-bottom: 4px; }
#info-ch-name { font-size: 1.8rem; font-weight: 700; text-shadow: 0 2px 4px rgba(0,0,0,0.6); }

#info-epg {
  flex: 1;
  padding: 0 20px;
  font-size: 0.9rem;
}
#info-now { margin-bottom: 6px; }
#info-next { color: var(--text2); }

.epg-tag {
  font-size: 0.65rem;
  font-weight: 700;
  background: var(--accent);
  color: #fff;
  padding: 2px 6px;
  border-radius: 3px;
  margin-right: 8px;
  vertical-align: middle;
}

#info-right {
  display: -webkit-flex;
  display: flex;
  -webkit-flex-direction: column;
  flex-direction: column;
  -webkit-align-items: flex-end;
  align-items: flex-end;
}

#info-time {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 10px;
  letter-spacing: 0.03em;
}

#info-controls {
  display: -webkit-flex;
  display: flex;
}

.ctrl-btn {
  width: 44px;
  height: 44px;
  background: rgba(255,255,255,0.1);
  border-radius: var(--radius);
  font-size: 1.1rem;
  display: -webkit-flex;
  display: flex;
  -webkit-align-items: center;
  align-items: center;
  -webkit-justify-content: center;
  justify-content: center;
  transition: background 0.15s;
  margin-left: 8px;
}
.ctrl-btn:hover { background: rgba(255,255,255,0.2); }
.ctrl-btn:focus, .ctrl-btn.focused { outline: 2px solid var(--accent); box-shadow: 0 0 0 3px rgba(230,57,70,0.3); }
.ctrl-btn.on { color: var(--gold); }

/* Number entry */
#num-entry {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(0,0,0,0.8);
  border-radius: 12px;
  padding: 24px 40px;
  text-align: center;
  z-index: 20;
}

#num-digits {
  font-size: 3rem;
  font-weight: 700;
  letter-spacing: 0.15em;
  color: #fff;
}

/* Spinner */
#player-spinner {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 48px;
  height: 48px;
  border: 4px solid rgba(255,255,255,0.2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  z-index: 15;
}

@keyframes spin {
  to { transform: translate(-50%, -50%) rotate(360deg); }
}

/* Player error */
#player-error {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px 40px;
  text-align: center;
  z-index: 20;
  max-width: 400px;
  width: 90%;
}

#player-error-msg {
  font-size: 1rem;
  color: var(--text2);
  margin-bottom: 16px;
}

/* Player channel list sidebar */
#player-ch-list {
  position: absolute;
  top: 0; left: 0;
  width: 300px;
  height: 100%;
  background: rgba(13,13,20,0.95);
  border-right: 1px solid var(--border);
  z-index: 20;
  overflow: hidden;
  backdrop-filter: blur(8px);
}

#player-ch-list-inner {
  height: 100%;
  overflow-y: auto;
  padding: 8px 0;
}

/* ============================================================
   TOAST
   ============================================================ */

#toast {
  position: fixed;
  top: 24px;
  right: 24px;
  z-index: 999;
  background: var(--surface2);
  color: var(--text);
  padding: 12px 20px;
  border-radius: var(--radius);
  font-size: 0.9rem;
  box-shadow: 0 4px 24px rgba(0,0,0,0.5);
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
  border: 1px solid var(--border);
  max-width: 300px;
}
#toast.show { opacity: 1; }

/* ============================================================
   MODAL
   ============================================================ */

#login-modal {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  z-index: 200;
  display: -webkit-flex;
  display: flex;
  -webkit-align-items: center;
  align-items: center;
  -webkit-justify-content: center;
  justify-content: center;
}

.modal-backdrop {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(4px);
}

.modal-card {
  position: relative;
  background: var(--surface);
  padding: 36px 32px;
  border-radius: 12px;
  width: 340px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
  border: 1px solid var(--border);
}

.modal-card h2 { margin-bottom: 6px; }
.modal-card .sub { color: var(--text2); font-size: 0.9rem; margin-bottom: 20px; }
.modal-card input { margin-bottom: 12px; }
.modal-card .err-text { margin-top: 8px; }

/* ============================================================
   TV LAYOUT — html.tv class, fixed 1920×1080
   ============================================================ */

html.tv {
  font-size: 1.1rem;
}

html.tv body {
  overflow: hidden;
}

html.tv #app {
  width: 1920px;
  height: 1080px;
  position: fixed;
  top: 0;
  left: 0;
}

html.tv #sidenav {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
}

html.tv .nav-btn {
  padding: 16px 18px;
  font-size: 1rem;
}

html.tv .nav-brand {
  padding: 24px 18px 18px;
  font-size: 1.2rem;
}

html.tv #cat-panel {
  width: var(--cat-w);
  min-width: var(--cat-w);
}

html.tv .cat-item {
  padding: 13px 18px;
  font-size: 1rem;
}

html.tv #epg-panel {
  width: var(--epg-w);
  min-width: var(--epg-w);
}

html.tv #epg-ch-name {
  font-size: 1.3rem;
}

html.tv #epg-now-title {
  font-size: 1.05rem;
}

html.tv .ch-row {
  height: 70px;
  padding: 10px 16px;
}

html.tv .ch-logo {
  width: 48px;
  height: 48px;
}

html.tv .ch-name {
  font-size: 1.05rem;
}

html.tv .ch-num {
  width: 40px;
  font-size: 0.85rem;
}

html.tv .focusable:focus,
html.tv .focusable.focused,
html.tv .cat-item:focus,
html.tv .cat-item.focused,
html.tv .ch-row:focus,
html.tv .ch-row.focused {
  outline: 3px solid var(--accent);
  outline-offset: -3px;
  box-shadow: 0 0 0 6px rgba(230,57,70,0.25);
}

html.tv #player-info {
  padding: 64px 48px 40px;
}

html.tv #info-ch-name {
  font-size: 2.2rem;
}

html.tv #info-time {
  font-size: 2rem;
}

html.tv .ctrl-btn {
  width: 56px;
  height: 56px;
  font-size: 1.3rem;
}

html.tv #num-digits {
  font-size: 4rem;
}

html.tv #player-spinner {
  width: 60px;
  height: 60px;
  border-width: 5px;
}

html.tv .btn-primary,
html.tv .btn-ghost {
  padding: 14px 28px;
  font-size: 1.05rem;
}

html.tv #bottomnav { display: none; }

/* ============================================================
   PHONE LAYOUT — max-width: 900px
   ============================================================ */

@media (max-width: 900px) {
  html, body {
    overflow: hidden;
  }

  #app {
    -webkit-flex-direction: column;
    flex-direction: column;
    height: 100vh;
    height: -webkit-fill-available;
  }

  /* Hide sidebar on phone */
  #sidenav { display: none; }

  /* Show bottom nav */
  #bottomnav {
    display: -webkit-flex;
    display: flex;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    height: var(--bottom-nav-h);
    background: var(--surface);
    border-top: 1px solid var(--border);
    z-index: 50;
    -webkit-align-items: stretch;
    align-items: stretch;
  }

  .bnav-btn {
    flex: 1;
    display: -webkit-flex;
    display: flex;
    -webkit-flex-direction: column;
    flex-direction: column;
    -webkit-align-items: center;
    align-items: center;
    -webkit-justify-content: center;
    justify-content: center;
    font-size: 1.2rem;
    color: var(--text2);
    transition: color 0.15s, background 0.15s;
    padding: 4px 0;
    border-top: 3px solid transparent;
  }

  .bnav-btn span {
    font-size: 0.65rem;
    margin-top: 2px;
    display: block;
  }

  .bnav-btn.active {
    color: var(--accent);
    border-top-color: var(--accent);
  }

  .bnav-btn:hover { color: var(--text); background: var(--surface2); }

  /* Main fills remaining height above bottom nav */
  #main {
    height: calc(100vh - var(--bottom-nav-h));
    height: calc(-webkit-fill-available - var(--bottom-nav-h));
    padding-bottom: 0;
  }

  /* Live screen: vertical layout */
  #screen-live {
    -webkit-flex-direction: column;
    flex-direction: column;
  }

  /* Cat panel: horizontal scroll strip */
  #cat-panel {
    width: 100%;
    min-width: 0;
    height: auto;
    min-height: 0;
    border-right: none;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
    padding: 0;
    overflow-y: hidden;
    overflow-x: auto;
    flex-shrink: 0;
    white-space: nowrap;
    display: block;
  }

  #cat-list {
    display: -webkit-inline-flex;
    display: inline-flex;
    padding: 6px 8px;
  }

  .cat-item {
    display: inline-block;
    border-radius: 20px;
    padding: 6px 14px;
    margin: 0 3px;
    font-size: 0.85rem;
    border-left: none;
    border: 1px solid var(--border);
  }
  .cat-item.active {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
  }
  .cat-item._separator { display: none; }

  /* Channel panel: full width */
  #channel-panel { flex: 1; min-height: 0; }

  /* EPG panel: hidden on phone */
  #epg-panel { display: none; }

  /* Channel header small */
  #channel-header { padding: 8px 12px; }

  /* Smaller rows on phone */
  .ch-row { height: 56px; padding: 6px 10px; }
  .ch-logo { width: 36px; height: 36px; margin-right: 10px; }
  .ch-num { width: 24px; font-size: 0.7rem; margin-right: 6px; }
  .ch-name { font-size: 0.9rem; }

  /* Settings: full width */
  .settings-wrap { padding: 16px 16px 80px; }

  /* Modal: full width on small screens */
  .modal-card { width: calc(100vw - 32px); padding: 28px 20px; }

  /* Player: full screen, portrait-friendly */
  #player-info {
    padding: 24px 16px 16px;
    -webkit-flex-direction: column;
    flex-direction: column;
    -webkit-align-items: flex-start;
    align-items: flex-start;
  }

  #info-left { margin-bottom: 8px; }
  #info-ch-name { font-size: 1.3rem; }
  #info-ch-num { font-size: 0.9rem; }

  #info-epg { padding: 0; margin-bottom: 10px; font-size: 0.82rem; }
  #info-right { width: 100%; -webkit-flex-direction: row; flex-direction: row; -webkit-align-items: center; align-items: center; -webkit-justify-content: space-between; justify-content: space-between; }
  #info-time { font-size: 1.1rem; margin-bottom: 0; }
  #info-controls { margin-left: 0; }
  .ctrl-btn { width: 38px; height: 38px; font-size: 1rem; margin-left: 6px; }

  /* Toast: top center on mobile */
  #toast {
    top: 12px;
    right: 12px;
    left: 12px;
    text-align: center;
    max-width: none;
  }

  /* Player sidebar narrower */
  #player-ch-list { width: 240px; }

  /* Search and favorites: full screen layout */
  #screen-favorites, #screen-search {
    padding-bottom: 0;
  }

  /* Settings screen scroll */
  #screen-settings { overflow-y: auto; }
}

/* ============================================================
   Utility
   ============================================================ */

[hidden] { display: none !important; }

.text-accent { color: var(--accent); }
.text-accent2 { color: var(--accent2); }
.text-muted { color: var(--text2); }
.text-gold { color: var(--gold); }

/* Loading skeleton shimmer */
@keyframes shimmer {
  0% { background-position: -400px 0; }
  100% { background-position: 400px 0; }
}

.skeleton {
  background: linear-gradient(90deg, var(--surface2) 25%, var(--border) 50%, var(--surface2) 75%);
  background-size: 800px 100%;
  animation: shimmer 1.5s infinite;
  border-radius: 4px;
}

/* Scrollbar on cat panel (horizontal) */
#cat-panel::-webkit-scrollbar { height: 3px; }
#cat-panel::-webkit-scrollbar-thumb { background: var(--border); }

/* Ensure player video covers correctly on TV */
html.tv #player-video { object-fit: contain; width: 1920px; height: 1080px; }

/* Responsive: medium screens — hide EPG panel */
@media (max-width: 1200px) and (min-width: 901px) {
  :root { --epg-w: 240px; }
}

@media (max-width: 1050px) and (min-width: 901px) {
  #epg-panel { display: none; }
  :root { --cat-w: 150px; }
}
