:root {
  --bg: #000;
  --panel: rgba(12, 14, 20, 0.97);
  --text: #f2f4f8;
  --muted: #9aa3b2;
  --accent: #3fa9f5;
  --focus-bg: rgba(63, 169, 245, 0.22);
  /* One design unit = 1px on a 1920-wide TV; scales down for laptops and phones
     (landscape and portrait alike), never below a comfortable touch size. */
  --u: clamp(0.55px, calc(100vmax / 1920), 1.4px);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, "Segoe UI", Arial, sans-serif;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
}

button { font: inherit; color: inherit; cursor: pointer; }

#player {
  position: fixed;
  top: 0; right: 0; bottom: 0; left: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
}

.hidden { display: none !important; }

/* Channel banner (top) */
#banner {
  position: fixed;
  top: calc(48 * var(--u) + var(--safe-t));
  right: calc(64 * var(--u) + var(--safe-r));   /* page is RTL */
  max-width: calc(100vw - 128 * var(--u));
  display: flex;
  align-items: center;
  gap: calc(24 * var(--u));
  padding: calc(20 * var(--u)) calc(36 * var(--u));
  background: var(--panel);
  border-radius: calc(16 * var(--u));
  font-size: calc(40 * var(--u));
  font-weight: 600;
  pointer-events: none;
}
#banner-num { color: var(--accent); font-variant-numeric: tabular-nums; }
#banner-logo { height: calc(64 * var(--u)); max-width: calc(160 * var(--u)); object-fit: contain; }
#banner-logo[src=""] { display: none; }
#banner-name { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }

/* Status / errors (center) */
#status {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  max-width: 90vw;
  padding: calc(24 * var(--u)) calc(40 * var(--u));
  background: var(--panel);
  border-radius: calc(16 * var(--u));
  font-size: calc(34 * var(--u));
  text-align: center;
  pointer-events: none;   /* taps go through to the video */
}

/* Channel guide (side panel) */
#guide {
  position: fixed;
  top: 0;
  bottom: 0;
  right: 0;   /* page is RTL */
  width: min(calc(620 * var(--u)), 90vw);
  padding: calc(40 * var(--u) + var(--safe-t)) calc(32 * var(--u)) calc(28 * var(--u) + var(--safe-b));
  padding-inline-start: calc(32 * var(--u) + var(--safe-r));
  background: var(--panel);
  display: flex;
  flex-direction: column;
  z-index: 5;
}
.guide-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: calc(20 * var(--u));
  padding-inline: calc(16 * var(--u));
}
#guide h1 { font-size: calc(44 * var(--u)); }
#guide-close {
  width: calc(64 * var(--u));
  height: calc(64 * var(--u));
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.08);
  font-size: calc(30 * var(--u));
}
#channel-list {
  list-style: none;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  scrollbar-width: none;
}
#channel-list::-webkit-scrollbar { display: none; }
#channel-list li {
  display: flex;
  align-items: center;
  gap: calc(20 * var(--u));
  height: calc(88 * var(--u));
  padding: 0 calc(20 * var(--u));
  border-radius: calc(12 * var(--u));
  font-size: calc(34 * var(--u));
  border: calc(3 * var(--u)) solid transparent;
  cursor: pointer;
}
#channel-list li .num {
  width: calc(64 * var(--u));
  flex: none;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
#channel-list li img { height: calc(52 * var(--u)); width: calc(92 * var(--u)); object-fit: contain; flex: none; }
#channel-list li.playing .name::after { content: "  ●"; color: #e5484d; font-size: 0.7em; }
#channel-list li.focused {
  background: var(--focus-bg);
  border-color: var(--accent);
}
#channel-list li .name { flex: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
#channel-list li .pick {
  width: calc(48 * var(--u));
  height: calc(48 * var(--u));
  flex: none;
  border-radius: 50%;
  border: calc(3 * var(--u)) solid var(--muted);
  font-size: calc(24 * var(--u));
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}
#channel-list li .pick.on { background: var(--accent); border-color: var(--accent); color: #fff; }
#channel-list li.split-row { border-bottom: 2px solid rgba(255,255,255,0.12); border-radius: calc(12 * var(--u)) calc(12 * var(--u)) 0 0; }
#channel-list li.split-row .num { color: var(--accent); }

.hint { margin-top: calc(16 * var(--u)); padding-inline: calc(16 * var(--u)); color: var(--muted); font-size: calc(26 * var(--u)); }
.hint-touch { display: none; }

/* Split screen */
#grid {
  position: fixed;
  top: 0; right: 0; bottom: 0; left: 0;
  padding: var(--safe-t) var(--safe-r) var(--safe-b) var(--safe-l);
  display: grid;
  justify-content: center;
  align-content: center;
  background: #000;
}
.tile {
  position: relative;
  background: #0b0d12;
  border: calc(4 * var(--u)) solid transparent;
  overflow: hidden;
  cursor: pointer;
}
.tile video { width: 100%; height: 100%; object-fit: contain; display: block; pointer-events: none; }
.tile.focused { border-color: var(--accent); }
/* Window that isn't playing live (TV decoder limit): channel card instead of video */
.tile-card {
  position: absolute;
  top: 0; right: 0; bottom: 0; left: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: calc(16 * var(--u));
  background: #0b0d12;
  color: var(--muted);
}
.tile-card img { max-width: 40%; max-height: 40%; object-fit: contain; }
.tile-card-name { font-size: var(--label-size, 26px); font-weight: 600; }
.tile.idle .tile-card { display: flex; }
.tile.idle video { visibility: hidden; }
.tile-label {
  position: absolute;
  top: calc(14 * var(--u));
  right: calc(14 * var(--u));   /* page is RTL */
  padding: calc(6 * var(--u)) calc(16 * var(--u));
  border-radius: calc(10 * var(--u));
  background: var(--panel);
  font-size: var(--label-size, 26px);
  font-weight: 600;
  white-space: nowrap;
  max-width: calc(100% - 28 * var(--u));
  overflow: hidden;
  text-overflow: ellipsis;
  opacity: 0;
  transition: opacity 0.4s ease;
}
.tile-label.show { opacity: 1; }
.tile.focused .tile-label::after { content: "  🔊"; }
.tile.tile-error::after {
  content: "הערוץ לא זמין, מנסה שוב…";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: calc(28 * var(--u));
  color: var(--muted);
  white-space: nowrap;
}

/* On-screen buttons (touch / mouse) */
#controls {
  position: fixed;
  left: 50%;
  bottom: calc(40 * var(--u) + var(--safe-b));
  transform: translateX(-50%);
  display: flex;
  gap: calc(20 * var(--u));
  padding: calc(14 * var(--u));
  background: var(--panel);
  border-radius: calc(60 * var(--u));
  z-index: 4;
}
#controls button {
  min-width: calc(88 * var(--u));
  height: calc(88 * var(--u));
  padding: 0 calc(24 * var(--u));
  border-radius: calc(44 * var(--u));
  border: none;
  background: rgba(255, 255, 255, 0.1);
  font-size: calc(36 * var(--u));
  white-space: nowrap;
}
#controls button.wide { font-size: calc(30 * var(--u)); }
#controls { flex-wrap: wrap; justify-content: center; align-items: center; max-width: calc(100vw - 24px); }
#volume {
  width: calc(220 * var(--u));
  accent-color: var(--accent);
  margin-inline: calc(8 * var(--u));
}
#controls button:active { background: var(--accent); }

/* Start screen (only if autoplay with sound is blocked) */
#start {
  position: fixed;
  top: 0; right: 0; bottom: 0; left: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.6);
  z-index: 10;
}
#start-btn {
  font-size: calc(48 * var(--u));
  padding: calc(28 * var(--u)) calc(64 * var(--u));
  border-radius: calc(16 * var(--u));
  border: calc(4 * var(--u)) solid var(--accent);
  background: var(--focus-bg);
  color: var(--text);
}
#start-btn:focus { outline: none; background: var(--accent); }

/* Touch screens: touch hints instead of remote hints */
@media (hover: none) and (pointer: coarse) {
  .hint-remote { display: none; }
  .hint-touch { display: block; }
  #channel-list li .pick { width: calc(64 * var(--u)); height: calc(64 * var(--u)); }
}

/* Phone portrait: the channel list becomes a bottom sheet */
@media (orientation: portrait) and (max-width: 900px) {
  #guide {
    top: auto;
    left: 0;
    right: 0;
    width: 100%;
    height: 72%;
    padding: calc(28 * var(--u)) calc(24 * var(--u)) calc(20 * var(--u) + var(--safe-b));
    border-radius: calc(32 * var(--u)) calc(32 * var(--u)) 0 0;
  }
  #banner {
    right: calc(24 * var(--u));   /* page is RTL */
    max-width: calc(100vw - 48 * var(--u));
  }
  #controls { gap: calc(10 * var(--u)); padding: calc(10 * var(--u)); flex-wrap: nowrap; }
  #controls button { min-width: calc(76 * var(--u)); height: calc(76 * var(--u)); padding: 0 calc(14 * var(--u)); font-size: calc(32 * var(--u)); }
  #controls button.wide { font-size: calc(26 * var(--u)); }
}

/* Short landscape screens (phones on their side): slimmer list rows */
@media (orientation: landscape) and (max-height: 500px) {
  #guide { padding-top: calc(20 * var(--u) + var(--safe-t)); }
  #channel-list li { height: calc(76 * var(--u)); }
  .hint { display: none; }
}
