:root {
    --bg: #0A0A0F;
    --bg-raised: #15141C;
    --bg-sunken: #0E0D13;
    --line: #262533;
    --line-soft: #1D1C26;
    --grad-1: #FF4D8D;
    --grad-2: #7C3AED;
    --grad-3: #4D7CFF;
    --text: #F5F3F7;
    --text-dim: #57546A;
    --text-mid: #8B8794;
    --warn: #FF6B6B;
    --display: 'Space Grotesk', sans-serif;
    --sans: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --nav-h: 64px;
    --safe-b: env(safe-area-inset-bottom, 0px);

    /* единая система скругления, в духе iOS: крупные блоки самые круглые */
    --r-xl: 26px;   /* крупные карточки, панели */
    --r-lg: 20px;   /* поля ввода, главные кнопки */
    --r-md: 16px;   /* средние кнопки, плеер, превью */
    --r-sm: 13px;   /* мелкие элементы внутри панелей */
    --r-pill: 999px; /* полностью круглые элементы */
  }

  * { box-sizing: border-box; }
  html, body { margin: 0; overflow-x: hidden; overflow-y: visible; height: auto; touch-action: auto; }
  html { scrollbar-width: none; -ms-overflow-style: none; }
  html::-webkit-scrollbar { display: none; }

  body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--sans);
    min-height: 100dvh;
    width: 100%;
    -webkit-tap-highlight-color: transparent;
  }

  /* мягкое радиальное зарево в верхней части экрана — атмосфера, не декор */
  body::before {
    content: "";
    position: fixed;
    top: -120px; left: 50%;
    width: 480px; height: 320px;
    transform: translateX(-50%);
    background: radial-gradient(ellipse at center, rgba(124,58,237,0.20), rgba(255,77,141,0.10) 45%, transparent 75%);
    pointer-events: none;
    z-index: 0;
    filter: blur(10px);
  }

  .screen {
    display: none;
    max-width: 640px;
    margin: 0 auto;
    padding: 28px 18px calc(var(--nav-h) + var(--safe-b) + 28px);
    position: relative;
    z-index: 2;
    min-height: 100dvh;
  }
  .screen.active { display: block; animation: screenIn 0.3s ease; }
  @keyframes screenIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }

  /* ── shared header ────────────────────────────────────── */

  .head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
  }
  .logo {
    font-family: var(--display);
    font-size: 24px; font-weight: 700; letter-spacing: -0.5px;
    background: linear-gradient(95deg, var(--grad-1), var(--grad-2) 60%, var(--grad-3));
    -webkit-background-clip: text; background-clip: text; color: transparent;
  }

  .subtitle { color: var(--text-mid); font-size: 13.5px; margin: 0 0 26px; line-height: 1.55; }

  /* ── input bars ───────────────────────────────────────── */

  .prompt-bar {
    background: var(--bg-raised);
    border: 1.5px solid var(--line);
    border-radius: var(--r-lg);
    display: flex;
    align-items: center;
    padding: 0 5px 0 18px;
    transition: border-color 0.2s, box-shadow 0.2s;
  }
  .prompt-bar:focus-within {
    border-color: transparent;
    box-shadow: 0 0 0 1.5px var(--grad-2), 0 0 24px rgba(124,58,237,0.25);
  }
  .prompt-bar .chevron { display: none; }
  .prompt-bar input {
    flex: 1; background: none; border: none; outline: none;
    color: var(--text); font-family: var(--sans); font-size: 15px; font-weight: 500;
    padding: 16px 4px; min-width: 0;
  }
  .prompt-bar input::placeholder { color: var(--text-dim); font-weight: 400; }

  .btn-go {
    background: linear-gradient(95deg, var(--grad-1), var(--grad-2));
    color: #fff; border: none;
    font-family: var(--sans); font-weight: 600; font-size: 13.5px;
    letter-spacing: 0; padding: 13px 22px; border-radius: var(--r-md);
    cursor: pointer; flex-shrink: 0; transition: opacity 0.15s, transform 0.1s, box-shadow 0.2s;
    margin: 5px;
    box-shadow: 0 4px 14px rgba(255,77,141,0.25);
  }
  .btn-go:active { transform: scale(0.96); box-shadow: 0 2px 8px rgba(255,77,141,0.2); }
  .btn-go:disabled { opacity: 0.3; cursor: default; box-shadow: none; }

  .hint-row { display: flex; gap: 16px; margin-top: 12px; padding-left: 4px; }
  .hint-row span { font-size: 11.5px; color: var(--text-dim); }
  .hint-row b { color: var(--text-mid); font-weight: 600; }

  /* ── console / output area ────────────────────────────── */

  .console { margin-top: 24px; min-height: 2px; }

  .line {
    font-size: 12.5px; line-height: 1.7; color: var(--text-mid); font-weight: 500;
    white-space: pre-wrap; word-break: break-all;
    opacity: 0; animation: fadeIn 0.25s ease forwards;
  }
  @keyframes fadeIn { to { opacity: 1; } }
  .line .ok { color: var(--grad-1); }
  .line .err { color: var(--warn); }
  .line .dim { color: var(--text-dim); }
  .cursor-blink::after { content: ""; }

  /* ── result card (download flow) ──────────────────────── */

  .card {
    margin-top: 18px; border: 1px solid var(--line); border-radius: var(--r-lg);
    background: var(--bg-raised); overflow: hidden;
    opacity: 0; animation: cardIn 0.3s ease forwards;
    box-shadow: 0 8px 28px rgba(0,0,0,0.35);
  }
  @keyframes cardIn { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: translateY(0); } }

  .card-head { padding: 16px 18px 14px; border-bottom: 1px solid var(--line); }
  .card-thumb {
    width: 100%; aspect-ratio: 16/9; object-fit: cover; border-radius: var(--r-sm);
    margin-bottom: 12px; background: var(--bg-sunken); display: block;
  }
  .card-platform {
    font-size: 10px; letter-spacing: 1.2px; text-transform: uppercase; margin-bottom: 7px;
    font-weight: 700;
    background: linear-gradient(95deg, var(--grad-1), var(--grad-3));
    -webkit-background-clip: text; background-clip: text; color: transparent;
    display: inline-block;
  }
  .card-title { font-size: 13.5px; color: var(--text); line-height: 1.4; word-break: break-word; font-weight: 500; }
  .card-meta { font-size: 11.5px; color: var(--text-dim); margin-top: 4px; font-weight: 500; }

  /* ── inline player (вместо статичного thumbnail, только YouTube) ───────── */

  .card-player {
    width: 100%; aspect-ratio: 16/9; border-radius: var(--r-sm);
    margin-bottom: 12px; background: var(--bg-sunken); display: block;
    border: none; overflow: hidden;
  }
  .card-thumb-wrap {
    position: relative; width: 100%; aspect-ratio: 16/9;
    margin-bottom: 12px; border-radius: var(--r-sm); overflow: hidden;
    background: var(--bg-sunken); cursor: pointer;
  }
  .card-thumb-wrap .card-thumb { margin-bottom: 0; height: 100%; }
  .card-thumb-wrap .play-overlay {
    position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
    background: rgba(10,10,15,0.25); transition: background 0.15s;
  }
  .card-thumb-wrap:active .play-overlay { background: rgba(10,10,15,0.4); }
  .play-overlay .play-circle {
    width: 52px; height: 52px; border-radius: var(--r-pill);
    background: rgba(21,20,28,0.85); border: 1.5px solid rgba(255,255,255,0.25);
    display: flex; align-items: center; justify-content: center;
    box-shadow: 0 6px 20px rgba(0,0,0,0.4);
  }
  .play-circle::after {
    content: ""; border-style: solid; border-width: 9px 0 9px 15px;
    border-color: transparent transparent transparent #fff;
    margin-left: 2px;
  }

  .fmt-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1px; background: var(--line); }
  .fmt-btn {
    background: var(--bg-raised); border: none; color: var(--text);
    font-family: var(--sans); font-size: 13px; font-weight: 600;
    padding: 17px 8px; cursor: pointer; transition: background 0.15s, color 0.15s;
  }
  .fmt-grid .fmt-btn:nth-last-child(3) { border-radius: 0 0 0 var(--r-sm); }
  .fmt-grid .fmt-btn:last-child { border-radius: 0 0 var(--r-sm) 0; }
  .fmt-btn:active { background: linear-gradient(135deg, var(--grad-1), var(--grad-2)); color: #fff; }
  .fmt-btn.mp3 { color: var(--text-mid); font-weight: 500; font-size: 11.5px; }

  .simple-actions { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1px; background: var(--line); }
  .simple-actions .fmt-btn:first-child { border-radius: 0 0 0 var(--r-sm); }
  .simple-actions .fmt-btn:last-child { border-radius: 0 0 var(--r-sm) 0; }

  .progress-wrap { padding: 16px 18px; }
  .spinner-row { display: flex; align-items: center; gap: 12px; }
  .spinner {
    width: 18px; height: 18px; flex-shrink: 0;
    border: 2.5px solid var(--line);
    border-top-color: var(--grad-1);
    border-radius: var(--r-pill);
    animation: spin 0.7s linear infinite;
  }
  @keyframes spin { to { transform: rotate(360deg); } }
  .spinner-label { font-size: 12.5px; color: var(--text-mid); font-weight: 500; flex: 1; }

  .inline-loader {
    display: flex; align-items: center; gap: 10px;
    padding: 14px 4px; font-size: 12.5px; color: var(--text-dim); font-weight: 500;
  }
  .inline-loader .spinner { width: 16px; height: 16px; }

  .watch-player-loader {
    position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
    background: rgba(10,10,15,0.55); flex-direction: column; gap: 10px;
  }
  .watch-player-loader .spinner { width: 26px; height: 26px; border-width: 3px; }

  .search-scroll-sentinel { height: 1px; width: 100%; }
  .search-load-more-loader { justify-content: center; padding: 18px 4px; }
  .cancel-btn {
    width: 28px; height: 28px; border-radius: var(--r-pill); flex-shrink: 0;
    background: var(--bg-sunken); border: 1px solid var(--line);
    color: var(--text-mid); font-size: 13px; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: color 0.15s, border-color 0.15s;
  }
  .cancel-btn:active { color: var(--warn); border-color: var(--warn); }

  .ready { padding: 18px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
  .ready-info { font-size: 11.5px; color: var(--text-mid); font-weight: 500; }
  .ready-info b { color: var(--text); font-size: 14px; font-family: var(--display); font-weight: 600; }

  .btn-dl {
    background: linear-gradient(95deg, var(--grad-1), var(--grad-2)); color: #fff; border: none;
    font-family: var(--sans); font-weight: 600; font-size: 12.5px;
    padding: 13px 20px; border-radius: var(--r-md); cursor: pointer; flex-shrink: 0;
    text-decoration: none; white-space: nowrap;
    box-shadow: 0 4px 14px rgba(255,77,141,0.25);
  }
  .btn-dl:active { transform: scale(0.96); }

  .err-box { padding: 16px 18px; color: var(--warn); font-size: 12.5px; line-height: 1.5; font-weight: 500; }

  /* ── toast: правый верхний угол, плавающие предупреждения, не сдвигают контент ── */

  .toast-stack {
    position: fixed;
    top: calc(env(safe-area-inset-top, 0px) + 14px);
    right: 14px;
    z-index: 100;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 8px;
    max-width: min(78vw, 320px);
    pointer-events: none;
  }
  .toast {
    pointer-events: auto;
    background: var(--bg-raised);
    border: 1px solid rgba(255,107,107,0.35);
    border-radius: var(--r-md);
    padding: 11px 14px;
    font-size: 11.5px;
    line-height: 1.45;
    font-weight: 500;
    color: var(--warn);
    box-shadow: 0 8px 24px rgba(0,0,0,0.45);
    animation: toastIn 0.22s ease;
    max-width: 100%;
  }
  @keyframes toastIn { from { opacity: 0; transform: translateX(12px); } to { opacity: 1; transform: translateX(0); } }
  .toast.toast-out { animation: toastOut 0.18s ease forwards; }
  @keyframes toastOut { to { opacity: 0; transform: translateX(12px); } }

  /* ── search screen ────────────────────────────────────── */

  .search-results {
    margin-top: 18px;
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px 12px;
  }

  .result-row {
    cursor: pointer;
    display: flex;
    flex-direction: column;
  }
  .result-thumb {
    width: 100%; aspect-ratio: 16/9; object-fit: cover; border-radius: var(--r-md);
    background: var(--line); margin-bottom: 9px;
    transition: opacity 0.15s, box-shadow 0.2s;
  }
  .result-row:active .result-thumb { opacity: 0.75; }
  .result-info { display: flex; flex-direction: column; min-width: 0; gap: 3px; }
  .result-title {
    font-size: 12.5px; color: var(--text); line-height: 1.35; font-weight: 600;
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  }
  .result-meta { font-size: 11px; color: var(--text-dim); font-weight: 500; }

  /* карточка скачивания, открытая под выбранным результатом, на всю ширину грида */
  .result-card-full { grid-column: 1 / -1; }

  /* ── history screen ───────────────────────────────────── */

  .history-list { display: flex; flex-direction: column; gap: 10px; margin-top: 4px; }
  .history-item {
    background: var(--bg-raised); border: 1px solid var(--line); border-radius: var(--r-md);
    padding: 14px 16px; display: flex; align-items: center; gap: 13px;
    position: relative;
  }
  .history-icon {
    font-size: 15px; flex-shrink: 0; width: 36px; height: 36px;
    display: flex; align-items: center; justify-content: center;
    border-radius: var(--r-sm);
    background: linear-gradient(135deg, rgba(255,77,141,0.15), rgba(124,58,237,0.15));
  }
  .history-body { flex: 1; min-width: 0; }
  .history-title {
    font-size: 12.5px; color: var(--text); line-height: 1.4; font-weight: 500;
    display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; overflow: hidden;
    word-break: break-all;
  }
  .history-meta { font-size: 10.5px; color: var(--text-dim); margin-top: 3px; font-weight: 500; }
  .history-empty { color: var(--text-dim); font-size: 12.5px; text-align: center; padding: 70px 20px; line-height: 1.6; }

  .history-menu-btn {
    flex-shrink: 0; background: none; border: none; color: var(--text-dim);
    font-size: 17px; cursor: pointer; padding: 4px 6px; line-height: 1;
    transition: color 0.15s;
  }
  .history-menu-btn:active { color: var(--text); }

  .history-menu {
    position: absolute; top: 44px; right: 12px; z-index: 5;
    background: var(--bg-sunken); border: 1px solid var(--line); border-radius: var(--r-sm);
    box-shadow: 0 8px 24px rgba(0,0,0,0.5);
    overflow: hidden;
    animation: menuIn 0.15s ease;
  }
  @keyframes menuIn { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: translateY(0); } }
  .history-menu-delete {
    background: none; border: none; color: var(--warn);
    font-family: var(--sans); font-size: 12.5px; font-weight: 600;
    padding: 12px 18px; cursor: pointer; white-space: nowrap;
  }
  .history-menu-delete:active { background: rgba(255,107,107,0.1); }

  /* ── bottom nav ────────────────────────────────────────── */

  .bottom-nav {
    position: fixed; left: 0; right: 0; bottom: 0;
    height: calc(var(--nav-h) + var(--safe-b));
    padding-bottom: var(--safe-b);
    background: rgba(13,12,18,0.98);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-top: 1px solid var(--line);
    display: flex;
    z-index: 30;
  }
  .nav-btn {
    flex: 1; display: flex; flex-direction: column; align-items: center;
    justify-content: center; gap: 4px; background: none; border: none;
    color: var(--text-dim); font-family: var(--sans); cursor: pointer;
    transition: color 0.15s;
  }
  .nav-btn .nav-icon { font-size: 19px; line-height: 1; }
  .nav-btn .nav-label { font-size: 10px; font-weight: 600; letter-spacing: 0.2px; }
  .nav-btn.active { color: var(--text); }
  .nav-btn.active .nav-icon { filter: drop-shadow(0 0 10px rgba(255,77,141,0.5)); }
  .nav-btn.active .nav-label {
    background: linear-gradient(95deg, var(--grad-1), var(--grad-2) 60%, var(--grad-3));
    -webkit-background-clip: text; background-clip: text; color: transparent;
  }

  .footer { margin-top: 40px; padding-top: 18px; border-top: 1px solid var(--line-soft); font-size: 10.5px; color: var(--text-dim); line-height: 1.6; font-weight: 500; }

  /* ── recently watched (на экране поиска, над результатами) ───────────── */

  .recent-watched { margin-top: 20px; margin-bottom: 26px; }
  .recent-watched-label {
    font-size: 11px; letter-spacing: 0.6px; text-transform: uppercase;
    color: var(--text-dim); font-weight: 700; margin-bottom: 10px;
  }
  .recent-watched-row {
    display: flex; gap: 12px; overflow-x: auto; overflow-y: hidden;
    padding-bottom: 4px; -ms-overflow-style: none; scrollbar-width: none;
    touch-action: pan-x;
  }
  .recent-watched-row::-webkit-scrollbar { display: none; }
  .recent-card {
    flex-shrink: 0; width: 148px; cursor: pointer;
  }
  .recent-card .result-thumb { width: 148px; aspect-ratio: 16/9; margin-bottom: 7px; }
  .recent-card .result-title { font-size: 11.5px; -webkit-line-clamp: 2; }
  .recent-card .result-meta { font-size: 10px; }

  /* ── watch screen: отдельный полноэкранный слой над контентом, под нав-баром ── */

  .watch-screen {
    display: none;
    position: relative;
    min-height: 100dvh;
    background: var(--bg);
    z-index: 2;
  }
  .watch-screen.active { display: block; animation: screenIn 0.25s ease; }

  .watch-back {
    position: sticky; top: 0; z-index: 5;
    display: flex; align-items: center; gap: 10px;
    padding: calc(env(safe-area-inset-top, 0px) + 22px) 22px 26px;
    background: linear-gradient(to bottom, var(--bg) 75%, transparent);
  }
  .watch-back button {
    position: relative;
    background: var(--bg-raised); border: 2px solid var(--line); color: var(--text);
    width: 50px; height: 50px; border-radius: var(--r-pill);
    display: flex; align-items: center; justify-content: center; cursor: pointer;
    box-shadow: 0 4px 16px rgba(0,0,0,0.4);
  }
  .watch-back button svg { width: 24px; height: 24px; display: block; }
  .watch-back button::before {
    content: ""; position: absolute; inset: -12px; /* увеличенная зона нажатия, кнопка визуально не меняется */
  }
  .watch-back button:active { background: var(--line); transform: scale(0.94); }

  .watch-body { padding: 0 18px calc(var(--nav-h) + var(--safe-b) + 28px); max-width: 640px; margin: 0 auto; }

  .watch-player-wrap {
    position: relative; width: 100%; aspect-ratio: 16/9;
    border-radius: var(--r-md); overflow: hidden; background: var(--bg-sunken);
    margin-bottom: 16px;
  }
  .watch-player-wrap img.watch-thumb { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: block; }
  .watch-player-wrap iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: none; display: block; }
  .watch-player-wrap .play-overlay {
    position: absolute; inset: 0; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    background: rgba(10,10,15,0.25); transition: background 0.15s;
  }
  .watch-player-wrap .play-overlay:active { background: rgba(10,10,15,0.4); }

  .watch-title { font-family: var(--display); font-size: 17px; font-weight: 600; line-height: 1.35; margin-bottom: 10px; }

  .watch-meta-row {
    display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
    font-size: 12px; color: var(--text-mid); font-weight: 500; margin-bottom: 18px;
  }
  .watch-meta-row .dot { color: var(--text-dim); }
  .watch-meta-row b { color: var(--text); font-weight: 600; }
  .watch-link-btn {
    margin-left: auto; flex-shrink: 0;
    width: 34px; height: 34px; border-radius: var(--r-pill);
    background: var(--bg-raised); border: 1px solid var(--line); color: var(--text-mid);
    display: flex; align-items: center; justify-content: center; cursor: pointer;
  }
  .watch-link-btn svg { width: 16px; height: 16px; }
  .watch-link-btn:active { background: var(--line); color: var(--text); }

  .watch-desc {
    background: var(--bg-raised); border: 1px solid var(--line); border-radius: var(--r-md);
    padding: 14px 16px; margin-bottom: 22px;
  }
  .watch-desc-text {
    font-size: 12.5px; line-height: 1.6; color: var(--text-mid); font-weight: 500;
    white-space: pre-wrap; word-break: break-word;
  }
  .watch-desc-text.collapsed {
    display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
  }
  .watch-desc-toggle {
    margin-top: 8px; background: none; border: none; color: var(--grad-3);
    font-family: var(--sans); font-size: 12px; font-weight: 600; cursor: pointer; padding: 0;
  }
  .watch-desc-empty { font-size: 12px; color: var(--text-dim); font-weight: 500; }

  .watch-dl-section { margin-top: 4px; }

  .btn-dl-main {
    width: 100%; background: linear-gradient(95deg, var(--grad-1), #ff3b6b);
    color: #fff; border: none; font-family: var(--sans); font-weight: 700; font-size: 14.5px;
    padding: 16px; border-radius: var(--r-lg); cursor: pointer;
    box-shadow: 0 6px 20px rgba(255,77,141,0.3);
    transition: transform 0.1s, box-shadow 0.2s;
  }
  .btn-dl-main:active { transform: scale(0.98); }

  .watch-fmt-panel {
    margin-top: 12px; border: 1px solid var(--line); border-radius: var(--r-md);
    overflow: hidden; background: var(--bg-raised);
    opacity: 0; animation: cardIn 0.25s ease forwards;
  }
  .watch-fmt-panel .fmt-grid,
  .watch-fmt-panel .simple-actions { background: var(--line); }
  .watch-fmt-panel .fmt-btn { background: var(--bg-raised); }

  @media (max-width: 380px) {
    .fmt-grid { grid-template-columns: repeat(2, 1fr); }
  }


