@import url("../../../assets/css/icons.css");

/* ClackMosh — same palette and menu chrome as the other standalone ClackOS
   apps, so it looks native in a window and on its own page. */

:root {
  color-scheme: only light;
  --ink: #09140d;
  --ink-soft: #14231a;
  --control-text: var(--ink-soft);
  --paper: #f8f2dd;
  --paper-deep: #f3ecd1;
  --paper-line: #d8cfa9;
  --sage: #66755a;
  --leaf: #4fae7d;
  --leaf-deep: #276b47;
  --menu-text: #f5efdb;
  --shadow: var(--ink);
  --danger: #a04a3a;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { min-height: 100%; margin: 0; }
body {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 12.5px;
  color: var(--ink-soft);
  background: var(--paper);
}
button, input, select { font: inherit; }
button, label, input[type="range"], input[type="checkbox"] { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible {
  outline: 2px solid var(--leaf);
  outline-offset: 2px;
}

.app { display: flex; min-height: 100vh; flex-direction: column; }
.app-main {
  display: flex; flex: 1; flex-direction: column; min-height: 0;
  padding: 14px 16px 10px; gap: 12px;
}

/* ClackOS in-app menu chrome */
.rm-bar {
  display: flex; gap: 2px; padding: 0 8px; min-height: 33px;
  background: var(--paper-deep); border-bottom: 1px solid var(--paper-line);
  position: sticky; top: 0; z-index: 40;
}
.rm { position: relative; }
.rm > button {
  all: unset; cursor: pointer; padding: 8px 12px; font: inherit; font-size: 12px; color: var(--control-text);
}
.rm > button:hover, .rm.open > button { background: var(--ink); color: var(--menu-text); }
.rm > button:focus-visible { outline: 2px solid var(--leaf); outline-offset: -2px; }
.rm-dd {
  position: absolute; top: 100%; left: 0; min-width: 280px; z-index: 50;
  background: var(--paper); border: 2px solid var(--ink); border-radius: 0 0 8px 8px;
  display: none; padding: 6px 2px;
  box-shadow: 6px 6px 0 color-mix(in srgb, var(--shadow) 20%, transparent);
}
.rm.open > .rm-dd { display: block; }
.rm-dd button {
  all: unset; box-sizing: border-box; display: flex; justify-content: space-between; gap: 18px;
  width: 100%; cursor: pointer; padding: 7px 14px; font: inherit; font-size: 12px;
  color: var(--control-text); white-space: nowrap;
}
.rm-dd button:hover:not(:disabled) { background: var(--ink); color: var(--menu-text); }
.rm-dd button:disabled { opacity: 0.4; cursor: default; }
.rm-dd .pixel-icon { width: 16px; height: 16px; }
.rm-dd .sep { height: 1px; background: var(--paper-line); margin: 6px 0; }
.menu-item-label { display: flex; align-items: center; gap: 9px; }

/* Fly-outs. The Mosh menu holds two dozen operations grouped by what they
   attack, which is a submenu each rather than one unreadable column. They sit
   beside the parent on a desktop and drop underneath it on a phone, where
   there is no room to the side. */
.rm-sub { position: relative; }
.rm-sub-arrow { margin-left: auto; font-size: 10px; }
.rm-sub-dd { top: -6px; left: 100%; min-width: 280px; border-radius: 0 8px 8px 8px; }
.rm-sub.open > .rm-sub-dd { display: block; }
.rm-sub.open > .rm-sub-open { background: var(--ink); color: var(--menu-text); }
/* On a phone a fly-out has nowhere to fly to, so it drops inline under its
   parent instead — and the labels, which are sentences rather than words, are
   allowed to wrap rather than forcing the menu off the side of the screen. */
@media (max-width: 620px) {
  /* Mosh and Help fell off the end of the bar on a phone, the way Video Lab's
     did before it wrapped its own — this file keeps its own copy of the menu
     chrome, so it needs its own copy of the fix. */
  .rm-bar { flex-wrap: wrap; padding-inline: 4px; }
  .rm-dd { min-width: 0; max-width: calc(100vw - 20px); }
  .rm-dd button { white-space: normal; }
  .menu-item-label { align-items: flex-start; }
  .rm-sub-dd { position: static; min-width: 0; max-width: none; border: 0; border-radius: 0;
               box-shadow: none; padding: 0 0 0 14px; background: transparent; }
}
kbd {
  font: inherit; font-size: 11px; color: var(--sage);
  border: 1px solid var(--paper-line); border-radius: 3px; padding: 0 4px;
}
.rm-dd button:hover kbd { color: var(--menu-text); border-color: color-mix(in srgb, var(--menu-text) 40%, transparent); }

/* Buttons */
button.primary, .toolbar button, .control-row button, dialog menu button {
  all: unset; box-sizing: border-box; display: inline-flex; align-items: center; gap: 7px;
  padding: 7px 12px; font: inherit; font-size: 12px; cursor: pointer;
  color: var(--control-text); background: var(--paper-deep);
  border: 2px solid var(--ink); border-radius: 6px;
  box-shadow: 3px 3px 0 color-mix(in srgb, var(--shadow) 18%, transparent);
}
button.primary { background: var(--leaf); color: var(--ink); font-weight: 600; }
.toolbar button:hover:not(:disabled), .control-row button:hover:not(:disabled),
dialog menu button:hover { background: var(--ink); color: var(--menu-text); }
button.primary:hover:not(:disabled) { background: var(--leaf-deep); color: var(--menu-text); }
.toolbar button:disabled, .control-row button:disabled { opacity: 0.4; cursor: default; box-shadow: none; }
button .pixel-icon { width: 15px; height: 15px; }
/* an apply button with something waiting to be committed */
#apply-button.dirty { animation: nudge 1.4s ease-in-out infinite; }
@keyframes nudge {
  0%, 100% { box-shadow: 3px 3px 0 color-mix(in srgb, var(--shadow) 18%, transparent); }
  50% { box-shadow: 3px 3px 0 var(--leaf-deep); }
}

/* Toolbar */
.toolbar {
  display: flex; flex-direction: column; gap: 9px;
  padding: 9px 11px; background: var(--paper-deep);
  border: 2px solid var(--ink); border-radius: 8px;
}
.toolbar-row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.toolbar-sep { width: 1px; align-self: stretch; min-height: 22px; background: var(--paper-line); }

/* Encoding disclosure — long enough to be worth folding away, and the
   settings only take effect on an import, so it is not somewhere you live. */
.encoding { border-top: 1px solid var(--paper-line); padding-top: 8px; }
.encoding > summary {
  display: flex; align-items: center; gap: 7px; cursor: pointer;
  font-size: 11.5px; color: var(--sage); list-style: none;
}
.encoding > summary::-webkit-details-marker { display: none; }
.encoding > summary::after { content: '▸'; }
.encoding[open] > summary::after { content: '▾'; }
.encoding > summary:hover { color: var(--ink); }
.encoding > summary .pixel-icon { width: 15px; height: 15px; }
.encoding-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 12px 18px; padding: 11px 2px 2px;
}
/* Wider label column than the editor's sliders: these names are words, not
   the editor's single verbs. */
.encoding .slider { grid-template-columns: 96px 1fr; }
.encoding-toggles { display: flex; flex-direction: column; gap: 9px; }
.encoding-toggles .check { align-items: flex-start; flex-wrap: wrap; }
.field-note {
  flex-basis: 100%; font-size: 10.5px; line-height: 1.45;
  color: var(--sage); grid-column: 1 / -1;
}
.encoding .hint { grid-column: 1 / -1; }
.field { display: inline-flex; align-items: center; gap: 6px; font-size: 11.5px; color: var(--sage); }
.field input {
  all: unset; box-sizing: border-box; width: 58px; padding: 5px 7px;
  border: 2px solid var(--ink); border-radius: 5px; background: var(--paper);
  color: var(--ink-soft); text-align: right;
}

/* Stage: the anchor editor beside the preview */
.stage { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; }
.panel {
  display: flex; flex-direction: column; gap: 10px; min-width: 0;
  padding: 11px 12px 13px; background: var(--paper-deep);
  border: 2px solid var(--ink); border-radius: 8px;
}
.panel-title {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  margin: 0; font-size: 12px; font-weight: 600; color: var(--ink);
}
.panel-title .pixel-icon { width: 16px; height: 16px; }
.panel-note { font-weight: 400; color: var(--sage); }

.canvas-wrap, .video-wrap {
  position: relative; display: flex; align-items: center; justify-content: center;
  min-height: 190px; padding: 8px;
  background: var(--ink); border-radius: 6px;
}
/* The frames are small by design — 480px is a generous mosh — so both views
   are scaled up to the panel rather than sat in the middle of it, and kept
   crisp rather than smoothed, because the blocking is the whole aesthetic. */
#editor-canvas, #preview-video {
  display: block; width: 100%; height: auto; max-height: 46vh;
  object-fit: contain; image-rendering: pixelated; background: #000;
}
#editor-canvas[hidden], #preview-video:not([src]) { display: none; }
.empty-note {
  margin: 0; padding: 22px 16px; text-align: center; font-size: 11.5px;
  color: color-mix(in srgb, var(--menu-text) 62%, transparent);
}

.controls { display: flex; flex-direction: column; gap: 7px; }

/* The adjustment sliders are folded away by default. Eight ranges stacked
   under the picture are eight things to catch with a thumb while scrolling
   the page on a phone, and every one of them is a change to the frame. */
.adjustments {
  border: 1px solid var(--paper-line); border-radius: 6px;
  background: color-mix(in srgb, var(--paper) 55%, transparent);
}
.adjustments > summary {
  display: flex; align-items: center; gap: 7px; cursor: pointer;
  padding: 7px 9px; font-size: 11.5px; color: var(--sage); list-style: none;
}
.adjustments > summary::-webkit-details-marker { display: none; }
.adjustments > summary::after { content: '▸'; }
.adjustments[open] > summary::after { content: '▾'; }
.adjustments > summary:hover { color: var(--ink); }
.adjustments > summary .pixel-icon { width: 15px; height: 15px; }
.adjust-body { display: flex; flex-direction: column; gap: 7px; padding: 2px 9px 10px; }

/* Says so when there are uncommitted changes hidden inside a closed fold. */
.touched-flag {
  margin-left: auto; padding: 1px 6px; border-radius: 3px;
  font-size: 10px; background: var(--leaf); color: var(--ink); visibility: hidden;
}
.adjustments.touched .touched-flag { visibility: visible; }
.control-row { display: flex; flex-wrap: wrap; gap: 7px; align-items: center; }
.control-row.actions { margin-top: 3px; }
.slider {
  display: grid; grid-template-columns: 62px 1fr; align-items: center;
  gap: 4px 9px; font-size: 11.5px; color: var(--sage);
}
.slider output { grid-column: 2; justify-self: end; font-size: 11px; color: var(--ink-soft); }
.slider input[type="range"] { grid-column: 1 / -1; width: 100%; accent-color: var(--leaf-deep); margin: 0; }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 11.5px; color: var(--sage); }
.check input { accent-color: var(--leaf-deep); }
.hint { margin: 0; font-size: 11px; color: var(--sage); }

/* Filmstrip — the frame map, and the app's main way of navigating */
.filmstrip-panel {
  display: flex; flex-direction: column; gap: 8px;
  padding: 11px 12px 12px; background: var(--paper-deep);
  border: 2px solid var(--ink); border-radius: 8px;
}
.legend { display: flex; align-items: center; gap: 10px; margin-left: auto; font-weight: 400; font-size: 11px; color: var(--sage); }
.key { display: inline-block; width: 11px; height: 11px; vertical-align: -1px; margin-right: 2px; border: 1px solid var(--ink); }
.key.i { background: var(--leaf); }
.key.p { background: var(--sage); }
.key.gone { background: var(--danger); }
.key.edited { background: var(--paper); border-color: var(--leaf-deep); box-shadow: inset 0 0 0 2px var(--leaf-deep); }

.filmstrip {
  display: flex; align-items: flex-end; gap: 2px;
  min-height: 78px; padding: 8px; overflow-x: auto; overflow-y: hidden;
  background: var(--ink); border-radius: 6px; scrollbar-width: thin;
}
.filmstrip:focus-visible { outline: 2px solid var(--leaf); outline-offset: 2px; }
.frame { flex: none; border: 0; padding: 0; background: none; cursor: pointer; }

/* A P-frame has no picture of its own to show — it is motion — so it is drawn
   as a tick, tall enough to read as part of the run it belongs to. */
.frame.p {
  width: 4px; height: 34px; background: var(--sage); border-radius: 1px; opacity: 0.75;
}
.frame.p:hover { background: var(--leaf); opacity: 1; }
.frame.p.deleted { background: var(--danger); height: 12px; }

.frame.i {
  position: relative; width: 62px; height: 58px; overflow: hidden;
  border: 2px solid var(--leaf); border-radius: 3px; background: #000;
}
.frame.i img { width: 100%; height: 100%; object-fit: cover; display: block; }
.frame.i .badge {
  position: absolute; left: 0; top: 0; padding: 0 3px;
  font-size: 9px; font-weight: 600; line-height: 13px;
  background: var(--leaf); color: var(--ink);
}
.frame.i.edited { border-color: var(--paper); }
.frame.i.edited .badge { background: var(--paper); }
.frame.i.deleted { border-color: var(--danger); opacity: 0.45; }
.frame.i.deleted .badge { background: var(--danger); color: var(--menu-text); }
.frame.i.deleted::after {
  content: ''; position: absolute; inset: 0;
  background: repeating-linear-gradient(45deg, transparent 0 5px, color-mix(in srgb, var(--danger) 55%, transparent) 5px 10px);
}
.frame.selected { outline: 3px solid var(--paper); outline-offset: 1px; }

/* Where one clip meets the next. Worth marking, because these are the anchors
   whose deletion moshes the two videos into each other. */
.frame.join { margin-left: 9px; box-shadow: -5px 0 0 var(--leaf-deep); }
.frame.join.deleted { box-shadow: -5px 0 0 var(--danger); }
.key.join { background: var(--leaf-deep); }

/* Status bar */
.statusbar {
  display: flex; align-items: center; gap: 12px; padding: 7px 16px;
  background: var(--ink); color: var(--menu-text); font-size: 11.5px;
}
.status-state {
  padding: 2px 7px; border-radius: 3px; font-weight: 600; font-size: 10.5px;
  background: var(--sage); color: var(--menu-text);
}
.status-state[data-state="READY"] { background: var(--leaf); color: var(--ink); }
.status-state[data-state="WORKING"], .status-state[data-state="LOADING"] { background: var(--warning); color: var(--ink); }
.status-state[data-state="ERROR"] { background: var(--danger); }
.status-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.progress { width: 140px; height: 8px; background: color-mix(in srgb, var(--menu-text) 22%, transparent); border-radius: 4px; overflow: hidden; }
.progress-fill { display: block; height: 100%; width: 0; background: var(--leaf); transition: width 0.15s linear; }

/* Dialogs */
dialog {
  border: 2px solid var(--ink); border-radius: 8px; background: var(--paper);
  color: var(--ink-soft); max-width: min(560px, 92vw); padding: 16px 18px;
  box-shadow: 8px 8px 0 color-mix(in srgb, var(--shadow) 26%, transparent);
}
dialog::backdrop { background: color-mix(in srgb, var(--ink) 46%, transparent); }
dialog h3 { margin: 0 0 10px; font-size: 13px; }
dialog p { margin: 0 0 9px; line-height: 1.55; }
dialog menu { display: flex; justify-content: flex-end; gap: 8px; margin: 14px 0 0; padding: 0; }
.picker-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 8px; max-height: 52vh; overflow-y: auto; padding: 2px;
}
.picker-grid button {
  all: unset; cursor: pointer; border: 2px solid var(--ink); border-radius: 4px;
  overflow: hidden; background: #000;
}
.picker-grid button:hover, .picker-grid button:focus-visible { border-color: var(--leaf); }
.picker-grid img { display: block; width: 100%; aspect-ratio: 4 / 3; object-fit: cover; }
.picker-grid .caption { display: block; padding: 2px 5px; font-size: 10.5px; background: var(--paper-deep); }

/* On a phone the panels stop being two columns and become one long scroll, so
   their order becomes the order of the job rather than an artefact of the
   desktop layout: bring a clip in, pick the anchor to work on, edit it, then
   look at the result. Putting the editor second — as the desktop grid implies
   — would bury the filmstrip under a screenful of sliders, when choosing a
   frame is the thing you do before any of them mean anything.

   `display: contents` drops the two-column wrapper out of the box tree so its
   children become flex items of .app-main and can be ordered alongside the
   toolbar and the filmstrip. */
@media (max-width: 860px) {
  .stage { display: contents; }
  .toolbar { order: 1; }
  .filmstrip-panel { order: 2; }
  .editor { order: 3; }
  .preview { order: 4; }

  #editor-canvas, #preview-video { max-height: 38vh; }
  .legend { margin-left: 0; width: 100%; }
  .encoding-grid { grid-template-columns: minmax(0, 1fr); }
  .filmstrip { min-height: 66px; }
  .frame.i { width: 54px; height: 50px; }
  /* the scroll target when an anchor is picked, so it does not land under
     the sticky menu bar */
  .panel, .filmstrip-panel { scroll-margin-top: 40px; }
}
