/* Roya TV — phone and installed-app behaviour (Android / iOS). Loaded last.
   Platform rules only: safe areas, touch behaviour, the mini player, the install card. No component restyling. */

/* ---------- safe areas (notch, status bar, home indicator) ---------- */
:root {
  --sa-t: env(safe-area-inset-top, 0px);
  --sa-b: env(safe-area-inset-bottom, 0px);
  --sa-l: env(safe-area-inset-left, 0px);
  --sa-r: env(safe-area-inset-right, 0px);
  --kb: 0px;
  /* same values as brand.css / app.css, grown by the device insets: every rule that uses them follows */
  --nav-h: calc(64px + var(--sa-t));
  --gutter: max(clamp(16px, 4vw, 56px), var(--sa-l), var(--sa-r));
}
@media (max-width: 960px) { :root { --nav-h: calc(58px + var(--sa-t)); } }
html { background: #050609; -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
.nav { padding-top: var(--sa-t); box-sizing: border-box; }
/* installed app: the status bar sits on top of the page, keep it readable while content scrolls under it */
.is-standalone body::before {
  content: ""; position: fixed; z-index: 49; inset: 0 0 auto; height: var(--sa-t); pointer-events: none;
  background: linear-gradient(rgba(5, 6, 9, 0.9), rgba(5, 6, 9, 0.55));
}

/* player (brand.css already pads .p-bottom for the home indicator on phones) */
.p-top { padding-top: max(22px, calc(var(--sa-t) + 8px)); }
@media (max-width: 720px) { .p-top { padding-top: max(12px, calc(var(--sa-t) + 4px)); } }
@media (min-width: 721px) { .p-bottom { padding-bottom: max(26px, calc(var(--sa-b) + 10px)); } }
.player.is-youtube .p-top { height: auto; min-height: 64px; padding-top: max(10px, var(--sa-t)); }
.zap header { padding-top: calc(18px + var(--sa-t)); }
.zap .list { padding-bottom: calc(20px + var(--sa-b)); }
.zap-entry { top: calc(24px + var(--sa-t)); }
/* radio now-playing screen */
.ra-stage { padding-top: calc(84px + var(--sa-t)); padding-bottom: calc(40px + var(--sa-b)); }
@media (max-height: 620px) and (max-aspect-ratio: 5/4) { .ra-stage { padding-top: calc(70px + var(--sa-t)); } }
/* full-screen search on phones: the field clears the status bar */
@media (max-width: 720px) { .pal-input { padding-top: calc(16px + var(--sa-t)); } }
@media (min-width: 961px) { .radio-mini { bottom: calc(18px + var(--sa-b)); } }

/* ---------- touch behaviour ---------- */
html { -webkit-tap-highlight-color: transparent; }
a, button, [role="button"], [role="tab"], [role="menuitemradio"], summary, label, input, select, textarea,
.btn, .chip, .icon-btn, .pcard, .ccard, .scard, .rcard-radio, .zrow, .eps-row, .tabbar a, [data-play], [data-open], [tabindex] {
  touch-action: manipulation; /* no 300 ms delay, no double-tap zoom on controls */
  -webkit-tap-highlight-color: transparent;
}
/* controls and cards are not text: no selection handles, no long-press image menu */
.nav, .tabbar, .btn, .chip, .icon-btn, .pcard, .ccard, .scard, .rcard-radio, .zrow, .eps-row, .player .p-ui, .radio-art, .radio-mini,
.rmini, .install-card, .bb-side, .rail-head, [data-scroll] {
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}
.pcard img, .ccard img, .scard img, .rcard-radio img, .logo-tile img, .zlogo img, .eps-thumb img, .art img, .roya-logo img, .radio-art img, .radio-mini img, .tabbar svg {
  -webkit-user-drag: none; -webkit-touch-callout: none; pointer-events: none;
}
input, textarea, [contenteditable] { -webkit-user-select: text; user-select: text; }

/* iOS zooms the page when a focused field is under 16px */
@media (hover: none) and (pointer: coarse) {
  /* :where() keeps this at zero specificity: fields the design already sizes at 16px or more are left alone */
  :where(input:not([type="range"]):not([type="checkbox"]):not([type="radio"]), select, textarea) { font-size: 16px; }
  .ra-inline input, .mv-cell select { font-size: 16px; } /* the two fields styled below 16px */
}

/* no rubber-band or page scroll behind fixed layers; momentum scrolling inside them */
html, body { overscroll-behavior-y: none; }
.overlay, .dialog, .palette, .rq-modal, .trailer-modal, .fb-sheet-wrap, .zap .list, .radio-art, .p-menu, .epg-scroll, .ra-sleep-menu {
  overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
}
.rail-track, .chips, .eps-seasons { -webkit-overflow-scrolling: touch; overscroll-behavior-x: contain; }
.watch, .player { overscroll-behavior: none; touch-action: manipulation; }
.p-seek, .p-vol input, .ra-range { touch-action: none; } /* dragging a slider never scrolls the page */
@media (hover: none) and (pointer: coarse) { .p-seek { height: 32px; } }

/* on-screen keyboard: fixed sheets end above it, so the focused field stays in view (--kb is set by js/mobile.js) */
.kb-open .overlay, .kb-open .palette, .kb-open .rq-modal, .kb-open .fb-sheet-wrap { padding-bottom: calc(var(--kb) + 12px); }
.kb-open .tabbar, .kb-open .radio-mini, .kb-open .rmini, .kb-open .install-card { display: none; }
input, textarea, select { scroll-margin-block: 96px; }

/* ---------- player on a phone held sideways ---------- */
.watch { height: 100vh; height: 100dvh; }
.watch.rmini { height: auto; }
@media (orientation: landscape) and (max-height: 520px) {
  .p-top { padding-top: max(8px, var(--sa-t)); padding-bottom: 28px; }
  .p-bottom { padding-top: 34px; padding-bottom: max(8px, var(--sa-b)); }
  .p-controls { margin-top: 2px; }
  .p-controls .icon-btn { width: 42px; height: 42px; }
  .osd { bottom: 92px; }
  .osd .osd-num { font-size: 2.2rem; padding: 8px 12px; }
  .p-menu { bottom: 72px; max-height: calc(100dvh - 96px); overflow-y: auto; }
  .player.is-youtube .p-top { min-height: 48px; padding-block: max(4px, var(--sa-t)) 4px; }
  .ra-stage { padding-top: calc(60px + var(--sa-t)); padding-bottom: calc(16px + var(--sa-b)); }
}
/* full screen: black to the edges, video inside the safe area */
.player:fullscreen { width: 100vw; height: 100vh; height: 100dvh; }
.player:fullscreen video { object-fit: contain; }
.player.in-pip > video { opacity: 0.25; }

/* ---------- mini player (video keeps playing while browsing) ---------- */
.watch.rmini {
  inset: auto; inset-inline-end: max(12px, var(--sa-r), var(--sa-l)); bottom: calc(18px + var(--sa-b));
  width: clamp(200px, 30vw, 380px); aspect-ratio: 16 / 9; z-index: 92; display: block;
  border-radius: 14px; overflow: hidden; background: #000;
  box-shadow: 0 18px 44px -12px rgba(0, 0, 0, 0.85), 0 0 0 1px rgba(255, 255, 255, 0.14);
  animation: rminiIn 0.32s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}
@keyframes rminiIn { from { opacity: 0; transform: translateY(18px) scale(0.92); } }
@media (max-width: 960px) {
  .watch.rmini { width: min(58vw, 250px); bottom: calc(76px + var(--sa-b)); }
}
@media (max-width: 960px) and (orientation: landscape) and (max-height: 520px) {
  .watch.rmini { width: min(34vw, 240px); }
}
.watch.rmini .player { cursor: default; }
.watch.rmini .player > video { object-fit: cover; }
.watch.rmini .p-ui, .watch.rmini .osd, .watch.rmini .zap, .watch.rmini .zap-entry, .watch.rmini .p-error,
.watch.rmini .p-flash, .watch.rmini .radio-art, .watch.rmini .curtain, .watch.rmini .p-slow { display: none !important; }
.watch.rmini .p-spinner { width: 30px; height: 30px; border-width: 3px; }
.rmini-ui { position: absolute; inset: 0; z-index: 30; display: grid; grid-template: "x . e" 40px ". p ." 1fr "t t t" auto / 40px 1fr 40px; align-items: center; justify-items: center; color: #fff;
  background: linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0) 38%, rgba(0, 0, 0, 0) 55%, rgba(0, 0, 0, 0.72)); }
.rmini-open { position: absolute; inset: 0; z-index: 0; background: none; border: 0; padding: 0; cursor: pointer; }
.rmini-btn { position: relative; z-index: 1; width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; border: 0; padding: 0; color: #fff; background: rgba(8, 9, 13, 0.55); -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px); cursor: pointer; }
.rmini-btn svg { width: 18px; height: 18px; }
.rmini-x { grid-area: x; }
.rmini-play { grid-area: p; width: 44px; height: 44px; }
.rmini-play svg { width: 22px; height: 22px; }
.rmini-expand { grid-area: e; position: relative; z-index: 1; pointer-events: none; display: grid; place-items: center; opacity: 0.9; }
.rmini-expand svg { width: 16px; height: 16px; }
.rmini-title { grid-area: t; position: relative; z-index: 1; pointer-events: none; justify-self: stretch; padding: 0 10px 7px; font-size: 12px; font-weight: 600; line-height: 1.5; text-align: start; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-shadow: 0 1px 4px rgba(0, 0, 0, 0.9); }
@media (hover: hover) and (pointer: fine) {
  .watch.rmini:not(.is-paused) .rmini-play { opacity: 0; transition: opacity 0.2s; }
  .watch.rmini:hover .rmini-play, .rmini-play:focus-visible { opacity: 1; }
}
.rmini-btn:focus-visible, .rmini-open:focus-visible { outline: 2px solid #fff; outline-offset: -2px; }
body.has-video-mini .toasts { bottom: calc(190px + var(--sa-b)); }
@media (max-width: 960px) { body.has-video-mini .toasts { bottom: calc(240px + var(--sa-b)); } }

/* ---------- install card ---------- */
.install-card {
  position: fixed; z-index: 94; inset-inline: 0; bottom: calc(18px + var(--sa-b)); margin-inline: auto;
  width: min(520px, calc(100% - 24px)); box-sizing: border-box; display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 4px 12px; align-items: center;
  padding: 14px; border-radius: 18px; color: #eceef3;
  background: rgba(16, 18, 26, 0.86); -webkit-backdrop-filter: blur(22px) saturate(160%); backdrop-filter: blur(22px) saturate(160%);
  border: 1px solid rgba(255, 255, 255, 0.12); box-shadow: 0 24px 60px -18px rgba(0, 0, 0, 0.9);
  opacity: 0; transform: translateY(24px); pointer-events: none; transition: opacity 0.35s ease, transform 0.35s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.install-card.show { opacity: 1; transform: none; pointer-events: auto; }
@media (max-width: 960px) { .install-card { bottom: calc(80px + var(--sa-b)); } }
body.has-radio-mini .install-card, body.has-video-mini .install-card { display: none; }
.ins-icon { width: 52px; height: 52px; border-radius: 13px; box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.12); }
.ins-txt { min-width: 0; }
.ins-txt b { display: block; font-size: 15px; font-weight: 700; line-height: 1.5; }
.ins-txt p { margin: 2px 0 0; font-size: 13px; line-height: 1.7; color: #a9adba; }
.ins-txt p span { color: #eceef3; font-weight: 600; }
.ins-share { display: inline-block; width: 18px; height: 18px; vertical-align: -4px; margin-inline: 2px; color: #fff; }
.ins-act { grid-column: 1 / -1; display: flex; gap: 8px; justify-content: flex-end; margin-top: 6px; }
.ins-act button { min-height: 44px; padding: 0 20px; border-radius: 999px; border: 0; font: inherit; font-size: 14px; font-weight: 700; cursor: pointer; }
.ins-go { background: var(--red, #e11d2a); color: #fff; }
.ins-x { background: rgba(255, 255, 255, 0.08); color: #eceef3; }
.ins-act button:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }

/* ---------- offline notice ---------- */
.net-pill {
  position: fixed; z-index: 210; top: calc(10px + var(--sa-t)); inset-inline: 0; margin-inline: auto; width: max-content; max-width: calc(100% - 32px);
  padding: 8px 16px; border-radius: 999px; font-size: 13px; font-weight: 600; color: #fff; background: rgba(30, 32, 42, 0.94); border: 1px solid rgba(255, 255, 255, 0.14);
  opacity: 0; transform: translateY(-12px); pointer-events: none; transition: opacity 0.3s, transform 0.3s;
}
.net-pill.show { opacity: 1; transform: none; }

/* ---------- reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  .watch.rmini { animation: none; }
  .install-card, .net-pill, .rmini-play { transition: none; }
  html { scroll-behavior: auto; }
}
@media print { .rmini, .install-card, .net-pill { display: none !important; } }
