:root {
  --bg: #07090d; --panel: #10141c; --card: #161b25; --card2: #1e2532;
  --text: #e9edf5; --muted: #8c96a8; --accent: #3d8bff; --focus: #ffcf3d;
  --side: 17rem;
  font-size: clamp(14px, 0.55vw + 10px, 22px);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; overflow: hidden; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }

#app { display: flex; height: 100%; }
#side { width: var(--side); flex: none; background: var(--panel); display: flex; flex-direction: column;
  padding: 1rem .75rem; gap: .6rem; overflow: hidden; }
.brand { font-weight: 800; font-size: 1.6rem; padding: 0 .5rem; }
.brand span { color: var(--accent); }
#search { width: 100%; padding: .7rem .9rem; border-radius: .6rem; border: 2px solid transparent;
  background: var(--card); color: var(--text); font: inherit; outline: none; }
#search:focus { border-color: var(--focus); }
#groups { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; padding-right: 4px; }
#groups h3 { font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted);
  margin: 1rem .6rem .3rem; }
.group, .toggle { display: flex; justify-content: space-between; align-items: center; gap: .5rem;
  text-align: left; padding: .55rem .7rem; border-radius: .5rem; outline: none; border: 2px solid transparent; }
.group small { color: var(--muted); font-size: .75rem; }
.group:hover, .toggle:hover { background: var(--card); }
.group.active { background: var(--accent); color: #fff; }
.group.active small { color: #dbe8ff; }
.group:focus, .toggle:focus { border-color: var(--focus); }
.toggle { font-size: .85rem; color: var(--muted); }
#updated { color: var(--muted); font-size: .7rem; padding: 0 .7rem; }

#main { flex: 1; overflow-y: auto; padding: 0 1.25rem 2rem; min-width: 0; }
#bar { position: sticky; top: 0; z-index: 2; display: flex; align-items: baseline; gap: .75rem;
  padding: 1rem 0; background: linear-gradient(var(--bg) 75%, transparent); }
#bar h1 { font-size: 1.4rem; margin: 0; }
#count { color: var(--muted); font-size: .85rem; }
#menuBtn { display: none; font-size: 1.4rem; align-self: center; }
#banner { background: var(--card2); border-left: 4px solid var(--accent); padding: .7rem 1rem;
  border-radius: .5rem; margin-bottom: 1rem; font-size: .9rem; }
#banner[hidden] { display: none; }

#grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(10rem, 1fr)); gap: .9rem; }
.card { background: var(--card); border-radius: .8rem; overflow: hidden; text-align: left; outline: none;
  border: 3px solid transparent; transition: transform .12s, border-color .12s; padding: 0; position: relative; min-width: 0; }
.card:hover { background: var(--card2); }
.card:focus { border-color: var(--focus); transform: scale(1.05); z-index: 1; box-shadow: 0 8px 30px #000a; }
.logo { position: relative; aspect-ratio: 16/9; display: grid; place-items: center;
  background: radial-gradient(circle at 50% 40%, #2a3344, #151a24); }
.logo img { position: absolute; left: 12%; top: 12%; width: 76%; height: 76%; object-fit: contain; }
.ph { font-weight: 800; font-size: 1.6rem; color: #5d6b83; }
.logo.ok .ph { display: none; }
.meta { display: flex; align-items: center; gap: .5rem; padding: .55rem .7rem; }
.num { font-variant-numeric: tabular-nums; color: var(--accent); font-weight: 700; font-size: .8rem; }
.name { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: .9rem; }
.star { color: var(--focus); }
.badge { position: absolute; top: .4rem; right: .4rem; background: #b3541e; color: #fff; font-size: .65rem;
  font-weight: 700; padding: .1rem .4rem; border-radius: .3rem; }
.empty { color: var(--muted); grid-column: 1 / -1; text-align: center; padding: 3rem; }
#more { height: 1px; }

#player { position: fixed; inset: 0; background: #000; z-index: 10; cursor: none; }
#player[hidden] { display: none; }
#player.ui { cursor: default; }
#video { width: 100%; height: 100%; object-fit: contain; background: #000; }
#osd { position: absolute; left: 0; right: 0; top: 0; display: flex; gap: 1rem; align-items: center;
  padding: max(1.5rem, env(safe-area-inset-top)) 2rem 2.5rem; background: linear-gradient(#000d, transparent);
  opacity: 0; transition: opacity .3s; pointer-events: none; }
#osdLogo { height: 3.5rem; max-width: 7rem; object-fit: contain; }
#osdLogo[src=""] { display: none; }
#osdNum { font-size: 2.2rem; font-weight: 800; color: var(--accent); line-height: 1; }
#osdName { font-size: 1.5rem; font-weight: 700; }
#osdInfo { color: #c8cfdb; font-size: .9rem; }
#osdEpg { margin-top: .5rem; font-size: .95rem; max-width: 46rem; }
#osdEpg .bar { height: 4px; background: #ffffff33; border-radius: 2px; margin: .3rem 0; overflow: hidden; }
#osdEpg .bar i { display: block; height: 100%; background: var(--accent); }
#osdEpg .desc { color: #c8cfdb; font-size: .85rem; margin-top: .2rem; }
#osdEpg .next { color: #c8cfdb; margin-top: .3rem; }
#guide { position: absolute; top: 0; right: 0; bottom: 0; width: min(28rem, 100%); background: #0b0e14f2;
  overflow-y: auto; padding: max(1.5rem, env(safe-area-inset-top)) 1.25rem 1.5rem; z-index: 3; }
#guide[hidden] { display: none; }
#guide h2 { margin: 0 0 1rem; font-size: 1.2rem; }
#guide .p { display: flex; gap: .8rem; padding: .55rem .4rem; border-radius: .4rem; }
#guide .p time { color: var(--accent); font-variant-numeric: tabular-nums; flex: none; width: 3.2rem; }
#guide .p.now { background: #3d8bff33; }
#guide .p small { display: block; color: var(--muted); }
#guide .day { color: var(--muted); font-size: .8rem; text-transform: uppercase; margin: 1rem 0 .3rem; }
.now-line { display: block; padding: 0 .7rem .55rem; color: var(--muted); font-size: .75rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: -.3rem; }
#ctrls { position: absolute; left: 50%; bottom: max(1.5rem, env(safe-area-inset-bottom)); transform: translateX(-50%);
  display: flex; gap: .5rem; opacity: 0; transition: opacity .3s; pointer-events: none; }
#ctrls button { background: #ffffff22; backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  padding: .7rem 1rem; border-radius: .7rem; min-width: 3rem; font-size: 1.1rem; border: 2px solid transparent; }
#ctrls button:focus { border-color: var(--focus); outline: none; }
#player.ui #osd, #player.ui #ctrls { opacity: 1; }
#player.ui #ctrls { pointer-events: auto; }
#status { position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none;
  font-size: 1.2rem; text-align: center; padding: 2rem; text-shadow: 0 2px 8px #000; }
#status:empty { display: none; }
#status.err { color: #ff9a9a; }
#numEntry { position: fixed; top: 1.5rem; right: 2rem; z-index: 20; font-size: 3rem; font-weight: 800;
  background: #000c; padding: .3rem 1.2rem; border-radius: .8rem; color: var(--focus); }
#numEntry:empty { display: none; }

#scrim { display: none; position: fixed; inset: 0; background: #0009; z-index: 4; }
@media (max-width: 800px) {
  #menuBtn { display: block; }
  #side { position: fixed; top: 0; bottom: 0; left: 0; z-index: 5; transform: translateX(-100%);
    transition: transform .2s; box-shadow: 0 0 40px #000; padding-top: max(1rem, env(safe-area-inset-top)); }
  body.drawer #side { transform: none; }
  body.drawer #scrim { display: block; }
  #main { padding: 0 1rem 2rem; }
  #grid { grid-template-columns: repeat(auto-fill, minmax(7.5rem, 1fr)); gap: .6rem; }
  #ctrls button { padding: .6rem .75rem; min-width: 2.6rem; }
  #numEntry { font-size: 2rem; }
}
