@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;500;600&family=IBM+Plex+Sans:wght@300;400;500;600&display=swap');

  /* ── LIGHT theme (default) ── */
  :root {
    --bg:        #f4f6f9;
    --surface:   #ffffff;
    --surface2:  #eef1f5;
    --border:    #d8dde6;
    --border2:   #c4ccd8;
    --accent:    #0072e5;
    --accent2:   #005bbf;
    --green:     #1a9e4a;
    --red:       #d93025;
    --yellow:    #c47b00;
    --text:      #1a202c;
    --muted:     #64748b;
    --mono:      'IBM Plex Mono', monospace;
    --sans:      'IBM Plex Sans', sans-serif;
    --radius:    6px;
    --transition: 180ms ease;
    --shadow:    0 1px 3px rgba(0,0,0,.08);
  }

  /* ── DARK theme ── */
  html.dark {
    --bg:        #0a0c10;
    --surface:   #111318;
    --surface2:  #181c24;
    --border:    #222730;
    --border2:   #2e3540;
    --accent:    #00d4ff;
    --accent2:   #0099bb;
    --green:     #00e676;
    --red:       #ff4444;
    --yellow:    #ffd600;
    --text:      #e2e8f0;
    --muted:     #64748b;
    --shadow:    0 1px 3px rgba(0,0,0,.4);
  }

  * { box-sizing: border-box; margin: 0; padding: 0; }

  body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--sans);
    font-size: 12px;
    line-height: 1.6;
    min-height: 100vh;
    transition: background var(--transition), color var(--transition);
  }

  /* ── Header ── */
  .app-header {
    border-bottom: 1px solid var(--border);
    padding: 7px 16px;
    display: flex;
    align-items: center;
    gap: 14px;
    background: var(--surface);
    box-shadow: var(--shadow);
    position: relative;
    z-index: 10;
  }

  .app-header .logo {
    font-family: var(--mono);
    font-size: 13px;
    font-weight: 600;
    color: var(--accent);
    letter-spacing: .08em;
    text-transform: uppercase;
  }

  .app-header .sep { color: var(--border2); }

  .app-header .title {
    font-size: 13px;
    color: var(--muted);
    font-family: var(--mono);
  }

  .header-controls {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 8px;
  }

  /* ── Toggle button (theme / lang) ── */
  .toggle-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 5px 10px;
    border-radius: 100px;
    font-family: var(--mono);
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid var(--border2);
    background: var(--surface2);
    color: var(--muted);
    transition: all var(--transition);
    white-space: nowrap;
  }
  .toggle-btn:hover { border-color: var(--accent); color: var(--accent); }

  /* Lang selector */
  .lang-select {
    font-family: var(--mono);
    font-size: 11px;
    font-weight: 600;
    padding: 5px 8px;
    border-radius: 100px;
    border: 1px solid var(--border2);
    background: var(--surface2);
    color: var(--muted);
    cursor: pointer;
    outline: none;
    transition: all var(--transition);
    appearance: none;
    -webkit-appearance: none;
    text-align: center;
  }
  .lang-select:hover, .lang-select:focus { border-color: var(--accent); color: var(--accent); }

  /* ── Layout ── */
  .app-body {
    display: grid;
    grid-template-columns: 380px 1fr;
    height: calc(100vh - 49px);
  }

  /* ── Sidebar ── */
  .sidebar {
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    background: var(--surface);
    overflow: hidden;  /* no global scroll — managed per section */
  }

  /* Step 1 — fixed height */
  .sidebar-section {
    border-bottom: 1px solid var(--border);
    padding: 12px 14px 14px;
    flex-shrink: 0;
  }

  /* Step 2 — grows and scrolls */
  .sidebar-section.vtt-section {
    flex: 1;
    overflow-y: auto;
    min-height: 80px;
  }

  .section-label {
    font-family: var(--mono);
    font-size: 9px;
    font-weight: 600;
    letter-spacing: .12em;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 8px;
  }

  .step-badge {
    background: var(--surface2);
    color: var(--accent);
    border: 1px solid var(--border2);
    border-radius: 50%;
    width: 15px; height: 15px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 9px;
    font-weight: 700;
    transition: all var(--transition);
  }

  .step-badge.done {
    background: var(--green);
    color: #fff;
    border-color: var(--green);
  }
  html:not(.dark) .step-badge.done { color: #fff; }

  /* ── Form ── */
  label {
    display: block;
    font-size: 12px;
    color: var(--muted);
    margin-bottom: 5px;
  }

  input[type="text"],
  input[type="number"] {
    width: 100%;
    background: var(--surface2);
    border: 1px solid var(--border2);
    color: var(--text);
    font-family: var(--mono);
    font-size: 12px;
    padding: 5px 8px;
    border-radius: var(--radius);
    outline: none;
    transition: border-color var(--transition), background var(--transition);
  }
  input[type="text"]:focus,
  input[type="number"]:focus { border-color: var(--accent); }
  input[type="text"]::placeholder,
  input[type="number"]::placeholder { color: var(--border2); }

  /* ── Buttons ── */
  .btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 10px;
    border-radius: var(--radius);
    font-family: var(--mono);
    font-size: 11px;
    font-weight: 500;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all var(--transition);
    white-space: nowrap;
  }

  .btn-ghost {
    background: transparent;
    color: var(--text);
    border-color: var(--border2);
  }
  .btn-ghost:hover { border-color: var(--accent); color: var(--accent); background: transparent; }

  .btn-success {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
    font-size: 13px;
    padding: 7px 16px;
  }
  .btn-success:hover { filter: brightness(1.1); }

  .btn:disabled { opacity: .35; cursor: not-allowed; pointer-events: none; }

  /* ── Drop zone ── */
  .drop-zone {
    border: 1px dashed var(--border2);
    border-radius: var(--radius);
    padding: 13px 10px;
    text-align: center;
    cursor: pointer;
    transition: all var(--transition);
    position: relative;
    background: var(--bg);
  }
  .drop-zone:hover, .drop-zone.drag-over {
    border-color: var(--accent);
    background: color-mix(in srgb, var(--accent) 5%, transparent);
  }
  .drop-zone input[type="file"] { display: none; }
  .drop-zone .dz-icon { font-size: 16px; margin-bottom: 4px; display: block; opacity: .5; }
  .drop-zone .dz-text { font-size: 10px; color: var(--muted); font-family: var(--mono); }

  /* ── VTT list ── */
  .vtt-list { margin-top: 7px; display: flex; flex-direction: column; gap: 5px; }

  .vtt-item {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 6px 8px;
    display: grid;
    grid-template-columns: auto 1fr auto;
    gap: 6px;
    align-items: start;
  }
  .vtt-item-name {
    font-family: var(--mono);
    font-size: 10px;
    color: var(--accent);
    margin-bottom: 3px;
    word-break: break-all;
  }
  .vtt-item-fields { display: flex; gap: 6px; }
  .vtt-item-fields input { flex: 1; font-size: 11px; padding: 4px 7px; }

  .vtt-remove {
    background: none; border: none; cursor: pointer;
    color: var(--muted); font-size: 16px; line-height: 1;
    padding: 3px; transition: color var(--transition);
  }
  .vtt-remove:hover { color: var(--red); }

  /* ── Delta-T ── */
  .delta-group { display: flex; align-items: center; gap: 8px; }
  .delta-group input { width: 110px; text-align: right; }
  .delta-unit { font-family: var(--mono); font-size: 11px; color: var(--muted); }
  .delta-hint { font-family: var(--mono); font-size: 10px; color: var(--muted); margin-top: 3px; }
  .delta-hint span { color: var(--yellow); }

  /* ── Chips ── */
  .chip {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 2px 8px; border-radius: 100px;
    font-family: var(--mono); font-size: 10px;
    font-weight: 600; text-transform: uppercase; letter-spacing: .06em;
  }
  .chip-ok   { background: color-mix(in srgb,var(--green) 12%,transparent); color: var(--green); border: 1px solid color-mix(in srgb,var(--green) 30%,transparent); }
  .chip-warn { background: color-mix(in srgb,var(--yellow) 12%,transparent); color: var(--yellow); border: 1px solid color-mix(in srgb,var(--yellow) 30%,transparent); }

  /* ── Main panel ── */
  .main-panel { display: flex; flex-direction: column; overflow: hidden; background: var(--bg); }

  .panel-toolbar {
    border-bottom: 1px solid var(--border);
    padding: 7px 14px;
    display: flex; align-items: center; gap: 10px;
    flex-shrink: 0;
    background: var(--surface);
  }
  .panel-toolbar .tool-label {
    font-family: var(--mono); font-size: 10px;
    color: var(--muted); text-transform: uppercase; letter-spacing: .1em;
  }

  /* ── Player ── */
  .player-area { flex: 1; display: flex; flex-direction: column; overflow: hidden; }

  .player-wrapper {
    position: relative; width: 100%;
    padding-bottom: min(56.25%, 58vh);
    background: #000; flex-shrink: 0;
  }
  .player-wrapper > div, .player-wrapper > iframe {
    position: absolute !important; inset: 0 !important;
    width: 100% !important; height: 100% !important;
    padding-bottom: 0 !important;
  }
  .player-empty {
    position: absolute; inset: 0;
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    gap: 10px; color: #555;
    font-family: var(--mono); font-size: 13px;
  }
  .player-empty .icon { font-size: 34px; opacity: .25; }

  /* ── Log ── */
  .log-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border-top: 1px solid var(--border);
    overflow: hidden;
  }
  .log-header {
    padding: 7px 14px 5px;
    flex-shrink: 0;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
  }
  .log-title {
    font-family: var(--mono); font-size: 10px; font-weight: 600;
    letter-spacing: .12em; text-transform: uppercase;
    color: var(--muted);
  }
  .log-body {
    flex: 1;
    overflow-y: auto;
    padding: 7px 14px 9px;
  }
  .log-entry {
    font-family: var(--mono); font-size: 11px;
    padding: 3px 0; border-bottom: 1px solid var(--border);
    display: flex; gap: 10px; align-items: baseline;
  }
  .log-entry:last-child { border-bottom: none; }
  .log-time { color: var(--muted); flex-shrink: 0; }
  .log-ok   { color: var(--green); }
  .log-err  { color: var(--red); }
  .log-info { color: var(--accent); }
  .log-warn { color: var(--yellow); }


  /* ── Result box ── */
  .result-box {
    margin-top: 12px;
    background: var(--surface2);
    border: 1px solid var(--border2);
    border-radius: var(--radius);
    padding: 9px;
  }
  .result-box h3 {
    font-family: var(--mono); font-size: 11px; color: var(--accent);
    text-transform: uppercase; letter-spacing: .08em; margin-bottom: 7px;
  }
  .result-url {
    font-family: var(--mono); font-size: 11px; word-break: break-all;
    color: var(--text); background: var(--bg);
    padding: 5px 7px; border-radius: 4px; margin-bottom: 5px;
  }
  .result-url a { color: var(--accent); text-decoration: none; }
  .result-url a:hover { text-decoration: underline; }

  /* ── m3u8 preview ── */
  .m3u8-preview {
    font-family: var(--mono); font-size: 11px;
    background: var(--bg); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 9px;
    max-height: 100px; overflow-y: auto;
    color: var(--accent); white-space: pre; margin-top: 7px;
    opacity: .85;
  }

  /* ── Process section ── */
  .process-section {
    padding: 12px 14px; border-top: 1px solid var(--border); flex-shrink: 0;
  }
  .process-section .section-label { margin-bottom: 8px; }

  .summary-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; margin-bottom: 8px; }
  .summary-item {
    background: var(--surface2); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 5px 7px;
  }
  .summary-item .s-label {
    font-size: 10px; color: var(--muted);
    font-family: var(--mono); text-transform: uppercase; letter-spacing: .07em;
  }
  .summary-item .s-value { font-size: 11px; font-family: var(--mono); color: var(--text); margin-top: 1px; }
  .summary-item .s-value.ok   { color: var(--green); }
  .summary-item .s-value.warn { color: var(--yellow); }

  /* ── Scrollbar ── */
  ::-webkit-scrollbar { width: 5px; height: 5px; }
  ::-webkit-scrollbar-track { background: transparent; }
  ::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 3px; }

  /* ── Spinner ── */
  @keyframes spin { to { transform: rotate(360deg); } }
  .spinner {
    display: inline-block; width: 13px; height: 13px;
    border: 2px solid color-mix(in srgb, currentColor 20%, transparent);
    border-top-color: currentColor; border-radius: 50%;
    animation: spin .7s linear infinite;
  }

  /* ── Utils ── */
  .mt8  { margin-top: 5px; }
  .mt12 { margin-top: 8px; }
  .flex-row { display: flex; gap: 8px; align-items: center; }

  /* ── VTT lang select ── */
  .vtt-lang-select {
    background: var(--surface2);
    border: 1px solid var(--border2);
    color: var(--text);
    font-family: var(--mono);
    font-size: 10px;
    padding: 3px 5px;
    border-radius: var(--radius);
    outline: none;
    cursor: pointer;
    max-width: 160px;
    transition: border-color var(--transition);
  }
  .vtt-lang-select:focus { border-color: var(--accent); }

  /* ── VTT drag handle & reorder ── */
  .vtt-item { cursor: default; }
  .drag-handle {
    color: var(--muted);
    font-size: 12px;
    cursor: grab;
    padding: 2px 6px 2px 2px;
    flex-shrink: 0;
    opacity: .5;
    transition: opacity var(--transition);
    user-select: none;
  }
  .drag-handle:hover { opacity: 1; }
  .vtt-item.dragging { opacity: .4; }
  .vtt-item.drag-over-item { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 6%, transparent); }

  /* ── Reload Player button (accented) ── */
  .btn-reload {
    background: color-mix(in srgb, var(--accent) 12%, transparent);
    color: var(--accent);
    border-color: color-mix(in srgb, var(--accent) 35%, transparent);
    font-weight: 600;
  }
  .btn-reload:hover {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
  }
