/* WiseM3U — configuration page: styles (Material 3, dark theme) */
/* ============ Material 3 — design tokens (dark theme) ============ */
  :root{
    /* Dracula theme (official dark palette) */
    --md-primary:#bd93f9;          --md-on-primary:#282a36;
    --md-primary-container:#44475a;--md-on-primary-container:#f8f8f2;
    --md-secondary-container:#343746;--md-on-secondary-container:#f8f8f2;
    --md-surface:#282a36;          --md-surface-1:#21222c;
    --md-surface-2:#2b2d3a;        --md-surface-3:#343746;  --md-surface-4:#44475a;
    --md-on-surface:#f8f8f2;       --md-on-surface-variant:#b8bcd0;
    --md-outline:#6272a4;          --md-outline-variant:#44475a;
    --md-error:#ff5555;            --md-on-error:#282a36;
    --md-error-container:#5c2a33;  --md-on-error-container:#ffd7d7;
    --md-success:#50fa7b;          --md-warning:#f1fa8c;
    /* Dracula accents for details and states */
    --accent-cyan:#8be9fd;         --accent-pink:#ff79c6;
    /* legacy aliases used by components */
    --bg:var(--md-surface); --card:var(--md-surface-1); --card2:var(--md-surface-2);
    --line:var(--md-outline-variant); --line2:var(--md-outline);
    --txt:var(--md-on-surface); --mut:var(--md-on-surface-variant);
    --acc:var(--md-primary); --ok:var(--md-success); --warn:var(--md-warning);
    --err:var(--md-error); --chip:var(--md-secondary-container);
    color-scheme:dark;
  }
  *{box-sizing:border-box}
  html{-webkit-text-size-adjust:100%;scroll-behavior:smooth}
  body{margin:0;color:var(--txt);font:15px/1.5 Roboto,system-ui,-apple-system,"Segoe UI",Ubuntu,sans-serif;
       background:var(--md-surface);padding-bottom:calc(90px + env(safe-area-inset-bottom))}
  ::selection{background:rgba(189,147,249,.35)}
  /* ---------- top app bar ---------- */
  header{position:sticky;top:0;z-index:20;background:var(--md-surface-2);
         border-bottom:1px solid var(--md-outline-variant);padding:10px 16px;
         display:flex;gap:12px;align-items:center;flex-wrap:wrap}
  header img{width:32px;height:32px;border-radius:8px}
  header h1{font-size:18px;font-weight:500;margin:0;letter-spacing:.1px}
  header .sub{color:var(--mut);font-size:12.5px}
  .spacer{flex:1}
  main{max-width:1180px;margin:0 auto;padding:16px}
  .links{display:flex;gap:6px;flex-wrap:wrap;align-items:center}
  a.lnk{color:var(--md-on-secondary-container);text-decoration:none;font-size:12px;font-weight:500;
        background:var(--md-secondary-container);border:1px solid transparent;
        padding:5px 12px;border-radius:8px;transition:background .15s}
  a.lnk:hover{background:var(--md-surface-4)}
  /* language selector: compact, always visible in the header */
  select.langselect{width:auto;max-width:132px;height:28px;padding:0 26px 0 10px;margin:0;
    border:1px solid transparent;border-radius:14px;background:var(--md-secondary-container);
    color:var(--md-on-secondary-container);font-size:11.5px;font-weight:600;cursor:pointer;
    appearance:none;-webkit-appearance:none;
    background-image:linear-gradient(45deg,transparent 50%,var(--md-on-secondary-container) 50%),
                     linear-gradient(135deg,var(--md-on-secondary-container) 50%,transparent 50%);
    background-position:calc(100% - 14px) 12px,calc(100% - 9px) 12px;
    background-size:5px 5px,5px 5px;background-repeat:no-repeat}
  select.langselect:hover{background-color:var(--md-surface-4)}
  select.langselect:focus-visible{outline:2px solid var(--md-primary);outline-offset:2px}

  /* ---------- cards and sections ---------- */
  .card{background:var(--md-surface-1);border:1px solid var(--md-outline-variant);border-radius:16px;padding:16px;margin-bottom:16px;
        box-shadow:0 10px 30px rgba(0,0,0,.55)}
  h2{font-size:16px;font-weight:500;margin:0 0 12px;letter-spacing:.15px;color:var(--md-on-surface);
     display:flex;align-items:center;gap:8px;flex-wrap:wrap}
  h2 .n{display:inline-grid;place-items:center;min-width:24px;height:24px;padding:0 6px;border-radius:50%;
        background:var(--md-primary-container);color:var(--md-on-primary-container);
        font-size:12px;font-weight:600;flex:0 0 auto}
  .secttl{margin:22px 2px 12px}
  label{display:block;font-size:12px;font-weight:500;color:var(--mut);margin-bottom:5px;letter-spacing:.2px}
  .hint{color:var(--mut);font-size:12.5px;margin-top:6px}
  .hint b{color:var(--txt)}
  code{background:var(--md-surface-3);border-radius:6px;padding:2px 7px;font-size:12.5px;
       color:var(--md-primary);word-break:break-all}
  .sep{height:1px;background:var(--line);margin:12px 0}
  .grid2{display:grid;grid-template-columns:repeat(auto-fit,minmax(225px,1fr));gap:12px}
  .refreshCustom[hidden]{display:none}
  .kv{font-size:12.5px;color:var(--mut)}
  .kv b{color:var(--txt);font-weight:600}
  .dim{opacity:.75}
  /* ---------- fields (filled text field M3) ---------- */
  input[type=text],input[type=url],input[type=number],input[type=password],select,textarea{
    width:100%;background:var(--md-surface-3);border:1px solid transparent;color:var(--txt);
    border-radius:12px;padding:11px 14px;font:inherit;outline:none;
    transition:background .15s,border-color .15s}
  input:focus,select:focus,textarea:focus{border-color:var(--md-primary);background:var(--md-surface-4)}
  input::placeholder,textarea::placeholder{color:#a0a4b8}
  textarea{resize:vertical}

  /* ---------- editable inputs with recommended presets ---------- */
  .uaCombo,.refreshCombo{position:relative}
  .uaCombo input,.refreshCombo input{padding-right:46px}
  .refreshCombo input[type=number]{-moz-appearance:textfield;appearance:textfield}
  .refreshCombo input[type=number]::-webkit-outer-spin-button,
  .refreshCombo input[type=number]::-webkit-inner-spin-button{-webkit-appearance:none;margin:0}
  .uaTgl,.refreshTgl{position:absolute;right:4px;top:50%;transform:translateY(-50%);
         min-height:0;padding:7px 10px;border-radius:9px;background:transparent;
         color:var(--mut);box-shadow:none;font-size:13px;line-height:1}
  .uaTgl:hover,.refreshTgl:hover{background:var(--md-surface-4);filter:none}
  .uaCombo.open .uaTgl,.refreshCombo.open .refreshTgl{color:var(--md-primary)}
  .uaMenu,.refreshMenu{position:absolute;z-index:40;top:calc(100% + 6px);left:0;right:0;
          max-height:270px;overflow:auto;padding:5px;background:var(--md-surface-2);
          border:1px solid var(--md-outline);border-radius:12px;
          box-shadow:0 12px 30px rgba(0,0,0,.45)}
  .uaMenu[hidden],.refreshMenu[hidden]{display:none}
  .uaOpt{display:block;width:100%;text-align:left;background:transparent;color:var(--txt);
         border-radius:8px;padding:8px 10px;box-shadow:none;font-weight:400;line-height:1.35}
  .uaOpt:hover,.uaOpt:focus-visible{background:var(--md-surface-4);filter:none}
  .uaOpt.sel{background:var(--md-primary-container);color:var(--md-on-primary-container)}
  .uaOpt .uan{display:block;font-size:13px;font-weight:600}
  .uaOpt .uav{display:block;font-size:11px;color:var(--mut);white-space:nowrap;
              overflow:hidden;text-overflow:ellipsis}
  .uaOpt.sel .uav{color:var(--md-on-primary-container);opacity:.85}
  /* ---------- M3 buttons: filled / tonal / error ---------- */
  button{background:var(--md-primary);color:var(--md-on-primary);border:0;border-radius:20px;
         padding:10px 20px;font:inherit;font-size:14px;font-weight:500;letter-spacing:.1px;cursor:pointer;
         transition:filter .15s,transform .05s,box-shadow .15s;box-shadow:none}
  button:hover{filter:brightness(1.08)}
  button:active{transform:translateY(1px)}
  button.ghost{background:var(--md-secondary-container);color:var(--md-on-secondary-container)}
  button.ghost:hover{background:var(--md-surface-4)}
  button.danger{background:var(--md-error-container);color:var(--md-on-error-container)}
  button.danger:hover{background:#6b2a35}
  button.small{padding:7px 14px;font-size:12.5px;border-radius:16px}
  button:disabled{opacity:.5;cursor:progress}
  :where(button,a,input,select,textarea,summary):focus-visible{outline:2px solid var(--md-primary);outline-offset:2px}
  .chk{display:flex;align-items:center;gap:8px;background:var(--md-surface-2);border:1px solid var(--line);
       border-radius:12px;padding:8px 12px;cursor:pointer;user-select:none;transition:border-color .15s,background .15s}
  .chk:hover{border-color:var(--line2)}
  .chk input{width:18px;height:18px;accent-color:var(--md-primary);flex:0 0 auto}
  .chk.on{border-color:var(--md-primary);background:var(--md-primary-container)}
  .chk.on{color:var(--md-on-primary-container)}
  /* ---------- feedback and badges ---------- */
  .badge{display:inline-flex;align-items:center;padding:3px 10px;border-radius:8px;font-size:11.5px;font-weight:500;
         background:var(--chip);color:var(--md-on-secondary-container);margin-left:6px;white-space:nowrap}
  h2 .badge,.listhead .badge,.plhead .badge{margin-left:0}
  .badge.ready{background:#2a4433;color:#50fa7b}
  .badge.error{background:var(--md-error-container);color:var(--md-on-error-container)}
  .badge.fetching{background:#3b3a2a;color:var(--md-warning);animation:pulse 1.6s ease-in-out infinite}
  .badge.idle{background:var(--md-surface-3);color:var(--mut)}
  @keyframes pulse{50%{opacity:.55}}
  .cnt{color:var(--mut);font-size:11.5px;white-space:nowrap}
  .pill{display:inline-flex;gap:6px;align-items:center;background:var(--md-surface-3);
        border-radius:8px;padding:4px 10px;font-size:12px;color:var(--mut)}
  .err{color:var(--md-on-error-container);font-size:12.5px;background:#4a2630;border-radius:12px;padding:9px 12px;margin-top:8px}
  .warn{color:#f1fa8c;font-size:12.5px;background:#3b3a2a;border-radius:12px;padding:9px 12px;margin-top:8px}
  .url{font-size:12px;color:var(--mut);word-break:break-all}
  .row{display:flex;gap:12px;flex-wrap:wrap}
  .row>*{flex:1 1 180px}
  .btns{display:flex;gap:8px;align-items:flex-end;flex:0 0 auto;flex-wrap:wrap}
  /* ---------- collapsible panels ---------- */
  details.fold{border:0;border-radius:16px;margin-top:12px;background:var(--md-surface-1)}
  details.fold>summary{cursor:pointer;list-style:none;padding:14px 16px;font-weight:500;font-size:14px;color:var(--md-on-surface);
    display:flex;align-items:center;gap:10px;user-select:none;border-radius:16px}
  details.fold>summary::-webkit-details-marker{display:none}
  details.fold>summary::before{content:"\25BE";color:var(--md-primary);transition:transform .2s;flex:0 0 auto;font-size:12px}
  details.fold[open]>summary::before{transform:rotate(0)}
  details.fold:not([open])>summary::before{transform:rotate(-90deg)}
  details.fold[open]>summary{border-radius:16px 16px 0 0}
  details.fold>summary:hover{background:rgba(189,147,249,.10)}
  details.fold .foldbody{padding:0 16px 16px}
  details.help{margin-top:8px}
  details.help>summary{cursor:pointer;color:var(--mut);font-size:12.5px;user-select:none}
  details.help>summary:hover{color:var(--md-primary)}
  details.help .hint{margin:6px 0 2px;padding:10px 12px;background:var(--md-surface-2);border-radius:12px}

  /* ---------- info icons: one panel per section, next to the title ---------- */
  details.info{flex:0 0 auto;margin:0}
  /* M3 "i" icon: 24px, ~44px touch area with a transparent ::after */
  details.info>summary{
    list-style:none;cursor:pointer;display:inline-grid;place-items:center;position:relative;
    width:24px;height:24px;border-radius:50%;border:1px solid var(--md-outline);
    background:transparent;color:var(--md-primary);font-size:0;user-select:none;vertical-align:middle;
    flex:0 0 auto;transition:background .15s,color .15s}
  details.info>summary::-webkit-details-marker{display:none}
  details.info>summary::before{content:"i";font:italic 600 12px/1 Georgia,"Times New Roman",serif}
  details.info>summary::after{content:"";position:absolute;inset:-8px;border-radius:50%}
  details.info>summary:hover{background:rgba(189,147,249,.14)}
  details.info[open]>summary{background:var(--md-primary-container);color:var(--md-on-primary-container);border-color:transparent}
  /* section notes panel: overlay anchored to the icon (M3 menu) */
  .sectinfo{position:relative;flex:0 0 auto}
  .sectinfo>.ibody{position:absolute;top:calc(100% + 8px);left:0;z-index:60;
    width:min(520px,calc(100vw - 40px));max-height:52vh;overflow:auto;
    background:var(--md-surface-3);border-radius:12px;padding:14px 16px;display:grid;gap:12px;
    box-shadow:0 10px 30px rgba(0,0,0,.55)}
  .sectinfo .inote .ilabel{font-size:11px;font-weight:600;letter-spacing:.5px;text-transform:uppercase;
    color:var(--md-primary);margin-bottom:3px}
  .sectinfo .inote .hint,.sectinfo .inote p{margin:0;padding:0;background:none;border:0;font-size:12.5px}
  /* headings: number + title + (i) + expand always on the same line */
  h2>.n{order:0}
  h2>.ttl{order:1;flex:1 1 0;min-width:0}
  h2>.sectinfo{order:2}
  h2>.sectgl{order:3}
  h2>.badge{order:4}
  .sectgl{margin-left:4px;flex:0 0 auto;width:32px;height:32px;min-height:32px;padding:0;
    display:inline-grid;place-items:center;border-radius:50%;border:0;
    background:transparent;color:var(--md-on-surface-variant);font-size:13px;line-height:1;box-shadow:none;
    pointer-events:none}
  /* the whole title opens/closes the section: the arrow is just an indicator */
  h2[role=button]{cursor:pointer;user-select:none;-webkit-user-select:none;border-radius:12px}
  h2[role=button]:hover .ttl{color:var(--md-primary)}
  h2[role=button]:focus-visible{outline:2px solid var(--md-primary);outline-offset:4px}
  .card.collapsed>*:not(h2):not(.listhead){display:none}
  /* list card title row: name + info icon */
  .listtitle{display:flex;align-items:center;gap:8px;flex:1 1 auto;min-width:0}
  .linfo{flex:0 0 auto}
  .listhead .name[data-ltgl]{cursor:pointer;user-select:none;display:flex;align-items:center;gap:6px;
    flex:1 1 auto;min-width:0;font-weight:500;font-size:17px;letter-spacing:.1px}
  .listhead .name[data-ltgl]::before{content:"\25BE";color:var(--md-primary);font-size:11px;flex:0 0 auto;
    transition:transform .2s}
  .listcard.collapsed .listhead .name[data-ltgl]::before{transform:rotate(-90deg)}
  /* ---------- floating buttons (mobile only) ---------- */
  .fabbar{display:none}
  #toTop{display:none}

  /* log live */
  .logbox{font-family:ui-monospace,Menlo,Consolas,monospace;font-size:12px;line-height:1.7;
    background:#1e1f29;border-radius:12px;padding:10px 12px;
    height:330px;overflow-y:auto;overflow-x:auto;white-space:pre-wrap;word-break:break-all}
  .logbox .hint{margin:0;padding:0;background:none;border:none}
  .lgline{display:block;color:#f8f8f2}
  .lgline.debug{color:#6272a4}
  .lgline.warn{color:var(--md-warning)}
  .lgline.error{color:var(--md-error)}
  .lgts{color:#7a7f9a;margin-right:7px}
  .lgscope{display:inline-block;background:var(--md-surface-3);color:var(--md-primary);border-radius:6px;
    padding:0 6px;margin-right:7px;font-size:11px}
  .logbar{display:flex;gap:7px;flex-wrap:wrap;align-items:center;margin-bottom:9px}
  .logbar .spacer{flex:1}
  .logbar select,.logbar input{flex:0 0 auto}
  .logbar input{flex:1 1 240px}
  /* ---------- list card ---------- */
  .listcard{scroll-margin-top:84px;background:var(--md-surface-2)}
  .listhead{display:flex;align-items:center;gap:8px;flex-wrap:wrap;margin-bottom:10px}
  .listhead .name{font-weight:500;font-size:17px;letter-spacing:.1px}
  .listhead .listdot{display:inline-block;width:9px;height:9px;border-radius:50%;flex:0 0 auto;
    background:var(--md-error);box-shadow:0 0 0 3px rgba(255,85,85,.12)}
  .listhead .listdot.on{background:var(--md-success);box-shadow:0 0 0 3px rgba(80,250,123,.12)}
  .activeCount{display:inline-flex;align-items:center;flex:0 0 auto;min-height:0;
    padding:4px 9px;border-radius:10px;background:var(--md-surface-3);color:var(--md-on-surface-variant);
    font:inherit;font-size:11.5px;font-weight:600;line-height:1.2;box-shadow:none;cursor:pointer}
  .activeCount:hover{background:var(--md-surface-4);color:var(--md-on-surface);filter:none}
  .url.copyurl{cursor:pointer;border-radius:8px;padding:4px 6px;margin-left:-6px;transition:background .15s}
  .url.copyurl:hover{background:rgba(189,147,249,.12)}
  .url.copyurl:focus-visible{outline:2px solid var(--md-primary);outline-offset:2px}
  .acts{display:flex;gap:8px;flex-wrap:wrap}
  /* ---------- playlist header ---------- */
  .plhead{display:flex;align-items:center;gap:10px;flex-wrap:wrap;margin-top:18px}
  .plhead h2{margin:0;flex:1 1 100%}
  .pltools{display:flex;gap:6px;flex-wrap:wrap;align-items:center;flex:1 1 330px;justify-content:flex-end}
  .pltools input{flex:1 1 150px;max-width:230px}
  .pltools button{flex:0 0 auto}
  /* active filter button (e.g. "Show active") */
  .pltools button.on{background:var(--md-primary);color:var(--md-on-primary);filter:none}
  /* collapsible playlist block */
  .plwrap.collapsed>.branches,.plwrap.collapsed>.trash,
  .plwrap.collapsed>.hint,.plwrap.collapsed .pltools{display:none}
  /* ---------- branches ---------- */
  .branches{max-height:min(520px,62vh);overflow:auto;background:var(--md-surface-1);
            border-radius:12px;padding:6px;margin-top:10px;scrollbar-width:thin}
  .branches::-webkit-scrollbar{width:8px}
  .branches::-webkit-scrollbar-thumb{background:var(--md-outline-variant);border-radius:8px}
  .brow{display:flex;align-items:center;gap:8px;flex-wrap:wrap;padding:6px 8px;border-radius:10px;transition:background .12s}
  .brow:hover{background:rgba(189,147,249,.09)}
  .brow.off{opacity:.45}
  .brow input[type=checkbox]{width:18px;height:18px;accent-color:var(--md-primary);cursor:pointer;flex:0 0 auto}
  .brow .bname{flex:1 1 150px;min-width:0}
  .brow .bname.renamed{border-color:var(--md-primary)}
  .bcount{flex:0 0 auto}
  .bhandle{cursor:grab;color:var(--mut);padding:2px 4px;flex:0 0 auto;user-select:none;font-size:15px;line-height:1}
  .bhandle:active{cursor:grabbing}
  .expbtn{background:var(--md-surface-3);border:0;color:var(--md-on-surface-variant);border-radius:14px;
          padding:6px 12px;font-size:11.5px;font-weight:500;cursor:pointer;flex:0 0 auto;white-space:nowrap;
          transition:background .15s,color .15s}
  .expbtn:hover{background:var(--md-surface-4);color:var(--md-primary)}
  /* ---------- channels of a branch ---------- */
  .chans{margin:2px 0 8px 24px;border-left:2px solid var(--md-primary-container);padding:6px 8px;
         background:var(--md-surface-2);border-radius:0 12px 12px 0}
  .chead{display:flex;align-items:center;gap:10px;flex-wrap:wrap;padding:2px 4px 6px}
  .chead .cfilter{flex:1 1 170px;max-width:250px;padding:6px 10px;font-size:12.5px}
  .chead input[data-cadd]{flex:1 1 220px}
  .chead button[data-caddbtn]{flex:0 0 auto}
  .crow{display:flex;align-items:center;gap:8px;flex-wrap:wrap;padding:5px 6px;border-radius:8px;transition:background .12s}
  .crow:hover{background:rgba(189,147,249,.09)}
  .crow.off{opacity:.45}
  .crow .cname{flex:1 1 150px;min-width:0;padding:6px 10px;font-size:12.5px}
  .crow .cname.renamed{border-color:var(--md-primary)}
  .crow .cmove{flex:1 1 130px;max-width:200px;background:var(--md-surface-3);color:var(--txt);border:1px solid transparent;border-radius:10px;padding:6px 10px;font-size:11.5px}
  .crow .cmove.renamed{border-color:var(--md-primary)}
  .crow input[type=checkbox]{width:18px;height:18px;accent-color:var(--md-primary);cursor:pointer;flex:0 0 auto}
  /* ---------- drag & drop ---------- */
  .brow.dragging,.crow.dragging{opacity:.35}
  .drag-before{box-shadow:0 -3px 0 var(--md-primary)}
  .drag-after{box-shadow:0 3px 0 var(--md-primary)}
  .drag-into{outline:2px dashed var(--md-primary);outline-offset:-2px;background:rgba(189,147,249,.12)}
  @keyframes sdflash{0%{box-shadow:0 0 0 4px var(--acc)}100%{box-shadow:0 0 0 0 rgba(79,140,255,0)}}
  .flash{animation:sdflash 1.4s ease-out}
  /* ---------- configuration history ---------- */
  .histbar{display:flex;gap:8px;align-items:center;flex-wrap:wrap;margin-bottom:10px;min-width:0;max-width:100%}
  .histbar label{margin:0}
  .histbar select{flex:0 1 240px;width:auto;min-width:0;max-width:100%}
  .histlist{display:grid;gap:8px;grid-template-columns:minmax(0,1fr)}
  .histrow{background:var(--md-surface-2);border-radius:12px;padding:10px 12px;min-width:0;max-width:100%;overflow-wrap:anywhere}
  .histhead{display:flex;align-items:center;gap:8px;flex-wrap:wrap;min-width:0;max-width:100%}
  .histhead b{font-size:13px;font-weight:500;color:var(--md-on-surface);min-width:0;overflow-wrap:anywhere}
  .histhead .badge{margin-left:0;white-space:normal;overflow-wrap:anywhere;max-width:100%}
  .histhead .cnt{white-space:normal;overflow-wrap:anywhere;min-width:0}
  .histchanges{font-size:11.5px;color:var(--mut);margin-top:4px;overflow-wrap:anywhere;word-break:break-word}
  .histactions{margin-left:auto;display:flex;gap:6px;max-width:100%;flex:0 1 auto}
  .histactions button{white-space:normal}
  .histrestore{margin-top:10px;padding-top:10px;border-top:1px solid var(--line);display:grid;gap:8px;min-width:0}
  .histrestore[hidden]{display:none}
  .histrestore .hcats{display:flex;flex-wrap:wrap;gap:6px}
  .histrestore label.hopt{display:inline-flex;align-items:center;gap:6px;background:var(--md-surface-3);
    border-radius:10px;padding:6px 10px;font-size:12px;color:var(--md-on-surface);margin:0;cursor:pointer}
  .histrestore label.hopt input{width:16px;height:16px;accent-color:var(--md-primary);margin:0}
  .histrestore .hrow{display:flex;gap:8px;flex-wrap:wrap;align-items:center}
  /* ---------- trash ---------- */
  .trash{margin-top:10px;border:1px dashed var(--md-outline-variant);border-radius:16px;padding:12px;background:var(--md-surface-1)}
  .trashrow{display:flex;align-items:center;gap:9px;flex-wrap:wrap;padding:6px 2px}
  .trashrow+.trashrow{border-top:1px solid rgba(255,255,255,.05)}
  /* ---------- list side menu ---------- */
  #sdToggle{position:fixed;right:12px;top:64px;z-index:60;box-shadow:0 4px 14px rgba(0,0,0,.4)}
  #sidemenu{position:fixed;right:12px;top:100px;width:240px;max-height:calc(100vh - 130px);overflow:auto;
    background:var(--md-surface-3);border-radius:16px;padding:8px;z-index:60;
    box-shadow:0 8px 24px rgba(0,0,0,.45);scrollbar-width:thin}
  #sidemenu[hidden]{display:none}
  .sdtitle{font-size:11px;font-weight:600;color:var(--mut);text-transform:uppercase;letter-spacing:.8px;padding:6px 8px 8px}
  .sditem{display:flex;gap:6px;align-items:center;margin:2px 0}
  .sditem .sdname{flex:1 1 auto;text-align:left;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;
    background:transparent;border:0;color:var(--txt);border-radius:10px;padding:8px 10px;cursor:pointer;
    font:inherit;font-size:13px;transition:background .15s}
  .sditem .sdname:hover{background:rgba(189,147,249,.14)}
  .sditem .sdhandle{padding:8px 4px;font-size:16px;color:var(--mut);touch-action:none}
  .sditem.dragging{opacity:.35}
  /* ---------- footer and toast ---------- */
  footer{position:fixed;left:0;right:0;bottom:0;background:var(--md-surface-2);
         border-top:1px solid var(--md-outline-variant);padding:10px 16px calc(10px + env(safe-area-inset-bottom));
         display:grid;grid-template-columns:minmax(0,1fr) auto minmax(0,1fr);
         gap:12px;align-items:center;z-index:30}
  footer #status{justify-self:start;min-width:0;overflow-wrap:anywhere}
  .footer-center{justify-self:center;display:flex;align-items:center;justify-content:center;gap:10px;flex-wrap:wrap;min-width:0}
  .footer-actions{justify-self:end;display:flex;align-items:center;gap:8px}
  footer #toTop{display:grid;place-items:center;width:38px;height:38px;min-height:0;padding:0;
    border-radius:50%;font-size:17px;line-height:1;background:var(--md-secondary-container);
    color:var(--md-on-secondary-container);box-shadow:none}
  footer #toTop:hover{background:var(--md-surface-4);filter:none}
  .footer-github{white-space:nowrap}
  .toast{position:fixed;left:50%;bottom:calc(96px + env(safe-area-inset-bottom));transform:translate(-50%,8px);
         background:#343746;color:#f8f8f2;border:1px solid #44475a;border-radius:12px;padding:12px 18px;z-index:50;opacity:0;
         transition:.25s;pointer-events:none;max-width:90vw;box-shadow:0 12px 34px rgba(0,0,0,.75);
         font-size:14px;font-weight:500}
  .toast.show{opacity:1;transform:translate(-50%,0)}
  .toast.has-act{pointer-events:auto;display:flex;align-items:center;gap:8px 12px;flex-wrap:wrap}
  .toast.has-act span{flex:1 1 auto;min-width:0}
  .toast-act{flex:0 0 auto;border:0;border-radius:10px;padding:9px 14px;min-height:38px;
             background:#44475a;color:#f8f8f2;font:inherit;font-weight:700;cursor:pointer}
  .toast-act:hover{background:#525568}
  .toast-act:active{background:#3b3d4d}
  /* ---------- active playlists modal ---------- */
  body.modal-open{overflow:hidden}
  .modal{position:fixed;inset:0;z-index:100;display:grid;place-items:center;padding:16px}
  .modal[hidden]{display:none}
  .modal-backdrop{position:absolute;inset:0;background:rgba(0,0,0,.62);backdrop-filter:blur(2px);
                  -webkit-backdrop-filter:blur(2px)}
  .modal-card{position:relative;display:flex;flex-direction:column;width:min(560px,100%);
              max-height:min(72vh,620px);background:var(--md-surface-2);border:1px solid var(--md-outline);
              border-radius:18px;box-shadow:0 20px 60px rgba(0,0,0,.65);overflow:hidden}
  .modal-head{display:flex;align-items:center;gap:10px;padding:14px 16px;border-bottom:1px solid var(--line)}
  .modal-head h3{margin:0;min-width:0;font-size:16px;font-weight:500;overflow-wrap:anywhere}
  .modal-close{margin-left:auto;flex:0 0 auto;min-height:0;width:36px;height:36px;padding:0;border-radius:50%;
    background:transparent;color:var(--md-on-surface-variant);font-size:16px;line-height:1;box-shadow:none}
  .modal-close:hover{background:var(--md-surface-4);color:var(--md-on-surface);filter:none}
  .modal-body{padding:10px 16px 16px;overflow:auto}
  .activePrevRow{display:flex;align-items:baseline;gap:12px;padding:9px 0;border-bottom:1px solid rgba(255,255,255,.06)}
  .activePrevRow:last-child{border-bottom:0}
  .activePrevRow b{min-width:0;font-weight:500;overflow-wrap:anywhere}
  .activePrevRow .cnt{flex:0 0 auto;color:var(--mut);font-size:11.5px;white-space:nowrap}
  /* open dropdowns use the system light background: force contrast */
  select option, datalist option{background:#343746;color:#f8f8f2}
  /* ---------- tablet ---------- */
  @media (max-width:760px){
    main{padding:12px}
    .card{padding:13px;border-radius:14px}
    .chans{margin-left:14px}
    .pltools{justify-content:flex-start;flex:1 1 100%}
    .pltools input{max-width:none}
  }
  /* ---------- smartphone ---------- */
  @media (max-width:560px){
    /* 16px: prevents iOS auto-zoom when inputs get focus */
    input[type=text],input[type=url],input[type=number],input[type=password],select,textarea,
    .crow .cname,.crow .cmove,.chead .cfilter{font-size:16px}

    /* --- header: logo, title and links on a single row --- */
    /* not sticky: on a phone a fixed bar takes space away from the list */
    header{position:static;padding:7px 9px;gap:6px;flex-wrap:nowrap;overflow:hidden}
    header img{width:28px;height:28px;border-radius:7px;flex:0 0 auto}
    header .brand{flex:1 1 auto;min-width:0;overflow:hidden}
    header h1{font-size:15px;font-weight:500;line-height:1.2;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
    header h1 .sub,header .sub,header .spacer{display:none}
    header .links{width:auto;flex:0 0 auto;flex-wrap:nowrap;overflow:visible;gap:4px;padding:0}
    a.lnk{padding:4px 6px;font-size:10px;line-height:1.2;white-space:nowrap;flex:0 0 auto;text-align:center}
    select.langselect{height:24px;max-width:62px;font-size:10px;padding:0 17px 0 7px;flex:0 0 auto;
      background-position:calc(100% - 9px) 10px,calc(100% - 6px) 10px}

    /* --- containers and controls --- */
    main{padding:10px}
    .card{padding:12px;border-radius:13px;margin-bottom:12px}
    .row{gap:10px}
    .row>*{flex:1 1 100%}
    .btns{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:8px;flex:1 1 100%;align-items:stretch}
    .btns button{width:100%}
    .btns #btnNewPList{grid-column:1/-1}
    .grid2{grid-template-columns:1fr;gap:10px}
    button{min-height:44px}
    button.small{min-height:40px;padding:8px 12px}
    .expbtn{min-height:38px;padding:7px 12px}
    .bhandle{padding:10px 5px;font-size:17px}
    .sectgl{width:32px;height:32px;min-height:32px;font-size:13px;margin-left:2px}
    h2{gap:8px}
    h2 .n{width:26px;height:26px;min-width:26px}
    .sectinfo>.ibody{position:fixed;left:12px;right:12px;bottom:calc(84px + env(safe-area-inset-bottom));
      top:auto;width:auto;max-height:52vh}
    details.fold>summary{padding:10px 11px;font-size:13px}
    details.fold .foldbody{padding:2px 11px 12px}

    /* --- list header: name on a full row, actions in a 2x2 grid --- */
    .listhead{align-items:flex-start;gap:6px;margin-bottom:10px}
    .listtitle{flex:1 1 100%}
    .listhead .name{flex:1 1 0;font-size:16px;line-height:1.3;overflow-wrap:anywhere}
    .listhead .badge{margin-left:0}
    .listhead .spacer{display:none}
    .acts{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:6px;width:100%}
    .acts button{width:100%;min-height:42px}
    /* source URL on max 2 lines; in personal lists the block also contains
       the "copy" button, so it stays whole */
    .listcard:not([data-kind=personal])>.url{display:-webkit-box;-webkit-line-clamp:2;
      -webkit-box-orient:vertical;overflow:hidden}

    /* --- playlist: wide search, then action grid --- */
    .plhead{gap:8px;margin-top:14px}
    .plhead h2{flex:1 1 100%;font-size:15px}
    .pltools{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:6px}
    .pltools input{grid-column:1/-1;order:0}
    .pltools button{width:100%;min-height:40px;font-size:12.5px;padding:6px 8px;white-space:normal;line-height:1.2}
    .pltools [data-act=onlyactive]{order:1}
    .pltools [data-act=all]{order:2}
    .pltools [data-act=none]{order:3}
    .pltools [data-act=trash]{order:4}
    .pltools [data-act=delsel]{order:5;grid-column:1/-1}

    /* --- branches: grid row, no nested scroll on touch --- */
    .branches{max-height:none;overflow:visible;padding:6px;border-radius:11px}
    .brow{display:grid;grid-template-columns:auto auto minmax(0,1fr) auto;
          grid-template-areas:"handle cb name del" "exp exp info info";
          gap:4px 8px;padding:8px 6px;align-items:center;
          border-bottom:1px solid rgba(255,255,255,.06);border-radius:8px}
    .brow:last-child{border-bottom:0}
    .brow>.bhandle{grid-area:handle}
    .brow>input[type=checkbox]{grid-area:cb;width:22px;height:22px;justify-self:center}
    .brow>.bname{grid-area:name;padding:9px 10px}
    .brow>.badge{display:none} /* the "personal" badge is already on the list card */
    .brow>.expbtn{grid-area:exp;justify-self:start}
    .brow>.bcount{grid-area:info;justify-self:end;text-align:right;white-space:normal;font-size:11.5px}
    .brow>button[data-bdel]{grid-area:del;width:42px;min-height:42px;padding:0;font-size:15px}

    /* --- channels: name, group, then actions; "from …" on a full row --- */
    .chans{margin:2px 0 10px 8px;padding:6px;border-radius:0 10px 10px 0}
    .chead{gap:6px;padding:2px 2px 8px}
    .chead .cfilter{flex:1 1 160px;max-width:none}
    .chead .ccount{flex:0 0 auto}
    .chead input[data-cadd]{flex:1 1 100%}
    .chead button[data-caddbtn]{flex:1 1 100%}
    .crow{display:grid;grid-template-columns:auto auto minmax(0,1fr) auto auto;
          grid-template-areas:"handle cb name name del" "mv mv mv apply reset" "from from from from from";
          gap:5px 6px;padding:8px 6px;align-items:center;
          border-bottom:1px solid rgba(255,255,255,.06);border-radius:8px}
    .crow:last-child{border-bottom:0}
    .crow>.bhandle{grid-area:handle}
    .crow>input[type=checkbox]{grid-area:cb;width:22px;height:22px;justify-self:center}
    .crow>.cname{grid-area:name;padding:9px 10px}
    .crow>.cmove{grid-area:mv;width:100%;max-width:none;padding:9px 10px}
    .crow>button[data-capply]{grid-area:apply;width:42px;min-height:42px;padding:0;font-size:15px}
    .crow>button[data-creset]{grid-area:reset;width:42px;min-height:42px;padding:0;font-size:15px}
    .crow>button[data-cdel]{grid-area:del;width:42px;min-height:42px;padding:0;font-size:15px}
    .crow>.cnt{grid-area:from;justify-self:start;white-space:normal;font-size:11.5px;line-height:1.35}

    /* --- history --- */
    html,body{overflow-x:hidden}
    .histbar select{flex:1 1 100%}
    .histactions{margin-left:0;width:100%}
    .histactions button,.histrestore .hrow button{flex:1 1 100%;width:100%}
    .histrestore label.hopt{flex:1 1 100%}

    /* --- trash --- */
    .trash{padding:8px}
    .trashrow{gap:6px;padding:8px 2px}
    .trashrow button{flex:1 1 100%;min-height:40px}
    .trashrow b,.trashrow .cnt{overflow-wrap:anywhere;white-space:normal;min-width:0}

    /* --- log --- */
    .logbar{gap:6px}
    .logbar select{flex:1 1 auto}
    .logbar input{flex:1 1 100%}
    .logbar button{flex:1 1 auto}
    .logbar .spacer{display:none}
    .logbox{height:42vh;font-size:11.5px}

    /* --- active playlists modal --- */
    .modal{padding:10px}
    .modal-card{max-height:80vh;border-radius:16px}
    .modal-head{padding:12px 14px}
    .modal-body{padding:8px 14px 14px}
    .activePrevRow{align-items:flex-start;flex-direction:column;gap:2px}

    /* --- static footer at the bottom of the page --- */
    /* used to be fixed: with the keyboard open it floated above the keys,
       stealing space. Now list count and version scroll with the page. */
    body{padding-bottom:0}
    footer{position:static;left:auto;right:auto;bottom:auto;display:flex;flex-direction:column;
           gap:4px;padding:12px 12px calc(76px + env(safe-area-inset-bottom));
           border-top:1px solid var(--line);background:transparent;box-shadow:none;
           backdrop-filter:none;-webkit-backdrop-filter:none}
    footer #btnSave{display:none}
    footer #status{width:100%;text-align:center;font-size:11.5px;line-height:1.4}
    footer .footer-center{width:100%;text-align:center;gap:6px}
    footer #appVersion{font-size:10.5px}
    footer .footer-actions{display:flex;justify-content:center;width:100%}

    /* --- floating buttons: Lists left, Save centered, top right --- */
    .fabbar{display:flex;position:fixed;left:50%;right:auto;bottom:calc(12px + env(safe-area-inset-bottom));
            gap:10px;z-index:61;transform:translateX(-50%);transition:opacity .18s,transform .18s}
    .fabbar button{box-shadow:0 6px 16px rgba(0,0,0,.45);border-radius:16px}
    #fabSave{min-height:54px;padding:0 20px;font-size:15px}
    #sdToggle{top:auto;left:12px;right:auto;bottom:calc(12px + env(safe-area-inset-bottom));
              width:auto;height:54px;padding:0 18px;border-radius:16px;font-size:14px;z-index:61;
              background:var(--md-surface-3);color:var(--md-on-surface);border:0;
              box-shadow:0 6px 16px rgba(0,0,0,.45);transition:opacity .18s,transform .18s}
    footer #toTop{display:grid;place-items:center;position:fixed;right:12px;
           bottom:calc(12px + env(safe-area-inset-bottom));z-index:61;
           width:54px;height:54px;padding:0;border-radius:16px;font-size:20px;line-height:1;
           background:var(--md-secondary-container);color:var(--md-on-secondary-container);
           box-shadow:0 6px 16px rgba(0,0,0,.45);transition:opacity .18s,transform .18s}
    /* keyboard open: floating buttons hide and cover nothing */
    body.kbd .fabbar{opacity:0;pointer-events:none;transform:translate(-50%,10px)}
    body.kbd #sdToggle,body.kbd #toTop{opacity:0;pointer-events:none;transform:translateY(10px)}

    /* --- list menu: bottom sheet above the floating buttons --- */
    #sidemenu{left:8px;right:8px;top:auto;bottom:calc(80px + env(safe-area-inset-bottom));
              width:auto;max-height:56vh;padding:8px}
    .sditem .sdname{padding:10px 12px;font-size:13px;min-height:40px}
    .toast{bottom:calc(82px + env(safe-area-inset-bottom))}

    /* the card title does not end flush with the edge when jumping between lists */
    .listcard{scroll-margin-top:12px}
    button,a.lnk,summary{touch-action:manipulation}
  }
  /* ---------- very small phones (iPhone SE and similar) ---------- */
  @media (max-width:380px){
    main{padding:8px}
    .card{padding:10px}
    header{padding:6px 7px;gap:4px}
    header img{width:26px;height:26px}
    header h1{font-size:14px}
    a.lnk{padding:4px 5px;font-size:9px}
    select.langselect{max-width:56px;font-size:9px}
    .acts{grid-template-columns:1fr}
    .pltools button{font-size:12px;padding:6px}
    .listhead .name{font-size:15px}
    .brow>.bname,.crow>.cname{padding:9px 8px}
    .crow>button[data-capply],.crow>button[data-creset],.crow>button[data-cdel],
    .brow>button[data-bdel]{width:38px;min-height:40px}
  }
  /* ---------- touch: no "sticky" hover ---------- */
  @media (hover:none){
    button:hover{filter:none}
    button.ghost:hover{background:var(--md-secondary-container)}
    .brow:hover,.crow:hover{background:transparent}
    .brow:active,.crow:active{background:rgba(189,147,249,.14)}
    a.lnk:hover{background:var(--md-secondary-container)}
    details.fold>summary:hover{background:transparent}
    .sectgl:hover{background:transparent;color:var(--md-on-surface-variant)}
    details.info>summary:hover{background:transparent}
  }
  @media (prefers-reduced-motion:reduce){
    *{animation-duration:.01ms !important;animation-iteration-count:1 !important;transition-duration:.01ms !important}
    html{scroll-behavior:auto}
  }
