:root {
  --bg: #08080b;
  --surface: #121218;
  --surface-2: #1b1b23;
  --line: rgba(255, 255, 255, 0.09);
  --line-strong: rgba(255, 255, 255, 0.16);
  --text: #f2f2f5;
  --muted: #8e8e9c;
  --accent: #ffb340;
  --accent-2: #ff7a45;
  --danger: #ff6b6b;
  --ok: #4ade80;
  --radius: 18px;
  --radius-sm: 12px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI",
    system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

body {
  min-height: 100dvh;
  /* Тёплый отсвет сверху — как от проектора. */
  background-image:
    radial-gradient(120% 60% at 50% -10%, rgba(255, 179, 64, 0.13), transparent 60%),
    radial-gradient(80% 40% at 80% 0%, rgba(255, 122, 69, 0.08), transparent 70%);
  background-repeat: no-repeat;
}

.shell {
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
  padding: max(20px, env(safe-area-inset-top)) 18px
    calc(36px + env(safe-area-inset-bottom));
}

/* --- Шапка --- */

.masthead {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 10px 2px 26px;
}

.mark {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  background: linear-gradient(145deg, var(--accent), var(--accent-2));
  box-shadow: 0 6px 20px rgba(255, 140, 60, 0.28);
  flex: none;
}

.mark svg { width: 19px; height: 19px; display: block; }

.wordmark {
  font-size: 19px;
  font-weight: 640;
  letter-spacing: -0.02em;
  margin: 0;
}

.masthead .spacer { flex: 1; }

/* --- Общие блоки --- */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
}

.lede {
  margin: 0 0 18px;
  color: var(--muted);
  font-size: 14.5px;
  line-height: 1.5;
}

label.field-label {
  display: block;
  font-size: 13px;
  font-weight: 560;
  color: var(--muted);
  margin-bottom: 9px;
  letter-spacing: 0.01em;
}

.input-row { display: flex; gap: 9px; }

input[type="url"], input[type="password"] {
  flex: 1;
  min-width: 0;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--text);
  /* 16px обязательны: на меньшем iOS зумит страницу при фокусе. */
  font-size: 16px;
  padding: 14px 15px;
  font-family: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input::placeholder { color: #5c5c69; }

input[type="url"]:focus, input[type="password"]:focus {
  outline: none;
  border-color: rgba(255, 179, 64, 0.55);
  box-shadow: 0 0 0 3.5px rgba(255, 179, 64, 0.13);
}

button {
  font-family: inherit;
  font-size: 15px;
  font-weight: 580;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: transform 0.12s, opacity 0.15s, background 0.15s;
}

button:active { transform: scale(0.975); }
button:disabled { opacity: 0.45; cursor: default; transform: none; }

.btn-primary {
  width: 100%;
  margin-top: 12px;
  padding: 15px 20px;
  color: #1a1205;
  background: linear-gradient(145deg, var(--accent), var(--accent-2));
  box-shadow: 0 6px 22px rgba(255, 140, 60, 0.22);
}

.btn-ghost {
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 12px 16px;
}

.btn-ghost:hover { border-color: var(--line-strong); }

.btn-icon {
  flex: none;
  width: 50px;
  display: grid;
  place-items: center;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--muted);
}

.btn-icon svg { width: 19px; height: 19px; }
.btn-icon:hover { color: var(--text); border-color: var(--line-strong); }

/* --- Состояния --- */

.hidden { display: none !important; }

.status {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 16px;
  padding: 15px 17px;
  border-radius: var(--radius-sm);
  font-size: 14.5px;
  line-height: 1.45;
}

.status.working { background: rgba(255, 179, 64, 0.09); color: #ffd9a3; }
.status.error { background: rgba(255, 107, 107, 0.1); color: #ffb3b3; }

.spinner {
  flex: none;
  width: 17px;
  height: 17px;
  border: 2px solid rgba(255, 179, 64, 0.25);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

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

.stage { margin-top: 22px; }

.player-frame {
  position: relative;
  background: #000;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 22px 60px rgba(0, 0, 0, 0.55);
}

video {
  display: block;
  width: 100%;
  max-height: 72dvh;
  background: #000;
  aspect-ratio: 16 / 9;
}

.meta { padding: 18px 2px 0; }

.meta h2 {
  margin: 0 0 7px;
  font-size: 18px;
  font-weight: 620;
  letter-spacing: -0.015em;
  line-height: 1.3;
}

.meta-line {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  align-items: center;
  color: var(--muted);
  font-size: 13px;
}

.pill {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 100px;
  padding: 4px 11px;
  font-size: 12.5px;
}

/* --- Кнопки под плеером --- */

.actions {
  display: flex;
  gap: 9px;
  margin-top: 16px;
  flex-wrap: wrap;
}

.actions button { flex: 1; min-width: 140px; }

.btn-airplay {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: rgba(255, 179, 64, 0.13);
  border: 1px solid rgba(255, 179, 64, 0.32);
  color: var(--accent);
  padding: 12px 16px;
}

.btn-airplay svg { width: 18px; height: 18px; }
.btn-airplay:hover { background: rgba(255, 179, 64, 0.19); }

/* --- Выбор качества и история --- */

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.chip {
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--muted);
  border-radius: 100px;
  padding: 8px 14px;
  font-size: 13.5px;
  font-weight: 540;
}

.chip[aria-pressed="true"] {
  background: rgba(255, 179, 64, 0.14);
  border-color: rgba(255, 179, 64, 0.42);
  color: var(--accent);
}

.section-title {
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: #6a6a78;
  margin: 30px 2px 11px;
}

.history-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 13px 15px;
  margin-bottom: 8px;
  color: var(--text);
  font-weight: 500;
}

.history-item:hover { border-color: var(--line-strong); }
.history-item .title { flex: 1; min-width: 0; font-size: 14.5px; }
.history-item .host { color: var(--muted); font-size: 12.5px; margin-top: 3px; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.hint {
  margin: 26px 2px 0;
  color: #62626f;
  font-size: 12.5px;
  line-height: 1.55;
}

/* --- Экран входа --- */

.login-wrap {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card { width: 100%; max-width: 380px; text-align: center; }
.login-card .mark { margin: 0 auto 18px; width: 44px; height: 44px; border-radius: 13px; }
.login-card .mark svg { width: 24px; height: 24px; }
.login-card h1 { font-size: 21px; margin: 0 0 6px; letter-spacing: -0.02em; }
.login-card p { color: var(--muted); font-size: 14px; margin: 0 0 22px; }
.login-card input { width: 100%; text-align: center; }

@media (min-width: 640px) {
  .shell { padding-top: 34px; }
  .card { padding: 24px; }
}

/* --- Каталог «Мосфильма» --- */

#catalog-q {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 16px;
  padding: 13px 15px;
  font-family: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
}

#catalog-q:focus {
  outline: none;
  border-color: rgba(255, 179, 64, 0.55);
  box-shadow: 0 0 0 3.5px rgba(255, 179, 64, 0.13);
}

.catalog-meta {
  color: #62626f;
  font-size: 12.5px;
  margin: 10px 2px 14px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

@media (min-width: 620px) {
  .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

.film {
  /* Именно block, а не flex: у флекс-элемента браузер блокифицирует
     display:-webkit-box, и обрезка названия по двум строкам отваливается. */
  display: block;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  overflow: hidden;
  padding: 0;
  text-align: left;
  color: var(--text);
}

.film:hover { border-color: var(--line-strong); }

.film .poster {
  display: block;
  position: relative;
  aspect-ratio: 16 / 9;
  background: var(--surface-2);
  overflow: hidden;
}

.film .poster img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.film .len {
  position: absolute;
  right: 6px;
  bottom: 6px;
  background: rgba(0, 0, 0, 0.78);
  color: #fff;
  font-size: 11.5px;
  font-weight: 550;
  padding: 2px 7px;
  border-radius: 5px;
}

.film .name {
  display: block;
  padding: 10px 11px 12px;
}

.film .clamp {
  font-size: 13.5px;
  line-height: 1.35;
  font-weight: 550;
  /* Работает только на вложенном элементе — см. комментарий в app.js. */
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.film .caption {
  display: block;
  margin-top: 4px;
  font-size: 11.5px;
  color: var(--muted);
}

.catalog-empty {
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 14px;
  padding: 18px 2px;
}

/* --- Страница закладки --- */

.steps {
  margin: 0;
  padding-left: 20px;
  color: var(--muted);
  font-size: 14.5px;
  line-height: 1.65;
}

.steps li { margin-bottom: 7px; }
.steps li::marker { color: var(--accent); font-weight: 600; }

.code-box {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  line-height: 1.5;
  padding: 12px;
  resize: vertical;
}

/* --- Логотип-ссылка и навигация --- */

.brand {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  text-decoration: none;
  color: inherit;
  border-radius: 12px;
  transition: opacity 0.15s;
}

.brand:hover { opacity: 0.82; }
.brand:active { transform: scale(0.98); }

.tabs {
  display: flex;
  gap: 6px;
  margin: 0 0 22px;
  padding: 4px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow-x: auto;
  scrollbar-width: none;
}

.tabs::-webkit-scrollbar { display: none; }

.tab {
  flex: 1;
  min-width: max-content;
  text-align: center;
  padding: 9px 16px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 540;
  color: var(--muted);
  text-decoration: none;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
}

.tab:hover { color: var(--text); }

.tab.is-active {
  background: rgba(255, 179, 64, 0.13);
  color: var(--accent);
}

/* Шапка теперь несёт навигацию — отступ снизу переехал на .tabs */
.masthead { padding-bottom: 16px; }

/* --- Живое окно браузера --- */

.browser-bar {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-bottom: 10px;
}

.addr {
  flex: 1;
  min-width: 0;
  font-size: 12.5px;
  color: var(--muted);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 100px;
  padding: 7px 13px;
}

.screen-frame {
  position: relative;
  background: #000;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  aspect-ratio: 16 / 9;
}

#screen {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  cursor: crosshair;
  touch-action: pan-y;
}

.veil {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.45);
}

.stream-row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 13px 15px;
  margin-bottom: 8px;
  color: var(--text);
}

.stream-row:hover { border-color: rgba(255, 179, 64, 0.42); }
.stream-row .info { flex: 1; min-width: 0; }
.stream-row .q { font-size: 14px; font-weight: 550; }
.stream-row .src { font-size: 11.5px; color: var(--muted); margin-top: 3px; }
.stream-row .go { color: var(--accent); font-size: 13px; font-weight: 560; flex: none; }

.empty-note { color: var(--muted); font-size: 14px; padding: 4px 2px 8px; }
