:root {
  color-scheme: dark;
  --bg: #000;
  --panel: #070707;
  --line: #222;
  --line2: #333;
  --text: #f2f2f2;
  --muted: #8b8b8b;
  --accent: #d6ff3f;
  --accentText: #111;
  --radius: 12px;
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; background: #000; }
body {
  overflow: hidden;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
button, input, select { font: inherit; }
button { touch-action: manipulation; }

.app {
  width: 100%;
  height: 100dvh;
  display: grid;
  grid-template-rows: 44px minmax(0, 1fr) auto;
  gap: 8px;
  padding: max(6px, env(safe-area-inset-top)) 8px max(8px, env(safe-area-inset-bottom));
  background: #000;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-width: 0;
  padding: 0 2px;
}
.topbar > div { min-width: 0; display: flex; align-items: baseline; gap: 10px; }
.topbar strong { letter-spacing: .06em; font-size: 14px; white-space: nowrap; }
.topbar span { color: var(--muted); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pick {
  border: 1px solid var(--line2);
  border-radius: 8px;
  height: 34px;
  min-width: 62px;
  display: grid;
  place-items: center;
  cursor: pointer;
  background: #0b0b0b;
  flex: none;
}
.pick input { display: none; }
.pick span { color: var(--text); font-weight: 700; letter-spacing: .03em; }

.stage {
  position: relative;
  min-height: 0;
  overflow: hidden;
  border: 1px solid #181818;
  border-radius: var(--radius);
  background: #030303;
}
.stage.drag { border-color: var(--accent); }
.stage video { width: 100%; height: 100%; object-fit: contain; display: block; background: #000; }
.empty {
  position: absolute; inset: 0;
  display: grid; place-content: center; text-align: center; gap: 4px;
  color: #aaa; font-size: 13px;
  background: radial-gradient(circle at 50% 40%, #0c0c0c 0, #030303 55%, #000 100%);
  cursor: pointer;
  user-select: none;
}
.empty[hidden] { display: none !important; }
.empty .mark { color: var(--accent); font: 400 42px/1 system-ui, sans-serif; margin-bottom: 4px; }
.empty small { color: #5f5f5f; font-size: 10px; padding: 0 12px; }
.stageHud {
  pointer-events: none;
  position: absolute; left: 8px; right: 8px; bottom: 8px;
  display: flex; justify-content: space-between; gap: 8px;
}
.stageHud span {
  max-width: 56%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  padding: 5px 7px;
  border: 1px solid rgba(255,255,255,.14);
  border-radius: 7px;
  background: rgba(0,0,0,.72);
  backdrop-filter: blur(8px);
  font-size: 10px;
}

.panel {
  background: var(--panel);
  border: 1px solid #171717;
  border-radius: var(--radius);
  padding: 9px;
  display: grid;
  gap: 8px;
}
.sliders { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 12px; }
.control { min-width: 0; display: grid; gap: 5px; }
.control > div, .selectRow { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.control span, .selectRow span { color: #a7a7a7; font-size: 10px; }
.control output { color: #e9e9e9; font-size: 10px; white-space: nowrap; }
input[type="range"] {
  width: 100%; height: 20px; margin: 0;
  appearance: none; -webkit-appearance: none;
  background: transparent; cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track { height: 3px; background: #2b2b2b; border-radius: 9px; }
input[type="range"]::-webkit-slider-thumb {
  appearance: none; -webkit-appearance: none;
  width: 15px; height: 15px; margin-top: -6px;
  border: 2px solid #000; border-radius: 5px; background: var(--accent);
  box-shadow: 0 0 0 1px #4d5b1a;
}
input[type="range"]::-moz-range-track { height: 3px; background: #2b2b2b; border-radius: 9px; }
input[type="range"]::-moz-range-thumb { width: 13px; height: 13px; border: 2px solid #000; border-radius: 5px; background: var(--accent); }

.statusBox { display: grid; gap: 5px; }
.statusLine { display: flex; justify-content: space-between; gap: 10px; font-size: 10px; color: #9e9e9e; min-height: 12px; }
.statusLine span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.progress { height: 2px; overflow: hidden; background: #1b1b1b; border-radius: 4px; }
.progress i { display: block; width: 0%; height: 100%; background: var(--accent); transition: width .12s linear; }

.actions { display: grid; grid-template-columns: 1fr 88px 70px; gap: 7px; }
button {
  height: 38px;
  border: 1px solid #2b2b2b;
  border-radius: 8px;
  color: #ddd;
  background: #111;
  font-weight: 800;
  font-size: 11px;
  letter-spacing: .035em;
  cursor: pointer;
}
button:active:not(:disabled) { transform: translateY(1px); }
button:disabled { opacity: .32; cursor: default; }
button.primary { color: var(--accentText); border-color: var(--accent); background: var(--accent); }

#gifDialog {
  width: min(440px, calc(100vw - 16px));
  padding: 0;
  border: 1px solid #2b2b2b;
  border-radius: 14px;
  background: #080808;
  color: var(--text);
}
#gifDialog::backdrop { background: rgba(0,0,0,.78); backdrop-filter: blur(4px); }
.sheet { padding: 12px; display: grid; gap: 12px; }
.sheetHead { display: flex; align-items: center; justify-content: space-between; }
.sheetHead strong { font-size: 12px; letter-spacing: .04em; }
.iconBtn { width: 32px; min-width: 32px; height: 32px; padding: 0; font: 20px/1 system-ui, sans-serif; }
.selectRow { min-height: 36px; }
select {
  height: 32px; min-width: 160px;
  color: #eee; background: #111; border: 1px solid #303030; border-radius: 7px;
  padding: 0 8px; font-size: 10px;
}
.wide { width: 100%; }

@media (max-width: 759px) {
  .app:has(.empty:not([hidden])) {
    grid-template-rows: 44px 150px auto;
    align-content: start;
  }
  .app:has(.empty:not([hidden])) .stageHud { display: none; }
}

@media (min-width: 760px) {
  .app {
    grid-template-columns: minmax(0, 1.45fr) minmax(320px, .55fr);
    grid-template-rows: 44px minmax(0, 1fr);
    max-width: 1500px;
    margin: auto;
    padding: 10px;
    gap: 10px;
  }
  .topbar { grid-column: 1 / -1; }
  .stage { grid-column: 1; grid-row: 2; }
  .panel { grid-column: 2; grid-row: 2; align-content: center; padding: 14px; gap: 12px; }
  .sliders { grid-template-columns: 1fr; gap: 12px; }
  .control { gap: 8px; }
  .control span, .control output, .selectRow span { font-size: 11px; }
  input[type="range"] { height: 24px; }
  .actions { grid-template-columns: 1fr 92px 76px; }
  button { height: 42px; }
}

@media (max-height: 620px) and (max-width: 759px) {
  .app { grid-template-rows: 38px minmax(0, 1fr) auto; gap: 5px; padding-top: 3px; }
  .app:has(.empty:not([hidden])) { grid-template-rows: 38px 110px auto; }
  .topbar { height: 38px; }
  .panel { padding: 7px; gap: 5px; }
  .sliders { gap: 4px 10px; }
  .control { gap: 2px; }
  input[type="range"] { height: 15px; }
  .actions button { height: 33px; }
  .statusBox { gap: 3px; }
}
