    :root {
      --bg:          #1a1a1a;
      --surface:     #232323;
      --alt:         #2c2c2c;
      --border:      rgba(255,255,255,0.10);
      --border2:     rgba(255,255,255,0.18);
      --text:        #f7eedc;
      --textSec:     #d8ccb5;
      --textDim:     #8a7e6e;
      --textMuted:   #ada091;
      --accent:      #5c9b70;
      --accentHov:   #74bb88;
      --accentDim:   rgba(92,155,112,0.22);
      --accentBord:  rgba(92,155,112,0.60);
      --err:         #d97a5c;
      --errDim:      rgba(217,122,92,0.18);
      --serif: 'Libre Baskerville', Georgia, serif;
      --sans:  'Source Sans 3', -apple-system, sans-serif;
      --mono:  'JetBrains Mono', monospace;
      --r:     10px;
      --sh:    0 4px 20px rgba(0,0,0,0.22);
    }

    *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
    html { scroll-behavior: smooth; }

    body {
      font-family: var(--sans);
      background: var(--bg);
      color: var(--text);
      line-height: 1.6;
      font-size: 15px;
      -webkit-font-smoothing: antialiased;
      min-height: 100dvh;
    }

    .hidden { display: none !important; }
    .hidden-by-tab { display: none !important; }

    /* ── Navbar ───────────────────────────────────────────── */
    .navbar {
      background: var(--surface);
      border-bottom: 1px solid var(--border);
      position: sticky; top: 0; z-index: 10;
    }
    .nav-inner {
      max-width: 560px; margin: 0 auto; padding: 0 20px;
      height: 50px; display: flex; align-items: center; justify-content: space-between;
    }
    .logo { font-family: var(--serif); font-size: 16px; color: var(--text); }
    .logo-dot { color: var(--accent); }
    .logo-sub { color: var(--textMuted); font-size: 14px; }
    .nav-right { display: flex; align-items: center; gap: 10px; }
    .nav-tag {
      font-family: var(--mono); font-size: 10px; color: var(--textDim);
      background: var(--alt); border: 1px solid var(--border);
      padding: 3px 8px; border-radius: 4px; letter-spacing: 0.04em;
    }
    .nav-avatar {
      width: 28px; height: 28px; border-radius: 50%;
      border: 1px solid var(--border2); cursor: pointer;
      transition: opacity 0.15s;
    }
    .nav-avatar:hover { opacity: 0.75; }
    .signout-btn {
      background: transparent; border: 1px solid rgba(217,122,92,0.40);
      border-radius: 6px; color: var(--err);
      font-family: var(--mono); font-size: 10px; letter-spacing: 0.04em;
      padding: 3px 10px; cursor: pointer;
      transition: color 0.15s, border-color 0.15s, background 0.15s;
    }
    .signout-btn:hover { color: #ec8e72; border-color: rgba(217,122,92,0.65); background: var(--errDim); }

    /* ── Auth screen ──────────────────────────────────────── */
    .auth-screen {
      min-height: calc(100dvh - 51px);
      display: flex; align-items: center; justify-content: center;
      padding: 40px 20px;
    }
    .auth-card {
      background: var(--surface);
      border: 1px solid var(--border);
      border-radius: var(--r);
      box-shadow: var(--sh);
      padding: 40px 32px;
      max-width: 360px; width: 100%;
      text-align: center;
    }
    .auth-title {
      font-family: var(--serif); font-size: 22px;
      color: var(--text); margin-bottom: 8px;
    }
    .auth-sub {
      font-family: var(--serif); font-size: 13px; font-style: italic;
      color: var(--textDim); margin-bottom: 32px;
    }
    .google-btn {
      display: flex; align-items: center; justify-content: center; gap: 10px;
      width: 100%; height: 46px;
      background: var(--alt); border: 1px solid var(--border2);
      border-radius: 8px; color: var(--text);
      font-family: var(--sans); font-size: 15px; font-weight: 500;
      cursor: pointer;
      transition: background 0.15s, border-color 0.15s;
    }
    .google-btn:hover { background: #2a2a2a; border-color: rgba(255,255,255,0.16); }
    .google-btn:active { opacity: 0.8; }
    .google-btn svg { flex-shrink: 0; }
    .auth-denied {
      margin-top: 20px; padding: 12px 16px;
      background: var(--errDim); border: 1px solid rgba(192,100,74,0.25);
      border-radius: 7px;
      font-family: var(--mono); font-size: 11px;
      color: var(--err); line-height: 1.6;
    }
    .auth-spinner {
      margin: 16px auto 0;
      width: 20px; height: 20px;
      border: 2px solid var(--border2);
      border-top-color: var(--accent);
      border-radius: 50%;
      animation: spin 0.75s linear infinite;
    }

    /* ── Page ─────────────────────────────────────────────── */
    .page {
      max-width: 560px; margin: 0 auto;
      padding: 36px 20px 72px;
    }

    .tagline {
      font-family: var(--serif); font-size: 13px; font-style: italic;
      color: var(--textDim); text-align: center; margin-bottom: 24px;
    }

    /* ── Tabs ─────────────────────────────────────────────── */
    .tab-bar {
      display: flex; gap: 4px; margin-bottom: 14px;
      border-bottom: 1px solid var(--border);
    }
    .tab-btn {
      background: transparent; border: none;
      border-bottom: 2px solid transparent;
      color: var(--textMuted);
      font-family: var(--mono); font-size: 12px; letter-spacing: 0.08em;
      text-transform: uppercase;
      padding: 10px 16px; cursor: pointer;
      transition: color 0.15s, border-color 0.15s;
      margin-bottom: -1px;
    }
    .tab-btn:hover { color: var(--text); }
    .tab-btn.active {
      color: var(--accentHov);
      border-bottom-color: var(--accentBord);
    }
    .tab-panel { display: none; }
    .tab-panel.active { display: block; }

    /* ── Card ─────────────────────────────────────────────── */
    .card {
      background: var(--surface);
      border: 1px solid var(--border);
      border-radius: var(--r);
      box-shadow: var(--sh);
      overflow: hidden;
    }
    .card-body { padding: 24px; }

    /* ── Field label ──────────────────────────────────────── */
    .lbl {
      font-family: var(--mono); font-size: 10px; letter-spacing: 0.10em;
      text-transform: uppercase; color: var(--textDim); margin-bottom: 8px;
    }

    /* ── URL input ────────────────────────────────────────── */
    .url-row { display: flex; gap: 8px; }

    .url-input {
      flex: 1; min-width: 0;
      background: var(--alt); border: 1px solid var(--border);
      border-radius: 7px; color: var(--text);
      font-family: var(--sans); font-size: 14px;
      padding: 0 14px; height: 44px; outline: none;
      transition: border-color 0.15s;
    }
    .url-input::placeholder { color: var(--textDim); }
    .url-input:focus { border-color: var(--accentBord); }
    /* убрать стандартные стрелки у number-input — выбиваются из стиля */
    input[type="number"] { -moz-appearance: textfield; appearance: textfield; }
    input[type="number"]::-webkit-outer-spin-button,
    input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

    .paste-btn {
      flex-shrink: 0;
      background: var(--alt); border: 1px solid var(--border);
      border-radius: 7px; color: var(--textMuted);
      font-family: var(--mono); font-size: 11px; letter-spacing: 0.04em;
      padding: 0 14px; height: 44px; cursor: pointer;
      transition: color 0.15s, border-color 0.15s;
    }
    .paste-btn:hover { color: var(--text); border-color: var(--border2); }
    .paste-btn:active { opacity: 0.75; }

    /* ── Quality chips ────────────────────────────────────── */
    .quality-group { margin-top: 18px; }

    .chips { display: flex; flex-wrap: wrap; gap: 6px; }

    .chip {
      background: var(--alt); border: 1px solid var(--border);
      border-radius: 6px; color: var(--textMuted);
      font-family: var(--mono); font-size: 12px; letter-spacing: 0.04em;
      padding: 0 14px; height: 34px; cursor: pointer;
      transition: all 0.15s; white-space: nowrap;
    }
    .chip:hover { color: var(--text); border-color: var(--border2); }
    .chip.active {
      background: var(--accentDim);
      border-color: var(--accentBord);
      color: var(--accentHov);
    }

    /* ── Download button ──────────────────────────────────── */
    .dl-btn {
      margin-top: 20px; width: 100%; height: 46px;
      background: var(--accent); border: none; border-radius: 8px;
      color: #fff; font-family: var(--sans); font-size: 15px; font-weight: 600;
      cursor: pointer; letter-spacing: 0.01em;
      transition: background 0.2s, transform 0.15s, box-shadow 0.2s;
    }
    .dl-btn:hover {
      background: var(--accentHov);
      transform: translateY(-1px);
      box-shadow: 0 4px 18px rgba(74,124,89,0.30);
    }
    .dl-btn:active { transform: translateY(0); box-shadow: none; }
    .dl-btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; box-shadow: none; }

    /* ── Queue ────────────────────────────────────────────── */
    .queue { margin-top: 16px; display: flex; flex-direction: column; gap: 10px; }

    .job-card {
      background: var(--surface);
      border: 1px solid var(--border);
      border-radius: var(--r);
      padding: 14px 16px;
      animation: slideIn 0.25s ease;
    }
    @keyframes slideIn {
      from { opacity: 0; transform: translateY(-6px); }
      to   { opacity: 1; transform: translateY(0); }
    }
    .job-card.fade-out {
      opacity: 0;
      transform: translateY(-4px);
      transition: opacity 0.3s ease, transform 0.3s ease, max-height 0.3s ease, padding 0.3s ease, margin 0.3s ease;
      max-height: 0; padding-top: 0; padding-bottom: 0; margin: 0;
      overflow: hidden;
    }

    .job-head {
      display: flex; align-items: center; gap: 10px;
      margin-bottom: 10px;
    }
    .job-title {
      flex: 1; min-width: 0;
      font-family: var(--sans); font-size: 13px; color: var(--textSec);
      overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    }
    .job-close {
      flex-shrink: 0;
      background: transparent; border: none; cursor: pointer;
      color: var(--textDim); font-size: 18px; line-height: 1;
      width: 22px; height: 22px; padding: 0;
      transition: color 0.15s;
    }
    .job-close:hover { color: var(--text); }

    .progress-track {
      height: 3px; background: var(--alt);
      border-radius: 2px; overflow: hidden; margin-bottom: 10px;
    }
    .progress-fill {
      height: 100%; border-radius: 2px; width: 0%;
      transition: width 0.45s ease;
      background: var(--accent);
    }
    .progress-fill.proc  { background: var(--textMuted); }
    .progress-fill.done  { background: var(--accent); transition: width 0.2s; }
    .progress-fill.err   { background: var(--err); }
    .progress-fill.queued {
      background: linear-gradient(90deg, transparent, var(--textDim), transparent);
      background-size: 200% 100%;
      animation: shimmer 1.6s linear infinite;
      width: 100% !important;
    }
    @keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

    .status-row {
      display: flex; align-items: center; gap: 8px;
      font-family: var(--mono); font-size: 11px; color: var(--textMuted);
      min-height: 18px;
    }
    .status-row.done { color: var(--accentHov); }
    .status-row.err  { color: var(--err); }

    .spinner {
      width: 9px; height: 9px; flex-shrink: 0;
      border: 1.5px solid rgba(255,255,255,0.10);
      border-top-color: var(--textMuted);
      border-radius: 50%;
      animation: spin 0.75s linear infinite;
    }
    @keyframes spin { to { transform: rotate(360deg); } }

    .status-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }

    .job-actions {
      margin-top: 12px; display: none; gap: 8px; flex-wrap: wrap;
    }
    .job-actions.visible { display: flex; }

    .save-btn {
      display: inline-flex; align-items: center; gap: 7px;
      background: var(--accentDim); border: 1px solid var(--accentBord);
      border-radius: 6px; color: var(--accentHov);
      font-family: var(--sans); font-size: 12px; font-weight: 500;
      padding: 0 14px; height: 32px; cursor: pointer; text-decoration: none;
      transition: background 0.15s;
    }
    .save-btn:hover { background: rgba(92,155,112,0.32); }

    /* ── Sites note ───────────────────────────────────────── */
    .sites {
      margin-top: 18px; text-align: center;
      font-family: var(--serif); font-size: 12px; font-style: italic;
      color: var(--textDim); line-height: 1.85;
    }
    .sites a { color: var(--textMuted); text-underline-offset: 3px; }

    /* ── Footer ───────────────────────────────────────────── */
    .footer {
      text-align: center; margin-top: 28px;
      font-family: var(--mono); font-size: 10px;
      color: var(--textDim); letter-spacing: 0.04em;
    }

    /* ── Toast ────────────────────────────────────────────── */
    .toast {
      position: fixed; bottom: 24px; left: 50%;
      transform: translateX(-50%) translateY(72px);
      background: var(--alt); border: 1px solid var(--border2);
      border-radius: 8px; padding: 9px 20px;
      font-size: 13px; color: var(--text);
      box-shadow: var(--sh); transition: transform 0.22s ease;
      z-index: 99; white-space: nowrap; pointer-events: none;
    }
    .toast.show { transform: translateX(-50%) translateY(0); }

    /* ── Burger menu ─────────────────────────────────────── */
    .menu-wrap { position: relative; }
    .menu-btn { background: transparent; border: 1px solid var(--border); border-radius: 6px;
      width: 36px; height: 30px; cursor: pointer; display: flex; flex-direction: column;
      justify-content: center; align-items: center; gap: 4px; padding: 0; }
    .menu-btn span { display: block; width: 18px; height: 2px; background: var(--textSec); border-radius: 1px; }
    .menu-btn:hover { border-color: var(--border2); }
    .menu-dropdown { position: absolute; right: 0; top: calc(100% + 8px); background: var(--surface);
      border: 1px solid var(--border2); border-radius: 8px; padding: 6px; min-width: 220px;
      display: flex; flex-direction: column; gap: 2px; z-index: 100; box-shadow: 0 8px 24px rgba(0,0,0,0.45); }
    .menu-dropdown.hidden { display: none; }
    .menu-item { background: none; border: none; color: var(--textSec); text-align: left;
      padding: 9px 11px; border-radius: 6px; cursor: pointer; font-family: var(--sans); font-size: 13px; }
    .menu-item:hover { background: var(--alt); color: var(--text); }

    /* ── Cancel all button ───────────────────────────────────── */
    .cancel-all-btn { width: 100%; margin-top: 14px; height: 46px; border: none; border-radius: 8px;
      background: var(--err); color: #fff; font-family: var(--sans); font-size: 15px; font-weight: 600;
      cursor: pointer; letter-spacing: 0.01em; }
    .cancel-all-btn:hover { background: #ec8e72; }
    .cancel-all-btn.hidden { display: none; }

    /* ── Input action row (sits BELOW the input, e.g. ABC + Paste) ─────── */
    /* All buttons inside split the row in equal flex shares, so two of them
       form 50/50 columns matching the input width above, and a single button
       takes the full input width.                                            */
    .input-actions {
      display: flex;
      gap: 6px;
      margin-top: 6px;
    }
    .input-action-btn {
      flex: 1; min-width: 0;
      background: var(--alt);
      border: 1px solid var(--border);
      border-radius: 6px;
      color: var(--textMuted);
      font-family: var(--mono); font-size: 11px; letter-spacing: 0.04em;
      height: 30px;
      cursor: pointer;
      transition: color 0.15s, border-color 0.15s, background 0.15s;
    }
    .input-action-btn:hover  { color: var(--text); border-color: var(--border2); }
    .input-action-btn:active { opacity: 0.75; }
    .input-action-btn.active {
      color: var(--accentHov);
      border-color: var(--accentBord);
      background: var(--accentDim);
    }

    /* ── Destination row (Downloads vs Pick folder) — full card width ───── */
    /* Two equal chips fill the row; when one is hidden (FSA unsupported on
       this browser), the visible one stretches to 100%.                     */
    .dest-row {
      display: flex;
      gap: 6px;
      margin-top: 6px;
    }
    .dest-row > .chip {
      flex: 1; min-width: 0;
      height: 38px;
      padding: 0 14px;
      text-align: center;
      display: inline-flex;
      align-items: center;
      justify-content: center;
    }

    /* ── Research tab: form layout (desktop default + mobile-friendly) ─── */
    .rs-params-grid {
      display: grid;
      grid-template-columns: 1fr 1fr;
      gap: 8px 12px;
      font-size: 13px;
      color: var(--textSec);
    }
    .rs-params-grid > label,
    .rs-params-grid > div { min-width: 0; }     /* let inputs shrink instead of overflowing */
    .rs-params-grid input.url-input { width: 100%; max-width: 100%; box-sizing: border-box; }

    .rs-langs                 { grid-column: 1 / -1; }   /* langs span full width */
    .rs-langs-label           { color: var(--textSec); margin-bottom: 4px; }
    .rs-langs-row             { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; }
    .rs-langs-row label       { display: flex; gap: 4px; align-items: center; }
    .rs-langs-hint            { display: block; margin-top: 6px; color: var(--textDim); font-size: 11px; font-weight: normal; }

    .rs-rate-row {
      display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
      font-size: 13px; color: var(--textSec);
    }
    .rs-rate-row input.url-input { width: 80px; height: 34px; }

    .rs-dest-row              { flex-wrap: wrap; align-items: center; }
    .rs-dest-row #rs-folder-name {
      color: var(--textMuted); font-size: 12px;
      overflow-wrap: anywhere; word-break: break-word; min-width: 0;
    }

    /* Research preview card — title can wrap to 2 lines on narrow screens */
    #rs-cand-list label > div > div:first-child {
      white-space: normal;
      display: -webkit-box; -webkit-line-clamp: 2; line-clamp: 2;
      -webkit-box-orient: vertical; overflow: hidden;
    }

    /* ── Mobile ───────────────────────────────────────────── */
    @media (max-width: 640px) {
      .rs-params-grid { grid-template-columns: 1fr; }
      #rs-cand-list   { max-height: 60vh; }            /* let list breathe */
      #rs-cand-list img {
        width: 64px !important; height: 36px !important;
      }
    }

    @media (max-width: 420px) {
      .card-body        { padding: 18px; }
      .progress-section { padding: 16px 18px; }
      .chip             { font-size: 11px; padding: 0 10px; }
      .auth-card        { padding: 32px 20px; }
      .rs-rate-row input.url-input { width: 72px; }
    }

    /* ── Scrollbar ────────────────────────────────────────── */
    * { scrollbar-width: thin; scrollbar-color: var(--border2) var(--surface); }
    ::-webkit-scrollbar { width: 10px; height: 10px; }
    ::-webkit-scrollbar-track { background: var(--surface); }
    ::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 5px; }
    ::-webkit-scrollbar-thumb:hover { background: var(--accentBord, var(--accent)); }
