/* Maple Player for the web.
   Colours, corners and focus frames follow the Android app (res/values/colors.xml, drawable/bg_*.xml).
   The whole player always fits one screen: the page itself never scrolls. Only the category rail,
   the channel list, the TV guide and the sheets scroll inside themselves. */
:root {
  --bg: #0F1014;
  --surface: #1A1B21;
  --surface2: #262832;
  --surface-focus: #33343F;
  --red: #D52B1E;
  --red-dark: #A51F15;
  --red-light: #E8493C;
  --red-soft: rgba(213, 43, 30, .25);
  --text: #F5F5F7;
  --text2: #A3A6B0;
  --hint: #6F727C;
  --divider: #2E3039;
  --gold: #FFC439;
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --pad: 20px;
  --gap: 16px;
  --rail-w: 220px;
  --btn-h: 44px;
  --pv-h: clamp(150px, 36vh, 420px);
  --g-chan: 210px;
  --g-row: 64px;
}
@supports (height: 1dvh) { :root { --pv-h: clamp(150px, 36dvh, 420px); } }

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; overscroll-behavior: none; }
body {
  position: fixed;
  inset: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
img { display: block; }
button { font: inherit; }

.app {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
  padding: calc(12px + var(--safe-t)) calc(var(--pad) + var(--safe-r)) calc(10px + var(--safe-b)) calc(var(--pad) + var(--safe-l));
}

/* ---------- Header: leaf, app name, profile, search, buttons (as on the TV home) ---------- */
.top { display: flex; align-items: center; gap: 12px; flex: none; min-width: 0; }
.brand { display: flex; align-items: center; gap: 12px; flex: 1 1 auto; min-width: 0; color: inherit; text-decoration: none; }
.brand .leaf { width: 42px; height: 42px; flex: none; }
.titles { display: flex; flex-direction: column; min-width: 0; }
.titles .name { font-size: 26px; font-weight: 700; line-height: 1.15; white-space: nowrap; }
.titles .profile { color: var(--text2); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.search, .input {
  font: inherit;
  font-size: 16px; /* 16px stops iOS zooming into the field */
  color: var(--text);
  background: var(--surface2);
  border: 1px solid var(--divider);
  border-radius: 10px;
  min-height: var(--btn-h);
  padding: 0 14px;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
  min-width: 0;
}
.search { width: 240px; flex: 0 1 240px; }
.search::placeholder, .input::placeholder { color: var(--hint); }
.search:focus, .input:focus { border: 2px solid var(--red); padding: 0 13px; }
.actions { display: flex; gap: 10px; flex: none; }

.btn {
  color: var(--text);
  background: var(--surface2);
  border: 0;
  border-radius: 10px;
  min-height: var(--btn-h);
  padding: 0 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 15px;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}
.btn .ico { display: none; font-size: 18px; line-height: 1; }
.btn:active { background: var(--red-dark); }
.btn:focus-visible { outline: 2px solid var(--text); outline-offset: 0; background: var(--red); }
.btn:disabled { background: var(--surface); color: var(--hint); cursor: default; }
.btn.primary { background: var(--red); font-weight: 700; }
.btn.primary:active { background: var(--red-dark); }
.btn.primary:focus-visible { background: var(--red-light); }
.btn.primary:disabled { background: var(--red-dark); color: rgba(245, 245, 247, .6); }
.btn.icon { min-width: var(--btn-h); padding: 0 12px; font-size: 17px; }
.btn.icon.on { color: var(--gold); }
.btn.on-mode { background: var(--red); font-weight: 700; }
.btn.wide { width: 100%; margin-top: 16px; min-height: 50px; font-size: 16px; }
@media (hover: hover) {
  .btn:hover:not(:disabled) { background: var(--surface-focus); }
  .btn.primary:hover:not(:disabled), .btn.on-mode:hover { background: var(--red-light); }
}

.status { margin: 8px 0 0; color: var(--text2); font-size: 14px; flex: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status.error { color: #FF8A80; white-space: normal; }

/* ---------- Body: one grid that fills what's left of the screen ---------- */
.body {
  flex: 1 1 auto;
  min-height: 0;
  margin-top: 14px;
  display: grid;
  gap: var(--gap) 18px;
  grid-template-columns: var(--rail-w) minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr);
  grid-template-areas: "rail stage" "rail list";
}
.main { display: contents; }

.rail {
  grid-area: rail;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-right: 4px;
}
.cat {
  text-align: left;
  color: var(--text);
  background: transparent;
  border: 0;
  border-radius: 10px;
  min-height: 46px;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  touch-action: manipulation;
  flex: none;
}
.cat .cat-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 16px; }
.cat .cat-count { color: var(--text2); font-size: 13px; }
.cat:active { background: var(--surface-focus); }
.cat.on { background: var(--red); font-weight: 700; }
.cat.on .cat-count { color: rgba(245, 245, 247, .8); }
.cat:focus-visible { outline: 2px solid var(--text); }
@media (hover: hover) { .cat:not(.on):hover { background: var(--surface2); } }

/* ---------- Preview box (top left) with the channel and programme beside it ---------- */
.stage {
  grid-area: stage;
  min-width: 0;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: var(--gap);
  align-items: stretch;
}
.screen {
  position: relative;
  width: min(calc(var(--pv-h) * 16 / 9), calc(100vw - var(--rail-w) - 2 * var(--pad) - var(--safe-l) - var(--safe-r) - 18px - var(--gap) - 300px));
  height: auto;
  aspect-ratio: 16 / 9;
  background: #000;
  border-radius: 14px;
  overflow: hidden;
  border: 1px solid var(--divider);
}
.screen video { position: absolute; inset: 0; width: 100%; height: 100%; background: #000; object-fit: contain; }
.screen:fullscreen, .screen:-webkit-full-screen { border-radius: 0; border: 0; width: 100%; height: 100%; max-width: none; aspect-ratio: auto; }
.screen-idle {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  color: var(--text2); font-size: 14px; text-align: center; padding: 16px;
  background: radial-gradient(ellipse at center, #1d1214 0%, #000 75%);
}
.screen-idle img { width: 48px; height: 48px; }
.spinner {
  position: absolute; left: 50%; top: 50%; width: 44px; height: 44px; margin: -22px 0 0 -22px;
  border: 4px solid rgba(255, 255, 255, .2); border-top-color: var(--red); border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.now {
  min-width: 0;
  min-height: 0;
  max-height: var(--pv-h);
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--divider);
  border-radius: 14px;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.now-head { display: flex; align-items: center; gap: 12px; min-width: 0; flex: none; }
.now-num { color: var(--text2); font-weight: 700; font-size: 16px; min-width: 1.5em; }
.now-logo { width: 60px; height: 38px; object-fit: contain; flex: none; }
.now-text { min-width: 0; }
.now-name { font-size: 20px; font-weight: 700; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.now-group { color: var(--text2); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.controls { display: flex; flex-wrap: wrap; gap: 8px; flex: none; }
.now-note { margin: 0; color: var(--text2); font-size: 13px; flex: none; }
.now-note:empty { display: none; }
.now-note.error { color: #FF8A80; }

.prog { min-height: 0; flex: 1 1 auto; overflow: hidden; display: flex; flex-direction: column; gap: 3px; }
.prog-label { color: var(--red-light); font-size: 12px; font-weight: 700; letter-spacing: .5px; text-transform: uppercase; }
.prog-title { font-size: 17px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.prog-time { color: var(--text2); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar { height: 4px; background: var(--surface2); border-radius: 2px; overflow: hidden; margin: 3px 0; flex: none; }
.bar span { display: block; height: 100%; width: 0; background: var(--red); }
.prog-desc { color: var(--text2); font-size: 14px; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; }
.prog-desc:empty, .prog-next:empty { display: none; }
.prog-next { color: var(--text2); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.prog-next b { color: var(--text); font-weight: 600; }

/* ---------- Channel list (scrolls inside itself) ---------- */
.channels { grid-area: list; min-height: 0; min-width: 0; display: flex; flex-direction: column; }
.channels-head { display: flex; align-items: baseline; gap: 10px; margin: 0 0 8px; flex: none; min-width: 0; }
.channels-head h2 { font-size: 20px; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.count { color: var(--text2); font-size: 14px; white-space: nowrap; }
.ch-scroll { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; padding: 4px 4px 12px 0; }

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(168px, 1fr)); gap: 12px; }
.tile {
  position: relative;
  color: var(--text);
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--divider);
  border-radius: 14px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform .12s ease, background .12s ease;
  min-width: 0;
}
.tile .t-top { position: relative; height: 60px; display: flex; align-items: center; justify-content: center; }
.tile .t-num { position: absolute; left: 0; top: 0; color: var(--text2); font-size: 14px; font-weight: 700; }
.tile .t-logo { max-width: calc(100% - 56px); max-height: 56px; object-fit: contain; }
.tile .t-mono {
  width: 54px; height: 54px; border-radius: 12px; background: var(--surface2);
  display: flex; align-items: center; justify-content: center;
  font-size: 21px; font-weight: 700; color: var(--text2);
}
.tile .t-fav { position: absolute; right: 12px; top: 10px; color: var(--gold); font-size: 18px; line-height: 1; }
.tile .t-text { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.tile .t-name { font-size: 16px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile .t-group, .tile .t-prog { color: var(--text2); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile .t-prog { color: #D6D8DE; }
.tile .t-prog:empty { display: none; }
.tile:active { background: var(--surface-focus); }
.tile:focus-visible { outline: none; background: var(--surface-focus); border: 4px solid var(--red); padding: 9px; transform: scale(1.03); }
.tile.playing { background: var(--surface-focus); border: 3px solid var(--red); padding: 10px; }
@media (hover: hover) { .tile:hover { background: var(--surface-focus); } }

.more { display: flex; justify-content: center; margin-top: 14px; }

.empty {
  background: var(--surface);
  border: 1px solid var(--divider);
  border-radius: 14px;
  padding: 26px 22px;
  text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
}
.empty img { width: 56px; height: 56px; }
.empty h3 { margin: 4px 0 0; font-size: 21px; }
.empty p { margin: 0; color: var(--text2); max-width: 460px; }
.empty-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; margin: 10px 0 4px; }
.small { color: var(--text2); font-size: 13px; margin: 8px 0 0; }
.small a { color: var(--text); }

/* ---------- TV guide grid (scrolls inside itself), modelled on the app's guide screen ---------- */
.guide { grid-area: list; min-height: 0; min-width: 0; display: flex; flex-direction: column; }
.guide-head { display: flex; align-items: center; gap: 12px; flex: none; margin-bottom: 8px; min-width: 0; }
.guide-titles { display: flex; align-items: baseline; gap: 10px; min-width: 0; flex: 1 1 auto; overflow: hidden; }
.guide-titles h2 { font-size: 20px; margin: 0; white-space: nowrap; }
.guide-titles .count { overflow: hidden; text-overflow: ellipsis; }
.clock { color: var(--text2); font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; flex: none; }
.guide-nav { display: flex; gap: 8px; flex: none; }
.guide-msg { margin: 0 0 8px; color: var(--text2); font-size: 14px; background: var(--surface); border: 1px solid var(--divider); border-radius: 10px; padding: 10px 14px; flex: none; }
.guide-msg.error { color: #FF8A80; }

.timebar { display: grid; grid-template-columns: var(--g-chan) minmax(0, 1fr); gap: 6px; flex: none; height: 36px; padding-right: 4px; }
.tb-corner { color: var(--text2); font-size: 14px; font-weight: 700; display: flex; align-items: center; padding-left: 4px; white-space: nowrap; overflow: hidden; }
.tb-slots { position: relative; border-bottom: 1px solid var(--divider); }
.tb-slot { position: absolute; top: 0; bottom: 0; display: flex; align-items: center; padding-left: 8px; color: var(--text2); font-size: 14px; border-left: 1px solid var(--divider); white-space: nowrap; overflow: hidden; }

.g-scroll { flex: 1 1 auto; min-height: 0; overflow-y: auto; overflow-x: hidden; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; padding: 6px 4px 12px 0; }
.g-grid { position: relative; }
.g-row { display: grid; grid-template-columns: var(--g-chan) minmax(0, 1fr); gap: 6px; height: var(--g-row); margin-bottom: 6px; }
.g-chan {
  min-width: 0; text-align: left; color: var(--text);
  background: var(--surface); border: 1px solid var(--divider); border-radius: 10px;
  padding: 0 10px; display: flex; align-items: center; gap: 10px; cursor: pointer; touch-action: manipulation;
}
.g-chan .g-num { color: var(--text2); font-size: 13px; font-weight: 700; min-width: 2.2em; }
.g-chan img { width: 48px; height: 32px; object-fit: contain; flex: none; }
.g-chan .t-mono { width: 32px; height: 32px; border-radius: 8px; background: var(--surface2); display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 700; color: var(--text2); flex: none; }
.g-chan .g-name { font-size: 15px; font-weight: 700; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.g-chan.playing { border: 2px solid var(--red); background: var(--surface-focus); }
.g-cells { position: relative; min-width: 0; overflow: hidden; border-radius: 10px; background: #14151A; }
.g-cell {
  position: absolute; top: 0; bottom: 0;
  text-align: left; color: var(--text);
  background: var(--surface); border: 1px solid var(--divider); border-radius: 10px;
  padding: 6px 10px; overflow: hidden; cursor: pointer; touch-action: manipulation;
  display: flex; flex-direction: column; justify-content: center; min-width: 0;
}
.g-cell .c-title { font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.g-cell .c-time { color: var(--text2); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.g-cell.now { background: #2A1C1E; border-color: #5A2A27; }
.g-cell.past { opacity: .55; }
.g-cell.sel, .g-cell:focus-visible { outline: none; border: 3px solid var(--red); padding: 4px 8px; background: var(--surface-focus); }
.g-cell.g-empty { background: transparent; border-style: dashed; }
.g-cell.g-empty .c-title { color: var(--text2); font-weight: 500; }
.g-none { position: absolute; inset: 0; display: flex; align-items: center; padding-left: 12px; color: var(--hint); font-size: 14px; }
.g-nowline { position: absolute; top: 0; bottom: 0; width: 2px; margin-left: -1px; background: var(--red); z-index: 2; pointer-events: none; box-shadow: 0 0 6px rgba(213, 43, 30, .6); }
@media (hover: hover) { .g-cell:hover, .g-chan:hover { background: var(--surface-focus); } }

/* ---------- Sheets (Providers, Donate, Help) scroll inside themselves ---------- */
.sheet {
  width: min(560px, calc(100% - 24px));
  max-height: calc(100% - 32px);
  padding: 0;
  border: 1px solid var(--divider);
  border-radius: 16px;
  background: var(--surface);
  color: var(--text);
  overflow: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}
.sheet::backdrop { background: rgba(0, 0, 0, .65); }
.sheet-inner { padding: 18px 20px 22px; display: flex; flex-direction: column; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.sheet-head h2 { margin: 0; font-size: 22px; }
.label { color: var(--text2); font-size: 13px; margin: 14px 0 6px; display: block; }
.input { width: 100%; }
.input.area { min-height: 110px; padding: 10px 14px; resize: vertical; font-family: ui-monospace, Menlo, monospace; font-size: 16px; }
.input.area:focus { padding: 9px 13px; }
.input.file { padding: 10px 14px; }
select.input { background-image: linear-gradient(45deg, transparent 50%, var(--text2) 50%), linear-gradient(135deg, var(--text2) 50%, transparent 50%); background-position: calc(100% - 20px) 50%, calc(100% - 14px) 50%; background-size: 6px 6px; background-repeat: no-repeat; padding-right: 36px; }

.segments { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 8px; }
.seg { font-size: 14px; color: var(--text); background: var(--surface2); border: 1px solid var(--divider); border-radius: 10px; min-height: 48px; padding: 4px 6px; cursor: pointer; touch-action: manipulation; }
.seg.on { background: var(--red-soft); border: 2px solid var(--red); font-weight: 700; }
.check { display: flex; align-items: center; gap: 10px; margin-top: 18px; font-size: 15px; cursor: pointer; }
.check input { width: 22px; height: 22px; accent-color: var(--red); margin: 0; }
.form-error { color: #FF8A80; font-size: 14px; margin: 12px 0 0; }

.saved { display: flex; align-items: center; justify-content: space-between; gap: 10px; background: var(--surface2); border-radius: 12px; padding: 12px 14px; margin: 4px 0 8px; flex-wrap: wrap; }
.saved .label { margin: 0 0 2px; }
.saved b { display: block; }
.saved-actions { display: flex; gap: 8px; }
.saved-actions .btn { background: var(--surface-focus); }

.donate { display: flex; flex-direction: column; align-items: center; text-align: center; }
.donate .qr { width: 220px; height: 220px; background: #fff; border-radius: 14px; padding: 10px; margin: 6px 0 12px; }
.donate p { color: var(--text2); margin: 0; }

.install-lead { color: var(--text); margin: 0 0 6px; }
.install h3 { font-size: 17px; margin: 14px 0 6px; }
.install ol { margin: 0; padding-left: 22px; }
.install li { color: var(--text2); margin-bottom: 8px; }
.install li b, .install p b { color: var(--text); }
.install p { color: var(--text2); }
.share-ico {
  display: inline-block; width: 18px; height: 20px; vertical-align: -3px; margin: 0 2px;
  background: no-repeat center / contain url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 18 22' fill='none' stroke='%230A84FF' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M9 1v13M4.5 5.5 9 1l4.5 4.5M6 9H3a1 1 0 0 0-1 1v10a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1V10a1 1 0 0 0-1-1h-3'/%3E%3C/svg%3E");
}

.help h3 { font-size: 17px; margin: 16px 0 6px; }
.help p, .help li { color: var(--text2); font-size: 15px; }
.help b { color: var(--text); }
.help ul { padding-left: 18px; margin: 0; }
.help li { margin-bottom: 8px; }
.help code { font-family: ui-monospace, Menlo, monospace; color: var(--text); background: var(--surface2); padding: 1px 5px; border-radius: 5px; font-size: 13px; overflow-wrap: anywhere; }

/* ======================= Fitting every screen ======================= */

/* Smaller laptops and iPad landscape */
@media (max-width: 1180px) {
  :root { --rail-w: 200px; --g-chan: 190px; }
  .search { flex-basis: 200px; width: 200px; }
}

/* Header buttons go icon-only before anything gets squeezed */
@media (max-width: 1020px) {
  .actions .btn .lbl { display: none; }
  .actions .btn .ico { display: inline; }
  .actions .btn { min-width: var(--btn-h); padding: 0 12px; }
}

/* Tablets in portrait, and other tall narrow windows: preview on top, details under it */
@media (max-width: 1100px) and (orientation: portrait), (max-width: 860px) {
  :root { --rail-w: 180px; --g-chan: 160px; }
  .stage { grid-template-columns: minmax(0, 1fr); gap: 10px; }
  .screen { height: auto; width: 100%; max-width: 100%; max-height: 34vh; }
  .now { height: auto; max-height: 24vh; }
  .prog-desc { -webkit-line-clamp: 2; }
  .tb-slot:nth-child(even) { color: transparent; }
}
@supports (height: 1dvh) {
  @media (max-width: 1100px) and (orientation: portrait), (max-width: 860px) {
    .screen { max-height: 34dvh; }
    .now { max-height: 24dvh; }
  }
}

/* Phones in portrait: compact header, category chips, preview, then the list */
@media (max-width: 699px) {
  :root { --pad: 12px; --gap: 8px; --btn-h: 40px; --g-chan: 112px; --g-row: 58px; }
  .app { padding-top: calc(8px + var(--safe-t)); padding-bottom: calc(6px + var(--safe-b)); }
  .top { flex-wrap: wrap; gap: 8px 6px; }
  .brand { gap: 6px; flex: 1 1 0; }
  .brand .leaf { width: 28px; height: 28px; }
  .titles .name { font-size: 17px; }
  .titles .profile { font-size: 11px; }
  .actions { gap: 4px; }
  .actions .btn, .actions .btn.icon { min-width: 36px; padding: 0 8px; }
  .search { order: 3; flex: 1 1 100%; width: 100%; min-height: 40px; }
  .status { margin-top: 6px; font-size: 13px; }
  .body {
    margin-top: 8px;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto minmax(0, 1fr);
    grid-template-areas: "stage" "rail" "list";
  }
  .rail { flex-direction: row; overflow-x: auto; overflow-y: hidden; padding: 0 0 2px; gap: 6px; scrollbar-width: none; }
  .rail::-webkit-scrollbar { display: none; }
  .rail:empty { display: none; }
  .cat { min-height: 36px; padding: 6px 14px; border-radius: 999px; background: var(--surface2); }
  .cat .cat-name { font-size: 14px; max-width: 160px; }
  .cat .cat-count { display: none; }
  .screen { max-height: 30vh; border-radius: 12px; }
  .now { padding: 10px 12px; gap: 8px; max-height: none; border-radius: 12px; }
  .now-head { gap: 10px; }
  .now-logo, .now-group { display: none; }
  .now-num { font-size: 14px; min-width: 0; }
  .now-name { font-size: 16px; }
  .now-note { font-size: 12px; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
  .controls { flex-wrap: nowrap; gap: 6px; }
  .controls .btn { flex: 1 1 0; min-width: 0; padding: 0 6px; }
  .controls .btn .lbl { display: none; }
  .controls .btn .ico { display: inline; }
  .prog { flex: none; flex-direction: row; flex-wrap: wrap; align-items: baseline; gap: 0 8px; }
  .prog-label, .prog-desc, .prog-next { display: none; }
  .prog-title { font-size: 14px; flex: 1 1 0; min-width: 0; }
  .prog-time { font-size: 12px; flex: none; }
  .prog .bar { flex: 1 1 100%; margin: 4px 0 0; height: 3px; }
  .channels-head { margin-bottom: 4px; }
  .channels-head h2 { font-size: 16px; }
  .tiles { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .tile { flex-direction: row; align-items: center; gap: 12px; border-radius: 0; border: 0; border-bottom: 1px solid var(--divider); background: transparent; padding: 8px 4px; }
  .tile .t-top { width: 56px; height: 40px; flex: none; }
  .tile .t-num { display: none; }
  .tile .t-logo { max-width: 56px; max-height: 40px; }
  .tile .t-mono { width: 40px; height: 40px; font-size: 16px; border-radius: 10px; }
  .tile .t-fav { position: static; order: 3; }
  .tile .t-text { flex: 1; }
  .tile .t-group { display: none; }
  .tile.playing { border: 0; border-bottom: 1px solid var(--divider); border-left: 3px solid var(--red); padding: 8px 4px 8px 8px; }
  .empty { padding: 18px 14px; }
  .empty img { width: 40px; height: 40px; }
  .empty h3 { font-size: 18px; }
  .guide-head { gap: 6px; margin-bottom: 4px; }
  .guide-titles h2 { font-size: 16px; }
  .guide-titles .count, .clock { display: none; }
  .timebar { height: 28px; }
  .tb-slot { font-size: 12px; }
  .guide-nav { gap: 6px; }
  .guide-nav .btn { padding: 0 10px; font-size: 14px; }
  #gRefresh { display: none; }
  .g-chan { padding: 0 6px; gap: 6px; }
  .g-chan .g-num, .g-chan img, .g-chan .t-mono { display: none; }
  .g-chan .g-name { font-size: 13px; white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
  .g-cell { padding: 4px 8px; }
  .g-cell .c-title { font-size: 13px; }
  .segments { grid-template-columns: repeat(2, 1fr); }
  .sheet-inner { padding: 14px 14px 18px; }
  .donate .qr { width: 180px; height: 180px; }
}
@supports (height: 1dvh) { @media (max-width: 699px) { .screen { max-height: 30dvh; } } }
/* Short phones in portrait (iPhone SE and smaller Androids) */
@media (max-width: 699px) and (max-height: 760px) {
  .screen { max-height: 26vh; }
  .titles .profile { display: none; }
  .now { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px 8px; align-items: center; }
  .now-head { grid-column: 1; grid-row: 1; }
  .controls { grid-column: 2; grid-row: 1; gap: 4px; }
  .controls .btn { flex: none; width: 36px; min-width: 36px; padding: 0; }
  #btnStop { display: none; }
  .prog, .now-note { grid-column: 1 / -1; }
  .guide-nav .btn { min-height: 32px; }
  .cat { min-height: 32px; padding: 4px 12px; }
  .timebar { height: 24px; }
  .now { padding: 8px 10px; }
  .g-row { height: 50px; margin-bottom: 4px; }
}
@supports (height: 1dvh) { @media (max-width: 699px) and (max-height: 760px) { .screen { max-height: 26dvh; } } }

/* Very short portrait screens (small phones with the browser's bars showing) */
@media (max-width: 699px) and (max-height: 620px) {
  .screen { max-height: 22vh; }
  .search { min-height: 36px; }
  .now-note { -webkit-line-clamp: 1; }
  .prog .bar { display: none; }
  .channels-head { margin-bottom: 2px; }
  .body { gap: 6px; }
}
@supports (height: 1dvh) { @media (max-width: 699px) and (max-height: 620px) { .screen { max-height: 22dvh; } } }

/* Very small phones */
@media (max-width: 360px) {
  .titles .profile { display: none; }
  .actions .btn { min-width: 38px; padding: 0 8px; }
}

/* Phones in landscape (short screens): preview on the left, list on the right */
@media (orientation: landscape) and (max-height: 560px) {
  :root { --pad: 14px; --gap: 10px; --btn-h: 38px; --g-chan: 120px; --g-row: 50px; }
  .app { padding-top: calc(6px + var(--safe-t)); padding-bottom: calc(4px + var(--safe-b)); }
  .top { flex-wrap: nowrap; gap: 8px; }
  .brand .leaf { width: 30px; height: 30px; }
  .titles .name { font-size: 18px; }
  .titles .profile { font-size: 12px; }
  .search { order: 0; flex: 0 1 200px; width: 200px; min-height: 38px; }
  .actions { gap: 6px; }
  .actions .btn .lbl { display: none; }
  .actions .btn .ico { display: inline; }
  .actions .btn { min-width: 38px; padding: 0 10px; }
  .status { margin-top: 4px; font-size: 13px; }
  .body {
    margin-top: 8px;
    grid-template-columns: minmax(0, 46fr) minmax(0, 54fr);
    grid-template-rows: auto minmax(0, 1fr);
    grid-template-areas: "stage rail" "stage list";
  }
  .rail { flex-direction: row; overflow-x: auto; overflow-y: hidden; padding: 0 0 2px; gap: 6px; scrollbar-width: none; }
  .rail::-webkit-scrollbar { display: none; }
  .rail:empty { display: none; }
  .cat { min-height: 34px; padding: 5px 12px; border-radius: 999px; background: var(--surface2); }
  .cat .cat-name { font-size: 13px; max-width: 150px; }
  .cat .cat-count { display: none; }
  .stage { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto auto; gap: 8px; min-height: 0; overflow-y: auto; overscroll-behavior: contain; align-content: start; scrollbar-width: none; }
  .stage::-webkit-scrollbar { display: none; }
  .now-note { font-size: 12px; }
  .screen { height: auto; width: 100%; max-width: 100%; max-height: 58vh; border-radius: 12px; }
  .now { height: auto; max-height: none; min-height: 0; padding: 8px 10px; gap: 6px; border-radius: 12px; }
  .now-logo { display: none; }
  .now-name { font-size: 15px; }
  .now-group { display: none; }
  .controls { flex-wrap: nowrap; gap: 6px; }
  .controls .btn { flex: 1 1 0; min-width: 0; padding: 0 6px; }
  .controls .btn .lbl { display: none; }
  .controls .btn .ico { display: inline; }
  .prog { gap: 1px; }
  .prog-label, .prog-desc, .prog-next, .bar { display: none; }
  .prog-title { font-size: 13px; }
  .prog-time { font-size: 12px; }
  .channels-head { margin-bottom: 4px; }
  .channels-head h2 { font-size: 15px; }
  .tiles { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .tile { flex-direction: row; align-items: center; gap: 10px; border-radius: 0; border: 0; border-bottom: 1px solid var(--divider); background: transparent; padding: 6px 4px; }
  .tile .t-top { width: 48px; height: 34px; flex: none; }
  .tile .t-num { display: none; }
  .tile .t-logo { max-width: 48px; max-height: 34px; }
  .tile .t-mono { width: 34px; height: 34px; font-size: 14px; border-radius: 8px; }
  .tile .t-fav { position: static; order: 3; }
  .tile .t-text { flex: 1; }
  .tile .t-group { display: none; }
  .tile.playing { border: 0; border-bottom: 1px solid var(--divider); border-left: 3px solid var(--red); padding: 6px 4px 6px 8px; }
  .empty { padding: 12px; gap: 4px; }
  .empty img { display: none; }
  .empty h3 { font-size: 16px; margin: 0; }
  .empty p { font-size: 13px; }
  .empty .small { display: none; }
  .guide-head { gap: 6px; margin-bottom: 4px; }
  .guide-titles h2 { font-size: 15px; }
  .guide-titles .count, .clock, #gRefresh { display: none; }
  .guide-nav .btn { padding: 0 10px; font-size: 13px; }
  .timebar { height: 28px; }
  .tb-slot { font-size: 12px; }
  .tb-slot:nth-child(even) { color: transparent; }
  .g-chan { padding: 0 6px; }
  .g-chan .g-num, .g-chan img, .g-chan .t-mono { display: none; }
  .g-chan .g-name { font-size: 12px; white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
  .g-cell { padding: 3px 8px; }
  .g-cell .c-title { font-size: 13px; }
  .g-cell .c-time { font-size: 11px; }
}
@supports (height: 1dvh) { @media (orientation: landscape) and (max-height: 560px) { .screen { max-height: 58dvh; } } }

/* Very short landscape (small phones): drop the profile line */
@media (orientation: landscape) and (max-height: 400px) {
  .titles .profile { display: none; }
  .status { display: none; }
}

/* Big screens: more room for the preview */
@media (min-width: 1600px) and (min-height: 900px) {
  :root { --rail-w: 250px; --pv-h: clamp(200px, 38vh, 520px); --g-chan: 240px; --g-row: 70px; }
}
