/* ========== Tokens ========== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  /* Neutral grey surround, as in grading suites: a tinted UI skews how you judge the picture */
  --desk: #1c1d1f;
  --panel: #26272a;
  --raised: #303135;
  --line: #3d3e43;
  --ink: #e8e8ea;
  --ink-2: #a3a4aa;
  --ink-3: #909197;

  /* SMPTE 75% bars: the only colour in the UI */
  --bar-grey: #c0c0c0;
  --bar-yellow: #c0c000;
  --bar-cyan: #00c0c0;
  --bar-green: #00c000;
  --bar-magenta: #c000c0;
  --bar-red: #c00000;
  --bar-blue: #0000c0;
  --bars: linear-gradient(90deg,
    var(--bar-grey) 0 14.29%, var(--bar-yellow) 0 28.57%, var(--bar-cyan) 0 42.86%,
    var(--bar-green) 0 57.14%, var(--bar-magenta) 0 71.43%, var(--bar-red) 0 85.71%,
    var(--bar-blue) 0);

  --accent: #1fc8cf;          /* bar cyan, lifted for contrast on grey */
  --accent-soft: rgba(31, 200, 207, 0.12);
  --success: #3ccf4e;
  --error: #ff5a5f;

  --font: 'Barlow', system-ui, sans-serif;
  --font-cond: 'Barlow Semi Condensed', 'Barlow', system-ui, sans-serif;
  --radius: 4px;
}

html { font-size: 16px; }

body {
  font-family: var(--font);
  font-size: 0.9375rem;
  line-height: 1.45;
  background: var(--desk);
  color: var(--ink);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

button { font: inherit; color: inherit; cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 4px; }

.bars-mark {
  display: inline-block;
  width: 1.05em;
  height: 0.8em;
  margin-right: 0.4em;
  background: var(--bars);
  border-radius: 1px;
}

/* ========== Loading ========== */
#loading-screen {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.25rem;
  background: var(--desk);
  transition: opacity 0.4s ease, visibility 0.4s;
}
#loading-screen.hidden { opacity: 0; visibility: hidden; pointer-events: none; }

.loading-logo {
  font-family: var(--font-cond);
  font-weight: 700;
  font-size: 2.25rem;
  letter-spacing: -0.01em;
  display: flex;
  align-items: center;
}
.loading-status { color: var(--ink-2); font-size: 0.875rem; max-width: 40ch; text-align: center; }

/* Bars-reveal fill: the stripe stays fixed to the track width while the fill grows over it */
.loading-bar-track, .progress-track {
  container-type: inline-size;
  background: var(--raised);
  border-radius: 2px;
  overflow: hidden;
}
.loading-bar-track { width: min(320px, 80vw); height: 6px; }
.loading-bar-fill, .progress-fill {
  position: relative;
  height: 100%;
  width: 0;
  overflow: hidden;
  transition: width 0.3s ease;
}
.loading-bar-fill::before, .progress-fill::before {
  content: '';
  position: absolute;
  inset: 0 auto 0 0;
  width: 100cqw;
  background: var(--bars);
}
.loading-bar-fill[style*="background"]::before { display: none; } /* app.js paints it red on failure */

/* ========== App shell ========== */
#app {
  display: none;
  height: 100vh;
  grid-template-rows: auto 1fr;
}
#app.active { display: grid; }

.header {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.7rem 1.25rem;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  min-width: 0;
}
.logo {
  font-family: var(--font-cond);
  font-weight: 700;
  font-size: 1.25rem;
  display: flex;
  align-items: center;
  padding-right: 1rem;
  border-right: 1px solid var(--line);
}
.file-name {
  color: var(--ink-2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}
.new-file-btn {
  display: none;
  margin-left: auto;
  padding: 0.35rem 0.8rem;
  background: none;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-size: 0.875rem;
  white-space: nowrap;
}
.new-file-btn.visible { display: block; }
.new-file-btn:hover { border-color: var(--ink-3); }

.main-content {
  display: grid;
  grid-template-columns: 1fr 380px;
  min-height: 0;
}

/* ========== Viewer ========== */
.preview-panel {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  min-width: 0;
  min-height: 0;
}

.upload-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 0.5rem;
  width: min(560px, 100%);
  padding: 4rem 2rem;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.upload-zone:hover, .upload-zone.drag-over { border-color: var(--accent); background: var(--accent-soft); }
.upload-zone.has-video { display: none; }
.upload-icon svg { width: 32px; height: 32px; stroke: var(--ink-2); margin-bottom: 0.5rem; }
.upload-text-primary { font-family: var(--font-cond); font-weight: 600; font-size: 1.25rem; }
.upload-text-secondary { color: var(--ink-2); font-size: 0.875rem; max-width: 46ch; }
#file-input { display: none; }

.video-container {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 0.9rem;
  width: 100%;
  height: 100%;
  min-height: 0;
}
.video-container.active { display: flex; }

.video-switch-row {
  display: flex;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 2px;
}
.switch-btn {
  padding: 0.3rem 1rem;
  background: none;
  border: 0;
  border-radius: 2px;
  color: var(--ink-2);
  font-size: 0.875rem;
}
.switch-btn.active { background: var(--raised); color: var(--ink); }

.video-wrapper {
  flex: 1;
  min-height: 0;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}
.video-wrapper video {
  display: block;
  max-width: 100%;
  max-height: 100%;
  background: #000;
}

.video-meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.25rem 1.5rem;
  color: var(--ink-2);
  font-size: 0.875rem;
  font-variant-numeric: tabular-nums;
}

/* ========== Inspector ========== */
.tools-sidebar {
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  background: var(--panel);
  border-left: 1px solid var(--line);
  min-height: 0;
}

.tools-header { padding: 1.1rem 1.25rem 0.6rem; }
.tools-title { font-family: var(--font-cond); font-weight: 600; font-size: 1.125rem; }
.tools-hint { color: var(--ink-2); font-size: 0.8125rem; }

.tools-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.375rem;
  padding: 0 1.25rem 1rem;
  border-bottom: 1px solid var(--line);
}
.tool-nav-btn {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 0.7rem 0.35rem 0.55rem;
  background: var(--raised);
  border: 1px solid transparent;
  border-radius: 999px;
  font-size: 0.875rem;
  color: var(--ink-2);
  transition: color 0.12s, border-color 0.12s, background 0.12s;
}
.tool-nav-btn:hover { color: var(--ink); }
.tool-nav-btn.active { color: var(--ink); background: var(--accent-soft); border-color: var(--accent); }
.tool-nav-icon { display: flex; }
.tool-nav-icon svg { width: 15px; height: 15px; stroke: currentColor; stroke-width: 1.8; fill: none; }
.tool-nav-btn.active .tool-nav-icon svg { stroke: var(--accent); }

.tools-body { overflow-y: auto; padding: 0 1.25rem; min-height: 0; }
.empty-state { color: var(--ink-3); padding: 1.5rem 0; }

.tool-panel { display: none; padding: 1.1rem 0 1.25rem; }
.tool-panel.active { display: block; }
.tool-panel.active ~ .tool-panel.active { border-top: 1px solid var(--line); }
.tool-panel-title { font-family: var(--font-cond); font-weight: 600; font-size: 1.0625rem; }
.tool-panel-desc { color: var(--ink-2); font-size: 0.875rem; margin-bottom: 0.8rem; max-width: 52ch; }
.tool-panel-title + .radio-group { margin-top: 0.6rem; }
#resize-custom-fields { display: none; margin-top: 0.75rem; }
#panel-resize:has(input[value="custom"]:checked) #resize-custom-fields { display: block; }

/* Fields */
.field-row { display: flex; gap: 0.75rem; margin-bottom: 0.75rem; }
.field { flex: 1; min-width: 0; }
.field-label { display: block; font-size: 0.8125rem; color: var(--ink-2); margin-bottom: 0.25rem; }
.field-input {
  width: 100%;
  padding: 0.45rem 0.6rem;
  background: var(--desk);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--ink);
  font: inherit;
  font-variant-numeric: tabular-nums;
}
.field-input:focus { border-color: var(--accent); outline: none; }
.field-input::placeholder { color: var(--ink-3); }
.field-hint { color: var(--ink-3); font-size: 0.8125rem; margin-top: 0.35rem; max-width: 52ch; }

/* Option tiles. Inputs stay focusable; the tile shows their state */
.radio-group { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.375rem; }
.radio-option {
  position: relative;
  display: flex;
  flex-direction: column;
  padding: 0.45rem 0.65rem;
  background: var(--raised);
  border: 1px solid transparent;
  border-radius: var(--radius);
  cursor: pointer;
}
.radio-option:hover { border-color: var(--line); }
.radio-option:has(:checked) { border-color: var(--accent); background: var(--accent-soft); }
.radio-option:has(:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
.radio-option input, .checkbox-option input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  pointer-events: none;
}
.radio-option-text { font-weight: 500; font-size: 0.9375rem; }
.radio-option-hint { color: var(--ink-2); font-size: 0.8125rem; }

.checkbox-option {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  cursor: pointer;
}
.checkbox-box {
  width: 16px;
  height: 16px;
  border: 1.5px solid var(--ink-3);
  border-radius: 3px;
  display: grid;
  place-items: center;
}
.checkbox-option:has(:checked) .checkbox-box { background: var(--accent); border-color: var(--accent); }
.checkbox-option:has(:checked) .checkbox-box::after {
  content: '';
  width: 4px;
  height: 8px;
  border: solid var(--desk);
  border-width: 0 2px 2px 0;
  transform: translateY(-1px) rotate(45deg);
}
.checkbox-option:has(:focus-visible) .checkbox-box { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Speed */
.speed-row { display: flex; align-items: center; gap: 1rem; margin-bottom: 0.9rem; }
.range-value {
  font-family: var(--font-cond);
  font-weight: 600;
  font-size: 1.375rem;
  min-width: 3.2ch;
  text-align: right;
  font-variant-numeric: tabular-nums;
}
input[type="range"] { flex: 1; accent-color: var(--accent); }

/* ========== Actions ========== */
.action-area {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 1rem 1.25rem 1.1rem;
  border-top: 1px solid var(--line);
}
.action-buttons { display: flex; gap: 0.5rem; }

.btn-process, .btn-download {
  flex: 1;
  padding: 0.7rem 1rem;
  border-radius: var(--radius);
  font-family: var(--font-cond);
  font-weight: 600;
  font-size: 1.0625rem;
  border: 1px solid transparent;
}
.btn-process { background: var(--ink); color: var(--desk); }
.btn-process:hover:not(:disabled) { background: #fff; }
.btn-process:disabled { background: var(--raised); color: var(--ink-3); cursor: not-allowed; }
.btn-process.processing { cursor: progress; }
.btn-download { display: none; border-color: var(--ink-2); color: var(--ink); text-align: center; text-decoration: none; }
.btn-download.visible { display: block; }
.btn-download:hover { border-color: var(--ink); }

.progress-area { display: none; }
.progress-area.active { display: block; }
.progress-track { height: 8px; }
.progress-text { color: var(--ink-2); font-size: 0.8125rem; margin-top: 0.35rem; font-variant-numeric: tabular-nums; }

.result-info {
  display: none;
  padding: 0.6rem 0.8rem;
  border-left: 3px solid var(--success);
  background: var(--raised);
  border-radius: 0 var(--radius) var(--radius) 0;
}
.result-info.visible { display: block; }
.result-info.error { border-left-color: var(--error); }
.result-info.error .result-info-text { color: var(--error); }
.result-info-text { font-weight: 600; }
.result-info-detail { color: var(--ink-2); font-size: 0.8125rem; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }

.log-toggle { display: none; }
.log-toggle.visible { display: block; }
.log-toggle-btn {
  background: none;
  border: 0;
  color: var(--ink-2);
  font-size: 0.8125rem;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.log-toggle-btn:hover { color: var(--ink); }

.log-console {
  display: none;
  max-height: 180px;
  overflow-y: auto;
  padding: 0.6rem 0.7rem;
  background: var(--desk);
  border-radius: var(--radius);
  font-family: ui-monospace, 'Cascadia Mono', Consolas, monospace; /* literal ffmpeg output */
  font-size: 0.75rem;
  color: var(--ink-2);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.log-console.open { display: block; }

/* ========== Small screens ========== */
@media (max-width: 860px) {
  #app { height: auto; min-height: 100vh; }
  .main-content { grid-template-columns: 1fr; }
  .preview-panel { padding: 1rem; }
  .video-wrapper video { max-height: 55vh; }
  .tools-sidebar { border-left: 0; border-top: 1px solid var(--line); }
  .header { padding: 0.6rem 1rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; }
}
