/* TeslaTV — dark, large touch targets, no frameworks. */
:root {
  --bg: #0b0b0d; --panel: #17171b; --panel2: #202026; --fg: #f2f2f2; --muted: #a0a0aa;
  --accent: #e31937; --ok: #3ccf7a; --bad: #ff5c5c; --radius: 14px; --touch: 72px; --adminbar: 60px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--fg);
  font: 18px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-tap-highlight-color: transparent; }
body.tesla { font-size: 22px; --touch: 84px; --adminbar: 76px; }
a { color: #8ab4ff; }
h1 { font-size: 1.8em; margin: .4em 0; } h2 { font-size: 1.3em; margin: .8em 0 .4em; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; } .small { font-size: .85em; } .break { word-break: break-all; }
.hint { color: var(--muted); font-size: .9em; } .warn { color: #ffcf70; } .error, .bad { color: var(--bad); } .ok { color: var(--ok); }
.center { text-align: center; } .hidden { display: none !important; }
.narrow { max-width: 640px; margin: 0 auto; padding: 24px 16px; } .wide-ok { max-width: 900px; }
.lead { font-size: 1.15em; }
.btn { display: inline-flex; align-items: center; justify-content: center; min-height: 48px; padding: 0 18px; border-radius: 10px;
  border: 1px solid #333; background: var(--panel2); color: var(--fg); font: inherit; text-decoration: none; cursor: pointer; }
.btn.small { min-height: 36px; padding: 0 12px; font-size: .85em; }
.btn.big { min-height: var(--touch); min-width: 240px; font-size: 1.2em; margin: 8px 8px 8px 0; }
.btn.primary { background: var(--accent); border-color: var(--accent); } .btn.danger { background: #4a1414; border-color: #7a2020; }
button.link { background: none; border: 0; color: #8ab4ff; font: inherit; cursor: pointer; text-decoration: underline; padding: 0; }
.status { min-height: 1.4em; color: var(--muted); }
form.inline { display: inline; } .row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 8px 0; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: .9em; color: var(--muted); }
input, select { font: inherit; color: var(--fg); background: #101014; border: 1px solid #333; border-radius: 8px; min-height: 44px; padding: 0 10px; }
input.wide { min-width: 320px; } input.num { width: 80px; } input[type=checkbox] { min-height: 0; width: 22px; height: 22px; }
.check { display: inline-flex; align-items: center; gap: 6px; margin-right: 12px; }
.code-input { font-size: 2em; letter-spacing: .15em; text-align: center; text-transform: uppercase; }

/* device login (car) */
.device-login { display: flex; align-items: center; justify-content: center; gap: 6vw; min-height: 100vh; padding: 24px; }
.qr { width: min(44vh, 460px); height: min(44vh, 460px); background: #fff; padding: 16px; border-radius: var(--radius); image-rendering: pixelated; }
.device-login .qr { width: min(62vh, 520px); height: min(62vh, 520px); }
.user-code { font: 700 3.2em/1.1 ui-monospace, Menlo, monospace; letter-spacing: .08em; margin: .2em 0; color: #fff; }
.confirm-label { margin-bottom: 0; color: var(--muted); }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; } .facts dt { color: var(--muted); } .facts dd { margin: 0; }
.decide .btn.big { min-width: 160px; }

/* home tiles */
.topbar { display: flex; align-items: center; gap: 12px; padding: 12px 20px; background: var(--panel); flex-wrap: wrap; }
.topbar .brand { font-weight: 700; font-size: 1.2em; color: var(--fg); text-decoration: none; margin-right: 8px; }
.topbar a:not(.btn):not(.brand) { color: var(--fg); text-decoration: none; padding: 8px; }
.topbar .spacer { flex: 1; }
.chip { min-height: 52px; padding: 0 20px; border-radius: 26px; border: 1px solid #444; background: transparent; color: var(--fg); font: inherit; margin-right: 6px; }
.chip.active { background: var(--fg); color: #000; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 22px; padding: 28px; }
.tile { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; min-height: 180px;
  border-radius: 20px; border: 0; background: #333; color: #fff; font: inherit; text-decoration: none; cursor: pointer;
  box-shadow: 0 6px 20px rgba(0,0,0,.4); transition: transform .08s; }
.tile:active { transform: scale(.97); }
.tile-icon { font-size: 2.6em; font-weight: 800; letter-spacing: -.02em; } .tile-name { font-size: 1.15em; font-weight: 600; }
.tile.ghost { background: var(--panel2) !important; }
body.tesla .tiles { grid-template-columns: repeat(4, 1fr); } body.tesla .tile { min-height: 220px; }

/* remote view */
body.watch { overflow: hidden; background: #000; }
.remote, .player { position: fixed; inset: 0; background: #000; }
.remote canvas#rv, .remote video, .remote .rgl, .player video { position: absolute; inset: 0; width: 100%; height: calc(100% - var(--touch)); object-fit: contain; background: #000; }
.touch-layer { position: absolute; left: 0; top: 0; right: 0; bottom: var(--touch); touch-action: none; outline: none; }
.overlay-msg { position: absolute; left: 50%; top: 40%; transform: translate(-50%, -50%); background: rgba(0,0,0,.7); padding: 16px 24px;
  border-radius: var(--radius); pointer-events: none; font-size: 1.2em; }
.overlay-msg:empty { display: none; }
/* Control row: plain flex row, nothing absolutely positioned inside it. Items
   never shrink (so a label can't spill over its neighbour); if the row is
   wider than the screen it scrolls sideways and #conn stays the last item. */
.controls { position: absolute; left: 0; right: 0; bottom: 0; height: var(--touch); display: flex; flex-wrap: nowrap; gap: 6px;
  align-items: center; padding: 6px 10px; background: #111; overflow-x: auto; overflow-y: hidden; }
.controls > * { flex: none; position: static; }
.ctl { min-width: var(--touch); height: calc(var(--touch) - 12px); border-radius: 12px; border: 1px solid #333; background: #1d1d22;
  color: #fff; font: inherit; font-size: 1.4em; display: inline-flex; align-items: center; justify-content: center; text-decoration: none;
  margin: 0; box-sizing: border-box; }
.ctl.wide { font-size: .9em; padding: 0 14px; } select.ctl { font-size: .9em; padding: 0 8px; }
/* "Tap for sound": right after fullscreen, same height as the other controls */
.controls .ctl.unmute { position: static; inset: auto; background: var(--accent); border-color: var(--accent); font-weight: 700;
  white-space: nowrap; }
.ctl-status { order: 99; margin-left: auto; color: var(--muted); font-size: .8em; padding: 0 8px; white-space: nowrap; max-width: 14em;
  overflow: hidden; text-overflow: ellipsis; }
/* new-deploy notice (common.js); sits above the control row, never blocks it */
.update-banner { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--touch) + 14px); z-index: 50;
  min-height: 48px; padding: 0 20px; border-radius: 24px; border: 1px solid #5a5a66; background: #24242c; color: var(--fg);
  font: inherit; font-size: .95em; cursor: pointer; box-shadow: 0 4px 18px rgba(0,0,0,.5); }
body:not(.watch) .update-banner { bottom: 18px; }
.kbd-panel { position: absolute; left: 0; right: 0; bottom: var(--touch); display: flex; gap: 8px; padding: 10px; background: #15151a; }
.kbd-panel input { flex: 1; font-size: 1.2em; min-height: 60px; }
/* admin console: bar | video | controls stacked, so the bar never covers the remote screen */
.admin-bar { height: var(--adminbar); box-sizing: border-box; display: flex; flex-wrap: nowrap; align-items: center; gap: 6px; padding: 6px; background: #14141a;
  overflow-x: auto; overflow-y: hidden; }
.admin-bar > * { flex: none; } .admin-bar input { width: 360px; } .admin-bar .hint { cursor: help; padding: 0 8px; font-size: 1.2em; }
.watch .remote[data-admin="1"] .admin-bar { order: 0; position: static; }
.watch .remote[data-admin="1"] canvas#rv, .watch .remote[data-admin="1"] video, .watch .remote[data-admin="1"] .rgl, .watch .remote[data-admin="1"] .touch-layer { position: absolute; left: 0; right: 0;
  top: var(--adminbar); bottom: var(--touch); width: 100%; height: calc(100% - var(--adminbar) - var(--touch)); }
.watch .remote[data-admin="1"] .overlay-msg { top: calc(var(--adminbar) + 40%); }

/* iptv */
.channel-groups { padding: 16px 24px; }
.channel .badge { margin-left: 10px; }
.iptv-search { display: flex; gap: 8px; margin-left: auto; flex: 1 1 320px; max-width: 640px; }
.iptv-search input { flex: 1; min-width: 0; min-height: 48px; }
body.tesla .iptv-search input, body.tesla .iptv-search .btn { min-height: 64px; }
.channels { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
.channel { display: flex; align-items: center; min-height: var(--touch); padding: 0 18px; border-radius: 12px; background: var(--panel2);
  color: var(--fg); text-decoration: none; font-size: 1.05em; }

/* admin */
.admin-main { padding: 12px 24px 48px; }
.card { background: var(--panel); border-radius: var(--radius); padding: 12px 18px; margin: 12px 0; }
.grid { border-collapse: collapse; width: 100%; } .grid th, .grid td { text-align: left; padding: 6px 8px; border-bottom: 1px solid #262630; vertical-align: middle; }
.grid tr.fail td { color: #ffb4b4; }
.badge { display: inline-block; font-size: .65em; padding: 2px 8px; border-radius: 10px; background: #333; vertical-align: middle; }
.badge.bad { background: #5a1a1a; }
.stepup-note { padding: 0 24px; }
.probe td { padding: 6px 10px; border-bottom: 1px solid #262630; } .probe td:first-child { color: var(--muted); }

/* IPTV: offline channels and the player's friendly error panel */
.channel.offline { opacity: .6; }
.offline-toggle { color: inherit; text-decoration: underline; }
.play-error { position: absolute; left: 50%; top: 40%; transform: translate(-50%, -50%); width: min(560px, calc(100% - 32px));
  background: rgba(0,0,0,.85); padding: 20px 24px; border-radius: 14px; text-align: center; z-index: 5; }
.play-error[hidden] { display: none; }
.play-error p { margin: 0 0 12px; }
.play-error .row { justify-content: center; }

/* IPTV favorites + recently watched (car first: big tiles, >=64px toggles) */
.dot { display: inline-block; flex: none; width: .62em; height: .62em; border-radius: 50%; margin-right: .45em; vertical-align: .05em; background: #8a8a95; }
.dot-ok { background: var(--ok); } .dot-dead { background: var(--bad); } .dot-unknown { background: #8a8a95; }
button.fav:not(.fav-ctl) { flex: none; min-width: 64px; min-height: 64px; padding: 0; border-radius: 12px; border: 1px solid #3a3a44; background: #15151a;
  color: #c9c9d2; font: inherit; font-size: 1.6em; line-height: 1; display: inline-flex; align-items: center; justify-content: center; cursor: pointer; }
button.fav.on { color: #ffc93c; border-color: #6b5a1e; background: #2a2412; }
button.fav:disabled { opacity: .7; }
body.tesla button.fav:not(.fav-ctl) { min-width: 76px; min-height: 76px; }
.row-head { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.row-head h2 { margin: .5em 0 .4em; }
.saved-row { margin-bottom: 10px; }
.all-h { margin-top: 1.1em; }
.saved { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }
body.tesla .saved { grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 18px; }
.saved-tile { display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-rows: auto auto; min-width: 0; min-height: 130px;
  background: var(--panel2); border: 1px solid #2c2c34; border-radius: 16px; overflow: hidden; }
body.tesla .saved-tile { min-height: 150px; }
.saved-link { grid-column: 1; grid-row: 1; min-width: 0; min-height: 130px; display: flex; flex-direction: column; justify-content: center; gap: 6px;
  padding: 14px 8px 14px 18px; color: var(--fg); text-decoration: none; }
body.tesla .saved-link { min-height: 150px; }
.saved-name { font-weight: 600; font-size: 1.1em; overflow: hidden; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.saved-sub { color: var(--muted); font-size: .8em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.saved-tile > button.fav { grid-column: 2; grid-row: 1; align-self: start; margin: 10px 10px 0 0; }
.saved-tile .move { display: none; grid-column: 1 / -1; grid-row: 2; gap: 10px; padding: 0 10px 10px; }
.saved-row.editing .move { display: flex; }
.mv { flex: 1; min-height: 64px; border-radius: 12px; border: 1px solid #3a3a44; background: #1d1d22; color: var(--fg); font: inherit; font-size: 1.2em; cursor: pointer; }
.saved-tile.gone { opacity: .55; } .saved-tile.offline .saved-name { opacity: .75; }
.saved-tile.removed { opacity: .45; border-style: dashed; }
.chan { display: flex; align-items: center; gap: 8px; min-width: 0; }
.chan .channel { flex: 1; min-width: 0; overflow-wrap: break-word; }
/* car: fewer, wider channel cards (real names like "AR: Al Jazeera [Geo-blocked]"
   fit on <=2 lines) and the star is the card's right-hand cell, same height,
   joined to it, so it can't be mistaken for the neighbour's */
body.tesla .channel-groups section .channels { grid-template-columns: repeat(auto-fill, minmax(380px, 1fr)); gap: 14px; }
body.tesla .chan { align-items: stretch; gap: 0; }
body.tesla .chan .channel { border-radius: 12px 0 0 12px; padding: 8px 18px; }
body.tesla .chan > button.fav { min-height: 0; border-radius: 0 12px 12px 0; border-left: 0; }
.chan .channel .cname { overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
/* car: every button >= 64px tall (top bar, Reorder/Done, offline panel) */
body.tesla .topbar .btn, body.tesla .topbar .chip, body.tesla #fav-edit, body.tesla .play-error .btn,
body.tesla .narrow .row .btn { min-height: 64px; }
body.tesla .play-error { width: min(820px, calc(100% - 32px)); }
/* reorder: no-op moves look disabled */
.saved-tile:first-child .mv[data-fav-move="up"], .saved-tile:first-child .mv[data-fav-move="first"],
.saved-tile:last-child .mv[data-fav-move="down"], .saved-tile.removed .mv { opacity: .3; pointer-events: none; }
/* player */
.ctl.disabled { opacity: .35; pointer-events: none; }
.controls .fav-ctl { min-width: var(--touch); min-height: 0; height: calc(var(--touch) - 12px); font-size: 1.5em; }
/* Channel −/+ show where they go (no tooltips on a touchscreen) */
.ctl.step { flex-direction: column; gap: 2px; line-height: 1.1; max-width: 16em; }
.ctl.step small { font-size: .72em; color: #c8c8d0; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* now playing + what Channel −/+ step through: takes the rest of the row */
.controls .ctl-status { flex: 1 1 auto; min-width: 8em; max-width: none; color: var(--fg); font-size: 1em; display: flex; flex-direction: column;
  align-items: flex-end; justify-content: center; line-height: 1.2; }
.ctl-status .now { font-weight: 600; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.ctl-status .mode { font-size: .75em; color: #c8c8d0; }
.ctl-status .mode.fav-mode { color: #ffc93c; }
.player:fullscreen, .player:-webkit-full-screen { width: 100%; height: 100%; }
/* home: favorite channel tiles */
.favtile { min-width: 0; background: #23232b; border-top: 4px solid #ffc93c; }
.favtile .tile-icon { color: #ffc93c; font-size: 2em; }
.favtile .tile-name, .favtile .tile-sub { display: block; max-width: 100%; padding: 0 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.favtile .tile-sub { color: var(--muted); font-size: .85em; }
.favtile.offline { opacity: .7; }
/* toast for favorite toggles */
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: 24px; z-index: 60; max-width: calc(100% - 32px); padding: 12px 22px;
  border-radius: 24px; border: 1px solid #5a5a66; background: #24242c; color: var(--fg); pointer-events: none; box-shadow: 0 4px 18px rgba(0,0,0,.5); }
.toast[hidden] { display: none; }
.watch .toast { bottom: calc(var(--touch) + 14px); }
.player video::-webkit-media-controls-fullscreen-button { display: none; }



/* Sharpen overlay never captures input */
.remote .rgl,
canvas#rgl,
.remote canvas#rgl {
  pointer-events: none !important;
  z-index: 1 !important;
}

/* Touch layer above the video; control bar and keyboard panel above it */
.remote .touch-layer {
  z-index: 10 !important;
  pointer-events: auto !important;
}
.remote .controls,
.remote .kbd-panel {
  z-index: 20 !important;
}
