:root {
  color-scheme: dark;
  --bg: #070b12;
  --card: #151d2b;
  --card-deep: #0f1622;
  --border: #273246;
  --text: #e8edf5;
  --muted: #8fa0b8;
  --accent: #4d8dff;
  --ok: #34d399;
  --danger: #f87171;
  --warn: #fbbf24;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
  padding: 16px 16px 80px;
}
body.tv { padding: 0 0 40px; }
h1 { font-size: 1.35rem; margin: 0 0 8px; font-weight: 650; }
h2 { font-size: 1rem; margin: 0; font-weight: 600; }
.muted { color: var(--muted); font-size: .88rem; }
.kicker {
  font-size: .68rem; font-weight: 700; letter-spacing: .08em;
  text-transform: uppercase; color: var(--muted);
}
.wrap { max-width: 720px; margin: 0 auto; padding: 16px; }
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px;
  margin-bottom: 12px;
}
.hidden { display: none !important; }
.status-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--muted); display: inline-block;
}
.status-dot.on { background: var(--ok); }
.status-dot.off { background: var(--danger); }
.status-dot.warn { background: var(--warn); }
button, .btn {
  appearance: none; border: 1px solid transparent; border-radius: 12px;
  display: inline-flex; align-items: center; justify-content: center;
  box-sizing: border-box;
  height: 48px; min-height: 48px; max-height: 48px; padding: 0 16px; line-height: 1;
  font-size: 1rem; font-weight: 650;
  background: var(--accent); color: #fff; cursor: pointer;
  text-decoration: none;
}
button.secondary, .btn.secondary {
  background: transparent; color: var(--accent);
  border: 1px solid var(--accent);
}
button.ghost, .btn.ghost {
  background: #1c2738; color: var(--text); border: 1px solid var(--border);
}
button:focus, a:focus, input:focus, select:focus, .tile:focus, .channel:focus {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat .k { display: block; color: var(--muted); font-size: .68rem; text-transform: uppercase; }
.stat .v { font-size: .95rem; word-break: break-word; }
input, select, textarea {
  width: 100%; padding: 12px 14px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--card-deep); color: var(--text);
  font-size: 1rem; margin: 6px 0;
}
code, .mono {
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: .82rem; word-break: break-all; color: var(--muted);
}
.banner {
  background: rgba(77,141,255,.12);
  border: 1px solid rgba(77,141,255,.35);
  border-radius: 10px; padding: 10px 12px; margin: 10px 16px; font-size: .88rem;
}
.banner.err { background: rgba(248,113,113,.12); border-color: rgba(248,113,113,.4); color: var(--danger); }
.banner.warn { background: rgba(251,191,36,.1); border-color: rgba(251,191,36,.35); }
.flash {
  position: fixed; inset: 0; background: #fff; z-index: 50; display: none;
}
.flash.show { display: block; }
.table { width: 100%; border-collapse: collapse; font-size: .88rem; }
.table th, .table td {
  text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--border); vertical-align: top;
}
.pill {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  background: #1c2738; border: 1px solid var(--border); font-size: .76rem; color: var(--muted);
}
.actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.actions .btn, .actions button { height: 48px; min-height: 48px; }

.tv-bar {
  display: flex; justify-content: space-between; align-items: flex-start;
  gap: 16px; padding: 18px 20px 8px;
}
.tv-bar-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.home-apps { padding: 0 0 24px; }
.group { padding: 4px 0 8px; }
.group-title {
  margin: 0 20px 8px;
  font-size: .78rem;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 700;
}
.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
  padding: 0 20px 12px;
}
.tile {
  min-height: 110px;
  border-radius: 16px;
  display: flex; flex-direction: column; justify-content: flex-end;
  align-items: flex-start; text-align: left;
  color: #fff; padding: 14px;
}
.tile-title { font-size: 1.15rem; font-weight: 750; }
.tile-mark { font-size: .75rem; opacity: .85; margin-top: 6px; font-weight: 500; }
.channels {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 8px;
  padding: 8px 20px 24px;
}
.channel {
  background: var(--card); color: var(--text); border: 1px solid var(--border);
  text-align: left; min-height: 64px; font-weight: 600;
  display: flex; flex-direction: row; align-items: center; justify-content: flex-start;
  gap: 12px; padding: 8px 12px;
}
.ch-logo {
  width: 48px; height: 48px; object-fit: contain; flex: none;
  background: #0f1622; border-radius: 8px;
}
.ch-logo-empty { display: inline-block; }
.ch-meta { min-width: 0; display: flex; flex-direction: column; align-items: flex-start; }
.ch-name { font-weight: 700; }
.channel small { font-weight: 500; color: var(--muted); margin-top: 2px; }
.player-screen {
  position: fixed; inset: 0; z-index: 90; background: #000;
  display: flex; flex-direction: column;
  padding: 0; height: 100%; width: 100%;
}
.player-screen.hidden { display: none !important; }
body.playing {
  padding: 0; overflow: hidden; height: 100%; width: 100%; position: fixed;
}
#player {
  width: 100%; flex: 1; min-height: 200px; background: #000; object-fit: contain;
}
.player-hud {
  display: flex; justify-content: space-between; align-items: center;
  gap: 12px; padding: 10px 16px; flex: none;
}
@media (max-width: 520px) {
  .grid2 { grid-template-columns: 1fr; }
  .tiles { grid-template-columns: repeat(2, 1fr); padding: 8px 12px 24px; }
}
