:root {
    /* surfaces — deep cool slate, layered for depth */
    --bg: #0a0d14;
    --bg2: #0d111a;
    --panel: #121724;
    --elev: #171d2b;
    --elev2: #1e2534;
    --hover: #232c3e;
    --line: #232b3a;
    --line2: #303b4e;
    /* text */
    --text: #e8edf4;
    --dim: #93a0b4;
    --faint: #5d6b80;
    /* accent — warm amber (cinematic) */
    --acc: #ffb545;
    --acc2: #ff9d2e;
    --acc-dim: #7a5a24;
    --acc-glow: rgba(255,181,69,.16);
    /* semantic */
    --ok: #46d07f;
    --err: #ff6b6b;
    --info: #56c7f0;
    /* type */
    --sans: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", sans-serif;
    --mono: "Cascadia Code", "JetBrains Mono", ui-monospace, "SFMono-Regular", Consolas, monospace;
    --r: 10px;
    --r-sm: 7px;
  }
  * { box-sizing: border-box; }
  html, body { height: 100%; margin: 0; }
  body {
    background:
      radial-gradient(1200px 600px at 72% -10%, rgba(255,181,69,.05), transparent 60%),
      radial-gradient(900px 500px at 100% 100%, rgba(86,199,240,.035), transparent 55%),
      var(--bg);
    color: var(--text);
    font-family: var(--sans);
    font-size: 13px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    display: flex;
    overflow: hidden;
    letter-spacing: .01em;
  }
  ::selection { background: var(--acc-glow); }
  .mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }

  /* scrollbars */
  ::-webkit-scrollbar { width: 10px; height: 10px; }
  ::-webkit-scrollbar-thumb { background: #2a3344; border-radius: 10px; border: 2px solid transparent; background-clip: padding-box; }
  ::-webkit-scrollbar-thumb:hover { background: #384358; background-clip: padding-box; }
  ::-webkit-scrollbar-track { background: transparent; }

  /* ---------------- buttons ---------------- */
  button {
    font-family: inherit; font-size: 13px; color: var(--text);
    background: var(--elev); border: 1px solid var(--line2);
    border-radius: var(--r-sm); padding: 7px 12px; cursor: pointer;
    display: inline-flex; align-items: center; gap: 7px; white-space: nowrap;
    transition: background .15s, border-color .15s, transform .06s, color .15s, box-shadow .15s;
  }
  button:hover:not(:disabled) { background: var(--hover); border-color: #3d4a61; }
  button:active:not(:disabled) { transform: translateY(1px); }
  button:disabled { opacity: .4; cursor: default; }
  button svg { width: 15px; height: 15px; flex: none; }
  button.primary {
    background: linear-gradient(180deg, var(--acc), var(--acc2));
    border-color: transparent; color: #241802; font-weight: 650;
    box-shadow: 0 1px 0 rgba(255,255,255,.25) inset, 0 6px 18px -8px var(--acc);
  }
  button.primary:hover:not(:disabled) { filter: brightness(1.06); background: linear-gradient(180deg, var(--acc), var(--acc2)); border-color: transparent; }
  button.ghost { background: transparent; border-color: transparent; color: var(--dim); }
  button.ghost:hover:not(:disabled) { background: var(--elev); color: var(--text); border-color: transparent; }
  button.icon { padding: 8px; }
  button.big { padding: 13px 20px; font-size: 14.5px; width: 100%; justify-content: center; }

  input[type=text], input[type=number], select {
    font-family: inherit; font-size: 13px; color: var(--text);
    background: var(--bg2); border: 1px solid var(--line2); border-radius: var(--r-sm);
    padding: 8px 10px; outline: none; transition: border-color .15s, box-shadow .15s;
  }
  input[type=text]:focus, input[type=number]:focus, select:focus {
    border-color: var(--acc-dim); box-shadow: 0 0 0 3px var(--acc-glow);
  }
  select { cursor: pointer; }

  /* ---------------- sidebar ---------------- */
  #sidebar {
    width: 316px; min-width: 316px; height: 100%;
    background: linear-gradient(180deg, var(--panel), var(--bg2));
    border-right: 1px solid var(--line);
    display: flex; flex-direction: column;
    animation: slideIn .5s cubic-bezier(.2,.7,.2,1) both;
  }
  #sidebar > header { padding: 16px 16px 12px; border-bottom: 1px solid var(--line); }
  .brand { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
  .brand .logo {
    width: 30px; height: 30px; border-radius: 8px; flex: none;
    background: linear-gradient(145deg, var(--acc), var(--acc2));
    display: flex; align-items: center; justify-content: center; color: #241802;
    box-shadow: 0 4px 14px -4px var(--acc);
  }
  .brand .logo svg { width: 18px; height: 18px; }
  .brand h1 { margin: 0; font-size: 15px; font-weight: 640; letter-spacing: .02em; }
  .brand .sub { font-size: 10.5px; color: var(--faint); letter-spacing: .09em; text-transform: uppercase; margin-top: 1px; }
  #pickRow { display: flex; gap: 8px; margin-bottom: 10px; }
  #pickRow #pickFolder { flex: 1; justify-content: center; }
  .search { position: relative; }
  .search svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); width: 15px; height: 15px; color: var(--faint); pointer-events: none; }
  #filter { width: 100%; padding-left: 32px; }
  #counts { margin-top: 12px; display: flex; gap: 6px; flex-wrap: wrap; align-items: center; color: var(--dim); font-size: 11.5px; }
  .chip { background: var(--elev); border: 1px solid var(--line); border-radius: 999px; padding: 2px 9px; font-size: 11px; color: var(--dim); }
  .chip b { color: var(--text); font-weight: 600; }

  #list { flex: 1; overflow-y: auto; padding: 8px 8px 28px; }
  .grp {
    padding: 12px 8px 5px; color: var(--faint); font-size: 10px; font-weight: 700;
    text-transform: uppercase; letter-spacing: .1em; word-break: break-all;
    position: sticky; top: 0; z-index: 1;
    background: linear-gradient(180deg, var(--panel) 60%, transparent);
    backdrop-filter: blur(2px);
  }
  .row {
    display: flex; align-items: center; gap: 11px;
    padding: 7px 9px; border-radius: var(--r-sm); cursor: pointer;
    position: relative; transition: background .13s;
  }
  .row + .row { margin-top: 1px; }
  .row:hover { background: var(--hover); }
  .row.sel { background: linear-gradient(90deg, var(--acc-glow), rgba(255,181,69,.03)); }
  .row.sel::before { content: ""; position: absolute; left: 0; top: 8px; bottom: 8px; width: 3px; border-radius: 3px; background: var(--acc); }
  .thumb {
    position: relative; width: 64px; height: 38px; flex: none;
    background: #060810; border: 1px solid var(--line); border-radius: 6px; overflow: hidden;
    display: flex; align-items: center; justify-content: center;
    box-shadow: 0 1px 3px rgba(0,0,0,.4);
  }
  .thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
  .thumb .ph { color: #37425a; display: flex; }
  .thumb .ph svg { width: 20px; height: 20px; }
  .thumb .tag {
    position: absolute; left: 3px; bottom: 3px; font-size: 7.5px; font-weight: 800; letter-spacing: .05em;
    padding: 1px 4px; border-radius: 3px; background: rgba(0,0,0,.72); color: var(--dim);
  }
  .thumb .tag.v { color: var(--acc); }
  .thumb .spin { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; }
  .thumb .spin::after { content: ""; width: 14px; height: 14px; border: 2px solid var(--line2); border-top-color: var(--acc); border-radius: 50%; animation: spin .7s linear infinite; }
  .rowmain { flex: 1; min-width: 0; }
  .nm { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12.5px; }
  .sz { color: var(--faint); font-size: 11px; }
  .row.sel .nm { color: #fff; }

  /* ---------------- main ---------------- */
  #main { flex: 1; height: 100%; display: flex; flex-direction: column; min-width: 0; animation: fadeUp .5s .06s cubic-bezier(.2,.7,.2,1) both; }

  #topbar {
    height: 52px; flex: none; display: flex; align-items: center; gap: 14px;
    padding: 0 18px; border-bottom: 1px solid var(--line);
    background: linear-gradient(180deg, var(--panel), transparent);
  }
  #title { font-size: 13.5px; font-weight: 550; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  #title .dir { color: var(--faint); }
  #minfo { display: flex; gap: 7px; align-items: center; margin-left: auto; flex: none; }
  #minfo .mi { display: none; align-items: center; gap: 5px; font-size: 11px; color: var(--dim); background: var(--elev); border: 1px solid var(--line); border-radius: 999px; padding: 3px 10px; }
  #minfo .mi.on { display: inline-flex; }
  #minfo .mi b { color: var(--text); font-weight: 600; }
  #minfo .mi svg { width: 12px; height: 12px; color: var(--faint); }

  #stage {
    flex: 1; min-height: 0; position: relative;
    display: flex; align-items: center; justify-content: center;
    background:
      radial-gradient(600px 340px at 50% 42%, rgba(255,255,255,.018), transparent 70%),
      #05070c;
    overflow: hidden;
  }
  #stage::after { content: ""; position: absolute; inset: 0; pointer-events: none; box-shadow: inset 0 0 120px rgba(0,0,0,.55); }
  #video { max-width: calc(100% - 40px); max-height: calc(100% - 40px); display: none; border-radius: 8px; box-shadow: 0 24px 70px -24px rgba(0,0,0,.8), 0 0 0 1px rgba(255,255,255,.04); }

  #empty { color: var(--dim); text-align: center; padding: 24px; max-width: 560px; animation: fadeUp .6s .12s both; }
  #empty .bigicon { width: 60px; height: 60px; margin: 0 auto 18px; color: var(--acc); opacity: .9; filter: drop-shadow(0 6px 20px var(--acc-glow)); }
  #empty h2 { color: var(--text); font-size: 20px; font-weight: 620; margin: 0 0 10px; letter-spacing: .01em; }
  #empty p { margin: 0 auto; max-width: 460px; line-height: 1.6; }
  #empty .keys { display: grid; grid-template-columns: auto 1fr; gap: 8px 16px; margin: 22px auto 0; max-width: 340px; text-align: left; font-size: 12px; }
  #empty .keys div:nth-child(odd) { text-align: right; }
  kbd { background: var(--elev2); border: 1px solid var(--line2); border-bottom-width: 2px; border-radius: 5px; padding: 2px 7px; font-family: var(--mono); font-size: 11px; color: var(--text); }

  #msg {
    position: absolute; left: 50%; bottom: 20px; transform: translateX(-50%) translateY(8px);
    background: rgba(30,16,4,.92); color: #ffe6c2; border: 1px solid var(--acc-dim);
    padding: 10px 16px; border-radius: 10px; max-width: 78%; display: none; z-index: 5;
    box-shadow: 0 16px 40px -12px rgba(0,0,0,.7); backdrop-filter: blur(8px);
    font-size: 12.5px; animation: toastIn .25s cubic-bezier(.2,.8,.2,1) both;
  }
  #msg.ok { background: rgba(8,30,18,.92); color: #c9f5da; border-color: #1d6b3f; }

  /* stage spinner (file-pick auto re-encode) */
  #stageSpin { position: absolute; inset: 0; display: none; flex-direction: column; align-items: center; justify-content: center; gap: 14px; z-index: 6; }
  #stageSpin.on { display: flex; animation: fadeIn .2s both; }
  #stageSpin .ring { width: 62px; height: 62px; }
  #stageSpin .ring svg { width: 100%; height: 100%; animation: spin 1s linear infinite; }
  #stageSpin .ring circle { stroke: var(--acc); stroke-linecap: round; stroke-dasharray: 90 150; filter: drop-shadow(0 0 8px var(--acc-glow)); }
  #stageSpin .slabel { font-size: 15px; font-weight: 560; color: var(--text); max-width: 70%; text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  #stageSpin .ssub { font-size: 12px; color: var(--dim); }
  #stageSpin .sbar { width: 240px; height: 6px; background: var(--elev2); border-radius: 999px; overflow: hidden; }
  #stageSpin #stageBar { height: 100%; width: 0%; background: linear-gradient(90deg, var(--acc2), var(--acc)); border-radius: 999px; transition: width .25s ease; box-shadow: 0 0 12px var(--acc-glow); }

  /* ---------------- control bar ---------------- */
  #controls { flex: none; display: none; padding: 14px 18px 16px; border-top: 1px solid var(--line); background: linear-gradient(0deg, var(--panel), transparent); }
  #controls.on { display: block; }

  #seekWrap { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
  #seek {
    -webkit-appearance: none; appearance: none; flex: 1; height: 22px; background: transparent; cursor: pointer; margin: 0;
  }
  #seek::-webkit-slider-runnable-track {
    height: 6px; border-radius: 999px;
    background: linear-gradient(90deg, var(--acc) 0 var(--fill,0%), var(--elev2) var(--fill,0%) 100%);
    border: 1px solid var(--line2);
  }
  #seek::-webkit-slider-thumb {
    -webkit-appearance: none; width: 16px; height: 16px; margin-top: -6px; border-radius: 50%;
    background: #fff; border: 3px solid var(--acc);
    box-shadow: 0 2px 8px rgba(0,0,0,.5); transition: transform .1s;
  }
  #seek:hover::-webkit-slider-thumb { transform: scale(1.12); }
  #seek:active::-webkit-slider-thumb { transform: scale(1.25); }
  #seek:disabled { opacity: .5; }
  #seek:disabled::-webkit-slider-thumb { border-color: var(--faint); }
  #seekTip { font-family: var(--mono); font-size: 11px; color: var(--dim); min-width: 42px; text-align: right; flex: none; }

  #btnRow { display: flex; align-items: center; gap: 10px; }
  .cluster { display: flex; align-items: center; gap: 6px; }
  .divider { width: 1px; height: 26px; background: var(--line2); margin: 0 4px; flex: none; }
  .spacer { flex: 1; }

  /* hero readout */
  .readout { display: flex; align-items: baseline; gap: 10px; padding: 4px 12px; background: var(--bg2); border: 1px solid var(--line); border-radius: 8px; }
  #tc { font-family: var(--mono); font-size: 17px; font-weight: 600; color: var(--text); letter-spacing: .02em; }
  .readout .frames { font-family: var(--mono); font-size: 12px; color: var(--dim); }
  .readout .frames b { color: var(--acc); font-weight: 650; }

  /* play/pause icon swap */
  #play .i-pause { display: none; }
  #play.playing .i-play { display: none; }
  #play.playing .i-pause { display: inline; }

  .fpsbox { display: flex; align-items: center; gap: 6px; }
  .fpsbox .lbl { color: var(--faint); font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; }
  #fps { width: 74px; text-align: center; }
  #res { font-family: var(--mono); font-size: 11px; color: var(--dim); }

  /* ---------------- drag overlay ---------------- */
  #drop { position: fixed; inset: 0; background: rgba(10,13,20,.86); border: 2.5px dashed var(--acc); display: none; align-items: center; justify-content: center; z-index: 100; pointer-events: none; backdrop-filter: blur(3px); }
  #drop.on { display: flex; }
  #drop .inner { text-align: center; color: var(--acc); animation: pulse 1.4s ease-in-out infinite; }
  #drop .inner svg { width: 54px; height: 54px; margin-bottom: 14px; }
  #drop .inner div { font-size: 18px; font-weight: 600; letter-spacing: .01em; }

  /* ---------------- HEVC modal ---------------- */
  #hevcModal { position: fixed; inset: 0; z-index: 200; background: rgba(4,6,11,.72); display: none; align-items: center; justify-content: center; padding: 24px; backdrop-filter: blur(6px); }
  #hevcModal.on { display: flex; animation: fadeIn .2s both; }
  .modal-card { background: linear-gradient(180deg, var(--elev), var(--panel)); border: 1px solid var(--line2); border-radius: 16px; max-width: 540px; width: 100%; padding: 26px 28px; box-shadow: 0 40px 90px -30px rgba(0,0,0,.8), 0 0 0 1px rgba(255,255,255,.03); animation: modalIn .3s cubic-bezier(.2,.8,.2,1) both; }
  .modal-eyebrow { color: var(--acc); font-size: 10.5px; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; margin-bottom: 8px; display: flex; align-items: center; gap: 7px; }
  .modal-eyebrow svg { width: 14px; height: 14px; }
  .modal-card h2 { margin: 0 0 12px; font-size: 21px; font-weight: 640; letter-spacing: .01em; }
  .modal-card > p { margin: 0 0 16px; color: var(--dim); line-height: 1.6; }
  .modal-card a { color: var(--acc); text-decoration: none; border-bottom: 1px solid var(--acc-dim); }
  .modal-card a:hover { border-bottom-color: var(--acc); }
  .hint { color: var(--faint); font-size: 12px; line-height: 1.55; }
  #hevcDecodeBox { margin-bottom: 18px; }
  #hevcDecodeBox .hint { margin-top: 10px; display: block; }
  #hevcProgress { margin-bottom: 18px; }
  .pbar { height: 10px; background: var(--bg2); border: 1px solid var(--line2); border-radius: 999px; overflow: hidden; position: relative; }
  #hevcBar { height: 100%; width: 0%; background: linear-gradient(90deg, var(--acc2), var(--acc)); border-radius: 999px; transition: width .25s ease; box-shadow: 0 0 12px var(--acc-glow); }
  #hevcStat { margin-top: 9px; color: var(--dim); }
  #hevcInstallDetails { margin: 6px 0 16px; border-top: 1px solid var(--line); padding-top: 14px; }
  #hevcInstallDetails summary { cursor: pointer; color: var(--dim); font-size: 12.5px; list-style: none; display: flex; align-items: center; gap: 7px; transition: color .15s; }
  #hevcInstallDetails summary:hover { color: var(--text); }
  #hevcInstallDetails summary::before { content: "▸"; color: var(--acc); transition: transform .15s; }
  #hevcInstallDetails[open] summary::before { transform: rotate(90deg); }
  #hevcInstallDetails ol { margin: 10px 0; padding-left: 20px; color: var(--dim); }
  #hevcInstallDetails li { margin: 6px 0; }
  #hevcInstallDetails p { margin: 8px 0; }
  .modal-btns { display: flex; gap: 10px; flex-wrap: wrap; }
  .modal-foot { margin-top: 16px; color: var(--faint); font-size: 11px; }

  /* ---------------- motion ---------------- */
  @keyframes slideIn { from { opacity: 0; transform: translateX(-14px); } to { opacity: 1; transform: none; } }
  @keyframes fadeUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
  @keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
  @keyframes modalIn { from { opacity: 0; transform: translateY(16px) scale(.98); } to { opacity: 1; transform: none; } }
  @keyframes toastIn { from { opacity: 0; transform: translateX(-50%) translateY(8px); } to { opacity: 1; transform: translateX(-50%) translateY(0); } }
  @keyframes spin { to { transform: rotate(360deg); } }
  @keyframes pulse { 0%,100% { opacity: .75; } 50% { opacity: 1; } }
  @media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
