/*
 * Base styles: design tokens, reset, shared widgets (buttons, fields, lists, modals, legend).
 * Everything is sized in rem; main.js sets html{font-size} from the viewport (16px at 1080p-high),
 * so the UI scales to any resolution / aspect ratio. A later design pass restyles via these tokens.
 */
:root {
  /* colours */
  --c-bg: #0d1117;
  --c-bg-2: #161b22;
  --c-panel: #1c2330;
  --c-panel-2: #253042;
  --c-fg: #e8edf4;
  --c-muted: #8b98a9;
  --c-dim: #5b6676;
  --c-accent: #3d8bff;
  --c-accent-fg: #ffffff;
  --c-focus: #ffd23f;
  --c-focus-bg: #2f4a75;
  --c-selected: #24364f;
  --c-live: #e5484d;
  --c-ok: #3fb950;
  --c-warn: #d29922;
  --c-error: #ff6b6b;
  --c-red: #e5484d;
  --c-green: #3fb950;
  --c-yellow: #f2c94c;
  --c-blue: #3d8bff;
  --c-overlay: rgba(0, 0, 0, 0.72);
  --c-line: #2d3748;

  /* type */
  --font: "Samsung One", "SamsungOneUI", "Tizen Sans", "Roboto", "Segoe UI", Arial, sans-serif;
  --fs-xs: 1.05rem;           /* type scale bumped in the scaling pass: fs-s = 18 px at 1080, 24 px at 1440 */
  --fs-s: 1.125rem;
  --fs-m: 1.3rem;
  --fs-l: 1.65rem;
  --fs-xl: 2.25rem;
  --fs-xxl: 3rem;

  /* spacing */
  --sp-1: 0.375rem;
  --sp-2: 0.75rem;
  --sp-3: 1.25rem;
  --sp-4: 2rem;
  --sp-5: 3rem;

  /* geometry */
  --radius: 0.4rem;
  --focus-w: 0.25rem;
  --row-h: 4.25rem;
  --cat-h: 3rem;
  /* fluid widths: the rem minimum is the 1080p layout; wider windows give panels more room, capped in rem */
  --sidebar-w: clamp(20rem, 13vw, 26rem);
  --info-w: clamp(28rem, 22vw, 56rem);
  --poster-w: 11rem;
  --poster-h: 16.5rem;
  --tile-w: clamp(17rem, 8.4vw, 24rem);
  --tile-h: 11rem;
  --logo-w: 5rem;
  --header-h: 4.5rem;
  --legend-h: 3rem;
  --epg-chan-w: clamp(17rem, 11vw, 24rem);
  --epg-row-h: 4rem;
  --gutter: 2.5rem;           /* outer safe margin */
  --scroll-ms: 120ms;         /* virtual-list smooth scroll duration */

  /* set at runtime by main.js */
  --screen-w: 100vw;
  --screen-h: 100vh;
  --ui-scale: 1;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; width: 100%; height: 100%; overflow: hidden;
  background: var(--c-bg); color: var(--c-fg);
  font-family: var(--font); font-size: 16px; line-height: 1.25;   /* html font-size is set by js/ui/ui-scale.js */
  -webkit-user-select: none; user-select: none;
  cursor: default;
}
/* The page background lives on <body> only: when <html> is transparent the body background is used for the
   whole canvas, so body.is-playing { background: transparent } makes the page see-through and the video plane
   behind it (Tizen AVPlay plane / desktop mpv window) becomes visible. An opaque <html> would cover it. */
html { background: transparent; }
body { font-size: 1rem; }
img { display: block; }

/* video plane sits behind the web layer */
#video-layer { position: fixed; left: 0; top: 0; width: 100%; height: 100%; z-index: 0; background: #000; overflow: hidden; }
#video-layer video, #video-layer object { position: absolute; left: 0; top: 0; width: 100%; height: 100%; }
#app { position: fixed; left: 0; top: 0; width: 100%; height: 100%; z-index: 1; background: var(--c-bg); overflow: hidden; }
body.is-playing, body.is-playing #app { background: transparent; }
#screens { position: absolute; inset: 0; }
#overlay-root { position: absolute; inset: 0; pointer-events: none; z-index: 50; }
#overlay-root > * { pointer-events: auto; }

.is-hidden { display: none !important; }

/* ---------- screens ---------- */
.screen { position: absolute; inset: 0; display: none; flex-direction: column; padding: 0 var(--gutter); }
.screen.is-active { display: flex; }
.screen__header { flex: 0 0 var(--header-h); display: flex; align-items: center; gap: var(--sp-3); }
.screen__title { font-size: var(--fs-xl); font-weight: 600; white-space: nowrap; }
.screen__sub { flex: 1 1 auto; font-size: var(--fs-m); color: var(--c-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.screen__clock { font-size: var(--fs-l); color: var(--c-muted); font-variant-numeric: tabular-nums; }
.screen__legend { flex: 0 0 var(--legend-h); display: flex; align-items: center; }

/* ---------- focus ---------- */
.is-focused {
  outline: var(--focus-w) solid var(--c-focus);
  outline-offset: calc(var(--focus-w) * -1);
  background-color: var(--c-focus-bg) !important;
}

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 3.25rem; padding: 0 var(--sp-3); border-radius: var(--radius);
  background: var(--c-panel-2); color: var(--c-fg); font-size: var(--fs-m); white-space: nowrap;
}
.btn--primary { background: var(--c-accent); color: var(--c-accent-fg); }
.btn--toggle.is-selected { box-shadow: inset 0 -0.25rem 0 var(--c-accent); }
.btn.is-focused { outline-offset: 0; }

/* ---------- text fields ---------- */
.field { display: flex; flex-direction: column; gap: var(--sp-1); padding: var(--sp-2); border-radius: var(--radius); background: var(--c-panel); }
.field__label { font-size: var(--fs-s); color: var(--c-muted); }
.field__input {
  font: inherit; font-size: var(--fs-m); color: var(--c-fg); background: var(--c-bg-2);
  border: 0.125rem solid var(--c-line); border-radius: var(--radius); padding: var(--sp-2); width: 100%; outline: none;
}
.field__input:focus { border-color: var(--c-focus); background: #000; }

/* ---------- virtual list ---------- */
.vlist { position: relative; overflow: hidden; }
.vlist__track {
  position: absolute; left: 0; top: 0; right: 0; height: 0;
  transition: transform var(--scroll-ms) ease-out; will-change: transform;
}
.vlist__track--jump { transition: none; }
.vlist__item { position: absolute; left: 0; top: 0; contain: layout style; }
.vlist:not(.vlist--grid) .vlist__item { right: 0; }
.vlist__empty { position: absolute; left: 0; right: 0; top: 30%; text-align: center; color: var(--c-muted); font-size: var(--fs-l); }

/* ---------- sidebar / categories ---------- */
.sidebar { background: var(--c-bg-2); border-radius: var(--radius); }
.cat-item {
  height: var(--cat-h); display: flex; align-items: center; gap: var(--sp-2); padding: 0 var(--sp-3);
  font-size: var(--fs-m); color: var(--c-muted); border-radius: var(--radius);
}
.cat-item__name { flex: 1 1 auto; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cat-item__count { font-size: var(--fs-s); color: var(--c-dim); }
.cat-item.is-selected { color: var(--c-fg); background: var(--c-selected); box-shadow: inset 0.3rem 0 0 var(--c-accent); }
.cat-item.is-focused { color: var(--c-fg); }

/* ---------- legend ---------- */
.legend { gap: var(--sp-4); font-size: var(--fs-s); color: var(--c-muted); }
.legend__item { display: inline-flex; align-items: center; gap: var(--sp-1); white-space: nowrap; }
.legend__key {
  display: inline-flex; align-items: center; justify-content: center; min-width: 1.6rem; height: 1.6rem;
  padding: 0 0.3rem; border-radius: 0.3rem; background: var(--c-panel-2); color: var(--c-fg); font-size: var(--fs-xs); font-weight: 700;
}
.legend__key--red { background: var(--c-red); }
.legend__key--green { background: var(--c-green); }
.legend__key--yellow { background: var(--c-yellow); color: #000; }
.legend__key--blue { background: var(--c-blue); }
.legend__key--ok:empty::before { content: "OK"; }
.legend__key--back:empty::before { content: "\21A9"; }
.legend__key--arrows:empty::before { content: "\2190\2191\2192\2193"; }
.legend__key--left:empty::before { content: "\2190"; }
.legend__key--right:empty::before { content: "\2192"; }

/* ---------- modals ---------- */
.modal { position: absolute; inset: 0; background: var(--c-overlay); display: flex; align-items: center; justify-content: center; }
.modal__panel {
  min-width: 28rem; max-width: min(60rem, 80vw); max-height: 80vh; display: flex; flex-direction: column; gap: var(--sp-3);
  padding: var(--sp-4); background: var(--c-panel); border-radius: calc(var(--radius) * 2); border: 0.125rem solid var(--c-line);
}
.modal__title { font-size: var(--fs-l); font-weight: 600; }
.modal__msg { font-size: var(--fs-m); color: var(--c-muted); white-space: pre-line; max-height: 30vh; overflow: hidden; }
.menu__list { overflow: hidden; display: flex; flex-direction: column; gap: var(--sp-1); }
.menu__item {
  flex: 0 0 auto; display: flex; align-items: center; gap: var(--sp-3); min-height: 3.25rem; padding: 0 var(--sp-3);
  border-radius: var(--radius); font-size: var(--fs-m); background: var(--c-bg-2);
}
.menu__label { flex: 1 1 auto; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.menu__sub { color: var(--c-muted); font-size: var(--fs-s); }
.menu__item.is-active .menu__label::before { content: "\2713  "; color: var(--c-accent); }
.confirm__buttons { display: flex; gap: var(--sp-3); justify-content: flex-end; }
.progress { min-width: 36rem; }
.progress__text { font-size: var(--fs-m); color: var(--c-muted); }
.progress__bar { height: 0.6rem; background: var(--c-bg-2); border-radius: 0.3rem; overflow: hidden; }
.progress__fill { height: 100%; width: 100%; background: var(--c-accent); transform-origin: 0 50%; transition: transform 200ms linear; }
.progress__bar.is-indeterminate .progress__fill { animation: progress-indet 1.4s linear infinite; }
@keyframes progress-indet { from { transform: translateX(-30%) scaleX(0.3); } to { transform: translateX(100%) scaleX(0.3); } }

.toast {
  position: absolute; left: 50%; bottom: calc(var(--legend-h) + var(--sp-4)); transform: translateX(-50%);
  max-width: 70vw; padding: var(--sp-2) var(--sp-4); border-radius: var(--radius);
  background: var(--c-panel-2); color: var(--c-fg); font-size: var(--fs-m); border: 0.125rem solid var(--c-line);
}
.num-entry {
  position: absolute; right: var(--gutter); top: var(--sp-4); min-width: 8rem; padding: var(--sp-2) var(--sp-4);
  text-align: right; font-size: var(--fs-xxl); font-weight: 700; font-variant-numeric: tabular-nums;
  background: var(--c-panel); color: var(--c-focus); border-radius: var(--radius); border: 0.125rem solid var(--c-focus);
}
.dev-tag {
  position: fixed; right: 0; bottom: 0; z-index: 100; padding: 0.15rem 0.5rem; font-size: var(--fs-xs); font-weight: 700;
  background: var(--c-warn); color: #000; pointer-events: none;
}

/* ---------- mouse (js/ui/pointer.js; body.has-pointer is never set on Tizen) ---------- */
.has-pointer .vlist__item, .has-pointer .tile, .has-pointer .menu__item, .has-pointer .btn,
.has-pointer .saved-row, .has-pointer .set-row, .has-pointer .season-item, .has-pointer .ep-row,
.has-pointer .is-clickable { cursor: pointer; }
.has-pointer .field__input { cursor: text; }
body.is-cursor-hidden, body.is-cursor-hidden * { cursor: none !important; }

/* Missing-artwork placeholder: the title on a tinted card (App.UI.placeholder). Shown only when the card has no image. */
.ph-title {
  position: absolute; inset: 0; display: none; align-items: center; justify-content: center; text-align: center;
  padding: 0.6em; overflow: hidden; color: var(--c-fg); font-weight: 600; font-size: var(--fs-s); line-height: 1.2;
  background: linear-gradient(160deg, hsl(var(--ph-h, 210), 28%, 26%), hsl(var(--ph-h, 210), 30%, 14%));
  border-radius: inherit; word-break: break-word;
}
.is-noimg > .ph-title { display: flex; }
.is-noimg > img { visibility: hidden; }

/* Desktop custom title bar (js/platform/desktop/platform.js). Windows draws minimise / maximise / close on the right
   (Windows Controls Overlay); env(titlebar-area-*) is the free area left of them. The app starts below the strip. */
body.has-titlebar { --titlebar-h: var(--titlebar-px, 36px); }
body.has-titlebar.is-fullscreen { --titlebar-h: 0px; }
body.has-titlebar #app, body.has-titlebar #video-layer { top: var(--titlebar-h); height: auto; bottom: 0; }
.titlebar {
  position: fixed; left: 0; top: 0; z-index: 1000; height: var(--titlebar-h, 36px);
  width: env(titlebar-area-width, calc(100% - 138px));     /* stops where the caption buttons start */
  display: flex; align-items: center; gap: 10px; padding-left: 12px; box-sizing: border-box;
  background: var(--c-bg); color: var(--c-fg); font-size: 13px; /* fixed px: matches the native caption buttons, not the UI scale */
  -webkit-app-region: drag; user-select: none;
}
body.is-fullscreen .titlebar { display: none; }
.titlebar__icon { width: 16px; height: 16px; border-radius: 3px; background: var(--c-accent); flex: 0 0 auto; }
.titlebar__title { flex: 1 1 auto; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; opacity: 0.85; }
.titlebar__back {
  -webkit-app-region: no-drag; flex: 0 0 auto; width: 46px; height: 100%; border: 0; margin: 0; padding: 0;
  background: transparent; color: var(--c-fg); font-size: 16px; line-height: 1; cursor: pointer;
}
.titlebar__back:hover { background: rgba(255, 255, 255, 0.10); }
.titlebar__back:active { background: rgba(255, 255, 255, 0.18); }
.titlebar__back:disabled { opacity: 0.3; cursor: default; background: transparent; }
body.is-mini .titlebar__back { display: none; }

/* Desktop Back button (normal Windows title bar): pinned top-right in the app's header row. */
.app-back {
  position: fixed; top: calc(var(--titlebar-h, 0px) + var(--sp-3, 1rem)); right: var(--sp-3, 1rem); z-index: 900;
  width: 2.75rem; height: 2.75rem; border-radius: 0.5rem; border: 1px solid var(--c-line, #2d3748);
  background: var(--c-panel); color: var(--c-fg); font-size: var(--fs-l); line-height: 1; cursor: pointer;
}
.app-back:hover { border-color: var(--c-focus); }
.app-back:disabled { opacity: 0.35; cursor: default; border-color: var(--c-line, #2d3748); }
body[data-screen="player"] .app-back, body.is-fullscreen .app-back, body.is-mini .app-back { display: none; }
/* keep the header's right side (clock) clear of the button */
body.has-app-back .screen__header { padding-right: calc(var(--sp-3, 1rem) + 3.5rem); }
