:root {
  --bg: #090b14;
  --surface: #141829;
  --surface2: #1d2238;
  --line: #2a304a;
  --text: #f1f3fa;
  --muted: #8d94ad;
  --a1: #ff4d5a;
  --a2: #ffb23f;
  --grad: linear-gradient(135deg, var(--a1), var(--a2));
  --st: env(safe-area-inset-top, 0px);
  --sb: env(safe-area-inset-bottom, 0px);
  --sl: env(safe-area-inset-left, 0px);
  --sr: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}
body { overflow: hidden; }

button, input { font: inherit; color: inherit; }
button { border: 0; background: none; padding: 0; cursor: pointer; touch-action: manipulation; }

.brand { font-size: 19px; font-weight: 600; letter-spacing: -0.01em; }
.brand b, h1 b {
  font-weight: 800;
  background: var(--grad);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

/* ---------- Nyitó képernyő ---------- */
#splash {
  position: fixed; inset: 0; z-index: 50;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px;
  background: radial-gradient(120% 80% at 50% 40%, #171c33 0%, var(--bg) 70%);
  transition: opacity .45s ease, visibility .45s;
}
#splash.out { opacity: 0; visibility: hidden; }
#splash img { border-radius: 30px; box-shadow: 0 18px 50px rgba(255, 90, 80, .28); animation: pop .7s cubic-bezier(.2, 1.3, .4, 1) both; }
#splash .brand { font-size: 24px; animation: rise .6s .25s ease both; }
@keyframes pop { from { transform: scale(.6); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes rise { from { transform: translateY(10px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- Belépés ---------- */
#login {
  position: fixed; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  padding: 24px calc(28px + var(--sr)) 24px calc(28px + var(--sl));
}
#login img { border-radius: 22px; }
#login h1 { margin: 2px 0 14px; font-size: 24px; font-weight: 600; }
#login input, #login button { width: 100%; max-width: 320px; height: 52px; border-radius: 14px; font-size: 17px; }
#login input { background: var(--surface); border: 1px solid var(--line); padding: 0 16px; text-align: center; outline: none; }
#login input:focus { border-color: var(--a2); }
#login button { background: var(--grad); color: #1a0d08; font-weight: 700; }
#login button:active { filter: brightness(.9); }
#login button:disabled { opacity: .6; }
#loginErr { min-height: 20px; margin: 0; color: #ff8088; font-size: 14px; }
#login.shake input { animation: shake .35s; border-color: var(--a1); }
@keyframes shake { 20% { transform: translateX(-8px); } 40% { transform: translateX(8px); } 60% { transform: translateX(-5px); } 80% { transform: translateX(5px); } }

/* ---------- App váz ---------- */
#app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }

header {
  flex: none;
  display: flex; align-items: center; gap: 10px;
  padding: calc(var(--st) + 10px) calc(16px + var(--sr)) 10px calc(16px + var(--sl));
}
header img { border-radius: 9px; }
#who { margin-left: auto; padding: 5px 12px; border-radius: 14px; background: var(--surface); border: 1px solid var(--line); color: var(--muted); font-size: 13px; font-weight: 600; }
#who:empty { display: none; }

#toast {
  position: fixed; left: 50%; bottom: calc(var(--sb) + 18px); transform: translateX(-50%); z-index: 40;
  max-width: calc(100% - 32px); padding: 10px 16px; border-radius: 14px;
  background: #2a1a1f; border: 1px solid #6b2a33; color: #ffc9cd; font-size: 14px; text-align: center;
}

#scroll { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 0 var(--sr) 0 var(--sl); }

/* ---------- Lejátszó ---------- */
#player { flex: none; background: #000; }
.screen { position: relative; background: #000; }
#video { display: block; width: 100%; aspect-ratio: 16 / 9; max-height: 52vh; background: #000; }
#overlay {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
  background: rgba(5, 6, 12, .86); text-align: center; padding: 16px;
}
#overlay p { margin: 0; font-size: 15px; color: #d6daea; }
#retry { height: 40px; padding: 0 22px; border-radius: 20px; background: var(--grad); color: #1a0d08; font-weight: 700; }
#overlay.loading #retry { display: none; }
#overlay.loading { background: rgba(5, 6, 12, .55); pointer-events: none; }
#overlay.loading p::before {
  content: ""; display: block; width: 30px; height: 30px; margin: 0 auto 10px;
  border-radius: 50%; border: 3px solid rgba(255, 255, 255, .2); border-top-color: var(--a2);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.nowbar { display: flex; align-items: center; gap: 2px; padding: 4px 6px; background: var(--surface); border-bottom: 1px solid var(--line); }
.nowbar button { flex: none; width: 44px; height: 44px; border-radius: 12px; font-size: 24px; line-height: 1; color: var(--text); }
.nowbar button:active { background: var(--surface2); }
#close { font-size: 17px; color: var(--muted); }
#star.on { color: var(--a2); }
#nowName { flex: 1; min-width: 0; padding: 0 6px; font-weight: 600; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- Eszköztár ---------- */
.toolbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; flex-direction: column; gap: 10px;
  padding: 10px 16px 12px;
  background: linear-gradient(var(--bg) 85%, transparent);
}
.tabs { display: flex; padding: 3px; border-radius: 12px; background: var(--surface); }
.tabs button { flex: 1; height: 36px; border-radius: 9px; font-size: 15px; font-weight: 600; color: var(--muted); }
.tabs button.on { background: var(--surface2); color: var(--text); box-shadow: 0 1px 0 rgba(255, 255, 255, .06) inset; }
#search {
  width: 100%; height: 42px; padding: 0 14px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface); font-size: 16px; outline: none;
  -webkit-appearance: none; appearance: none;
}
#search:focus { border-color: var(--a2); }
#chips { display: flex; gap: 8px; }
#chips button { height: 32px; padding: 0 14px; border-radius: 16px; border: 1px solid var(--line); font-size: 14px; color: var(--muted); }
#chips button.on { border-color: transparent; background: var(--grad); color: #1a0d08; font-weight: 700; }

/* ---------- Csatornáim rács ---------- */
#list { padding: 0 16px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 12px 10px; }
.card { display: flex; flex-direction: column; gap: 6px; text-align: center; min-width: 0; }
.tile {
  position: relative; width: 100%; aspect-ratio: 16 / 10; border-radius: 14px; overflow: hidden;
  display: flex; align-items: center; justify-content: center;
  background: #eef0f5; color: #2a3050; font-weight: 800; font-size: 22px; letter-spacing: -0.02em;
  outline: 0 solid transparent; transition: transform .12s;
}
.tile img { position: absolute; inset: 0; width: 100%; height: 100%; padding: 12%; object-fit: contain; background: #eef0f5; filter: drop-shadow(0 0 1px rgba(0, 0, 0, .55)); }
.card:active .tile { transform: scale(.96); }
.card.on .tile { outline: 3px solid var(--a2); outline-offset: 2px; }
.card .name { font-size: 12.5px; line-height: 1.25; color: #d6daea; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card.on .name { color: var(--a2); font-weight: 600; }

/* ---------- Összes csatorna lista ---------- */
.rows { display: flex; flex-direction: column; }
.row { display: flex; align-items: center; gap: 12px; min-height: 60px; border-bottom: 1px solid #171b2d; }
.row .pick { flex: 1; min-width: 0; display: flex; align-items: center; gap: 12px; text-align: left; padding: 8px 0; }
.row .thumb {
  position: relative; flex: none; width: 58px; height: 40px; border-radius: 9px; overflow: hidden;
  display: flex; align-items: center; justify-content: center;
  background: #eef0f5; color: #2a3050; font-weight: 800; font-size: 14px;
}
.row .thumb img { position: absolute; inset: 0; width: 100%; height: 100%; padding: 4px; object-fit: contain; background: #eef0f5; filter: drop-shadow(0 0 1px rgba(0, 0, 0, .55)); }
.row .txt { min-width: 0; }
.row .name { font-size: 15.5px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .sub { margin-top: 2px; font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row.on .name { color: var(--a2); }
.row .fav { flex: none; width: 44px; height: 44px; font-size: 22px; color: var(--muted); border-radius: 12px; }
.row .fav.on { color: var(--a2); }
.row .fav:active { background: var(--surface); }

.note { padding: 28px 12px; text-align: center; color: var(--muted); font-size: 15px; line-height: 1.45; }

footer {
  display: flex; align-items: center; justify-content: space-between;
  padding: 22px 16px calc(var(--sb) + 22px); color: var(--muted); font-size: 13px;
}
#logout { height: 36px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--line); color: var(--muted); font-size: 13px; }

/* ---------- Fektetett telefon: a kép kitölti a kijelzőt ---------- */
@media (orientation: landscape) and (max-height: 520px) {
  body.playing header, body.playing #scroll, body.playing .nowbar { display: none; }
  body.playing #player { flex: 1; }
  body.playing .screen { height: 100vh; height: 100dvh; }
  body.playing #video { height: 100%; max-height: none; aspect-ratio: auto; }
}

@media (min-width: 900px) {
  #app { max-width: 1100px; margin: 0 auto; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); }
  #video { max-height: 60vh; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
