:root {
  color-scheme: dark;
  --bg: #111114;
  --card: #1d1d23;
  --text: #f4f4f7;
  --muted: #a4a4b0;
  --accent: #2f6fed;
  --gutter: 20px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); }
body {
  font: 18px/1.35 -apple-system, "Helvetica Neue", Arial, sans-serif;
  padding: max(env(safe-area-inset-top), 16px) max(env(safe-area-inset-right), var(--gutter)) max(env(safe-area-inset-bottom), 24px) max(env(safe-area-inset-left), var(--gutter));
  -webkit-user-select: none;
  user-select: none;
}
/* В установленном приложении iPad размывает полосу у верхнего края: опускаем содержимое ниже неё. */
@media (display-mode: standalone) {
  body { padding-top: calc(env(safe-area-inset-top) + 44px); }
}
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }
input { font: inherit; color: inherit; -webkit-user-select: text; user-select: text; }
h1, h2 { margin: 0; }

.primary { background: var(--accent); color: #fff; padding: 14px 26px; border-radius: 14px; font-weight: 600; }
.quiet { background: var(--card); padding: 12px 20px; border-radius: 14px; }

/* Шапка */
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.top h1 { font-size: 26px; color: var(--accent); filter: brightness(1.25); }
.time { background: var(--card); color: var(--muted); padding: 6px 14px; border-radius: 999px; font-size: 16px; white-space: nowrap; }

/* Карточка видео */
.video { display: block; min-width: 0; }
.thumb { position: relative; display: block; aspect-ratio: 16 / 9; border-radius: 14px; overflow: hidden; background: var(--card); }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.duration { position: absolute; right: 8px; bottom: 8px; background: rgba(0, 0, 0, 0.75); color: #fff; font-size: 14px; padding: 2px 7px; border-radius: 6px; }
.name { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2; overflow: hidden; margin-top: 8px; font-size: 16px; }
.channel { display: block; color: var(--muted); font-size: 14px; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Полный экран: ряды полок */
.search { width: 100%; padding: 13px 16px; background: var(--card); border: 0; border-radius: 14px; margin-bottom: 20px; outline: none; }
.search::placeholder { color: var(--muted); }
.shelf { margin-bottom: 26px; }
.shelf h2 { font-size: 21px; margin-bottom: 10px; }
.row { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(230px, 280px); gap: 14px; overflow-x: auto; scroll-snap-type: x proximity; padding-bottom: 6px; margin: 0 calc(var(--gutter) * -1); padding-inline: var(--gutter); scrollbar-width: none; }
.row::-webkit-scrollbar { display: none; }
.row .video { scroll-snap-align: start; scroll-margin-left: var(--gutter); }
.results { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 18px 14px; }

.ask { margin-top: 8px; }
.ask form { display: flex; gap: 10px; margin-top: 12px; flex-wrap: wrap; }
.ask input { flex: 1 1 240px; min-width: 0; padding: 13px 16px; background: var(--card); border: 0; border-radius: 14px; outline: none; }
.sent { color: var(--muted); margin-top: 10px; }

/* Экран с картинками для младшего */
.shelf-buttons { display: flex; gap: 12px; overflow-x: auto; margin: 0 calc(var(--gutter) * -1) 18px; padding: 4px var(--gutter); scrollbar-width: none; }
.shelf-buttons::-webkit-scrollbar { display: none; }
.shelf-button { flex: none; width: 104px; padding: 12px 6px 10px; border-radius: 22px; background: var(--card); text-align: center; }
.shelf-button[aria-pressed="true"] { background: var(--accent); }
.shelf-button .icon { display: block; font-size: 48px; line-height: 1.1; }
.shelf-button .label { display: block; font-size: 15px; margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.big-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 18px; }
.big-grid .thumb { border-radius: 20px; }
.big-grid .name { font-size: 17px; }

/* Плеер */
.player-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.back { background: var(--card); width: 60px; height: 60px; border-radius: 50%; font-size: 30px; line-height: 1; flex: none; }
.limit-warning { visibility: hidden; flex: 1; min-width: 0; text-align: center; font-size: 24px; font-weight: 700; padding: 10px 16px; border-radius: 16px; background: #ffcf40; color: #1c1c20; }
.limit-warning.show { visibility: visible; animation: limit-pulse 0.8s ease-in-out 4 alternate; }
@keyframes limit-pulse { to { transform: scale(1.06); } }
.stage { width: min(100%, calc((100dvh - 170px) * 16 / 9)); aspect-ratio: 16 / 9; margin: 0 auto; background: #000; border-radius: 16px; overflow: hidden; display: flex; align-items: center; justify-content: center; }
.stage iframe { width: 100%; height: 100%; border: 0; display: block; }
.player-title { width: min(100%, calc((100dvh - 170px) * 16 / 9)); margin: 12px auto 0; font-size: 18px; }

.end { width: 100%; height: 100%; padding: 16px; display: flex; flex-direction: column; justify-content: center; overflow: hidden; }
.end h2 { text-align: center; font-size: 24px; margin-bottom: 14px; }
.end-grid { display: grid; grid-template-columns: repeat(2, minmax(0, min(280px, 40%))); justify-content: center; gap: 14px; }
.end-grid .name, .end-grid .channel { display: none; }
.stage .message { text-align: center; padding: 20px; }

/* Сообщения на весь экран */
.center { min-height: 78dvh; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 16px; }
.center .big { font-size: 84px; line-height: 1; }
.center h1 { font-size: 30px; }
.center p { color: var(--muted); margin: 0; max-width: 460px; }
.code-input { width: 240px; max-width: 100%; text-align: center; font-size: 36px; letter-spacing: 8px; padding: 12px; background: var(--card); border: 0; border-radius: 16px; outline: none; }
.error { color: #ff8f86; min-height: 1.3em; }
.empty { color: var(--muted); text-align: center; padding: 60px 16px; }
