:root {
      --bg: #0d1117;
      --card-bg: #161b22;
      --card-border: #30363d;
      --accent-blue: #388bfd;
      --accent-cyan: #22d3ee;
      --accent-green: #238636;
      --text: #c9d1d9;
      --text-muted: #8b949e;
      --text-bright: #f0f6fc;
      --slider-track: #21262d;
    }
    * { box-sizing: border-box; margin: 0; padding: 0; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }
    body { background-color: var(--bg); color: var(--text); min-height: 100vh; padding: 24px; display: flex; flex-direction: column; align-items: center; }
    .container { max-width: 1100px; width: 100%; display: flex; flex-direction: column; gap: 20px; }
    header { padding-bottom: 16px; border-bottom: 1px solid var(--card-border); }
    h1 { color: var(--text-bright); font-size: 24px; display: flex; align-items: center; gap: 10px; }
    p.desc { color: var(--text-muted); font-size: 13px; margin-top: 4px; }
    .public-link {
      margin-top: 10px; padding: 10px 12px; border-radius: 8px;
      background: #161b22; border: 1px solid var(--card-border);
      font-size: 13px; color: var(--text-muted); word-break: break-all;
    }
    .public-link a { color: var(--accent-cyan); text-decoration: none; font-weight: 600; }
    .public-link a:hover { text-decoration: underline; }
    .public-link .copy-btn {
      margin-left: 8px; padding: 2px 8px; border-radius: 6px; border: 1px solid var(--card-border);
      background: #21262d; color: var(--text-bright); font-size: 12px; cursor: pointer;
    }

    .upload-zone {
      display: block;
      border: 2px dashed var(--card-border);
      background: var(--card-bg);
      border-radius: 12px;
      padding: 30px 20px;
      text-align: center;
      cursor: pointer;
      transition: all 0.2s;
      user-select: none;
    }
    .upload-zone:hover { border-color: var(--accent-blue); background: #1c2128; }
    .upload-zone.dragover {
      border-color: var(--accent-cyan);
      background: #1c2128;
      box-shadow: 0 0 0 3px rgba(34, 211, 238, 0.18);
    }
    .file-input { position: absolute; width: 0; height: 0; opacity: 0; pointer-events: none; }

    .grid-panels { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; }
    .panel { background: var(--card-bg); border: 1px solid var(--card-border); border-radius: 12px; padding: 18px; display: flex; flex-direction: column; gap: 14px; overflow: visible; }
    .panel-header { display: flex; justify-content: space-between; align-items: center; font-weight: 600; color: var(--text-bright); gap: 10px; }
    .panel-title { display: inline-flex; align-items: center; gap: 6px; position: relative; cursor: help; }
    .control-group { display: flex; flex-direction: column; gap: 4px; position: relative; z-index: 1; }
    .control-group:hover, .control-group:focus-within { z-index: 12; }
    .label-row { display: flex; justify-content: space-between; align-items: center; font-size: 13px; gap: 8px; }
    .label-val { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--accent-cyan); font-weight: bold; white-space: nowrap; }
    .param-brief { font-size: 11px; color: var(--text-muted); line-height: 1.4; }
    .param-label {
      position: relative;
      display: inline-flex;
      align-items: center;
      gap: 6px;
      cursor: help;
    }
    .info-i {
      display: inline-flex; align-items: center; justify-content: center;
      width: 14px; height: 14px; border-radius: 50%; flex-shrink: 0;
      border: 1px solid #484f58; color: var(--text-muted); font-size: 10px; font-style: normal;
      font-weight: 700; line-height: 1;
    }
    .param-label:hover .info-i, .panel-title:hover .info-i { border-color: var(--accent-cyan); color: var(--accent-cyan); }
    .param-tip {
      display: none;
      position: absolute;
      top: calc(100% + 8px);
      left: 0;
      width: min(320px, 78vw);
      padding: 12px;
      background: #1c2128;
      border: 1px solid var(--card-border);
      border-radius: 10px;
      box-shadow: 0 12px 32px rgba(0,0,0,0.55);
      z-index: 40;
      font-size: 12px;
      font-weight: 400;
      color: var(--text);
      line-height: 1.55;
      text-align: left;
      white-space: normal;
    }
    .param-label:hover .param-tip, .param-label:focus-within .param-tip,
    .panel-title:hover .param-tip, .panel-title:focus-within .param-tip { display: block; }
    .param-tip-title { color: var(--text-bright); font-weight: 600; font-size: 13px; margin-bottom: 6px; }
    .param-tip-range { display: block; margin-top: 8px; color: var(--accent-cyan); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11px; }
    .subhead {
      display: flex; justify-content: space-between; align-items: center; gap: 8px;
      font-size: 13px; font-weight: 600; color: var(--text-bright);
      padding-top: 8px; margin-top: 2px; border-top: 1px solid var(--card-border);
    }
    .subhead.first { border-top: none; padding-top: 0; margin-top: 0; }
    input[type="range"] { width: 100%; height: 6px; border-radius: 3px; background: var(--slider-track); outline: none; -webkit-appearance: none; appearance: none; cursor: pointer; }
    input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 16px; height: 16px; border-radius: 50%; background: #58a6ff; cursor: pointer; }
    input[type="range"]::-moz-range-thumb { width: 16px; height: 16px; border: none; border-radius: 50%; background: #58a6ff; cursor: pointer; }

    .toggle-switch { position: relative; width: 40px; height: 22px; display: inline-block; }
    .toggle-switch input { opacity: 0; width: 0; height: 0; }
    .slider-toggle { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background: #30363d; border-radius: 22px; transition: .3s; }
    .slider-toggle:before { position: absolute; content: ""; height: 16px; width: 16px; left: 3px; bottom: 3px; background: white; border-radius: 50%; transition: .3s; }
    input:checked + .slider-toggle { background: var(--accent-green); }
    input:checked + .slider-toggle:before { transform: translateX(18px); }

    .action-box { background: var(--card-bg); border: 1px solid var(--card-border); border-radius: 12px; padding: 20px; display: flex; flex-direction: column; gap: 16px; align-items: center; }
    .btn { display: inline-flex; align-items: center; gap: 8px; padding: 12px 28px; border-radius: 8px; font-size: 15px; font-weight: 600; cursor: pointer; border: none; transition: 0.2s; }
    .btn-submit { background: #238636; color: white; width: 100%; max-width: 320px; justify-content: center; }
    .btn-submit:hover { background: #2ea043; }
    .btn-submit:disabled { opacity: 0.5; cursor: not-allowed; }

    .preview-section, .result-section {
      width: 100%;
      display: none;
      flex-direction: column;
      gap: 14px;
      background: #111418;
      padding: 16px;
      border-radius: 8px;
      border: 1px solid #30363d;
    }
    .preview-grid {
      display: grid;
      grid-template-columns: 1fr 1fr;
      gap: 16px;
    }
    @media (max-width: 720px) {
      .preview-grid { grid-template-columns: 1fr; }
    }
    .preview-card {
      display: flex;
      flex-direction: column;
      gap: 8px;
      background: var(--card-bg);
      padding: 12px;
      border-radius: 8px;
      border: 1px solid var(--card-border);
    }
    .preview-card h4 {
      color: var(--text-bright);
      font-size: 14px;
    }
    .preview-card video, .preview-card audio { width: 100%; border-radius: 6px; }
    .preview-card video { max-height: 280px; background: #000; }
    .preview-hint { font-size: 12px; color: var(--text-muted); }
    .download-btn { background: #1f6feb; color: white; text-decoration: none; padding: 10px 20px; border-radius: 6px; font-weight: 600; display: inline-flex; align-items: center; gap: 6px; justify-content: center; }
    .download-btn:hover { background: #388bfd; }
    .progress-bar { width: 100%; height: 8px; background: #21262d; border-radius: 4px; overflow: hidden; display: none; }
    .progress-fill { height: 100%; background: #58a6ff; width: 0%; transition: width 0.3s; }
    body.dragging .upload-zone { border-color: var(--accent-cyan); }

    .preset-panel { background: var(--card-bg); border: 1px solid var(--card-border); border-radius: 12px; padding: 16px 18px; display: flex; flex-direction: column; gap: 12px; overflow: visible; }
    .preset-header { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
    .preset-title { color: var(--text-bright); font-weight: 600; font-size: 14px; }
    .preset-hint { color: var(--text-muted); font-size: 12px; }
    .preset-chips { display: flex; flex-wrap: wrap; gap: 8px; overflow: visible; }
    .preset-chip-wrap {
      position: relative;
      display: inline-flex;
      align-items: center;
      border-radius: 20px;
      border: 1px solid var(--card-border);
      background: #21262d;
    }
    .preset-chip-wrap:hover { border-color: var(--accent-blue); background: #1c2128; }
    .preset-chip-wrap.active { background: var(--accent-blue); border-color: var(--accent-blue); }
    .preset-chip {
      display: inline-flex; align-items: center; gap: 6px;
      padding: 8px 14px; border-radius: 20px; border: 1px solid var(--card-border);
      background: #21262d; color: var(--text-bright); font-size: 13px; font-weight: 500;
      cursor: pointer; transition: 0.15s; line-height: 1.2; text-decoration: none;
    }
    .preset-chip:hover { border-color: var(--accent-blue); }
    .preset-chip-wrap .preset-chip {
      background: transparent; border: none; padding: 8px 12px;
    }
    .preset-chip-wrap.active .preset-chip { color: #fff; }
    .preset-chip.custom { font-style: normal; }
    .preset-open {
      color: var(--text-muted); text-decoration: none; font-size: 12px;
      padding: 0 8px 0 0; line-height: 1;
    }
    .preset-chip-wrap.active .preset-open { color: rgba(255,255,255,0.88); }
    .preset-open:hover { color: var(--accent-cyan); }
    .preset-chip-del {
      display: inline-flex; align-items: center; justify-content: center;
      width: 16px; height: 16px; border-radius: 50%; border: none; margin-right: 6px;
      background: rgba(255,255,255,0.14); color: inherit; font-size: 12px; line-height: 1;
      cursor: pointer; padding: 0; color: var(--text-bright);
    }
    .preset-chip-wrap.active .preset-chip-del { color: #fff; }
    .preset-chip-del:hover { background: #da3633; color: #fff; }
    .preset-tip {
      display: none;
      position: absolute;
      top: calc(100% + 8px);
      left: 0;
      min-width: 280px;
      max-width: 360px;
      max-height: 70vh;
      overflow-y: auto;
      padding: 12px;
      background: #1c2128;
      border: 1px solid var(--card-border);
      border-radius: 10px;
      box-shadow: 0 12px 32px rgba(0,0,0,0.5);
      z-index: 50;
      font-size: 12px;
      font-weight: 400;
      color: var(--text);
      line-height: 1.5;
      text-align: left;
      white-space: normal;
    }
    .preset-chip-wrap:hover .preset-tip { display: block; }
    .preset-tip-title { color: var(--text-bright); font-weight: 600; font-size: 13px; margin-bottom: 8px; }
    .preset-tip-grid { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; }
    .preset-tip-k { color: var(--text-muted); }
    .preset-tip-v { color: var(--accent-cyan); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; text-align: right; }
    .preset-tip-link {
      display: inline-block; margin-top: 10px; color: var(--accent-blue);
      text-decoration: none; font-weight: 600;
    }
    .preset-tip-link:hover { text-decoration: underline; }
    .preset-save-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
    .preset-name-input {
      flex: 1; min-width: 180px; height: 36px; padding: 0 12px;
      border-radius: 8px; border: 1px solid var(--card-border); background: #0d1117;
      color: var(--text-bright); font-size: 13px; outline: none;
    }
    .preset-name-input:focus { border-color: var(--accent-blue); }
    .btn-save-preset {
      height: 36px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--card-border);
      background: #21262d; color: var(--text-bright); font-size: 13px; font-weight: 600; cursor: pointer;
    }
    .btn-save-preset:hover { border-color: var(--accent-blue); background: #1c2128; }

    .tabs {
      display: flex; gap: 6px; flex-wrap: wrap;
      background: var(--card-bg); border: 1px solid var(--card-border);
      border-radius: 12px; padding: 6px;
    }
    .tab-btn {
      flex: 1; min-width: 110px; padding: 10px 14px; border: none; border-radius: 8px;
      background: transparent; color: var(--text-muted); font-size: 14px; font-weight: 600;
      cursor: pointer; transition: 0.15s;
    }
    .tab-btn:hover { color: var(--text-bright); background: #21262d; }
    .tab-btn.active { color: #fff; background: var(--accent-blue); }
    .tab-panel { display: none; flex-direction: column; gap: 20px; }
    .tab-panel.active { display: flex; }

    .trim-card {
      background: var(--card-bg); border: 1px solid var(--card-border);
      border-radius: 12px; padding: 16px; display: none; flex-direction: column; gap: 14px;
    }
    .trim-card.show { display: flex; }
    .trim-player video { width: 100%; max-height: 420px; background: #000; border-radius: 8px; }
    .trim-times { display: grid; grid-template-columns: 1fr auto 1fr; gap: 12px; align-items: end; }
    @media (max-width: 720px) { .trim-times { grid-template-columns: 1fr; } }
    .trim-field { display: flex; flex-direction: column; gap: 6px; }
    .trim-field label { font-size: 12px; color: var(--text-muted); }
    .trim-field-row { display: flex; gap: 8px; align-items: center; }
    .time-input {
      flex: 1; height: 36px; padding: 0 10px; border-radius: 8px;
      border: 1px solid var(--card-border); background: #0d1117; color: var(--text-bright);
      font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px;
    }
    .time-input:focus { border-color: var(--accent-blue); outline: none; }
    .btn-ghost {
      height: 36px; padding: 0 10px; border-radius: 8px; border: 1px solid var(--card-border);
      background: #21262d; color: var(--text-bright); font-size: 12px; font-weight: 600;
      cursor: pointer; white-space: nowrap;
    }
    .btn-ghost:hover { border-color: var(--accent-blue); }
    .btn-ghost:disabled { opacity: 0.45; cursor: not-allowed; }
    .trim-now {
      text-align: center; padding: 8px 12px; border-radius: 8px; background: #0d1117;
      border: 1px solid var(--card-border); min-width: 150px;
    }
    .trim-now .k { display: block; font-size: 11px; color: var(--text-muted); margin-bottom: 2px; }
    .trim-now .v { color: var(--accent-cyan); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-weight: 700; font-size: 15px; }
    .trim-now .f { display: block; margin-top: 4px; font-size: 11px; color: var(--text-muted); }
    .trim-sliders { position: relative; height: 36px; margin: 4px 0 2px; }
    .trim-track {
      position: absolute; left: 0; right: 0; top: 14px; height: 8px;
      background: var(--slider-track); border-radius: 4px; overflow: hidden;
    }
    .trim-sel { position: absolute; top: 0; height: 100%; background: rgba(56, 139, 253, 0.55); }
    .trim-playhead {
      position: absolute; top: 8px; width: 2px; height: 20px; background: #f0f6fc;
      left: 0; transform: translateX(-1px); pointer-events: none; z-index: 3;
    }
    .trim-sliders input[type=range] {
      position: absolute; left: 0; width: 100%; top: 4px; height: 28px;
      background: none; pointer-events: none; z-index: 2; margin: 0;
    }
    .trim-sliders input[type=range]::-webkit-slider-thumb { pointer-events: auto; }
    .trim-sliders input[type=range]::-moz-range-thumb { pointer-events: auto; }
    .trim-sliders input[type=range].end-range::-webkit-slider-thumb { background: #22d3ee; }
    .trim-sliders input[type=range].end-range::-moz-range-thumb { background: #22d3ee; }
    .trim-hint { font-size: 12px; color: var(--text-muted); line-height: 1.5; }
    .trim-player audio { width: 100%; }
    .trim-sels { position: absolute; inset: 0; pointer-events: none; }
    .trim-sels .trim-block {
      position: absolute; top: 0; height: 100%;
      background: rgba(34, 211, 238, 0.38);
    }
    .trim-seg-bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
    .seg-list { list-style: none; display: flex; flex-direction: column; gap: 6px; }
    .seg-item {
      display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
      padding: 8px 10px; background: #0d1117; border: 1px solid var(--card-border);
      border-radius: 8px; font-size: 12px;
    }
    .seg-item .seg-time {
      font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
      color: var(--accent-cyan); flex: 1; min-width: 180px;
    }
    .seg-item .seg-actions { display: flex; gap: 6px; }
    .btn-ghost.danger:hover { border-color: #f85149; color: #ffa198; }
    .trim-player img, .preview-card img {
      width: 100%; max-height: 420px; object-fit: contain; background: #000; border-radius: 8px; display: block;
    }
    .check-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px; }
    .check-item {
      display: flex; align-items: center; justify-content: space-between; gap: 10px;
      padding: 12px 14px; background: var(--card-bg); border: 1px solid var(--card-border);
      border-radius: 10px; font-size: 13px; color: var(--text-bright);
    }
    .check-item span.sub { display: block; font-size: 11px; color: var(--text-muted); font-weight: 400; margin-top: 3px; }

    .sub-tabs {
      display: flex; gap: 6px; flex-wrap: wrap;
      background: var(--card-bg); border: 1px solid var(--card-border);
      border-radius: 12px; padding: 6px;
    }
    .sub-tab {
      padding: 8px 12px; border: none; border-radius: 8px;
      background: transparent; color: var(--text-muted); font-size: 13px; font-weight: 600;
      cursor: pointer;
    }
    .sub-tab:hover { color: var(--text-bright); background: #21262d; }
    .sub-tab.active { color: #fff; background: #1f6feb; }
    .tool-grid {
      display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 10px;
    }
    .tool-card {
      text-align: left; padding: 14px; border-radius: 10px; cursor: pointer;
      background: var(--card-bg); border: 1px solid var(--card-border); color: var(--text);
    }
    .tool-card:hover { border-color: var(--accent-blue); }
    .tool-card.active { border-color: var(--accent-cyan); box-shadow: 0 0 0 1px var(--accent-cyan); }
    .tool-card.disabled { opacity: 0.45; cursor: not-allowed; }
    .tool-card h4 { color: var(--text-bright); font-size: 14px; margin-bottom: 4px; }
    .tool-card p { font-size: 12px; color: var(--text-muted); line-height: 1.45; }
    .tool-need { display: block; margin-top: 6px; font-size: 11px; color: #f0883e; }
    .tool-form {
      display: none; flex-direction: column; gap: 12px;
      background: var(--card-bg); border: 1px solid var(--card-border);
      border-radius: 12px; padding: 16px;
    }
    .tool-form.show { display: flex; }
    .form-row { display: flex; flex-direction: column; gap: 6px; }
    .form-row label { font-size: 12px; color: var(--text-muted); }
    .form-row input[type="text"], .form-row input[type="number"], .form-row select, .form-row input[type="color"] {
      height: 36px; padding: 0 10px; border-radius: 8px;
      border: 1px solid var(--card-border); background: #0d1117; color: var(--text-bright);
    }
    .form-row input[type="file"] { color: var(--text-muted); font-size: 12px; }
    .player-wrap { position: relative; }
    .region-layer {
      position: absolute; inset: 0; cursor: crosshair; display: none;
    }
    .region-layer.on { display: block; }
    .region-box {
      position: absolute; border: 2px solid var(--accent-cyan);
      background: rgba(34, 211, 238, 0.18); pointer-events: none;
    }
    .cap-bar { font-size: 12px; color: var(--text-muted); }

    .enhance-mode-bar {
      display: flex; gap: 6px; flex-wrap: wrap;
      background: var(--card-bg); border: 1px solid var(--card-border);
      border-radius: 12px; padding: 6px;
    }
    .enhance-mode-btn {
      flex: 1; min-width: 120px; padding: 10px 14px; border: none; border-radius: 8px;
      background: transparent; color: var(--text-muted); font-size: 14px; font-weight: 600;
      cursor: pointer; transition: 0.15s;
    }
    .enhance-mode-btn:hover { color: var(--text-bright); background: #21262d; }
    .enhance-mode-btn.active { color: #fff; background: var(--accent-blue); }
    #tab-enhance.mode-pro .preset-panel,
    #tab-enhance.mode-pro .grid-panels,
    #tab-enhance.mode-pro > .action-box { display: none; }
    #tab-enhance.mode-pro .pitch-studio { display: flex; }
    .pitch-studio { display: none; flex-direction: column; gap: 12px; }
    .pitch-hint, .pitch-legend {
      font-size: 12px; color: var(--text-muted); line-height: 1.55;
    }
    .pitch-toolbar {
      display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
    }
    .pitch-sel {
      font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
      font-size: 13px; color: var(--accent-cyan); font-weight: 600;
    }
    .pitch-status { font-size: 12px; color: var(--text-muted); }
    .pitch-roll-wrap {
      position: relative;
      height: 440px;
      overflow: auto;
      background: #0d1117;
      border: 1px solid var(--card-border);
      border-radius: 12px;
      cursor: crosshair;
    }
    .pitch-roll-wrap:focus { outline: 1px solid var(--accent-blue); }
    #pitch-canvas { display: block; }