/* =========================================================
   Multiview – 4 maty na żywo
   Układ sterowany WYŁĄCZNIE atrybutami:
     #app[data-layout="grid|focus|mobile"]
     #app[data-viewport="desktop|phone-portrait|phone-landscape"]
     .tile[data-slot="0..3 | main | hidden"]
   Kafelki są pozycjonowane absolutnie w procentach, więc zmiana
   układu to płynna animacja top/left/width/height – iframe'y
   YouTube zostają na swoim miejscu w DOM i nie przeładowują się.
   ========================================================= */

:root {
  --bg: #0a0d13;
  --surface: #131923;
  --surface-2: #1a2230;
  --border: #253043;
  --text: #eef2f7;
  --muted: #8d98ab;
  --accent: #e5202f;
  --live: #ff2d3d;
  --warn: #f2b53c;
  --gap: 6px;
  --radius: 10px;
  --bar-h: 36px;
  --ease: cubic-bezier(.4, 0, .2, 1);
  --dur: .45s;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Barlow', system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
button { font: inherit; color: inherit; }
svg { width: 1.2em; height: 1.2em; fill: currentColor; flex: none; }

.app {
  min-height: 100dvh; display: flex; flex-direction: column;
  --chrome: calc(var(--header-h, 64px) + 64px); /* nagłówek (mierzy JS) + footer 40px + paddingi stage 24px */
}

/* ---------- Header ---------- */
.header {
  min-height: 64px; flex: none;
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px 12px;
  padding: 6px 20px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, #121823, #0d1118);
}
.header__brand { display: flex; align-items: center; gap: 14px; min-width: 0; flex: 1 1 160px; }
.header__text { min-width: 0; }
.header__logo { height: 40px; width: auto; }
.header__title {
  margin: 0; font-family: 'Barlow Condensed', 'Barlow', sans-serif;
  font-weight: 800; font-size: 26px; line-height: 1; letter-spacing: .02em; text-transform: uppercase;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.header__title-short { display: none; }
.header__sub { margin: 3px 0 0; color: var(--muted); font-size: 13px; }
.header__actions { display: flex; gap: 8px; flex: none; margin-left: auto; }

.btn {
  display: inline-flex; align-items: center; gap: 8px;
  height: 38px; padding: 0 14px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface);
  cursor: pointer; font-weight: 600; font-size: 14px; letter-spacing: .01em;
  transition: background .15s, border-color .15s;
}
.btn:hover { background: var(--surface-2); border-color: #334057; }
.btn:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
.btn[aria-pressed="true"] { border-color: var(--accent); color: #fff; background: #2a1419; }
.btn--mobile-only { display: none; }
[data-viewport="phone-portrait"] .btn--mobile-only,
[data-viewport="phone-landscape"] .btn--mobile-only { display: inline-flex; }
#btnMute .icon-on { display: none; }
#btnMute[aria-pressed="true"] .icon-on { display: block; }
#btnMute[aria-pressed="true"] .icon-off { display: none; }

/* ---------- Zakładki (tylko telefon w pionie) ---------- */
.tabs { display: none; flex: none; border-bottom: 1px solid var(--border); background: #0d1118; }
.tab {
  flex: 1; height: 44px; border: 0; background: none; cursor: pointer;
  font-family: 'Barlow Condensed', sans-serif; font-weight: 700; font-size: 17px; letter-spacing: .04em;
  color: var(--muted); border-bottom: 3px solid transparent;
}
.tab[aria-selected="true"] { color: #fff; border-bottom-color: var(--tab-color, var(--accent)); }

/* ---------- Scena ---------- */
.stage {
  flex: 1; min-height: 0; position: relative;
  display: flex; align-items: center; justify-content: center;
  padding: 12px;
}
.multiview {
  position: relative;
  width: min(100%, calc((100dvh - var(--chrome)) * 16 / 9));
  aspect-ratio: 16 / 9;
}

/* ---------- Kafelek ---------- */
.tile {
  position: absolute; padding: var(--gap);
  display: flex; flex-direction: column;
  transition:
    top var(--dur) var(--ease), left var(--dur) var(--ease),
    width var(--dur) var(--ease), height var(--dur) var(--ease),
    opacity .3s var(--ease);
  will-change: top, left, width, height;
}
.tile__inner {
  flex: 1; min-height: 0; display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden;
  transition: border-color .15s, box-shadow .15s;
}
.tile.has-audio .tile__inner { border-color: var(--mat-color); box-shadow: 0 0 0 1px var(--mat-color); }

/* Pasek z etykietą – NAD playerem, nie zasłania treści YouTube */
.tile__bar {
  flex: none; height: var(--bar-h);
  display: flex; align-items: center; gap: 10px; padding: 0 8px 0 12px;
  border-left: 4px solid var(--mat-color);
  background: linear-gradient(90deg, color-mix(in srgb, var(--mat-color) 18%, var(--surface)), var(--surface) 60%);
  transition: height var(--dur) var(--ease);
}
.tile__label {
  font-family: 'Barlow Condensed', sans-serif; font-weight: 800; font-size: 19px; letter-spacing: .06em;
  text-transform: uppercase; color: #fff; white-space: nowrap;
}
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  height: 20px; padding: 0 8px; border-radius: 4px;
  font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
  background: #2a3242; color: var(--muted); white-space: nowrap;
}
.badge::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge[data-status="live"] { background: var(--live); color: #fff; }
.badge[data-status="live"]::before { background: #fff; animation: pulse 1.2s ease-in-out infinite; }
.badge[data-status="buffering"] { background: #3a2f12; color: var(--warn); }
.badge[data-status="buffering"]::before { animation: pulse .8s ease-in-out infinite; }
.badge[data-status="offline"] { background: #2a3242; color: #b4bccb; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .25; } }

.tile__audio {
  margin-left: auto; width: 30px; height: 28px; border-radius: 6px;
  border: 1px solid transparent; background: none; cursor: pointer; color: var(--muted);
  display: inline-flex; align-items: center; justify-content: center;
}
.tile__audio:hover { background: var(--surface-2); color: #fff; }
.tile__audio[aria-pressed="true"] { color: #fff; background: var(--mat-color); }
.tile__audio .icon-on { display: none; }
.tile__audio[aria-pressed="true"] .icon-on { display: block; }
.tile__audio[aria-pressed="true"] .icon-off { display: none; }

/* Obszar playera – iframe zajmuje całość, nic go nie przycina */
.tile__player { position: relative; flex: 1; min-height: 0; background: #000; }
.tile__player iframe,
.tile__player > .player-slot { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; display: block; }

/* Przezroczysta warstwa klikalna – tylko w siatce i miniaturach */
.tile__click {
  position: absolute; inset: 0; z-index: 3;
  border: 0; background: transparent; cursor: pointer; padding: 0;
  display: flex; align-items: flex-end; justify-content: flex-end;
}
.tile__click span {
  margin: 10px; padding: 4px 10px; border-radius: 6px;
  background: rgba(10, 13, 19, .85); font-size: 12px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase;
  opacity: 0; transform: translateY(4px); transition: opacity .15s, transform .15s;
}
.tile__click:hover span, .tile__click:focus-visible span { opacity: 1; transform: none; }
.tile__click:focus-visible { outline: 2px solid #fff; outline-offset: -2px; }
.tile:has(.tile__click:hover) .tile__inner { border-color: var(--mat-color); }

/* Główny kafelek w FOCUS i widoczny kafelek na mobile: bez warstwy, działają kontrolki YT */
[data-layout="focus"] .tile[data-slot="main"] .tile__click,
[data-layout="mobile"] .tile[data-slot="main"] .tile__click { display: none; }

/* Komunikat zamiast czarnego ekranu */
.tile__offline {
  position: absolute; inset: 0; z-index: 2; display: none;
  flex-direction: column; align-items: center; justify-content: center; gap: 6px; padding: 16px; text-align: center;
  background: radial-gradient(ellipse at center, #1a2130, #0a0d13);
}
.tile.is-offline .tile__offline { display: flex; }
.tile__offline strong { font-family: 'Barlow Condensed', sans-serif; font-size: 28px; letter-spacing: .1em; color: #c7cfdb; }
.tile__offline span { color: var(--muted); font-size: 13px; max-width: 32ch; }
.tile__offline svg { width: 36px; height: 36px; color: #4a5568; margin-bottom: 4px; }

/* ---------- Układ GRID 2×2 ---------- */
[data-layout="grid"] .tile[data-slot="0"] { top: 0;   left: 0;   width: 50%; height: 50%; }
[data-layout="grid"] .tile[data-slot="1"] { top: 0;   left: 50%; width: 50%; height: 50%; }
[data-layout="grid"] .tile[data-slot="2"] { top: 50%; left: 0;   width: 50%; height: 50%; }
[data-layout="grid"] .tile[data-slot="3"] { top: 50%; left: 50%; width: 50%; height: 50%; }

/* ---------- Układ FOCUS: duży 75% + kolumna 3 miniatur ---------- */
[data-layout="focus"] .tile[data-slot="main"] { top: 0; left: 0; width: 75%; height: 100%; z-index: 2; }
[data-layout="focus"] .tile:not([data-slot="main"]) { left: 75%; width: 25%; height: 33.3334%; }
[data-layout="focus"] .tile[data-slot="0"] { top: 0; }
[data-layout="focus"] .tile[data-slot="1"] { top: 33.3333%; }
[data-layout="focus"] .tile[data-slot="2"] { top: 66.6667%; }
[data-layout="focus"] .tile:not([data-slot="main"]) .tile__bar { --bar-h: 30px; }
[data-layout="focus"] .tile:not([data-slot="main"]) .tile__label { font-size: 16px; }
[data-layout="focus"] .tile:not([data-slot="main"]) .badge { height: 18px; font-size: 10px; padding: 0 6px; }

/* ---------- Układ MOBILE: jeden widoczny kafelek ---------- */
[data-layout="mobile"] .tile {
  top: 0; left: 0; width: 100%; height: 100%; opacity: 0; visibility: hidden; pointer-events: none;
  transition: opacity .3s var(--ease), visibility 0s linear var(--dur); /* ukrycie dopiero po wygaszeniu */
}
[data-layout="mobile"] .tile[data-slot="main"] { opacity: 1; visibility: visible; pointer-events: auto; z-index: 2; transition-delay: 0s; }

/* ---------- Overlay dźwięku (polityka autoplay) ---------- */
.audio-overlay {
  position: absolute; inset: 0; z-index: 20;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  background: rgba(10, 13, 19, .72); backdrop-filter: blur(2px);
}
.audio-overlay[hidden] { display: none; }
.audio-overlay__btn {
  display: inline-flex; align-items: center; gap: 12px;
  padding: 16px 28px; border-radius: 12px; border: 0; cursor: pointer;
  background: var(--accent); color: #fff;
  font-family: 'Barlow Condensed', sans-serif; font-weight: 700; font-size: 24px; letter-spacing: .03em;
  box-shadow: 0 10px 40px rgba(229, 32, 47, .4);
}
.audio-overlay__btn svg { width: 28px; height: 28px; }
.audio-overlay__skip { background: none; border: 0; color: var(--muted); cursor: pointer; text-decoration: underline; font-size: 14px; }

.audio-hint {
  position: absolute; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 25;
  max-width: 90%; padding: 10px 16px; border-radius: 999px;
  background: rgba(10, 13, 19, .92); border: 1px solid var(--border); color: var(--text);
  font-size: 14px; font-weight: 500; text-align: center; white-space: nowrap;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .4);
  animation: hint-in .25s var(--ease);
}
[data-viewport="phone-portrait"] .audio-hint { bottom: auto; top: calc(100vw * 9 / 16 + 60px); white-space: normal; border-radius: 12px; }
@keyframes hint-in { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }

.global-msg {
  position: absolute; left: 50%; top: 24px; transform: translateX(-50%); z-index: 30;
  max-width: min(90%, 560px); padding: 12px 18px; border-radius: 10px;
  background: #2a1419; border: 1px solid var(--accent); color: #fff; font-size: 14px; text-align: center;
}
.global-msg[hidden] { display: none; }

/* ---------- Footer ---------- */
.footer {
  height: 40px; flex: none;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 0 20px; border-top: 1px solid var(--border);
  color: var(--muted); font-size: 13px;
}
.footer strong { color: var(--text); }
kbd {
  display: inline-block; min-width: 20px; padding: 1px 5px; border-radius: 4px; text-align: center;
  border: 1px solid var(--border); background: var(--surface); font: 600 11px 'Barlow', sans-serif; color: var(--text);
}

/* ---------- Pełny ekran (Fullscreen API na .stage) ---------- */
.stage:fullscreen, .stage:-webkit-full-screen { background: #000; padding: 0; }
.stage:fullscreen .multiview, .stage:-webkit-full-screen .multiview { --chrome: 0px; }

/* ---------- Telefon w pionie (< 768 px) ---------- */
[data-viewport="phone-portrait"] .header { min-height: 56px; padding: 6px 12px; gap: 4px 8px; }
[data-viewport="phone-portrait"] .header__brand { gap: 10px; }
[data-viewport="phone-portrait"] .header__actions { gap: 6px; }
[data-viewport="phone-portrait"] .header__logo { height: 32px; }
[data-viewport="phone-portrait"] .header__title { font-size: 20px; }
[data-viewport="phone-portrait"] .header__sub { display: none; }
[data-viewport="phone-portrait"] .header__title-short:not([hidden]) { display: inline; }
[data-viewport="phone-portrait"] .header__title[data-has-short="true"] .header__title-full { display: none; }
[data-viewport="phone-portrait"] .btn__label { display: none; }
[data-viewport="phone-portrait"] .btn { padding: 0 10px; }
[data-viewport="phone-portrait"] .tabs { display: flex; }
[data-viewport="phone-portrait"] .stage { align-items: flex-start; padding: 8px 8px 0; }
[data-viewport="phone-portrait"] .multiview {
  width: 100%; aspect-ratio: auto;
  height: calc((100vw - 16px) * 9 / 16 + var(--bar-h) + 2 * var(--gap));
}
[data-viewport="phone-portrait"] .footer { padding: 0 12px; }
[data-viewport="phone-portrait"] .footer__keys { display: none; }

/* ---------- Telefon w poziomie: FOCUS z miniaturami pod spodem ---------- */
[data-viewport="phone-landscape"] .header { min-height: 44px; padding: 4px 12px; gap: 4px 8px; }
[data-viewport="phone-landscape"] .header__logo { height: 28px; }
[data-viewport="phone-landscape"] .header__title { font-size: 18px; }
[data-viewport="phone-landscape"] .header__sub { display: none; }
[data-viewport="phone-landscape"] .header__title-short:not([hidden]) { display: inline; }
[data-viewport="phone-landscape"] .header__title[data-has-short="true"] .header__title-full { display: none; }
[data-viewport="phone-landscape"] .btn { height: 32px; padding: 0 10px; }
[data-viewport="phone-landscape"] .btn__label { display: none; }
[data-viewport="phone-landscape"] .footer { display: none; }
[data-viewport="phone-landscape"] .stage { padding: 4px; }
[data-viewport="phone-landscape"] .multiview { width: 100%; aspect-ratio: auto; height: calc(100dvh - var(--header-h, 44px) - 8px); }
[data-viewport="phone-landscape"] { --main-h: 70%; }

/* ---------- FOCUS z miniaturami POD dużym playerem (telefon poziom; pion w trybie „Wszystkie na żywo”) ---------- */
[data-thumbs="below"][data-layout="focus"] .tile[data-slot="main"] { top: 0; left: 0; width: 100%; height: var(--main-h); }
[data-thumbs="below"][data-layout="focus"] .tile:not([data-slot="main"]) { top: var(--main-h); height: calc(100% - var(--main-h)); width: 33.3334%; }
[data-thumbs="below"][data-layout="focus"] .tile[data-slot="0"] { left: 0; }
[data-thumbs="below"][data-layout="focus"] .tile[data-slot="1"] { left: 33.3333%; }
[data-thumbs="below"][data-layout="focus"] .tile[data-slot="2"] { left: 66.6667%; }
[data-thumbs="below"] .tile { --gap: 3px; }
[data-thumbs="below"] .tile:not([data-slot="main"]) .tile__bar { --bar-h: 24px; padding-left: 8px; gap: 6px; }
[data-thumbs="below"] .tile:not([data-slot="main"]) .tile__label { font-size: 14px; }
[data-thumbs="below"] .tile:not([data-slot="main"]) .tile__audio { display: none; }
/* w wąskich miniaturach status tylko jako kropka (czerwona pulsująca = LIVE) */
[data-thumbs="below"] .tile:not([data-slot="main"]) .badge { width: 12px; height: 12px; padding: 0; gap: 0; font-size: 0; border-radius: 50%; justify-content: center; }
[data-thumbs="below"] .tile:not([data-slot="main"]) .tile__offline strong { font-size: 16px; }
[data-thumbs="below"] .tile:not([data-slot="main"]) .tile__offline span,
[data-thumbs="below"] .tile:not([data-slot="main"]) .tile__offline svg { display: none; }

/* Telefon pion + „Wszystkie na żywo”: duży player 16:9 i rząd miniatur o stałej wysokości.
   Miniatury muszą być WIDOCZNE – Chrome na Androidzie wstrzymuje wyciszone filmy poza ekranem. */
[data-viewport="phone-portrait"] { --thumbs-h: 104px; --main-h: calc(100% - var(--thumbs-h)); }
[data-viewport="phone-portrait"][data-layout="focus"] .multiview {
  height: calc((100vw - 16px) * 9 / 16 + var(--bar-h) + 2 * var(--gap) + var(--thumbs-h));
}
[data-viewport="phone-portrait"][data-layout="focus"] .audio-hint { top: auto; bottom: 16px; }

/* ---------- Tablet / małe desktopy ---------- */
@media (min-width: 768px) and (max-width: 1100px) {
  .header__title { font-size: 22px; }
  .btn__label { display: none; }
  .footer__keys { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .tile, .tile__bar { transition: none; }
}
