/* Тема берётся из Telegram: он подставляет --tg-theme-* под клиент пользователя.
   Значения после запятой — на случай, когда мини-апп открыт вне Telegram
   (например, вручную в браузере при отладке). */
:root {
  --bg: var(--tg-theme-bg-color, #17212b);
  --panel: var(--tg-theme-secondary-bg-color, #232e3c);
  --text: var(--tg-theme-text-color, #f5f5f5);
  --hint: var(--tg-theme-hint-color, #8a97a5);
  --link: var(--tg-theme-link-color, #62bcf9);
  --button: var(--tg-theme-button-color, #3390ec);
  --button-text: var(--tg-theme-button-text-color, #ffffff);
  --danger: #e5534b;
  --line: rgba(128, 140, 155, .25);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; height: 100%;
  background: var(--bg); color: var(--text);
  font: 15px/1.35 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
}

body {
  display: flex; flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom);
}

.hidden { display: none !important; }

/* ---------- плеер ---------- */
#player {
  position: relative; background: #000;
  flex: 0 0 auto; line-height: 0;
}
#video { width: 100%; max-height: 38vh; object-fit: contain; }

#overlay {
  position: absolute; inset: 0; display: flex;
  align-items: center; justify-content: center;
  color: var(--hint); font-size: 13px; line-height: 1.4;
  text-align: center; padding: 16px; background: #000;
  white-space: pre-line;   /* перенос в сообщении — по \n, а не по ширине */
}
/* Оверлей, по которому есть смысл тапнуть (повторить загрузку видео). */
#overlay.tappable { cursor: pointer; }

/* Охранное поле: рамка по границе зоны, свободной от интерфейса площадки.
   Координаты ставит app.js — они зависят и от формата, и от того, каким
   прямоугольником видео реально легло в плеер (object-fit: contain). */
#safe {
  position: absolute; inset: 0;
  pointer-events: none;
}
#safe.on { outline: 1px dashed rgba(255, 90, 90, .9); outline-offset: -1px; }
#safe-label {
  position: absolute; top: 2px; left: 4px;
  font-size: 10px; line-height: 1.2; color: #ff8a8a;
  text-shadow: 0 1px 2px #000; letter-spacing: .02em;
}
#safe:not(.on) #safe-label { display: none; }

/* Подпись поверх видео — не «как в рендере», а чтобы видеть, что читается
   в этот момент. Точный кегль и переносы считает libass при сборке. */
#sub {
  position: absolute; left: 0; right: 0; bottom: 4%;
  text-align: center; padding: 0 4%;
  font-weight: 700; font-size: clamp(13px, 3.6vw, 20px); line-height: 1.25;
  color: #fff; text-shadow: 0 0 4px #000, 0 1px 3px #000;
  pointer-events: none; white-space: pre-wrap;
}

/* ---------- транспорт ---------- */
#bar {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px; background: var(--panel);
  border-bottom: 1px solid var(--line); flex: 0 0 auto;
}
#clock { font-variant-numeric: tabular-nums; font-size: 13px; color: var(--hint); min-width: 42px; }
#seek { flex: 1; accent-color: var(--button); }

button {
  font: inherit; color: var(--text); background: transparent;
  border: 1px solid var(--line); border-radius: 8px;
  padding: 7px 12px; cursor: pointer;
}
button:active { opacity: .6; }
button.icon { border: none; padding: 4px 8px; font-size: 18px; line-height: 1; }
button.icon.on { color: var(--link); }
button.icon.off { color: var(--hint); }
button.primary { background: var(--button); color: var(--button-text); border-color: transparent; font-weight: 600; }
button.danger { color: var(--danger); border-color: var(--danger); }
button[disabled] { opacity: .45; pointer-events: none; }

/* ---------- список реплик ---------- */
#list { flex: 1 1 auto; overflow-y: auto; -webkit-overflow-scrolling: touch; }

.cue {
  display: flex; gap: 10px; align-items: baseline;
  padding: 10px 12px; border-bottom: 1px solid var(--line);
  cursor: pointer;
}
.cue.active { background: rgba(51, 144, 236, .16); }
.cue .num {
  flex: 0 0 auto; min-width: 26px; text-align: right;
  color: var(--hint); font-size: 12px; font-variant-numeric: tabular-nums;
}
.cue .body { flex: 1 1 auto; min-width: 0; }
.cue .txt { white-space: pre-wrap; overflow-wrap: anywhere; }
.cue .meta { color: var(--hint); font-size: 11px; margin-top: 3px; font-variant-numeric: tabular-nums; }
/* Реплика, которую не разложить в max_lines строк заданной длины: её кегль
   при сборке ужмётся, а с autofit=uniform утянет за собой всё видео. */
.cue.over .meta { color: var(--danger); }

#empty { padding: 28px 16px; text-align: center; color: var(--hint); }

/* ---------- подвал ---------- */
#foot {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; background: var(--panel);
  border-top: 1px solid var(--line); flex: 0 0 auto;
}
#status { flex: 1; font-size: 12px; color: var(--hint); }

/* ---------- лист правки ---------- */
#sheet {
  position: fixed; inset: 0; z-index: 10;
  background: rgba(0, 0, 0, .55);
  display: flex; align-items: flex-end;
}
#sheet-inner {
  width: 100%; background: var(--panel);
  border-radius: 14px 14px 0 0; padding: 14px;
  padding-bottom: calc(14px + env(safe-area-inset-bottom));
  max-height: 92vh; overflow-y: auto;
}
#sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
#sheet-title { font-weight: 600; }

#sheet-text {
  width: 100%; resize: vertical; font: inherit;
  color: var(--text); background: var(--bg);
  border: 1px solid var(--line); border-radius: 10px; padding: 10px;
}
#sheet-hint { font-size: 12px; color: var(--hint); margin: 6px 2px 12px; }
#sheet-hint.warn { color: var(--danger); }

#sheet-times { display: flex; gap: 12px; margin-bottom: 12px; }
#sheet-times label { flex: 1; font-size: 12px; color: var(--hint); }
.nudge {
  display: flex; align-items: center; justify-content: space-between;
  gap: 6px; margin-top: 5px;
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 4px;
}
.nudge span { color: var(--text); font-size: 14px; font-variant-numeric: tabular-nums; }
.nudge button { border: none; padding: 4px 12px; font-size: 17px; line-height: 1; }

#sheet-actions { display: flex; flex-wrap: wrap; gap: 8px; }
#sheet-actions button { flex: 1 1 calc(50% - 8px); }
