/* ============================================================
   vid2apng — terminal theme
   Dark "hacker" aesthetic: phosphor-green accent, hairline
   borders, faint grid, monospace-forward type, subtle glow.
   ============================================================ */

/* --- Fonts (self-hosted, no CDN) --------------------------- */
@font-face {
  font-family: "JetBrains Mono";
  src: url("/static/fonts/JetBrainsMono-Regular.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "JetBrains Mono";
  src: url("/static/fonts/JetBrainsMono-Medium.woff2") format("woff2");
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "JetBrains Mono";
  src: url("/static/fonts/JetBrainsMono-Bold.woff2") format("woff2");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

/* --- Design tokens ------------------------------------------ */
:root {
  --bg: #0a0e12;            /* deep base                    */
  --surface: #10151b;       /* panels                       */
  --raised: #161d25;        /* raised elements              */
  --inset: #05070a;         /* sunken wells (log, inputs)   */
  --line: #243040;          /* hairline border              */
  --line-soft: #1a2230;    /* subtle separator             */
  --text: #d3e0e8;
  --muted: #6b7d8c;
  --accent: #00e584;       /* phosphor green               */
  --accent-soft: rgba(0, 229, 132, 0.12);
  --accent-glow: rgba(0, 229, 132, 0.35);
  --ok: #2ee66b;
  --warn: #f5c542;
  --err: #ff5c57;
  --font-mono: "JetBrains Mono", ui-monospace, "Cascadia Code", "Fira Code",
               Menlo, Consolas, "DejaVu Sans Mono", monospace;
  --radius: 3px;
}

* { box-sizing: border-box; }

/* --- Base --------------------------------------------------- */
body {
  font-family: var(--font-mono);
  background:
    linear-gradient(rgba(0, 229, 132, 0.022) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0, 229, 132, 0.022) 1px, transparent 1px),
    var(--bg);
  background-size: 24px 24px, 24px 24px;
  color: var(--text);
  margin: 0;
  padding: 0;
  height: 100vh;
  overflow: hidden;
}

::selection {
  background: var(--accent);
  color: #04120b;
}

:focus-visible {
  outline: 1px solid var(--accent);
  outline-offset: 2px;
}

/* Thin terminal scrollbars */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #334155; }

/* --- App shell: topbar / workarea / console strip ------------ */
.app-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100vw;
}

/* Top bar */
.topbar {
  flex: none;
  display: flex;
  align-items: baseline;
  gap: 14px;
  padding: 14px 22px 12px;
  border-bottom: 1px solid var(--line-soft);
  background: rgba(16, 21, 27, 0.55);
  backdrop-filter: blur(4px);
}
.topbar h1 {
  margin: 0;
  font-size: 1.15em;
  font-weight: 500;
  color: var(--text);
  text-transform: uppercase;
  letter-spacing: 0.18em;
  white-space: nowrap;
}
.topbar h1::before {
  content: "> ";
  color: var(--accent);
  text-shadow: 0 0 8px var(--accent-glow);
}
.topbar-tag {
  color: var(--muted);
  font-size: 0.72em;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.workarea {
  flex: 1;
  display: flex;
  min-height: 0;
}

/* LEFT SIDEBAR */
.sidebar {
  width: 380px;
  min-width: 380px;
  background: var(--surface);
  display: flex;
  flex-direction: column;
  padding: 16px;
  border-right: 1px solid var(--line);
  overflow-y: auto;
  gap: 14px;
}

/* Panels (sidebar cards) */
.panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  background: rgba(22, 29, 37, 0.45);
}
.panel-title {
  margin: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.78em;
  font-weight: 500;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.16em;
}
.panel-title .step-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  flex: none;
  border: 1px solid var(--accent);
  border-radius: 2px;
  color: var(--accent);
  font-size: 0.95em;
  text-shadow: 0 0 8px var(--accent-glow);
}
.file-hint {
  margin: 0;
  font-size: 0.72em;
  color: var(--muted);
  line-height: 1.5;
}
.unit {
  font-size: 0.85em;
  color: var(--muted);
}

/* --- Buttons ------------------------------------------------ */
.btn-action {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
  padding: 11px 20px;
  font-size: 1em;
  font-weight: 500;
  font-family: inherit;
  letter-spacing: 0.06em;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.15s ease, box-shadow 0.15s ease, color 0.15s ease;
  width: 100%;
  text-align: center;
}
.btn-action:hover {
  background: var(--accent-soft);
  box-shadow: 0 0 18px var(--accent-glow), inset 0 0 12px var(--accent-soft);
}
.btn-action:active { transform: translateY(1px); }
.btn-action:disabled {
  background: transparent;
  border-color: var(--line);
  color: var(--muted);
  cursor: not-allowed;
  box-shadow: none;
}

/* --- Controls ----------------------------------------------- */
.controls-section { display: flex; flex-direction: column; gap: 15px; }
.control-group { display: flex; flex-direction: column; gap: 8px; }

label { color: var(--text); }
.label-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* live value readouts (slider numbers glow) */
#colVal, #fpsVal {
  color: var(--accent);
  font-weight: 500;
  text-shadow: 0 0 8px var(--accent-glow);
  font-variant-numeric: tabular-nums;
}

#lblColours, #paramColours { transition: opacity 0.2s; }

/* range sliders */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 18px;
  background: transparent;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 3px;
  background: var(--line);
  border-radius: 2px;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px;
  height: 12px;
  margin-top: -4.5px;
  background: var(--accent);
  border-radius: 2px;
  box-shadow: 0 0 10px var(--accent-glow);
  transition: box-shadow 0.15s ease, transform 0.15s ease;
}
input[type="range"]:hover::-webkit-slider-thumb { transform: scale(1.15); }
input[type="range"]:disabled { cursor: not-allowed; }
input[type="range"]:disabled::-webkit-slider-thumb {
  background: var(--muted);
  box-shadow: none;
  transform: none;
}
input[type="range"]::-moz-range-track {
  height: 3px;
  background: var(--line);
  border-radius: 2px;
}
input[type="range"]::-moz-range-thumb {
  width: 12px;
  height: 12px;
  border: none;
  background: var(--accent);
  border-radius: 2px;
  box-shadow: 0 0 10px var(--accent-glow);
}
input[type="range"]:disabled::-moz-range-thumb { background: var(--muted); box-shadow: none; }

/* lossless toggle (styled checkbox) */
.lossless-toggle {
  font-size: 0.85em;
  display: flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  color: var(--muted);
}
#paramLossless {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  flex: none;
  border: 1px solid var(--line);
  background: var(--inset);
  border-radius: var(--radius);
  cursor: pointer;
  position: relative;
  transition: background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}
#paramLossless:hover { border-color: var(--accent); }
#paramLossless:checked {
  background: var(--accent);
  border-color: var(--accent);
  box-shadow: 0 0 10px var(--accent-glow);
}
#paramLossless:checked::after {
  content: "✓";
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #04120b;
  font-size: 11px;
  font-weight: 700;
}

/* frame range inputs */
.frame-row { display: flex; gap: 10px; }
input[type="number"] {
  padding: 8px 10px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--inset);
  color: var(--text);
  outline: none;
  font-family: inherit;
  font-size: 0.9em;
  flex: 1;
  min-width: 0;
  width: 100%;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
input[type="number"]:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent-soft), 0 0 12px var(--accent-soft);
}
input[type="number"]::placeholder { color: var(--muted); opacity: 0.7; }

/* --- Bottom console strip ------------------------------------ */
.console-strip {
  flex: none;
  border-top: 1px solid var(--line);
  background: var(--surface);
}
/* NOTE: this must stay a plain block. Chromium wraps a <details>'
   non-summary children in an anonymous block, so display:flex on the
   <details> itself never makes the log a real flex item — the log was
   sized to its full content height and blew out of the fixed 200px
   container (which is also why it never showed a scrollbar). The log
   therefore gets a definite px height below: container minus header. */
details.console-container {
  --console-h: 200px;
  --console-header-h: 34px;
  height: var(--console-h);
  overflow: hidden;
}
details.console-container summary {
  height: var(--console-header-h); /* border-box (global), incl. padding */
  font-size: 0.8em;
  color: var(--muted);
  font-weight: 500;
  cursor: pointer;
  user-select: none;
  padding: 8px 22px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
  flex: none;
  transition: color 0.15s ease;
}
details.console-container summary::-webkit-details-marker { display: none; }
details.console-container summary::before {
  content: "▸";
  color: var(--accent);
  display: inline-block;
  transition: transform 0.15s ease;
}
details.console-container[open] summary::before { transform: rotate(90deg); }
details.console-container summary:hover { color: var(--text); }

.console-output {
  /* Definite height: container minus the summary header. (A percentage
     can't be used — it would resolve against the anonymous block that
     wraps the children of <details>, which has auto height. */
  height: calc(var(--console-h) - var(--console-header-h));
  background: var(--inset);
  color: var(--accent);
  padding: 10px 22px 14px;
  font-family: inherit;
  font-size: 0.78em;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-y: auto;
  text-shadow: 0 0 6px rgba(0, 229, 132, 0.25);
}

/* Console scrollbar: a touch more visible than the app-wide hairline */
.console-output {
  scrollbar-color: #334155 transparent;
}
.console-output::-webkit-scrollbar { width: 10px; }
.console-output::-webkit-scrollbar-thumb {
  background: #334155;
  border-radius: 4px;
}
.console-output::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 229, 132, 0.35);
}

/* --- Center stage ------------------------------------------- */
.stage {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 18px 22px;
  background: transparent; /* body grid shows through */
}

.stage-grid {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 22px;
  align-items: stretch;
}

.media-panel {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  gap: 10px;
}

.media-panel h3 {
  margin: 0;
  font-size: 0.8em;
  font-weight: 500;
  color: var(--muted);
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 0.15em;
}
.media-panel h3::before { content: "[ "; color: var(--accent); opacity: 0.7; }
.media-panel h3::after { content: " ]"; color: var(--accent); opacity: 0.7; }
.output-title {
  display: flex;
  justify-content: center;
  gap: 10px;
  align-items: center;
}

/* Media wells */
.media-preview {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background:
    repeating-conic-gradient(#0d1218 0% 25%, #10151b 0% 50%) 0 0 / 16px 16px;
  overflow: auto; /* allows scrolling for 1:1 images */
}
.media-preview i {
  color: var(--muted);
  font-style: normal;
  font-size: 0.85em;
  letter-spacing: 0.08em;
}

/* input video preview: contain, never upscale */
video {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background:
    repeating-conic-gradient(#141a21 0% 25%, #0d1218 0% 50%) 0 0 / 16px 16px;
}

/* output APNG "Fit to Screen": fill the preview box (upscales if needed), letterboxed */
.img-scale-fit {
  width: 100%;
  height: 100%;
  object-fit: contain;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background:
    repeating-conic-gradient(#141a21 0% 25%, #0d1218 0% 50%) 0 0 / 16px 16px;
}

.img-original {
  max-width: none;
  max-height: none;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background:
    repeating-conic-gradient(#141a21 0% 25%, #0d1218 0% 50%) 0 0 / 16px 16px;
}

/* --- Top-bar status chip + elapsed -------------------------- */
.topbar-status {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 12px;
}
.chip {
  font-size: 0.72em;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  padding: 4px 10px;
  border: 1px solid var(--line);
  color: var(--muted);
  border-radius: 2px;
  white-space: nowrap;
}
.chip.ready { color: var(--accent); border-color: var(--accent); }
.chip.rendering {
  color: var(--accent);
  border-color: var(--accent);
  animation: chip-pulse 1.2s ease-in-out infinite;
}
.chip.done { color: var(--ok); border-color: var(--ok); }
.chip.failed, .chip.error { color: var(--err); border-color: var(--err); }
.chip.stopped { color: var(--warn); border-color: var(--warn); }
@keyframes chip-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.55; }
}
.elapsed {
  color: var(--muted);
  font-size: 0.8em;
  font-variant-numeric: tabular-nums;
}

/* Stop button (visible only during render) */
.btn-stop {
  margin-top: 12px;
  background: transparent;
  color: var(--err);
  border: 1px solid var(--err);
  padding: 8px 18px;
  font-family: inherit;
  font-size: 0.85em;
  letter-spacing: 0.08em;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.15s ease, box-shadow 0.15s ease;
}
.btn-stop:hover {
  background: rgba(255, 92, 87, 0.12);
  box-shadow: 0 0 16px rgba(255, 92, 87, 0.3);
}

/* Drag & drop targets */
body.dragging .upload-panel,
body.dragging #leftPreview {
  border-color: var(--accent);
  box-shadow: inset 0 0 24px var(--accent-soft);
}

/* Contextual metadata */
.meta-stats {
  margin-top: 12px;
  font-family: inherit;
  font-size: 0.8em;
  color: var(--muted);
  background: rgba(16, 21, 27, 0.8);
  border: 1px solid var(--line-soft);
  padding: 8px 12px;
  border-radius: var(--radius);
  display: none;
  text-align: center;
  line-height: 1.5;
}
.meta-stats b { color: var(--text); font-weight: 600; }

/* Centered action column */
.render-column {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 0 10px;
}

.btn-render-central {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
  padding: 15px 25px;
  font-size: 1.05em;
  font-weight: 500;
  font-family: inherit;
  letter-spacing: 0.08em;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.15s ease, box-shadow 0.15s ease,
              color 0.15s ease, transform 0.15s ease;
  box-shadow: 0 0 18px rgba(0, 229, 132, 0.12);
  white-space: nowrap;
}
.btn-render-central:hover:not(:disabled) {
  background: var(--accent);
  color: #04120b;
  transform: translateY(-1px);
  box-shadow: 0 0 28px var(--accent-glow), 0 0 56px rgba(0, 229, 132, 0.2);
}
.btn-render-central:disabled {
  background: transparent;
  border-color: var(--line);
  color: var(--muted);
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

/* Output scale toggle: segmented control, active mode highlighted */
#scaleBtn {
  display: none;
  gap: 4px;
}
#scaleBtn .scale-opt {
  font-size: 0.7em;
  padding: 3px 10px;
  cursor: pointer;
  border-radius: var(--radius);
  background: var(--raised);
  border: 1px solid var(--line);
  color: var(--muted);
  font-family: inherit;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  transition: border-color 0.15s ease, color 0.15s ease;
}
#scaleBtn .scale-opt:hover {
  border-color: var(--accent);
  color: var(--accent);
}
#scaleBtn .scale-opt.active {
  border-color: var(--accent);
  color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent-soft), 0 0 8px var(--accent-soft);
}

#fileInput { display: none; }

/* Reduced motion: kill blink/glow transitions */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
  }
}

/* --- P4: a11y, motion, responsive ------------------------------ */
:focus-visible {
  outline: 1px solid var(--accent);
  outline-offset: 2px;
  box-shadow: 0 0 0 1px var(--accent-soft), 0 0 12px var(--accent-soft);
}
::selection {
  background: rgba(0, 229, 132, 0.25);
  color: var(--text);
}

/* media fade-in */
#leftPreview video, #outImage {
  animation: media-fade 0.25s ease-out;
}
@keyframes media-fade {
  from { opacity: 0; }
  to { opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .chip.rendering,
  #leftPreview video,
  #outImage {
    animation: none;
  }
  * {
    transition-duration: 0.01ms !important;
  }
}

@media (max-width: 1100px) {
  .workarea {
    flex-direction: column;
    overflow-y: auto;
  }
  .sidebar {
    width: 100%;
    min-width: 0;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    overflow: visible;
  }
  .stage {
    overflow: visible;
  }
  .stage-grid {
    grid-template-columns: 1fr;
    gap: 16px;
  }
  .media-preview {
    min-height: 240px;
  }
  details.console-container {
    --console-h: 150px;
  }
  .topbar {
    flex-wrap: wrap;
    row-gap: 8px;
  }
  .topbar-status {
    margin-left: 0;
  }
}
