:root {
  --bg: #14181f;
  --bg-elev: #1c222c;
  --bg-soft: #242b37;
  --line: rgba(255, 255, 255, 0.08);
  --text: #eef1f5;
  --muted: #9aa3b2;
  --accent: #4f8cff;
  --accent-2: #7eb0ff;
  --danger: #e25b5b;
  --ok: #3dbf8a;
  --radius: 14px;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
  --font: "Manrope", system-ui, sans-serif;
  --display: "Fraunces", Georgia, serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --top: 56px;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
}

body {
  background:
    radial-gradient(1200px 500px at 10% -10%, rgba(79, 140, 255, 0.16), transparent 55%),
    radial-gradient(900px 420px at 100% 0%, rgba(62, 90, 130, 0.18), transparent 50%),
    var(--bg);
}

button, input, textarea, select {
  font: inherit;
  color: inherit;
}

#app {
  max-width: 920px;
  margin: 0 auto;
  min-height: 100dvh;
  padding-bottom: calc(24px + var(--safe-b));
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  height: var(--top);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 14px;
  background: rgba(20, 24, 31, 0.85);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
}

.brand-mark {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  background: linear-gradient(145deg, #5b95ff, #3a6fd6);
  font-weight: 700;
  font-size: 14px;
}

.brand-mark.lg {
  width: 52px;
  height: 52px;
  font-size: 22px;
  border-radius: 14px;
  margin: 0 auto 12px;
}

.brand-name {
  font-family: var(--display);
  font-size: 1.25rem;
  letter-spacing: 0.01em;
}

.topbar-actions { margin-left: auto; }

.icon-btn, .text-btn, .btn, .tab {
  border: 0;
  background: transparent;
  cursor: pointer;
}

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--bg-soft);
}

.text-btn {
  color: var(--accent-2);
  font-weight: 600;
  padding: 8px 10px;
}

.view { padding: 16px 14px 0; }
.hidden { display: none !important; }

.hero-strip h1 {
  margin: 4px 0 6px;
  font-family: var(--display);
  font-size: 1.8rem;
  font-weight: 700;
}

.hero-strip p {
  margin: 0 0 16px;
  color: var(--muted);
  line-height: 1.45;
}

.search-row { margin-bottom: 16px; }

.search-row input {
  width: 100%;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--bg-elev);
  outline: none;
}

.search-row input:focus {
  border-color: rgba(79, 140, 255, 0.55);
}

.catalog-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

@media (min-width: 640px) {
  .catalog-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
}

.card-title {
  display: block;
  text-align: left;
  border: 0;
  padding: 0;
  background: var(--bg-elev);
  border-radius: 16px;
  overflow: hidden;
  border: 1px solid var(--line);
  cursor: pointer;
  transition: transform 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease;
}

.card-title:active { transform: scale(0.98); }
.card-title:hover {
  border-color: rgba(79, 140, 255, 0.35);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.28);
}

.card-cover {
  aspect-ratio: 3 / 4;
  background:
    linear-gradient(160deg, #2a3344, #1a2030 60%),
    var(--bg-soft);
  background-size: cover;
  background-position: center;
}

.card-body { padding: 11px 12px 13px; }
.card-body h3 {
  margin: 0 0 4px;
  font-size: 0.98rem;
  line-height: 1.3;
  font-weight: 650;
}
.card-body p {
  margin: 0;
  color: var(--muted);
  font-size: 0.8rem;
}

.empty, .hint, .muted { color: var(--muted); }
.empty { text-align: center; padding: 40px 10px; }

.title-hero {
  position: relative;
  min-height: 220px;
  border-radius: 18px;
  overflow: hidden;
  background: linear-gradient(145deg, #2b3446, #171c26);
  background-size: cover;
  background-position: center;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}

.title-hero-shade {
  position: absolute;
  inset: auto 0 0 0;
  padding: 22px 16px 16px;
  background: linear-gradient(to top, rgba(10, 12, 16, 0.92), transparent);
}

.title-hero h1 {
  margin: 0 0 6px;
  font-family: var(--display);
  font-size: 1.7rem;
}

.title-desc {
  line-height: 1.55;
  color: #c5ccd8;
  margin: 0 0 18px;
  white-space: pre-wrap; /* абзаци, переноси й пробіли як у вводі */
  word-break: break-word;
}

.section-label {
  margin: 0 0 10px;
  font-size: 1rem;
  font-weight: 700;
}

.episode-list { display: grid; gap: 8px; }

.ep-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--bg-elev);
  cursor: pointer;
}

.ep-item:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.ep-num {
  width: 42px;
  height: 42px;
  border-radius: 11px;
  display: grid;
  place-items: center;
  background: var(--bg-soft);
  font-weight: 700;
  color: var(--accent-2);
  flex-shrink: 0;
}

.ep-item strong { display: block; font-size: 0.95rem; }
.ep-item span { font-size: 0.8rem; color: var(--muted); }
.ep-item .go { margin-left: auto; color: var(--accent-2); font-weight: 700; }

/* ——— Cinema player ——— */
.player-view {
  padding: 0 !important;
  margin: 0;
}

body.cinema-mode .topbar { display: none; }
body.cinema-mode #app {
  max-width: none;
  padding-bottom: 0;
}

.cinema {
  position: relative;
  width: 100%;
  min-height: 100dvh;
  background: #000;
}

.cinema-stage {
  position: relative;
  width: 100%;
  height: 100dvh;
  background: #000;
  overflow: hidden;
  touch-action: manipulation;
}

#player {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
  outline: none;
}

.cinema-ui {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  background: linear-gradient(to bottom, rgba(0,0,0,.72) 0%, transparent 28%, transparent 62%, rgba(0,0,0,.78) 100%);
  opacity: 1;
  transition: opacity 0.25s ease;
  pointer-events: none;
}

.cinema-ui.is-hidden { opacity: 0; }
.cinema-ui > * { pointer-events: auto; }

.cinema-top, .cinema-bottom {
  padding: 12px 14px;
}

.cinema-top {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding-top: calc(12px + env(safe-area-inset-top, 0px));
}

.cinema-head { flex: 1; min-width: 0; }
.cinema-head h2 {
  margin: 0 0 2px;
  font-size: 1.05rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cinema-head p {
  margin: 0;
  font-size: 0.85rem;
  color: rgba(255,255,255,.72);
}

.cinema-icon, .cinema-playbtn, .cinema-bigplay {
  border: 0;
  cursor: pointer;
  color: #fff;
  background: rgba(255,255,255,.12);
}

.cinema-icon {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-size: 1.05rem;
  flex-shrink: 0;
}

.cinema-playbtn {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  font-size: 1.1rem;
  background: var(--accent);
}

.cinema-bigplay {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 72px;
  height: 72px;
  border-radius: 50%;
  font-size: 1.4rem;
  background: rgba(79, 140, 255, 0.92);
  z-index: 3;
  box-shadow: 0 10px 40px rgba(0,0,0,.45);
}

.cinema-bigplay.hidden { display: none; }

.cinema-progress {
  height: 4px;
  border-radius: 99px;
  background: rgba(255,255,255,.2);
  margin-bottom: 12px;
  cursor: pointer;
  touch-action: none;
}

.cinema-progress-bar {
  height: 100%;
  width: 0%;
  border-radius: inherit;
  background: var(--accent);
  pointer-events: none;
}

.cinema-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

.cinema-time {
  margin-left: 4px;
  font-size: 0.8rem;
  color: rgba(255,255,255,.78);
  font-variant-numeric: tabular-nums;
}

.cinema-autonext {
  margin-left: auto;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ok);
  opacity: 0.9;
}

.cinema-loading, .cinema-error {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 12px;
  text-align: center;
  background: rgba(0,0,0,.45);
  z-index: 2;
  color: rgba(255,255,255,.85);
}

.cinema-spinner {
  width: 36px;
  height: 36px;
  margin: 0 auto;
  border-radius: 50%;
  border: 3px solid rgba(255,255,255,.2);
  border-top-color: #fff;
  animation: spin 0.7s linear infinite;
}

.cinema-error p {
  margin: 0 16px 8px;
  max-width: 320px;
  line-height: 1.4;
}

.cinema-icon:disabled, .cinema-playbtn:disabled {
  opacity: 0.35;
  cursor: default;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ——— Admin ——— */
.admin-shell { padding-bottom: 8px; }

.admin-nav {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 4px;
  margin-bottom: 16px;
  border-radius: 14px;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--line);
}

.admin-nav-btn {
  padding: 11px 12px;
  border-radius: 11px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-weight: 650;
  cursor: pointer;
}

.admin-nav-btn.active {
  background: var(--bg-elev);
  color: var(--text);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
}

.admin-toolbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.admin-toolbar .btn {
  flex-shrink: 0;
  white-space: nowrap;
}

.btn.is-busy {
  opacity: 0.7;
  pointer-events: none;
}

.admin-heading {
  margin: 0 0 4px;
  font-family: var(--display);
  font-size: 1.45rem;
}

.admin-sub {
  margin: 0;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.4;
}

.admin-title-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

@media (min-width: 640px) {
  .admin-title-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

.admin-title-card {
  display: block;
  text-align: left;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 16px;
  overflow: hidden;
  background: var(--bg-elev);
  cursor: pointer;
  transition: border-color 0.18s ease, transform 0.18s ease;
}

.admin-title-card:active { transform: scale(0.98); }
.admin-title-card:hover { border-color: rgba(79, 140, 255, 0.4); }

.admin-title-cover {
  aspect-ratio: 16 / 10;
  background: linear-gradient(145deg, #2b3446, #171c26);
  background-size: cover;
  background-position: center;
}

.admin-title-body { padding: 10px 11px 12px; }
.admin-title-body h3 {
  margin: 0 0 6px;
  font-size: 0.95rem;
  line-height: 1.25;
}
.admin-title-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 10px;
  align-items: center;
  font-size: 0.78rem;
}

.chip-soft {
  display: inline-flex;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(79, 140, 255, 0.14);
  color: var(--accent-2);
  font-weight: 600;
}

.media-controls { display: grid; gap: 10px; margin-bottom: 14px; }
.media-controls input {
  width: 100%;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--bg-elev);
  outline: none;
}

.filter-chips {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.chip {
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--bg-elev);
  color: var(--muted);
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
}

.chip.active {
  color: var(--text);
  border-color: rgba(79, 140, 255, 0.45);
  background: rgba(79, 140, 255, 0.14);
}

.attach-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  margin-bottom: 12px;
  border-radius: 14px;
  border: 1px solid rgba(79, 140, 255, 0.35);
  background: linear-gradient(135deg, rgba(79, 140, 255, 0.16), rgba(79, 140, 255, 0.05));
}

.attach-banner strong { display: block; margin-bottom: 2px; }
.attach-banner span { font-size: 0.85rem; }

.media-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

@media (min-width: 560px) {
  .media-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

.media-card {
  display: grid;
  gap: 6px;
  text-align: left;
  padding: 12px 13px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--bg-elev);
  cursor: pointer;
  transition: border-color 0.15s ease, transform 0.15s ease, background 0.15s ease;
}

.media-card:hover { border-color: rgba(79, 140, 255, 0.35); }
.media-card.is-pickable {
  border-color: rgba(61, 191, 138, 0.35);
  background: linear-gradient(180deg, rgba(61, 191, 138, 0.08), var(--bg-elev));
}
.media-card.is-used { opacity: 0.72; }
.media-card:active { transform: scale(0.985); }

.media-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.file-icon {
  min-width: 44px;
  height: 44px;
  padding: 0 8px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: linear-gradient(145deg, #3a4a66, #243044);
  color: #d7e4ff;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.04em;
}

.file-icon.lg {
  min-width: 52px;
  height: 52px;
  font-size: 0.8rem;
}

.media-badge {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.media-fname {
  margin: 2px 0 0;
  font-size: 0.92rem;
  line-height: 1.3;
  word-break: break-word;
  font-weight: 650;
}

.media-meta, .media-status {
  margin: 0;
  font-size: 0.78rem;
}

.media-status { color: var(--accent-2); min-height: 1.1em; }

.row-2 {
  display: grid;
  gap: 10px;
}

@media (min-width: 520px) {
  .row-2 { grid-template-columns: 1fr 1fr; }
}

.form-actions {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}

.btn {
  padding: 10px 14px;
  border-radius: 11px;
  font-weight: 650;
  border: 0;
  cursor: pointer;
}

.btn.primary {
  background: var(--accent);
  color: #fff;
}

.btn.ghost {
  background: var(--bg-soft);
  color: var(--text);
}

.btn.danger {
  background: rgba(226, 91, 91, 0.18);
  color: #ffb0b0;
}

.btn.grow { width: 100%; }

/* Sheets */
body.sheet-open { overflow: hidden; }

.sheet {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(6, 8, 12, 0.62);
  backdrop-filter: blur(4px);
}

.sheet-card {
  position: relative;
  z-index: 1;
  width: min(100%, 560px);
  max-height: min(88dvh, 760px);
  overflow: auto;
  padding: 8px 16px calc(18px + var(--safe-b));
  border-radius: 22px 22px 0 0;
  background: #1a1f29;
  border: 1px solid var(--line);
  border-bottom: 0;
  box-shadow: 0 -20px 60px rgba(0, 0, 0, 0.45);
  animation: sheetUp 0.22s ease;
}

.sheet-card-sm { max-height: 70dvh; }

.sheet-handle {
  width: 42px;
  height: 4px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.18);
  margin: 4px auto 12px;
}

.sheet-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.sheet-head h2 {
  margin: 0;
  font-size: 1.2rem;
  font-family: var(--display);
}

.eyebrow {
  margin: 0 0 4px;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-weight: 700;
}

.sheet-actions {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.sheet-form label {
  display: grid;
  gap: 6px;
  margin-bottom: 10px;
  font-size: 0.85rem;
  color: var(--muted);
}

.sheet-form input,
.sheet-form textarea,
.sheet-form select,
.sheet-card label input {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg);
  outline: none;
  color: var(--text);
}

.sheet-form textarea.desc-input {
  min-height: 160px;
  resize: vertical;
  line-height: 1.5;
  white-space: pre-wrap;
  field-sizing: content;
}

.sheet-form .check,
.sheet-card .check {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
}

.sheet-form .check input { width: auto; }

.sheet-card label {
  display: grid;
  gap: 6px;
  margin-bottom: 10px;
  font-size: 0.85rem;
  color: var(--muted);
}

.ws-episodes { display: grid; gap: 8px; }

.ws-ep {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--bg);
  border: 1px solid var(--line);
}

.ws-ep-body { flex: 1; min-width: 0; }
.ws-ep-body strong { display: block; font-size: 0.92rem; }
.ws-ep-body .file-name {
  display: block;
  margin-top: 2px;
  font-size: 0.78rem;
  color: var(--muted);
  word-break: break-all;
}

.ep-num.sm {
  width: 36px;
  height: 36px;
  font-size: 0.85rem;
}

.danger-soft {
  background: rgba(226, 91, 91, 0.14) !important;
  color: #ffb0b0;
}

.pin-preview {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 12px;
  margin-bottom: 12px;
  border-radius: 14px;
  background: var(--bg);
  border: 1px solid var(--line);
}

.pin-preview strong {
  display: block;
  word-break: break-word;
  margin-bottom: 4px;
}

.pin-target { margin: 0 0 12px; }

.empty.soft { padding: 18px 8px; }

@keyframes sheetUp {
  from { transform: translateY(18px); opacity: 0.6; }
  to { transform: none; opacity: 1; }
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(18px + var(--safe-b));
  transform: translateX(-50%);
  z-index: 50;
  max-width: min(92vw, 420px);
  padding: 12px 16px;
  border-radius: 12px;
  background: #10141b;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  font-size: 0.9rem;
}

.boot {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  background: var(--bg);
}

.boot-card { text-align: center; color: var(--muted); }

@keyframes fadein {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

.view:not(.hidden) { animation: fadein 0.22s ease; }
.card-title { animation: fadein 0.28s ease; }
