/* Вёрстка «от высоты»: окно в машине маленькое и широкое (ориентир 450–1000 × 250–420),
   поэтому 1rem = 5% высоты окна, и все размеры считаются от него. */
:root {
  --bg: #0b0b0d;
  --panel: #18181c;
  --panel-2: #24242a;
  --line: #34343c;
  --text: #f2f2f4;
  --muted: #a3a3ad;
  --accent: #ff3b30;
  --filmix: #f5a623;
  --ok: #34c759;
  --bar: 14vh;
  --gap: 2vh;
  --tap: 12vh; /* минимальная высота области нажатия */
  color-scheme: dark;
}

html {
  font-size: 5vh;
  background: var(--bg);
}

@media (orientation: portrait) {
  /* Портрет — это телефон, не машина: там важнее, чтобы влезла ширина.
     Переопределения компонентов — в конце файла, иначе их перебьют общие правила. */
  html { font-size: min(5vh, 4.4vw); }
  :root { --bar: min(14vh, 13vw); --tap: min(12vh, 12vw); }
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 400 1rem/1.25 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

button, a.btn {
  font: inherit;
  color: inherit;
  background: var(--panel-2);
  border: 0;
  border-radius: 1.6vh;
  padding: 0 1.2em;
  min-height: var(--tap);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4em;
  cursor: pointer;
  touch-action: manipulation;
  text-decoration: none;
}
button:active, a.btn:active, .pressed { filter: brightness(1.5); }
button.primary, a.btn.primary { background: var(--accent); }

svg.i { width: 1.4em; height: 1.4em; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; flex: none; }

[hidden] { display: none !important; }

/* --- Экраны --- */

#app { height: 100%; }

.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
}

.bar {
  flex: none;
  height: var(--bar);
  display: flex;
  align-items: center;
  gap: var(--gap);
  padding: 1vh var(--gap);
  background: var(--bg);
}
.bar .icon-btn { width: calc(var(--bar) - 2vh); min-height: var(--tap); height: calc(var(--bar) - 2vh); padding: 0; }
.bar h1 {
  margin: 0 0 0 0.3em;
  font-size: 1.15rem;
  font-weight: 650;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

.scroll {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 0 var(--gap) 4vh;
}

.status {
  padding: 6vh 2vh;
  text-align: center;
  color: var(--muted);
  font-size: 1.1rem;
}
.status.err { color: #ff8a80; }
.status button { margin-top: 3vh; }

/* --- Главная --- */

.tiles {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--gap);
}
.tile {
  height: 30vh;
  min-height: 12vh;
  flex-direction: column;
  justify-content: center;
  border-radius: 2.4vh;
  background: var(--panel);
  font-size: 1.2rem;
  font-weight: 600;
  padding: 0 0.4em;
  text-align: center;
  line-height: 1.1;
}
.tile svg.i { width: 1.8em; height: 1.8em; }
.tile.wide { grid-column: span 2; }

.accounts { display: grid; grid-template-columns: 1fr 1fr; gap: var(--gap); }
.acct {
  min-height: min(18vh, 20vw);
  display: flex;
  align-items: center;
  color: inherit;
  text-decoration: none;
  touch-action: manipulation;
  justify-content: flex-start;
  gap: 0.6em;
  padding: 1.5vh 0.8em;
  background: var(--panel);
  border-radius: 2.4vh;
  text-align: left;
}
.acct:active { filter: brightness(1.5); }
.acct svg.i { width: 1.6em; height: 1.6em; color: var(--accent); }
.acct.filmix svg.i { color: var(--filmix); }
.acct-txt { display: flex; flex-direction: column; min-width: 0; }
.acct-name { font-weight: 650; line-height: 1.15; }
.acct-sub { color: var(--muted); font-size: 0.85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.acct-sub.ok { color: var(--ok); }
.tile.login { background: var(--accent); grid-column: span 2; }

h2 {
  margin: 5vh 0 2vh;
  font-size: 1.1rem;
  font-weight: 650;
  color: var(--muted);
}

.row {
  display: flex;
  gap: var(--gap);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
  padding-bottom: 1vh;
}
.row::-webkit-scrollbar { display: none; }
.row .card { flex: 0 0 58vh; }

.chip {
  flex: none;
  min-height: var(--tap);
  border-radius: calc(var(--tap) / 2);
  background: var(--panel-2);
  padding: 0 1em;
  white-space: nowrap;
  max-width: 70vw;
  overflow: hidden;
  text-overflow: ellipsis;
  display: inline-block;
  line-height: var(--tap);
}

/* --- Карточки роликов --- */

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(62vh, 1fr));
  gap: 4vh var(--gap);
}

.card {
  display: block;
  background: none;
  padding: 0;
  min-height: 12vh;
  text-align: left;
  border-radius: 1.6vh;
  color: inherit;
  text-decoration: none;
  touch-action: manipulation;
  cursor: pointer;
}
.card:active { filter: brightness(1.4); }

.thumb {
  position: relative;
  aspect-ratio: 16 / 9;
  border-radius: 1.6vh;
  overflow: hidden;
  background: var(--panel);
}
.thumb-ph { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: var(--muted); }
.thumb-ph svg.i { width: 2.4em; height: 2.4em; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .dur {
  position: absolute;
  right: 1vh;
  bottom: 1vh;
  background: rgba(0, 0, 0, 0.82);
  border-radius: 1vh;
  padding: 0.3vh 1vh;
  font-size: 0.85rem;
  font-weight: 600;
}
.thumb .dur.live { background: var(--accent); }
.thumb .prog { position: absolute; left: 0; bottom: 0; height: 1.2vh; background: var(--accent); }

.card .title {
  margin-top: 1.2vh;
  font-weight: 600;
  line-height: 1.2;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card .meta {
  margin-top: 0.6vh;
  color: var(--muted);
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sentinel { height: 1px; }

/* Постеры Filmix (2:3) */
.grid.posters { grid-template-columns: repeat(auto-fill, minmax(34vh, 1fr)); }
.thumb.poster { aspect-ratio: 2 / 3; }
.thumb .badge.q {
  position: absolute;
  left: 1vh;
  top: 1vh;
  background: var(--filmix);
  color: #000;
  border-radius: 1vh;
  padding: 0.3vh 1vh;
  font-size: 0.8rem;
  font-weight: 700;
}
.thumb .dur.ep { left: 1vh; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.filmix-mark { color: var(--filmix); }
.status .btn { margin-top: 3vh; }
.more-status .btn { margin-top: 1vh; }
.more-status { grid-column: 1 / -1; text-align: center; color: var(--muted); padding: 3vh; }

/* --- Поиск --- */

.query {
  flex: 1;
  min-width: 0;
  height: var(--tap);
  display: flex;
  align-items: center;
  background: var(--panel);
  border-radius: 1.6vh;
  padding: 0 0.6em;
  font-size: 1.2rem;
  white-space: nowrap;
  overflow: hidden;
  direction: ltr;
}
.query .txt { overflow: hidden; text-overflow: clip; white-space: pre; display: flex; justify-content: flex-end; }
.query .ph { color: var(--muted); }
.query .caret { width: 0.12em; height: 1.2em; background: var(--accent); margin-left: 0.05em; flex: none; animation: blink 1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }

.seg { display: flex; background: var(--panel); border-radius: 1.6vh; flex: none; overflow: hidden; }
.seg button { min-height: var(--tap); height: var(--tap); background: none; padding: 0 0.6em; font-size: 0.95rem; border-radius: 0; }
.seg button.on { background: var(--panel-2); }
.seg button.on[data-target="yt"] { color: #fff; background: var(--accent); }
.seg button.on[data-target="filmix"] { color: #000; background: var(--filmix); }

.suggest {
  flex: none;
  height: calc(var(--tap) + 2vh);
  padding: 1vh var(--gap);
  align-items: center;
}
.suggest .empty { color: var(--muted); line-height: var(--tap); padding-left: 0.3em; font-size: 0.95rem; white-space: nowrap; }

.kb {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 1.2vh;
  padding: 0 1vh 1.2vh;
  min-height: 0;
}
.kb-row { flex: 1; display: flex; gap: 0.8vh; min-height: var(--tap); }
.key {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 1.4vh;
  background: var(--panel-2);
  font-size: min(1.4rem, 6vw);
  touch-action: none;
}
.key.fn { background: var(--panel); font-size: min(1rem, 4.4vw); }
.key.go { background: var(--accent); font-weight: 650; }
.key.go.filmix { background: var(--filmix); color: #000; }
.key.on { background: var(--text); color: var(--bg); }
.key.down { filter: brightness(1.7); }

/* --- Вход с телефона --- */

.pair {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6vh;
  padding: 0 4vh 4vh;
}
.pair .qr { height: 72vh; aspect-ratio: 1; background: #fff; border-radius: 2vh; padding: 1vh; flex: none; }
.pair .qr svg { width: 100%; height: 100%; display: block; }
.pair .code { font-size: 3.2rem; font-weight: 700; letter-spacing: 0.12em; font-variant-numeric: tabular-nums; line-height: 1.1; }
.pair .url { font-size: 1.2rem; font-weight: 600; word-break: break-all; }
.pair p { margin: 1.5vh 0; }
.pair .muted { color: var(--muted); }

/* --- Плеер --- */

#player-layer {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: #000;
}
#player-layer .yt, #player-layer iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
}
/* Прозрачный слой над iframe: ловит касания, чтобы показать свои кнопки и не дать им провалиться в YouTube. */
.catcher { position: absolute; inset: 0; z-index: 2; }
.catcher.pass { pointer-events: none; }

.ctl { position: absolute; inset: 0; z-index: 3; pointer-events: none; display: flex; flex-direction: column; justify-content: space-between; }
.ctl > * { pointer-events: auto; }
.ctl .top, .ctl .bottom { display: flex; align-items: center; gap: min(var(--gap), 2vw); padding: 2vh; background: rgba(0, 0, 0, 0.65); }
.ctl .top .title { flex: 1; min-width: 0; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ctl .bottom { justify-content: center; }
.ctl button { min-height: min(16vh, 17vw); min-width: min(16vh, 17vw); padding: 0 0.6em; background: rgba(255, 255, 255, 0.14); border-radius: 2vh; }
.ctl button svg.i { width: 1.7em; height: 1.7em; }
.ctl button.big { min-width: min(22vh, 22vw); background: rgba(255, 255, 255, 0.24); }
.ctl .time { font-variant-numeric: tabular-nums; color: #ddd; font-size: 0.95rem; white-space: nowrap; }
.ctl .spacer { flex: 1; }

.hint {
  position: absolute;
  left: 50%;
  bottom: 8vh;
  transform: translateX(-50%);
  z-index: 4;
  background: rgba(0, 0, 0, 0.8);
  padding: 2vh 3vh;
  border-radius: 2vh;
  font-size: 1.3rem;
  font-weight: 650;
  text-align: center;
  pointer-events: none;
  white-space: nowrap;
}
.msg {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4vh;
  background: rgba(0, 0, 0, 0.88);
  text-align: center;
  padding: 4vh;
  font-size: 1.2rem;
}
.msg .btns { display: flex; gap: var(--gap); flex-wrap: wrap; justify-content: center; }

/* --- Портрет (телефон): переопределения, должны идти последними --- */

@media (orientation: portrait) {
  .tiles { grid-template-columns: repeat(2, 1fr); }
  .tile { height: min(30vh, 28vw); }
  .tile.login { grid-column: span 2; }
  .accounts { grid-template-columns: 1fr; }
  .kb { flex: none; height: 78vw; margin-top: auto; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(40vw, 1fr)); }
  .grid.posters { grid-template-columns: repeat(auto-fill, minmax(28vw, 1fr)); }
  .pair { flex-direction: column; }
  .pair .qr { height: auto; width: 60vw; }
}
