/* Video & GIF Tool — only the pieces media-tools.css has no equivalent for:
   the stage, the crop overlay, the trim timeline, and the log disclosure.
   Everything is prefixed .vg- so it cannot leak into another tool. */

.vg-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin: 13px 0 0;
}

.vg-chip {
  padding: 5px 10px;
  border: 1px solid var(--media-line);
  border-radius: 999px;
  color: var(--media-muted);
  background: rgba(255, 253, 248, .8);
  font-family: "DM Mono", ui-monospace, monospace;
  font-size: .6rem;
  letter-spacing: .015em;
}

.vg-chip.is-good {
  border-color: color-mix(in srgb, var(--media-accent) 32%, var(--media-line));
  color: var(--media-accent-dark);
  background: color-mix(in srgb, var(--media-soft) 55%, white);
}

.vg-chip.is-warning { border-color: #d9c08a; color: #7a5c14; background: #faf1dc; }
.vg-chip-quiet { color: #918c82; }

.vg-drop-note {
  max-width: 34rem;
  margin: 18px auto 0 !important;
  color: #948f85 !important;
  font-size: .68rem !important;
}

/* ---------- stage ---------- */

.vg-stage {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 260px;
  padding: 16px;
  border-radius: 17px;
  background: #ded8cd;
  background-image: linear-gradient(160deg, rgba(255, 255, 255, .35), transparent 60%);
}

.vg-frame {
  position: relative;
  width: 100%;
  /* Both custom properties are set from JS. Pinning the box to the video's own aspect ratio means
     the element rect *is* the picture rect, so crop coordinates map to source pixels with a plain
     multiply instead of letterbox arithmetic. */
  max-width: calc(52vh * var(--vg-ar-num, 1.7778));
  aspect-ratio: var(--vg-aspect, 16 / 9);
  overflow: hidden;
  border-radius: 12px;
  background: #16150f;
  box-shadow: 0 14px 36px rgba(38, 32, 22, .2);
}

/* Set from JS only while the crop rectangle is on, so a swipe over the preview scrolls the page
   the rest of the time. */
.vg-frame.is-cropping { touch-action: none; }

.vg-frame video {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: fill; /* The box already matches the source ratio, so there is nothing to letterbox. */
  background: #16150f;
}

/* ---------- crop overlay ---------- */

.vg-crop {
  position: absolute;
  border: 1.5px solid #fff;
  box-shadow: 0 0 0 100vmax rgba(16, 14, 10, .5);
  cursor: move;
}

.vg-crop::before,
.vg-crop::after {
  position: absolute;
  border: 1px solid rgba(255, 255, 255, .32);
  content: "";
  pointer-events: none;
}

.vg-crop::before { inset: 0 33.33%; border-width: 0 1px; }
.vg-crop::after { inset: 33.33% 0; border-width: 1px 0; }

/* Sits inside the rectangle: .vg-frame clips overflow so an outside label would be cut off
   whenever the crop is dragged against the top edge. */
.vg-crop-size {
  position: absolute;
  top: 6px;
  left: 50%;
  padding: 3px 8px;
  border-radius: 7px;
  color: #fff;
  background: var(--media-accent);
  font-family: "DM Mono", ui-monospace, monospace;
  font-size: .58rem;
  white-space: nowrap;
  transform: translateX(-50%);
  pointer-events: none;
}

.vg-handle {
  position: absolute;
  width: 15px;
  height: 15px;
  padding: 0;
  border: 1.5px solid var(--media-accent);
  border-radius: 4px;
  background: #fff;
  cursor: pointer;
}

.vg-handle[data-grip="nw"] { top: -8px; left: -8px; cursor: nwse-resize; }
.vg-handle[data-grip="ne"] { top: -8px; right: -8px; cursor: nesw-resize; }
.vg-handle[data-grip="se"] { right: -8px; bottom: -8px; cursor: nwse-resize; }
.vg-handle[data-grip="sw"] { bottom: -8px; left: -8px; cursor: nesw-resize; }
.vg-handle[data-grip="n"] { top: -8px; left: 50%; margin-left: -7px; cursor: ns-resize; }
.vg-handle[data-grip="s"] { bottom: -8px; left: 50%; margin-left: -7px; cursor: ns-resize; }
.vg-handle[data-grip="w"] { top: 50%; left: -8px; margin-top: -7px; cursor: ew-resize; }
.vg-handle[data-grip="e"] { top: 50%; right: -8px; margin-top: -7px; cursor: ew-resize; }

/* ---------- transport ---------- */

.vg-transport {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 14px;
}

.vg-play {
  display: grid;
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  place-items: center;
  border: 1px solid var(--media-line);
  border-radius: 13px;
  color: var(--media-ink);
  background: #fffdf8;
  cursor: pointer;
}

.vg-play:hover:not(:disabled) { border-color: var(--media-accent); color: var(--media-accent); }
.vg-play:disabled { opacity: .4; cursor: not-allowed; }
.vg-play svg { width: 20px; height: 20px; }

.vg-clock {
  flex: 1;
  min-width: 0;
  color: var(--media-muted);
  font-family: "DM Mono", ui-monospace, monospace;
  font-size: .72rem;
  font-variant-numeric: tabular-nums;
}

.vg-transport-actions { display: flex; flex: 0 0 auto; gap: 7px; }

/* ---------- timeline ---------- */

.vg-timeline-wrap { margin-top: 12px; }

.vg-timeline {
  position: relative;
  height: 64px;
  overflow: visible;
  border: 1px solid var(--media-line);
  border-radius: 12px;
  background: #e7e2d9;
  cursor: pointer;
  touch-action: none;
}

.vg-frames {
  position: absolute;
  inset: 0;
  display: flex;
  overflow: hidden;
  border-radius: inherit;
}

.vg-frame-cell {
  flex: 1;
  min-width: 0;
  background-color: #d8d2c6;
  background-position: center;
  background-size: cover;
}

.vg-shade {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  border-radius: inherit;
  background: rgba(244, 240, 232, .74);
  pointer-events: none;
}

.vg-selection {
  position: absolute;
  top: 0;
  bottom: 0;
  border-top: 2px solid var(--media-accent);
  border-bottom: 2px solid var(--media-accent);
  pointer-events: none;
}

.vg-playhead {
  position: absolute;
  top: -3px;
  bottom: -3px;
  width: 2px;
  background: #191918;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, .7);
  transform: translateX(-1px);
  pointer-events: none;
}

.vg-trim {
  position: absolute;
  top: -4px;
  bottom: -4px;
  width: 14px;
  padding: 0;
  border: 1px solid color-mix(in srgb, var(--media-accent) 60%, #000);
  border-radius: 6px;
  background: var(--media-accent);
  box-shadow: 0 3px 10px rgba(40, 20, 30, .28);
  cursor: ew-resize;
  transform: translateX(-50%);
  touch-action: none;
}

.vg-trim::after {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 2px;
  height: 16px;
  border-right: 1px solid rgba(255, 255, 255, .85);
  border-left: 1px solid rgba(255, 255, 255, .85);
  content: "";
  transform: translate(-50%, -50%);
}

.vg-trim-fields {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr)) auto;
  gap: 10px;
  align-items: end;
  margin-top: 12px;
}

.vg-trim-fields .field { min-width: 0; }
.vg-trim-fields .field label { display: block; margin-bottom: 7px; color: #625f58; font-size: .66rem; font-weight: 700; }
.vg-mono { font-family: "DM Mono", ui-monospace, monospace; font-variant-numeric: tabular-nums; }
#trimLengthField { color: var(--media-accent-dark); background: #f2ede4; }

/* ---------- sidebar extras ---------- */

.vg-sub {
  margin-top: 16px;
  padding-top: 15px;
  border-top: 1px dashed var(--media-line);
}

.vg-inline-label {
  display: block;
  margin: 12px 0 7px;
  color: #625f58;
  font-size: .66rem;
  font-weight: 700;
}

.vg-seg-2 { grid-template-columns: repeat(2, 1fr); }
.vg-seg-4 { grid-template-columns: repeat(4, 1fr); }
.vg-seg-5 { grid-template-columns: repeat(5, 1fr); }
.vg-seg-5 button { padding: 0 3px; font-size: .62rem; }

.segmented button:disabled { opacity: .38; cursor: not-allowed; }
.segmented button.is-locked { opacity: .5; pointer-events: none; }

.vg-size-grid { margin-top: 12px; }
.control-help.is-warning { color: #8a4a1c; font-weight: 600; }

/* ---------- log disclosure ---------- */

.vg-log {
  margin-top: 12px;
  border: 1px solid var(--media-line);
  border-radius: 12px;
  background: rgba(248, 245, 238, .7);
}

.vg-log > summary {
  padding: 10px 12px;
  color: #625f58;
  cursor: pointer;
  font-size: .68rem;
  font-weight: 700;
  list-style: none;
}

.vg-log > summary::-webkit-details-marker { display: none; }
.vg-log > summary::before { content: "▸ "; color: var(--media-accent); }
.vg-log[open] > summary::before { content: "▾ "; }

.vg-log-cmd {
  margin: 0;
  padding: 0 12px 10px;
  overflow-wrap: anywhere;
  color: var(--media-accent-dark);
  font-family: "DM Mono", ui-monospace, monospace;
  font-size: .6rem;
  line-height: 1.55;
  white-space: pre-wrap;
}

.vg-log-out {
  max-height: 190px;
  margin: 0;
  padding: 10px 12px;
  overflow: auto;
  border-top: 1px solid var(--media-line);
  color: #58554e;
  font-family: "DM Mono", ui-monospace, monospace;
  font-size: .58rem;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.vg-log-out:empty::before { color: #948f85; content: "FFmpeg output will appear here once a render starts."; }

/* ---------- result ---------- */

.vg-result {
  display: grid;
  overflow: hidden;
  border: 1px solid var(--media-line);
  border-radius: 12px;
  background: #16150f;
  place-items: center;
}

.vg-result:empty { display: none; }
.vg-result img,
.vg-result video { display: block; width: 100%; max-height: 220px; object-fit: contain; }
.vg-result audio { width: 100%; padding: 12px; background: #f8f5ee; }

.vg-result-name {
  overflow: hidden;
  margin: 11px 0 0;
  font-size: .74rem;
  font-weight: 750;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.vg-result-size {
  margin: 3px 0 6px;
  color: var(--media-accent-dark);
  font-family: "DM Mono", ui-monospace, monospace;
  font-size: 1.05rem;
  font-weight: 500;
  letter-spacing: -.02em;
}

.vg-result-size.is-warning { color: #b0431f; }
#downloadButton { text-decoration: none; }

/* ---------- confirmation modal ---------- */

.vg-modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100000;
  display: grid;
  padding: 20px;
  background: rgba(28, 24, 18, .44);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  place-items: center;
}

.vg-modal {
  width: min(400px, 100%);
  padding: 22px 24px 18px;
  border: 1px solid var(--border, #ded8cd);
  border-radius: 16px;
  background: #fffdf8;
  box-shadow: 0 26px 70px rgba(35, 30, 22, .3);
}

.vg-modal h2 { margin: 0 0 7px; font-size: 1rem; font-weight: 800; letter-spacing: -.02em; }
.vg-modal p { margin: 0 0 18px; color: var(--text-secondary, #626159); font-size: .82rem; line-height: 1.55; }
.vg-modal-actions { display: flex; justify-content: flex-end; gap: 8px; }

.vg-modal-btn {
  padding: 9px 16px;
  border: 1px solid var(--border, #ded8cd);
  border-radius: 10px;
  color: var(--text, #191918);
  background: #fff;
  cursor: pointer;
  font: inherit;
  font-size: .8rem;
  font-weight: 700;
}

.vg-modal-btn:hover { border-color: var(--border-hover, #aaa297); background: #faf7f0; }
.vg-modal-btn.is-primary { border-color: var(--media-ink); color: #fff; background: var(--media-ink); }
.vg-modal-btn.is-primary:hover { border-color: var(--media-accent); background: var(--media-accent); }

/* ---------- responsive ---------- */

@media (max-width: 840px) {
  .vg-frame { max-width: calc(44vh * var(--vg-ar-num, 1.7778)); }
}

@media (max-width: 540px) {
  .vg-stage { padding: 8px; }
  .vg-trim-fields { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .vg-trim-fields > .btn { grid-column: 1 / -1; }
  .vg-transport { flex-wrap: wrap; }
  .vg-clock { order: 3; flex-basis: 100%; }
  .vg-seg-5 button { font-size: .56rem; }
}

@media (prefers-reduced-motion: reduce) {
  .vg-timeline, .vg-frame, .vg-play { transition: none !important; }
}
